@@ -83,6 +83,8 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
8383 mmap = make_tiff_memmap (straightened_volume_path , mode = "r" )
8484 del mmap
8585 except BaseException as e :
86+ print (f"Direct memory mapping failed (Error { e } )\n . Using TiffWriter." )
87+
8688 # Create a new path for the straightened volume
8789 new_straightened_volume_path = join_path (
8890 config .output_file_folder ,
@@ -187,7 +189,8 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
187189 min_bounding_box = chunks_and_boxes [0 ][
188190 0
189191 ] # The first chunk bounding box has the same offset as the minimum bounding box
190- pipeline_input .backprojection_offset = f"{ min_bounding_box .x_min } ,{ min_bounding_box .y_min } ,{ min_bounding_box .z_min } "
192+ pipeline_input .backprojection_offset = \
193+ f"{ min_bounding_box .x_min } ,{ min_bounding_box .y_min } ,{ min_bounding_box .z_min } "
191194
192195 # Save the backprojected volume to a series of tif files
193196 offset = (
@@ -292,7 +295,7 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
292295
293296 # Copy the intersection volume to the chunk volume
294297 intersection_volume = volume [
295- x_min : x_max + 1 , y_min : y_max + 1 , z_min : z_max + 1
298+ x_min : x_max + 1 , y_min : y_max + 1 , z_min : z_max + 1
296299 ]
297300 non_zero_mask = (
298301 np .sum (intersection_volume , axis = - 1 ) != 0
@@ -301,9 +304,9 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
301304 )
302305
303306 chunk_volume [
304- int_x_min : int_x_max + 1 ,
305- int_y_min : int_y_max + 1 ,
306- int_z_min : int_z_max + 1 ,
307+ int_x_min : int_x_max + 1 ,
308+ int_y_min : int_y_max + 1 ,
309+ int_z_min : int_z_max + 1 ,
307310 ][non_zero_mask ] = intersection_volume [non_zero_mask ]
308311
309312 # If make_backprojection_binary, set all non-zero values to 1
@@ -342,23 +345,27 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]:
342345 # Save the backprojected volume to a single tif file
343346 if config .make_single_file :
344347 try :
345- metadata = {}
348+ # Volume cache resolution is in voxel size, but .tiff XY resolution is in voxels per unit, so we invert.
349+ resolution = [1.0 / voxel_size for voxel_size in volume_cache .get_resolution_um ()[:2 ] * 0.0001 ]
350+ resolutionunit = "CENTIMETER"
351+ # However, Z Resolution doesn't have an inbuilt property or strong convention, so going with this atm.
352+ metadata = {
353+ "spacing" : volume_cache .get_resolution_um ()[2 ],
354+ "unit" : "um"
355+ }
346356
347357 if config .backproject_min_bounding_box :
348358 metadata ["backprojection_offset_min_xyz" ] = (
349359 pipeline_input .backprojection_offset
350360 )
351361
352- resolution = volume_cache .get_resolution_um ()[:2 ]
353- resolutionunit = "MICROMETER"
354-
355362 load_and_save_tiff_from_slices (
356363 folder_path ,
357364 folder_path + ".tif" ,
358365 delete_intermediate = False ,
359366 compression = config .backprojection_compression ,
360367 metadata = metadata ,
361- resolution = resolution ,
368+ resolution = resolution , # XY Resolution
362369 resolutionunit = resolutionunit ,
363370 )
364371 except BaseException as e :
@@ -509,7 +516,8 @@ def create_volume_chunks(
509516 # Create bounding boxes along the first axis each containing chunk_size slices
510517 chunks_and_boxes = []
511518
512- # If backproject_min_bounding_box is True, create a bounding box that contains the minimum bounding box of the volume
519+ # If backproject_min_bounding_box is True,
520+ # create a bounding box that contains the minimum bounding box of the volume.
513521 min_bounding_box = None
514522
515523 # Calculate the range of slices to process
0 commit comments