Skip to content

Commit

Permalink
feat: add segmentation property objects
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed Sep 20, 2024
1 parent 759def1 commit d7664bc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cryoet_data_portal_neuroglancer/models/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ def __str__(self):
return self.name.lower()


@dataclass
class SegmentPropertyJSONGenerator:
"""Generates a JSON file for segmentation properties.
Supports a subset of the properties that can be set in Neuroglancer.
See https://github.com/google/neuroglancer/blob/3efc90465e702453916d2b03d472c16378848132/src/datasource/precomputed/segment_properties.md
"""

ids: list[int]
labels: list[str]

def generate_json(self) -> dict:
return {
"inline": {
"ids": [str(val) for val in self.ids],
"properties": [
{
"values": self.labels,
"type": "label",
"id": "label",
},
],
},
"@type": "neuroglancer_segment_properties",
}


@dataclass
class RenderingJSONGenerator:
"""Generates a JSON file for Neuroglancer to read."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
from pathlib import Path

from cryoet_data_portal_neuroglancer.models.json_generator import SegmentPropertyJSONGenerator


def write_segment_properties(base_folder: str | Path, ids: list[int], labels: list[str]):
segment_generator = SegmentPropertyJSONGenerator(ids=ids, labels=labels)
segment_properties = segment_generator.generate_json()
segment_properties_path = Path(base_folder) / "segment_properties" / "info"
segment_properties_path.parent.mkdir(exist_ok=True, parents=True)
segment_properties_path.write_text(json.dumps(segment_properties, indent=2))

0 comments on commit d7664bc

Please sign in to comment.