2323import numpy as np
2424import concurrent .futures
2525from tifffile import imwrite , memmap
26- import os
2726import multiprocessing
2827import time
2928
@@ -68,21 +67,19 @@ def _process(self, input_data: tuple[any]) -> None | str:
6867 if len (slice_rects ) == 0 :
6968 return "No slice rects were provided."
7069
71- # Create a folder with the same name as the output file
72- folder_name = join_path (
73- config .output_file_folder ,
74- format_slice_output_multiple (config .output_file_name ),
75- )
70+ # Makes output file folder
71+ Path (config .output_file_folder ).mkdir (parents = True , exist_ok = True )
7672
73+ # Create a folder with the same name as the output file
7774 if config .make_single_file :
78- os .makedirs (folder_name , exist_ok = True )
75+ output_file_path = join_path (config .output_file_folder , format_slice_output_file (config .output_file_name ))
76+ else :
77+ output_folder = Path (config .output_file_folder , format_slice_output_multiple (config .output_file_name ))
78+ output_folder .mkdir (parents = True , exist_ok = True )
7979
80- output_file_path = join_path (
81- config .output_file_folder , format_slice_output_file (config .output_file_name )
82- )
8380 temp_file_path = Path (
84- config .output_file_folder , format_slice_output_file ( config .output_file_name )
85- ).with_suffix (".temptif " )
81+ config .output_file_folder , f" { config .output_file_name } _temp"
82+ ).with_suffix (".tif " )
8683
8784 # Start setting up metadata
8885 # Volume cache resolution is in voxel size, but .tiff XY resolution is in voxels per unit, so we invert.
@@ -203,7 +200,7 @@ def processor_completed(future):
203200 else :
204201 pool .starmap (write_normalized ,
205202 [(temp_file ,
206- partial (imwrite , join_path ( folder_name , format_tiff_name (i , num_digits )), ** tiff_metadata ), # noqa: E501
203+ partial (imwrite , output_folder . joinpath ( format_tiff_name (i , num_digits )), ** tiff_metadata ), # noqa: E501
207204 convert_func ,
208205 i ) for i in range (len (temp_file ))])
209206 del temp_file
@@ -213,7 +210,10 @@ def processor_completed(future):
213210 return f"Error downloading data: { e } "
214211
215212 # Update the pipeline input with the output file path
216- pipeline_input .output_file_path = output_file_path
213+ if config .make_single_file :
214+ pipeline_input .output_file_path = output_file_path
215+ else :
216+ pipeline_input .output_file_path = str (output_folder )
217217
218218 return None
219219
0 commit comments