From ca54b91b094c8890d5a84149f4faa9585e9f30c8 Mon Sep 17 00:00:00 2001 From: Manasa Venkatakrishnan Date: Fri, 4 Oct 2024 15:44:59 -0700 Subject: [PATCH] Cleaning up paths --- ingestion_tools/scripts/importers/alignment.py | 2 +- ingestion_tools/scripts/importers/tomogram.py | 9 ++++----- .../scripts/importers/visualization_config.py | 2 +- ingestion_tools/scripts/tests/fixtures/dataset1.yaml | 1 + .../scripts/tests/s3_import/test_tomograms.py | 12 +++++++++++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ingestion_tools/scripts/importers/alignment.py b/ingestion_tools/scripts/importers/alignment.py index 2f6da899..1ccabc08 100644 --- a/ingestion_tools/scripts/importers/alignment.py +++ b/ingestion_tools/scripts/importers/alignment.py @@ -53,7 +53,7 @@ class AlignmentImporter(BaseFileImporter): finder_factory = MultiSourceFileFinder has_metadata = True dir_path = "{dataset_name}/{run_name}/Alignments" - metadata_path = "{dataset_name}/{run_name}/Alignments/{alignment_id}-alignment_metadata.json" + metadata_path = os.path.join(dir_path, "{alignment_id}-alignment_metadata.json") def __init__(self, *args, file_paths: dict[str, str], **kwargs): super().__init__(*args, **kwargs) diff --git a/ingestion_tools/scripts/importers/tomogram.py b/ingestion_tools/scripts/importers/tomogram.py index be6f8467..e22b5421 100644 --- a/ingestion_tools/scripts/importers/tomogram.py +++ b/ingestion_tools/scripts/importers/tomogram.py @@ -121,14 +121,13 @@ def get_alignment_metadata_path(self) -> str: for alignment in AlignmentImporter.finder(self.config, **self.parents): return alignment.get_metadata_path() - # TODO: This should be an error, but we need to fix the data first. + # TODO: As all tomograms need to be associated to an alignment this should be an error, but we need to fix the + # data first. return None - def get_neuroglancer_config_path(self) -> str: + def get_neuroglancer_config_path(self) -> str | None: if self.metadata.get("is_visualization_default"): - # TODO: Refactor this to a method in the viz_config importer with identifier in the name - return self.config.resolve_output_path("viz_config", self).format(identifier=self.identifier) - + return self.config.resolve_output_path("viz_config", self) return None @classmethod diff --git a/ingestion_tools/scripts/importers/visualization_config.py b/ingestion_tools/scripts/importers/visualization_config.py index 73a01de4..2a50910a 100644 --- a/ingestion_tools/scripts/importers/visualization_config.py +++ b/ingestion_tools/scripts/importers/visualization_config.py @@ -25,7 +25,7 @@ class VisualizationConfigImporter(BaseImporter): has_metadata = False dir_path = ( "{dataset_name}/{run_name}/Reconstructions/VoxelSpacing{voxel_spacing_name}/NeuroglancerPrecompute/" - "{{identifier}}-neuroglancer_config.json" + "{tomogram_id}-neuroglancer_config.json" ) def import_item(self) -> None: diff --git a/ingestion_tools/scripts/tests/fixtures/dataset1.yaml b/ingestion_tools/scripts/tests/fixtures/dataset1.yaml index b9d56208..2833b50d 100644 --- a/ingestion_tools/scripts/tests/fixtures/dataset1.yaml +++ b/ingestion_tools/scripts/tests/fixtures/dataset1.yaml @@ -209,6 +209,7 @@ tomograms: processing: raw reconstruction_method: WBP reconstruction_software: IMOD + is_visualization_default: true tomogram_version: 1 sources: - source_glob: diff --git a/ingestion_tools/scripts/tests/s3_import/test_tomograms.py b/ingestion_tools/scripts/tests/s3_import/test_tomograms.py index 8b0ea33e..65668652 100644 --- a/ingestion_tools/scripts/tests/s3_import/test_tomograms.py +++ b/ingestion_tools/scripts/tests/s3_import/test_tomograms.py @@ -145,16 +145,26 @@ def test_tomogram_import_metadata( item.import_metadata() run_name = parents["run"].name voxel_spacing = 13.48 - prefix = f"output/{parents['dataset'].name}/{run_name}/Reconstructions/VoxelSpacing{voxel_spacing:.3f}/Tomograms" + run_path = f"output/{parents['dataset'].name}/{run_name}" + vs_path = f"{run_path}/Reconstructions/VoxelSpacing{voxel_spacing:.3f}" + prefix = f"{vs_path}/Tomograms" tomogram_files = get_children(s3_client, test_output_bucket, prefix) id_prefix = 100 assert f"{id_prefix}-tomogram_metadata.json" in tomogram_files + image_path = f"{parents['dataset'].name}/{run_name}/Reconstructions/VoxelSpacing{voxel_spacing:.3f}/Images/{id_prefix}-key-photo-" expected = { "omezarr_dir": f"{id_prefix}-{run_name}.zarr", "mrc_files": [f"{id_prefix}-{run_name}.mrc"], "voxel_spacing": 13.48, "scales": [{"x": 6, "y": 8, "z": 10}, {"x": 3, "y": 4, "z": 5}, {"x": 2, "y": 2, "z": 3}], "size": {"x": 6, "y": 8, "z": 10}, + "alignment_metadata_path": f"{test_output_bucket}/{run_path}/Alignments/100-alignment_metadata.json", + "neuroglancer_config_path": f"{test_output_bucket}/{vs_path}/NeuroglancerPrecompute/" + f"{id_prefix}-neuroglancer_config.json", + "key_photo": { + "snapshot": f"{image_path}snapshot.png", + "thumbnail": f"{image_path}thumbnail.png", + }, } validate_metadata(expected, prefix, id_prefix)