Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default value to false for code editor display #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions cryoet_data_portal_neuroglancer/models/json_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,17 @@ class ImageJSONGenerator(RenderingJSONGenerator):
volume_rendering_is_visible: bool = False
volume_rendering_gain: float = 0.0
can_hide_high_values_in_neuroglancer: bool = False
blend: str = "additive"
opacity: float = 1.0
is_code_editor_visible: bool = False

def __post_init__(self):
self._type = RenderingTypes.IMAGE

def _compute_contrast_limits(self) -> tuple[float, float]:
if self.mean is None or self.rms is None:
return self.contrast_limits
# return self.contrast_limits
return (0.0, 1.0)
width = 3 * self.rms
return (self.mean - width, self.mean + width)

Expand All @@ -140,7 +144,7 @@ def _create_shader_and_controls(self) -> dict[str, Any]:
else:
shader_builder = ImageShaderBuilder(
contrast_limits=self.contrast_limits,
can_hide_high_values_in_neuroglancer=self.can_hide_high_values_in_neuroglancer,
# can_hide_high_values_in_neuroglancer=self.can_hide_high_values_in_neuroglancer,
)
return shader_builder.build()

Expand All @@ -159,11 +163,13 @@ def generate_json(self) -> dict:
"type": self.layer_type,
"name": self.name,
"source": create_source(f"zarr://{self.source}", self.scale, self.scale),
"opacity": 0.51,
"opacity": self.opacity,
"blend": self.blend,
"tab": "rendering",
"visible": self.is_visible,
"volumeRendering": "on" if self.volume_rendering_is_visible else "off",
"volumeRenderingGain": self.volume_rendering_gain,
"codeVisible": self.is_code_editor_visible,
}
if self.has_volume_rendering_shader:
config["volumeRenderingDepthSamples"] = self.volume_rendering_depth_samples
Expand All @@ -178,6 +184,7 @@ class AnnotationJSONGenerator(RenderingJSONGenerator):
point_size_multiplier: float = 1.0
is_instance_segmentation: bool = False
is_visible: bool = True
is_code_editor_visible: bool = False

def __post_init__(self):
self._type = RenderingTypes.ANNOTATION
Expand All @@ -197,6 +204,7 @@ def generate_json(self) -> dict:
"source": create_source(f"precomputed://{self.source}", self.scale, self.scale),
"tab": "rendering",
"visible": self.is_visible,
"codeVisible": self.is_code_editor_visible,
**self._get_shader(),
}

Expand Down Expand Up @@ -228,6 +236,7 @@ class SegmentationJSONGenerator(RenderingJSONGenerator):
highlight_on_hover: bool = False
mesh_render_scale: float = 1.0
visible_segments: tuple[int, ...] = (1,)
enable_pick: bool = False

def __post_init__(self):
self._type = RenderingTypes.SEGMENTATION
Expand All @@ -250,6 +259,7 @@ def generate_json(self) -> dict:
"segments": sorted((self.visible_segments)),
"visible": self.is_visible,
"meshRenderScale": self.mesh_render_scale,
"pick": self.enable_pick,
}
# self.color === None means that the color will be random
# This is useful for multiple segmentations
Expand All @@ -268,6 +278,8 @@ class ImageVolumeJSONGenerator(RenderingJSONGenerator):

color: str
rendering_depth: int
blend: str = "additive"
opacity: float = 1.0

