Skip to content
Snippets Groups Projects
Commit e9f2ebf5 authored by Egor Sobolev's avatar Egor Sobolev
Browse files

Add parameter to keep temporary files

parent ffe7d8fe
No related branches found
No related tags found
No related merge requests found
import argparse import argparse
import pathlib
import importlib_resources import importlib_resources
import nbformat import nbformat
import papermill as pm import papermill as pm
import pathlib
import yaml import yaml
from traitlets.config import Config
from nbconvert import PDFExporter
from extra_data import open_run from extra_data import open_run
from geomtools.motor import (AGIPD1M_DATA_SELECTOR, AGIPD1M_MOTORS,
get_physical_names, read_motor_positions)
from nbconvert import PDFExporter
from traitlets.config import Config
from .xwizio import parse_xwiz_summary
from .crystfelio import extract_geometry from .crystfelio import extract_geometry
from geomtools.motor import ( from .xwizio import parse_xwiz_summary
read_motor_positions, AGIPD1M_MOTORS, AGIPD1M_DATA_SELECTOR,
get_physical_names,
)
REPO = pathlib.Path("/gpfs/exfel/data/scratch/spb_geom") REPO = pathlib.Path("/gpfs/exfel/data/scratch/spb_geom")
DET = { DET = {
...@@ -25,7 +22,7 @@ DET = { ...@@ -25,7 +22,7 @@ DET = {
} }
def make_report(notebook_filename, parameters): def make_report(notebook_filename, parameters, clean=True):
report_ref = importlib_resources.files("geomtools.sfx") / "report.ipynb" report_ref = importlib_resources.files("geomtools.sfx") / "report.ipynb"
with importlib_resources.as_file(report_ref) as report_path: with importlib_resources.as_file(report_ref) as report_path:
pm.execute_notebook( pm.execute_notebook(
...@@ -43,7 +40,8 @@ def make_report(notebook_filename, parameters): ...@@ -43,7 +40,8 @@ def make_report(notebook_filename, parameters):
(body, resources) = pdf_exporter.from_notebook_node(notebook) (body, resources) = pdf_exporter.from_notebook_node(notebook)
notebook_filename.with_suffix(".pdf").write_bytes(body) notebook_filename.with_suffix(".pdf").write_bytes(body)
notebook_filename.unlink() if clean:
notebook_filename.unlink()
def push_geometry(): def push_geometry():
...@@ -57,6 +55,7 @@ def push_geometry(): ...@@ -57,6 +55,7 @@ def push_geometry():
help="Crystfel stream file") help="Crystfel stream file")
parser.add_argument('-c', '--connected', default="modules") parser.add_argument('-c', '--connected', default="modules")
parser.add_argument('-r', '--report-only', action="store_true") parser.add_argument('-r', '--report-only', action="store_true")
parser.add_argument('--keep-tmp-files', action="store_true", default=False)
parser.add_argument('detector', choices=DET.keys()) parser.add_argument('detector', choices=DET.keys())
parser.add_argument('tag') parser.add_argument('tag')
parser.add_argument('sample') parser.add_argument('sample')
...@@ -171,11 +170,13 @@ def push_geometry(): ...@@ -171,11 +170,13 @@ def push_geometry():
prefix=prefix, prefix=prefix,
output_dir=str(output_dir.absolute()), output_dir=str(output_dir.absolute()),
) )
make_report(notebook_filename, report_parameters) make_report(notebook_filename, report_parameters,
clean=not args.keep_tmp_files)
if args.report_only: if args.report_only:
print("Clean up files...") if not args.keep_tmp_files:
geom_file.unlink() print("Clean up files...")
geom_file.unlink()
if __name__ == "__main__": if __name__ == "__main__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment