Skip to content

Commit a62762e

Browse files
committed
Minor Comment and Other Cleanup
1 parent dcd42fe commit a62762e

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

python/ouroboros/helpers/slice.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,27 +201,37 @@ def backproject_box(bounding_box: BoundingBox, slice_rects: np.ndarray, slices:
201201
# No slices, just return
202202
return np.empty((0), dtype=np.uint32), np.empty(0, dtype=np.float32), np.empty(0, dtype=np.float32)
203203

204+
# Plot the backprojected X/Y/Z coordinates for each of the slice rects in this chunk.
205+
grid_call = partial(coordinate_grid, shape=slices[0].shape, floor=bounding_box.get_min(), flip=True)
206+
precise_points = np.concatenate(list(map(grid_call, slice_rects)))
207+
208+
# Flatten values to 1-Dimension Array for Efficient Allocation.
209+
# Use ZYX domain rather than XYZ as the former is what is written to disk.
204210
values = slices.flatten()
205211
zyx_shape = np.flip(bounding_box.get_shape())
206212
flat_shape = np.prod(zyx_shape)
207213

208-
grid_call = partial(coordinate_grid, shape=slices[0].shape, floor=bounding_box.get_min(), flip=True)
209-
precise_points = np.concatenate(list(map(grid_call, slice_rects)))
214+
# Determine minimum dtype for index of flattened shape.
215+
squish_type = np.min_scalar_type(flat_shape)
210216

217+
# Allocate the flattened data volume.
211218
volume = np.zeros((2, flat_shape), dtype=np.float32)
212-
squish_type = np.min_scalar_type(flat_shape)
213219

220+
# Get the top corner (integer) points and full weight matrix.
214221
points, weights = _points_and_weights(precise_points.reshape(-1, 3).T, zyx_shape, squish_type)
215222

223+
# Sequentially allocate the points and weights for each corner to the flattened array.
216224
for corner in np.array(list(np.ndindex(2, 2, 2))):
217225
w_values, c_weights = _apply_weights(values, weights, corner)
218226
point_inc = np.ravel_multi_index(corner, zyx_shape).astype(squish_type)
219227

220228
np.add.at(volume[0], points + point_inc, w_values)
221229
np.add.at(volume[1], points + point_inc, c_weights)
222230

231+
# Get indicies of the flattened Z-Y-X backprojected domain that have values.
223232
nz_vol = np.flatnonzero(volume[0])
224233

234+
# Return indicies and only the volume region with values.
225235
return nz_vol, volume[0, nz_vol].squeeze(), volume[1, nz_vol].squeeze()
226236

227237

python/ouroboros/helpers/volume_cache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,22 @@ def update_writable_rects(processed: np.ndarray, slice_rects: np.ndarray, min_di
252252
253253
Parameters:
254254
-----------
255-
processed (np.ndarray): Marker of which chunks are processed,
256-
by their (Z, Y, X) indicies.
255+
processed (np.ndarray): Marker of which chunks are processed,
256+
by their (Z, Y, X) indicies.
257257
slice_rects: All full-size slice rects from the straightened volume.
258258
min_dim (int): Minimum (z) dimension of the full object.
259259
writeable (np.ndarray): Tracker of writable Z-stacks (index 0 = z min_dim).
260-
Values: 0 (not writeable), 1 (writable), 2 (dispatched to writer).
260+
Values: 0 (not writeable), 1 (writable), 2 (dispatched to writer).
261261
chunk_size (int): Size of 3D chunk in (z) dimension.
262262
263263
Return:
264264
-------
265265
np.ndarray: Sorted values in the given dimension that ready to be written to.
266266
267267
"""
268-
# Each chunk covers part of chunk_size slice_rects in z (straightened) dimension,
269-
# except last may be shorter (so capped to length of slice_rects).
270-
# A full slice_rect is ready if all (y, x) chunks for it are processed.
268+
# Each chunk covers part of chunk_size slice_rects in z (straightened) dimension,
269+
# except last may be shorter (so capped to length of slice_rects).
270+
# A full slice_rect is ready if all (y, x) chunks for it are processed.
271271
processed_slices = np.repeat(np.all(processed, axis=(1, 2)), chunk_size)[:len(slice_rects)]
272272
if np.all(processed_slices):
273273
# All slice_rects processed, remaining z (backprojected) slices are to be written.

python/ouroboros/pipeline/backproject_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ def note_written(write_future):
274274
pipeline_input.backprojected_folder_path = folder_path
275275

276276
self.add_timing("export", time.perf_counter() - start)
277-
278-
if config.make_single_file:
277+
278+
if config.make_single_file:
279279
shutil.rmtree(folder_path)
280280

281281
return None

0 commit comments

Comments
 (0)