Skip to content

Commit

Permalink
fix wrong ordering of tilts and mishandling of extra tilts in mdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Aug 28, 2023
1 parent 04f8d18 commit ec3ebda
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/waretomo/_fix_mdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ def _tilt_mdoc(
if not dry_run:
mdoc = Mdoc.from_file(mdoc_file)
new_angles = iter(pd.read_csv(tlt_file, header=None)[0])
for i, section in enumerate(mdoc.section_data):
if i in skipped_tilts:
# mdoc is still out of order, but aretomo puts the new_angles in order
# this gives us tuples like (original_index, section), but ordered by angle
# like aretomo so we can compare it with the new angles
sorted_section_data = sorted(
enumerate(mdoc.section_data), key=lambda x: x[1].TiltAngle
)
for idx, section in sorted_section_data:
if idx in skipped_tilts:
continue
try:
section.TiltAngle = next(new_angles)
except StopIteration as e:
raise RuntimeError(
f"not enough tilts generated by aretomo in {tlt_file}"
f"not enough tilts generated by aretomo in {tlt_file}, "
f"or Mdoc is corrupted"
) from e

try:
Expand Down
13 changes: 13 additions & 0 deletions src/waretomo/_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from xml.etree import ElementTree

import mdocfile
from rich import print


def parse_data(
Expand Down Expand Up @@ -51,6 +52,18 @@ def parse_data(
even = []
valid_xml = None
for i, tilt in enumerate(tilts):
if not tilt.exists():
print(
f"[red]WARN: {tilt.name} is listed in an mdoc file, "
"but the file does not exists."
)
print(
"[red] The tilt will be skipped, "
"but you may want to check your data."
)
skipped_tilts.append(i)
continue

xml = ElementTree.parse(tilt.with_suffix(".xml")).getroot()
if xml.attrib["UnselectManual"] == "True":
skipped_tilts.append(i)
Expand Down
2 changes: 1 addition & 1 deletion src/waretomo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def cli(
if roi_dir is not None:
roi_dir = Path(roi_dir)

pretrained_models = ("unet-3d-10a", "unet-3d-20a")
pretrained_models = ("unet-3d-10a", "unet-3d-20a")
if train:
if topaz_model in pretrained_models:
raise click.UsageError(
Expand Down

0 comments on commit ec3ebda

Please sign in to comment.