Skip to content

Commit 18f50bf

Browse files
committed
Make spline interpolation multi-band aware
Refs #78
1 parent a4d8628 commit 18f50bf

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

marblecutter/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def read_window(src, (bounds, bounds_crs), (height, width)):
262262
0, r[0] - buffer_pixels[1]), r[1] + buffer_pixels[1]), (max(
263263
0, c[0] - buffer_pixels[0]), c[1] + buffer_pixels[0]))
264264

265-
data = vrt.read(1, window=window)
265+
data = vrt.read(window=window)
266266

267267
# mask with NODATA values
268268
if vrt.nodata is not None:
@@ -282,10 +282,10 @@ def read_window(src, (bounds, bounds_crs), (height, width)):
282282
"Applying spline interpolation with order %d (scale factor: %s)",
283283
order, scale_factor)
284284

285-
zoom = (round(1 / scale_factor[1]), round(1 / scale_factor[0]))
285+
zoom = (1, round(1 / scale_factor[1]), round(1 / scale_factor[0]))
286286

287-
LOG.info("target dimensions: %s", (data.shape[0] * zoom[0],
288-
data.shape[1] * zoom[1]))
287+
LOG.info("target dimensions: %s", (data.shape[1] * zoom[1],
288+
data.shape[2] * zoom[2]))
289289

290290
# resample data, respecting NODATA values
291291
data = ndimage.zoom(
@@ -294,22 +294,22 @@ def read_window(src, (bounds, bounds_crs), (height, width)):
294294
zoom,
295295
order=order)
296296

297-
scaled_buffer = (int((data.shape[1] - width) / 2), int(
298-
(data.shape[0] - height) / 2))
297+
scaled_buffer = (int((data.shape[2] - width) / 2), int(
298+
(data.shape[1] - height) / 2))
299299

300300
# crop data
301-
data = data[scaled_buffer[1]:scaled_buffer[1] + height,
301+
data = data[:, scaled_buffer[1]:scaled_buffer[1] + height,
302302
scaled_buffer[0]:scaled_buffer[0] + width]
303303

304304
if len(mask.shape) > 0:
305305
mask = ndimage.zoom(mask, zoom, mode='nearest')
306306

307307
# crop mask
308-
mask = mask[scaled_buffer[1]:scaled_buffer[1] + height,
308+
mask = mask[:, scaled_buffer[1]:scaled_buffer[1] + height,
309309
scaled_buffer[0]:scaled_buffer[0] + width]
310310

311311
# copy the mask over
312-
data = np.ma.masked_array(data, mask=mask)[np.newaxis]
312+
data = np.ma.masked_array(data, mask=mask)
313313
else:
314314
data = vrt.read(
315315
out_shape=(vrt.count, height, width), window=dst_window)

0 commit comments

Comments
 (0)