diff --git a/cryoet_data_portal_neuroglancer/models/json_generator.py b/cryoet_data_portal_neuroglancer/models/json_generator.py index 154cf71..96cb9a8 100644 --- a/cryoet_data_portal_neuroglancer/models/json_generator.py +++ b/cryoet_data_portal_neuroglancer/models/json_generator.py @@ -116,13 +116,16 @@ 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 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) @@ -140,7 +143,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() @@ -159,7 +162,8 @@ 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", @@ -268,6 +272,8 @@ class ImageVolumeJSONGenerator(RenderingJSONGenerator): color: str rendering_depth: int + blend: str = "additive" + opacity: float = 1.0 def __post_init__(self): self._type = RenderingTypes.IMAGE @@ -291,7 +297,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, diff --git a/cryoet_data_portal_neuroglancer/state_generator.py b/cryoet_data_portal_neuroglancer/state_generator.py index e1f9e42..3ffbb5b 100644 --- a/cryoet_data_portal_neuroglancer/state_generator.py +++ b/cryoet_data_portal_neuroglancer/state_generator.py @@ -185,6 +185,8 @@ 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, ) -> dict[str, Any]: """Generates JSON for an image layer with optional contrast limits. @@ -211,6 +213,8 @@ 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, ).to_json() @@ -222,6 +226,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) @@ -232,6 +238,8 @@ def generate_image_volume_layer( scale=scale, is_visible=is_visible, rendering_depth=rendering_depth, + blend=blend, + opacity=opacity, ).to_json() diff --git a/tests/test_state_generators.py b/tests/test_state_generators.py new file mode 100644 index 0000000..0d8e00e --- /dev/null +++ b/tests/test_state_generators.py @@ -0,0 +1,9 @@ +from cryoet_data_portal_neuroglancer.state_generator import generate_image_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