From c934d566a8dfc2ccbba2b158bbe93983656c68b8 Mon Sep 17 00:00:00 2001 From: Philip MacMenamin Date: Wed, 4 Oct 2023 20:25:38 +0100 Subject: [PATCH 1/2] convert output of visual_min_max to new callback format --- em_workflows/brt/flow.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/em_workflows/brt/flow.py b/em_workflows/brt/flow.py index 2bdfd83b..3bd05fe0 100644 --- a/em_workflows/brt/flow.py +++ b/em_workflows/brt/flow.py @@ -508,7 +508,31 @@ def gen_ng_metadata(fp_in: FilePath) -> Dict: ng_asset = file_path.gen_asset( asset_type=AssetType.NEUROGLANCER_ZARR, asset_fp=asset_fp ) - ng_asset["metadata"] = visual_min_max(mad_scale=5, input_image=first_zarr_arr) + shader_params = visual_min_max(mad_scale=5, input_image=first_zarr_arr) + # visual_min_max currently returns an dict like: + # "metadata": { + # "neuroglancerPrecomputedMin": "-53", + # "neuroglancerPrecomputedMax": "58", + # "neuroglancerPrecomputedFloor": "-571", + # "neuroglancerPrecomputedLimit": "370" + # } + # this needs to be converted to the new format, below. + sp_massaged = { + "window": [ + shader_params["neuroglancerPrecomputedFloor"], + shader_params["neuroglancerPrecomputedLimit"], + ], + "range": [ + shader_params["neuroglancerPrecomputedMin"], + shader_params["neuroglancerPrecomputedMax"], + ], + } + metadata = { + "shader": "Grayscale", + "dimensions": "XYZ", + "shaderParameters": sp_massaged, + } + ng_asset["metadata"] = metadata return ng_asset From 5f3684cdd51e4443b1cea3bc4a97488f19c02735 Mon Sep 17 00:00:00 2001 From: Philip MacMenamin Date: Wed, 4 Oct 2023 21:50:16 +0100 Subject: [PATCH 2/2] use HedwigImages iface --- em_workflows/brt/flow.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/em_workflows/brt/flow.py b/em_workflows/brt/flow.py index 3bd05fe0..4de2bcd6 100644 --- a/em_workflows/brt/flow.py +++ b/em_workflows/brt/flow.py @@ -38,6 +38,8 @@ from typing import Dict import glob import os + +from pytools.HedwigZarrImages import HedwigZarrImages from em_workflows.file_path import FilePath import subprocess import math @@ -46,7 +48,6 @@ from prefect import task, Flow, Parameter, unmapped from prefect.run_configs import LocalRun from prefect.engine import signals -from pytools.workflow_functions import visual_min_max from em_workflows.utils import utils from em_workflows.utils import neuroglancer as ng @@ -502,35 +503,17 @@ def gen_zarr(fp_in: FilePath): def gen_ng_metadata(fp_in: FilePath) -> Dict: file_path = fp_in asset_fp = Path(f"{file_path.assets_dir}/{file_path.base}.zarr") - - first_zarr_arr = Path(asset_fp.as_posix() + "/0/0") + zarr_fp = Path(f"{file_path.working_dir}/{file_path.base}.zarr") + hw_images = HedwigZarrImages(zarr_fp) + _, hw_image = next(hw_images.series()) ng_asset = file_path.gen_asset( asset_type=AssetType.NEUROGLANCER_ZARR, asset_fp=asset_fp ) - shader_params = visual_min_max(mad_scale=5, input_image=first_zarr_arr) - # visual_min_max currently returns an dict like: - # "metadata": { - # "neuroglancerPrecomputedMin": "-53", - # "neuroglancerPrecomputedMax": "58", - # "neuroglancerPrecomputedFloor": "-571", - # "neuroglancerPrecomputedLimit": "370" - # } - # this needs to be converted to the new format, below. - sp_massaged = { - "window": [ - shader_params["neuroglancerPrecomputedFloor"], - shader_params["neuroglancerPrecomputedLimit"], - ], - "range": [ - shader_params["neuroglancerPrecomputedMin"], - shader_params["neuroglancerPrecomputedMax"], - ], - } metadata = { "shader": "Grayscale", "dimensions": "XYZ", - "shaderParameters": sp_massaged, + "shaderParameters": hw_image.neuroglancer_shader_parameters(), } ng_asset["metadata"] = metadata return ng_asset