Skip to content

Commit ddd5ea1

Browse files
authored
Merge pull request #8 from den-sq/main
Tests pass apart from failing when writing the coverage XML (will look at test setup soon but this doesn't happen when the action is run locally).
2 parents f59c2a8 + 8f562e0 commit ddd5ea1

File tree

7 files changed

+276
-44
lines changed

7 files changed

+276
-44
lines changed

.github/workflows/pr-coverage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414

1515
permissions:
1616
contents: write
17+
pull-requests: write
1718

1819
steps:
1920
- name: Check out Git repository

python/ouroboros/pipeline/backproject_pipeline.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

python/ouroboros/pipeline/slice_parallel_pipeline.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ def _process(self, input_data: tuple[any]) -> None | str:
7676
return "No slice rects were provided."
7777

7878
try:
79-
resolution = volume_cache.get_resolution_um()[:2]
80-
resolutionunit = "MICROMETER"
79+
# Volume cache resolution is in voxel size, but .tiff XY resolution is in voxels per unit, so we invert.
80+
resolution = [1.0 / voxel_size for voxel_size in volume_cache.get_resolution_um()[:2] * 0.0001]
81+
resolutionunit = "CENTIMETER"
82+
# However, Z Resolution doesn't have an inbuilt property or strong convention, so going with this.
83+
metadata = {
84+
"spacing": volume_cache.get_resolution_um()[2],
85+
"unit": "um"
86+
}
87+
88+
print(f"Resolution: {volume_cache.get_resolution_um()} | {resolution}")
8189

8290
# Determine the dimensions of the image
8391
has_color_channels = volume_cache.has_color_channels()
@@ -97,13 +105,14 @@ def _process(self, input_data: tuple[any]) -> None | str:
97105
output_file_path,
98106
temp_data,
99107
software="ouroboros",
100-
resolution=resolution,
108+
resolution=resolution[:2], # XY Resolution
101109
resolutionunit=resolutionunit,
102110
photometric=(
103111
"rgb"
104112
if has_color_channels and num_color_channels > 1
105113
else "minisblack"
106114
),
115+
metadata=metadata,
107116
)
108117
except BaseException as e:
109118
return f"Error creating single tif file: {e}"

0 commit comments

Comments
 (0)