From b0d3fedcbd620b2e71dfe4c3cb8a56bc6a4a6bd8 Mon Sep 17 00:00:00 2001 From: Cole Frederick Date: Wed, 1 Sep 2021 10:19:42 -0600 Subject: [PATCH] Pull apart patch into 3 separate indices for Numpy array --- READY/patch.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/READY/patch.py b/READY/patch.py index 5a3e2e0..6e26532 100644 --- a/READY/patch.py +++ b/READY/patch.py @@ -20,13 +20,19 @@ def all_patches(samples, x, y, patch_size): DNB[p] where p is a patch identifier.""" return list(it.product(range(samples), slices(x, patch_size), slices(y, patch_size))) +def index(arr, patch): + i, rows, cols = patch + return arr[i, rows.start:rows.stop, cols.start:cols.stop] + def patch_case(case, patch_size=256): shape = case['latitude'].shape a_patches = all_patches(shape[0], shape[1], shape[2], patch_size) arr_channels = case['channels'] meta_channels = [ch for ch in case.files if ch not in arr_channels] log.info(f'Patching channels: {arr_channels}') - arr_data = {c: np.stack([case[c][p] for p in a_patches], axis=-1) + #arr_data = {c: np.stack([case[c][p] for p in a_patches], axis=-1) + # for c in arr_channels} + arr_data = {c: np.stack([index(case[c], p) for p in a_patches], axis=-1) for c in arr_channels} metas = {c: case[c] for c in meta_channels} patch_samples = [case['samples'][p[0]] for p in a_patches]