1+ import argparse
12import os
23import cryoet_data_portal as cdp
34import zarr
@@ -28,8 +29,7 @@ def write_ome_zarr(output_file, segmentation, voxel_size):
2829
2930
3031def run_prediction (tomogram , deposition_id , processing_type ):
31- output_root = f"upload_CZCDP-{ deposition_id } "
32- output_folder = os .path .join (output_root , str (tomogram .run .dataset_id ))
32+ output_folder = os .path .join (f"upload_CZCDP-{ deposition_id } " , str (tomogram .run .dataset_id ))
3333 os .makedirs (output_folder , exist_ok = True )
3434
3535 output_file = os .path .join (output_folder , f"{ tomogram .run .name } .zarr" )
@@ -50,7 +50,35 @@ def run_prediction(tomogram, deposition_id, processing_type):
5050 write_ome_zarr (output_file , segmentation , voxel_size )
5151
5252
53+ def check_result (tomogram , deposition_id , processing_type ):
54+ import napari
55+
56+ # Read tomogram data on the fly.
57+ data , voxel_size = read_data_from_cryo_et_portal_run (
58+ tomogram .run_id , processing_type = processing_type
59+ )
60+
61+ # Read the output file if it exists.
62+ output_folder = os .path .join (f"upload_CZCDP-{ deposition_id } " , str (tomogram .run .dataset_id ))
63+ output_file = os .path .join (output_folder , f"{ tomogram .run .name } .zarr" )
64+ if os .path .exists (output_file ):
65+ segmentation = "" # TODO load the segmentation from zarr
66+ else :
67+ segmentation = None
68+
69+ v = napari .Viewer ()
70+ v .add_image (data )
71+ if segmentation is not None :
72+ v .add_labels (segmentation )
73+ napari .run ()
74+
75+
5376def main ():
77+ parser = argparse .ArgumentParser ()
78+ # Whether to check the result with napari instead of running the prediction.
79+ parser .add_argument ("-c" , "--check" , action = "store_true" )
80+ args = parser .parse_args ()
81+
5482 deposition_id = 10313
5583 processing_type = "denoised"
5684
@@ -59,7 +87,10 @@ def main():
5987
6088 # Process each tomogram.
6189 for tomogram in tqdm (tomograms , desc = "Run prediction for tomograms on-the-fly" ):
62- run_prediction (tomogram , deposition_id , processing_type )
90+ if args .check :
91+ check_result (tomogram , deposition_id , processing_type )
92+ else :
93+ run_prediction (tomogram , deposition_id , processing_type )
6394
6495
6596if __name__ == "__main__" :
0 commit comments