diff --git a/src/zarr_tools/__main__.py b/src/zarr_tools/__main__.py index 3ca4ef48202281c06151c4028f66e26f84f7b291..9ea2becc619325b7782f48852b1b3f2b44d1eb00 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)