From e030265c8540cd6669860ee9458df3a027b4f633 Mon Sep 17 00:00:00 2001 From: Lorenzo Gaifas Date: Fri, 26 Apr 2024 16:53:29 +0200 Subject: [PATCH] add dose, better logging --- src/waretomo/_parse.py | 13 +++++++++++-- src/waretomo/main.py | 30 ++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/waretomo/_parse.py b/src/waretomo/_parse.py index 9492909..bc116e2 100644 --- a/src/waretomo/_parse.py +++ b/src/waretomo/_parse.py @@ -6,7 +6,15 @@ def parse_data( - progress, warp_dir, mdoc_dir, output_dir, roi_dir, just=(), exclude=(), train=False + progress, + warp_dir, + mdoc_dir, + output_dir, + roi_dir, + just=(), + exclude=(), + train=False, + dose=None, ): log = logging.getLogger("waretomo") @@ -34,6 +42,7 @@ def parse_data( tilt_series_unprocessed = [] for mdoc_file in progress.track(mdocs, description="Reading mdocs..."): + log.info(f"Parsing {mdoc_file}.") mdoc = Mdoc.from_file(mdoc_file) # warp uses mdoc name in many places, but some times the ts_name is important @@ -110,7 +119,7 @@ def parse_data( else: roi_file = None - dose = mdoc.section_data[0].ExposureDose + dose = mdoc.section_data[0].ExposureDose if dose is None else dose if not dose: log.error("Exposure dose not present in mdoc! Setting to 0.") px_size_raw = mdoc.section_data[0].PixelSpacing diff --git a/src/waretomo/main.py b/src/waretomo/main.py index 3e5b867..e6f97de 100644 --- a/src/waretomo/main.py +++ b/src/waretomo/main.py @@ -46,7 +46,12 @@ def __str__(self): is_flag=True, help="only print some info, without running the commands.", ) -@click.option("-v", "--verbose", count=True, help="echo all individual commands") +@click.option( + "-v", + "--verbose", + count=True, + help="level of verbosity; can be passed multiple times.", +) @click.option( "-j", "--just", @@ -82,6 +87,11 @@ def __str__(self): default=4, help="binning for aretomo reconstruction (relative to warp pre-processed binning)", ) +@click.option( + "--dose", + type=float, + help="exposure dose (e/A^2/tilt_image). If not passed, guess from mdocs.", +) @click.option( "-a", "--tilt-axis", type=float, help="starting tilt axis for AreTomo, if any" ) @@ -159,6 +169,7 @@ def cli( sample_thickness, z_thickness, binning, + dose, tilt_axis, patches, roi_dir, @@ -246,6 +257,7 @@ def cli( just=just, exclude=exclude, train=train, + dose=dose, ) aretomo_kwargs = { @@ -321,7 +333,21 @@ def cli( ts = tilt_series[0] ts_name = ts["name"] ts_info = {k: v for k, v in ts.items() if k not in ("even", "odd")} - log.info(f'Metadata from tiltseries "{ts_name}": {ts_info}') + ts_info = { + k: (str(v.relative_to(warp_dir)) if isinstance(v, Path) else v) + for k, v in ts_info.items() + if k + } + ts_info.update(ts_info.pop("aretomo_kwargs")) + ts_info = "".join(f'{nl}{" " * 12}- {k}: {v}' for k, v in ts_info.items()) + first_ts_summary = cleandoc( + f""" + Double check that these values make sense for {ts_name}: + {ts_info} + """ + ) + + print(Panel(first_ts_summary)) if not dry_run: with open(output_dir / "waretomo.log", "a") as f: