diff --git a/src/waretomo/_fix_mdoc.py b/src/waretomo/_fix_mdoc.py index 4d9aeea..ef834ed 100644 --- a/src/waretomo/_fix_mdoc.py +++ b/src/waretomo/_fix_mdoc.py @@ -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: diff --git a/src/waretomo/_parse.py b/src/waretomo/_parse.py index 881c8b6..c529598 100644 --- a/src/waretomo/_parse.py +++ b/src/waretomo/_parse.py @@ -2,6 +2,7 @@ from xml.etree import ElementTree import mdocfile +from rich import print def parse_data( @@ -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) diff --git a/src/waretomo/main.py b/src/waretomo/main.py index 58254f0..1a41a72 100644 --- a/src/waretomo/main.py +++ b/src/waretomo/main.py @@ -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(