1010import zarr
1111
1212import flamingo_tools .s3_utils as s3_utils
13+ from flamingo_tools .file_utils import read_image_data
1314
1415
1516def main (
1617 input_path : str ,
1718 coords : List [int ],
18- output_dir : str = None ,
19- input_key : str = "setup0/timepoint0/s0" ,
19+ output_dir : Optional [ str ] = None ,
20+ input_key : Optional [ str ] = None ,
2021 output_key : Optional [str ] = None ,
2122 resolution : float = 0.38 ,
2223 roi_halo : List [int ] = [128 , 128 , 64 ],
@@ -88,24 +89,17 @@ def main(
8889 roi = tuple (slice (co - rh , co + rh ) for co , rh in zip (coords , roi_halo ))
8990
9091 if s3 :
91- s3_path , fs = s3_utils .get_s3_path (input_path , bucket_name = s3_bucket_name ,
92- service_endpoint = s3_service_endpoint , credential_file = s3_credentials )
92+ input_path , fs = s3_utils .get_s3_path (input_path , bucket_name = s3_bucket_name ,
93+ service_endpoint = s3_service_endpoint , credential_file = s3_credentials )
9394
94- with zarr .open (s3_path , mode = "r" ) as f :
95- raw = f [input_key ][roi ]
96-
97- elif ".tif" in input_path :
98- raw = read_tif (input_path )[roi ]
99-
100- else :
101- with zarr .open (input_path , mode = "r" ) as f :
102- raw = f [input_key ][roi ]
95+ data_ = read_image_data (input_path , input_key )
96+ data_roi = data_ [roi ]
10397
10498 if tif :
105- imageio .imwrite (output_file , raw , compression = "zlib" )
99+ imageio .imwrite (output_file , data_roi , compression = "zlib" )
106100 else :
107101 with zarr .open (output_file , mode = "w" ) as f_out :
108- f_out .create_dataset (output_key , data = raw , compression = "gzip" )
102+ f_out .create_dataset (output_key , data = data_roi , compression = "gzip" )
109103
110104
111105if __name__ == "__main__" :
@@ -118,7 +112,7 @@ def main(
118112 parser .add_argument ('-c' , "--coord" , type = str , required = True ,
119113 help = "3D coordinate as center of extracted block, json-encoded." )
120114
121- parser .add_argument ('-k' , "--input_key" , type = str , default = "setup0/timepoint0/s0" ,
115+ parser .add_argument ('-k' , "--input_key" , type = str , default = None ,
122116 help = "Input key for data in input file." )
123117 parser .add_argument ("--output_key" , type = str , default = None ,
124118 help = "Output key for data in output file." )
0 commit comments