Skip to content

Commit

Permalink
fix: Oriented point rendering in Neuroglancer (#358)
Browse files Browse the repository at this point in the history
* Fixing oriented point rendering

* Refactor pytest fixture name

* Adding tests

* reverting config change

* updating oriented point layer name

* addresing pr feedback
  • Loading branch information
manasaV3 authored Nov 18, 2024
1 parent 862bc01 commit fd1966d
Show file tree
Hide file tree
Showing 3 changed files with 296 additions and 30 deletions.
34 changes: 19 additions & 15 deletions ingestion_tools/scripts/importers/visualization_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def _to_segmentation_mask_layer(
**kwargs,
) -> dict[str, Any]:
return state_generator.generate_segmentation_mask_layer(
source_path,
f"{name_prefix} segmentation",
self.config.https_prefix,
source=source_path,
name=f"{name_prefix} segmentation",
url=self.config.https_prefix,
color=color,
scale=resolution,
is_visible=file_metadata.get("is_visualization_default"),
Expand All @@ -90,18 +90,23 @@ def _to_point_layer(
name_prefix: str,
color: str,
resolution: tuple[float, float, float],
is_instance_segmentation: bool,
shape: str,
**kwargs,
) -> dict[str, Any]:
return state_generator.generate_point_layer(
source_path,
f"{name_prefix} point",
self.config.https_prefix,
color=color,
scale=resolution,
is_visible=file_metadata.get("is_visualization_default"),
is_instance_segmentation=is_instance_segmentation,
)
is_instance_segmentation = shape == "InstanceSegmentation"
args = {
"source": source_path,
"url": self.config.https_prefix,
"color": color,
"scale": resolution,
"is_visible": file_metadata.get("is_visualization_default"),
"is_instance_segmentation": is_instance_segmentation,
}
if shape == "OrientedPoint":
args["name"] = f"{name_prefix} orientedpoint"
return state_generator.generate_oriented_point_layer(**args)
args["name"] = f"{name_prefix} point"
return state_generator.generate_point_layer(**args)

def get_annotation_layer_info(self, alignment_metadata_path: str) -> dict[str, Any]:
precompute_path = self.config.resolve_output_path("annotation_viz", self)
Expand Down Expand Up @@ -155,7 +160,7 @@ def get_annotation_layer_info(self, alignment_metadata_path: str) -> dict[str, A
"file_metadata": file,
"name_prefix": name_prefix,
"color": hex_colors[0],
"is_instance_segmentation": is_instance_seg,
"shape": shape,
},
}

Expand All @@ -180,7 +185,6 @@ def _create_config(self, alignment_metadata_path: str) -> dict[str, Any]:
layers.append(self._to_segmentation_mask_layer(**args))
elif info["shape"] in {"Point", "OrientedPoint", "InstanceSegmentation"}:
layers.append(self._to_point_layer(**args))

return state_generator.combine_json_layers(layers, scale=resolution)

@classmethod
Expand Down
30 changes: 15 additions & 15 deletions ingestion_tools/scripts/tests/s3_import/test_alignments.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def validate(expected: dict, prefix: str) -> None:


@pytest.fixture
def create_config(
def config_generator(
s3_fs: FileSystemApi,
test_output_bucket: str,
input_bucket: str,
Expand All @@ -102,15 +102,15 @@ def _create(path: str) -> DepositionImportConfig:
],
)
def test_alignment_import_item(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
add_alignment_metadata: Callable[[str, int], None],
validate_dataframe: Callable[[str, str], None],
validate_metadata: Callable[[dict, str], None],
test_output_bucket: str,
deposition_id: int,
id_prefix: int,
) -> None:
config = create_config("dataset1.yaml")
config = config_generator("dataset1.yaml")
parents = get_parents(config)
dataset_name = parents.get("dataset").name
run_name = parents.get("run").name
Expand Down Expand Up @@ -182,15 +182,15 @@ def test_alignment_import_item(
],
)
def test_alignment_import_item_aretomo(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
add_alignment_metadata: Callable[[str, int], None],
validate_dataframe: Callable[[str, str], None],
validate_metadata: Callable[[dict, str], None],
test_output_bucket: str,
deposition_id: int,
id_prefix: int,
) -> None:
config = create_config("dataset2.yaml")
config = config_generator("dataset2.yaml")
parents = get_parents(config)
dataset_name = parents.get("dataset").name
run_name = parents.get("run").name
Expand Down Expand Up @@ -251,12 +251,12 @@ def test_alignment_import_item_aretomo(


def test_default_alignment_import_with_tomograms(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
s3_client: S3Client,
test_output_bucket: str,
validate_metadata: Callable[[dict, str], None],
) -> None:
config = create_config("alignments/alignment1.yaml")
config = config_generator("alignments/alignment1.yaml")
parents = get_parents(config)

alignments = list(AlignmentImporter.finder(config, **parents))
Expand Down Expand Up @@ -289,11 +289,11 @@ def test_default_alignment_import_with_tomograms(


def test_default_alignment_import_without_tomograms(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
s3_client: S3Client,
test_output_bucket: str,
) -> None:
config = create_config("alignments/alignment2.yaml")
config = config_generator("alignments/alignment2.yaml")
parents = get_parents(config)

alignments = list(AlignmentImporter.finder(config, **parents))
Expand All @@ -309,11 +309,11 @@ def test_default_alignment_import_without_tomograms(


def test_custom_alignment_import_without_tomograms(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
s3_client: S3Client,
test_output_bucket: str,
) -> None:
config = create_config("alignments/alignment3.yaml")
config = config_generator("alignments/alignment3.yaml")
parents = get_parents(config)

alignments = list(AlignmentImporter.finder(config, **parents))
Expand All @@ -329,12 +329,12 @@ def test_custom_alignment_import_without_tomograms(


def test_custom_alignment_with_dimensions_import_without_tomograms(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
test_output_bucket: str,
validate_dataframe: Callable[[str, str, int], None],
validate_metadata: Callable[[dict, str, int], None],
) -> None:
config = create_config("alignments/alignment4.yaml")
config = config_generator("alignments/alignment4.yaml")
parents = get_parents(config)

alignments = list(AlignmentImporter.finder(config, **parents))
Expand Down Expand Up @@ -389,11 +389,11 @@ def test_custom_alignment_with_dimensions_import_without_tomograms(


def test_allow_import_is_false(
create_config: Callable[[str], DepositionImportConfig],
config_generator: Callable[[str], DepositionImportConfig],
test_output_bucket: str,
s3_client: S3Client,
) -> None:
config = create_config("alignments/alignment4.yaml")
config = config_generator("alignments/alignment4.yaml")
parents = get_parents(config)

alignments = list(AlignmentImporter.finder(config, **parents))
Expand Down
Loading

0 comments on commit fd1966d

Please sign in to comment.