Skip to content

Commit

Permalink
add dose, better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Apr 26, 2024
1 parent f50a508 commit e030265
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/waretomo/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions src/waretomo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -159,6 +169,7 @@ def cli(
sample_thickness,
z_thickness,
binning,
dose,
tilt_axis,
patches,
roi_dir,
Expand Down Expand Up @@ -246,6 +257,7 @@ def cli(
just=just,
exclude=exclude,
train=train,
dose=dose,
)

aretomo_kwargs = {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e030265

Please sign in to comment.