From 95267652e9f73cf218d8aa45ae0c2aef6e9eeb0e Mon Sep 17 00:00:00 2001 From: Andrey Aristov <aaristov@pasteur.fr> Date: Tue, 17 May 2022 15:19:31 +0200 Subject: [PATCH] save metadata, add lut limits --- src/zarr_tools/__main__.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/zarr_tools/__main__.py b/src/zarr_tools/__main__.py index 3ca4ef4..9ea2bec 100644 --- a/src/zarr_tools/__main__.py +++ b/src/zarr_tools/__main__.py @@ -16,15 +16,24 @@ def main(nd2_path:str, output:str=None, channel_axis:int=1, steps:int=5, dry_run if output is None: output = nd2_path.replace('.nd2', '.zarr') + + out = to_zarr( + data, + output, + steps=steps, + dry_run=dry_run, + channel_axis=channel_axis, + sizes=d.sizes, + lut=get_lut(d)) + + assert os.path.exists(out), "Saving zarr failed..." + try: meta_path = save_metadata(d, output) print(f'Saved metadata to {meta_path}') except Exception as e: print(f'Saving metadata Failed due to {e}') - out = to_zarr(data, output, steps=steps, dry_run=dry_run, channel_axis=channel_axis, sizes=d.sizes) - - assert os.path.exists(out), "Saving zarr failed..." exit(0) def save_metadata(data:nd2.ND2File, output:str): @@ -37,5 +46,19 @@ def save_metadata(data:nd2.ND2File, output:str): raise e return meta_path +def get_lut(data:nd2.ND2File): + try: + meta = data.custom_data + return \ + [ + [ + meta['LUTDataV1_0']['LutParam']['CompLutParam'][f'{ch:02d}'][lim][0] \ + for lim in ['MinSrc','MaxSrc'] + ] for ch in range(data.sizes['C']) + ] + except Exception as e: + print(f'Unable to get LUT due to {e}') + return None + if __name__=="__main__": fire.Fire(main) -- GitLab