@@ -639,7 +639,7 @@ def process(args):
639639 f_name = progress_dir / f"{ start [0 ]} -{ end [0 ]} _{ start [1 ]} -{ end [1 ]} .done"
640640 print (f"Processing chunk: { start } to { end } , file: { f_name } " )
641641 if f_name .exists () and not overwrite_output :
642- return
642+ return ( start , end )
643643
644644 rawdata = load_data_from_zarr_store (loaded_zarr_store )
645645
@@ -754,7 +754,7 @@ def process(args):
754754
755755# %% Function to check the output directory for completed chunks and upload them to GCS
756756
757- processed_chunks_bounds = [( np . inf , np . inf , np . inf ), ( - np . inf , - np . inf , - np . inf )]
757+ processed_chunks_bounds = None
758758
759759
760760# TODO this probably wants to bulk together uploads to reduce overhead
@@ -766,9 +766,6 @@ def check_and_upload_completed_chunks():
766766 Returns:
767767 int: Number of chunks uploaded
768768 """
769- if not use_gcs_output :
770- return 0
771-
772769 uploaded_count = 0
773770
774771 for mip_level in range (num_mips ):
@@ -790,6 +787,10 @@ def check_and_upload_completed_chunks():
790787 [c * factor for c in chunk_bounds [0 ]],
791788 [c * factor for c in chunk_bounds [1 ]],
792789 ]
790+ # Clamp the chunk bounds to the volume size
791+ chunk_bounds [1 ] = [
792+ min (cb , vs ) for cb , vs in zip (chunk_bounds [1 ], volume_size )
793+ ]
793794 # 2. Check if the chunk is fully covered by the processed bounds
794795 if all (
795796 pb0 <= cb0 and pb1 >= cb1
@@ -811,7 +812,8 @@ def check_and_upload_completed_chunks():
811812 uploaded_count += 1
812813 print (f"Uploaded chunk: { gcs_chunk_path } " )
813814 # Remove local chunk to save space
814- chunk_file .unlink ()
815+ if use_gcs_output :
816+ chunk_file .unlink ()
815817
816818 return uploaded_count
817819
@@ -851,8 +853,10 @@ def upload_any_remaining_chunks():
851853total_uploaded_files = 0
852854for coord in reversed_coords :
853855 bounds = process (coord )
854- if bounds is not None :
855- start , end = bounds
856+ start , end = bounds
857+ if processed_chunks_bounds is None :
858+ processed_chunks_bounds = [start , end ]
859+ else :
856860 processed_chunks_bounds [0 ] = [
857861 min (ps , s ) for ps , s in zip (processed_chunks_bounds [0 ], start )
858862 ]
0 commit comments