Skip to content

Commit 8ff4fbf

Browse files
moved method (#138)
1 parent f2ffc90 commit 8ff4fbf

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

wkcuber/cubing.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from natsort import natsorted
77

88
from .mag import Mag
9-
from .downsampling import downsample_cube, parse_interpolation_mode
9+
from .downsampling import parse_interpolation_mode, downsample_unpadded_data
1010
from .utils import (
1111
get_chunks,
1212
find_files,
@@ -193,29 +193,6 @@ def cubing_job(args):
193193
raise exc
194194

195195

196-
def downsample_unpadded_data(buffer, target_mag, interpolation_mode):
197-
logging.info(
198-
f"Downsampling buffer of size {buffer.shape} to mag {target_mag.to_layer_name()}"
199-
)
200-
target_mag_np = np.array(target_mag.to_array())
201-
current_dimension_size = np.array(buffer.shape[1:])
202-
padding_size_for_downsampling = (
203-
target_mag_np - (current_dimension_size % target_mag_np) % target_mag_np
204-
)
205-
padding_size_for_downsampling = list(zip([0, 0, 0], padding_size_for_downsampling))
206-
buffer = np.pad(
207-
buffer, pad_width=[(0, 0)] + padding_size_for_downsampling, mode="constant"
208-
)
209-
dimension_decrease = np.array([1] + target_mag.to_array())
210-
downsampled_buffer_shape = np.array(buffer.shape) // dimension_decrease
211-
downsampled_buffer = np.empty(dtype=buffer.dtype, shape=downsampled_buffer_shape)
212-
for channel in range(buffer.shape[0]):
213-
downsampled_buffer[channel] = downsample_cube(
214-
buffer[channel], target_mag.to_array(), interpolation_mode
215-
)
216-
return downsampled_buffer
217-
218-
219196
def cubing(source_path, target_path, layer_name, dtype, batch_size, args=None) -> dict:
220197

221198
target_mag = Mag(args.target_mag)

wkcuber/downsampling.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,29 @@ def downsample_cube(cube_buffer, factors, interpolation_mode):
412412
raise Exception("Invalid interpolation mode: {}".format(interpolation_mode))
413413

414414

415+
def downsample_unpadded_data(buffer, target_mag, interpolation_mode):
416+
logging.info(
417+
f"Downsampling buffer of size {buffer.shape} to mag {target_mag.to_layer_name()}"
418+
)
419+
target_mag_np = np.array(target_mag.to_array())
420+
current_dimension_size = np.array(buffer.shape[1:])
421+
padding_size_for_downsampling = (
422+
target_mag_np - (current_dimension_size % target_mag_np) % target_mag_np
423+
)
424+
padding_size_for_downsampling = list(zip([0, 0, 0], padding_size_for_downsampling))
425+
buffer = np.pad(
426+
buffer, pad_width=[(0, 0)] + padding_size_for_downsampling, mode="constant"
427+
)
428+
dimension_decrease = np.array([1] + target_mag.to_array())
429+
downsampled_buffer_shape = np.array(buffer.shape) // dimension_decrease
430+
downsampled_buffer = np.empty(dtype=buffer.dtype, shape=downsampled_buffer_shape)
431+
for channel in range(buffer.shape[0]):
432+
downsampled_buffer[channel] = downsample_cube(
433+
buffer[channel], target_mag.to_array(), interpolation_mode
434+
)
435+
return downsampled_buffer
436+
437+
415438
def downsample_mag(
416439
path,
417440
layer_name,

0 commit comments

Comments
 (0)