def __post_init__(self):
self._type = RenderingTypes.IMAGE
Expand All @@ -291,7 +303,8 @@ def generate_json(self) -> dict:
"name": f"{self.name}",
"source": create_source(f"zarr://{self.source}", self.scale, self.scale),
"tab": "rendering",
"blend": "additive",
"blend": self.blend,
"opacity": self.opacity,
"volumeRendering": "on",
"volumeRenderingDepthSamples": self.rendering_depth,
"visible": self.is_visible,
Expand Down
14 changes: 14 additions & 0 deletions cryoet_data_portal_neuroglancer/state_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def generate_oriented_point_layer(
scale: float | tuple[float, float, float] = (1.0, 1.0, 1.0),
is_visible: bool = True,
is_instance_segmentation: bool = False,
is_code_editor_visible: bool = False,
) -> dict[str, Any]:
source, name, url, _, scale = _setup_creation(source, name, url, scale=scale)
_validate_color(color)
Expand All @@ -80,6 +81,7 @@ def generate_oriented_point_layer(
scale=scale,
is_visible=is_visible,
is_instance_segmentation=is_instance_segmentation,
is_code_editor_visible=is_code_editor_visible,
).to_json()


Expand All @@ -95,6 +97,7 @@ def generate_segmentation_mask_layer(
highlight_on_hover: bool = False,
mesh_render_scale: float = 2.0,
visible_segments: tuple[int, ...] = (1,),
enable_pick: bool = False,
) -> dict[str, Any]:
source, name, url, _, scale = _setup_creation(source, name, url, scale=scale)
_validate_color(color)
Expand All @@ -109,6 +112,7 @@ def generate_segmentation_mask_layer(
highlight_on_hover=highlight_on_hover,
mesh_render_scale=mesh_render_scale,
visible_segments=visible_segments,
enable_pick=enable_pick,
).to_json()


Expand Down Expand Up @@ -185,6 +189,9 @@ def generate_image_layer(
volume_rendering_is_visible: bool = False,
volume_rendering_gain: float = -7.8,
can_hide_high_values_in_neuroglancer: bool | None = None,
blend: str = "additive",
opacity: float = 1.0,
is_code_editor_visible: bool = False,
) -> dict[str, Any]:
"""Generates JSON for an image layer with optional contrast limits.

Expand All @@ -211,6 +218,9 @@ def generate_image_layer(
volume_rendering_is_visible=volume_rendering_is_visible,
volume_rendering_gain=volume_rendering_gain,
can_hide_high_values_in_neuroglancer=can_hide_high_values_in_neuroglancer,
blend=blend,
opacity=opacity,
is_code_editor_visible=is_code_editor_visible,
).to_json()


Expand All @@ -222,6 +232,8 @@ def generate_image_volume_layer(
scale: tuple[float, float, float] | list[float] | float = (1.0, 1.0, 1.0),
is_visible: bool = True,
rendering_depth: int = 1024,
blend: str = "additive",
opacity: float = 1.0,
) -> dict[str, Any]:
source, name, url, _, scale = _setup_creation(source, name, url, scale=scale)
_validate_color(color)
Expand All @@ -232,6 +244,8 @@ def generate_image_volume_layer(
scale=scale,
is_visible=is_visible,
rendering_depth=rendering_depth,
blend=blend,
opacity=opacity,
).to_json()


Expand Down
37 changes: 37 additions & 0 deletions tests/test_state_generators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from cryoet_data_portal_neuroglancer.state_generator import (
generate_image_layer,
generate_oriented_point_layer,
generate_point_layer,
generate_segmentation_mask_layer,
)


def test__generate_image_layer_default_values():
state = generate_image_layer(source="mysource", scale=1.5, size={"a": 2.0})

assert "blend" in state
assert state["blend"] == "additive"
assert state["opacity"] == 1.0
assert "codeVisible" in state
assert state["codeVisible"] is False


def test__generate_segmentation_layer_default_values():
state = generate_segmentation_mask_layer(source="mysource")

assert "pick" in state
assert state["pick"] is False


def test__generate_oriented_point_layer_default_values():
state = generate_oriented_point_layer(source="mysource")

assert "codeVisible" in state
assert state["codeVisible"] is False


def test__generate_point_layer_default_values():
state = generate_point_layer(source="mysource")

assert "codeVisible" in state
assert state["codeVisible"] is False
Loading