Skip to content

Commit 9dd5c03

Browse files
committed
refactor: allow different file handling
1 parent f1478de commit 9dd5c03

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

examples/create_downampled.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,29 @@
2121
OUTPUT_PATH.mkdir(exist_ok=True, parents=True)
2222
OVERWRITE = False
2323
NUM_MIPS = 5
24-
MIP_CUTOFF = 3 # To save time you can start at the lowest resolution and work up
25-
NUM_CHANNELS = 2 # For less memory usage (can't be 1 right now though)
24+
MIP_CUTOFF = 0 # To save time you can start at the lowest resolution and work up
25+
NUM_CHANNELS = 4 # For less memory usage (can't be 1 right now though)
2626
NUM_ROWS = 3
2727
NUM_COLS = 6
2828
ALLOW_NON_ALIGNED_WRITE = True
2929

3030
# %% Load the data
3131
OUTPUT_PATH.mkdir(exist_ok=True, parents=True)
32-
# Need to figure out some sizes by checking the data
32+
33+
# You don't need all files if you download them on demand
34+
# See get_file_for_row_col function
3335
all_files = list(INPUTFOLDER.glob("**/*.zarr"))
3436

3537

38+
def get_file_for_row_col(row, col):
39+
"""Get the file path for a specific row and column."""
40+
if row < 0 or row >= NUM_ROWS or col < 0 or col >= NUM_COLS:
41+
raise ValueError("Row and column indices must be within the defined grid.")
42+
index = row * NUM_COLS + col
43+
# You could also download the file here and then delete it after use
44+
return all_files[index] if index < len(all_files) else None
45+
46+
3647
def load_zarr_data(file_path):
3748
zarr_store = zarr.open(file_path, mode="r")
3849
return zarr_store
@@ -136,10 +147,9 @@ def load_data_from_zarr_store(zarr_store):
136147

137148
def process(args):
138149
x_i, y_i, z_i = args
139-
flat_index = x_i * NUM_COLS + y_i
140-
print(f"Processing chunk {flat_index} at coordinates ({x_i}, {y_i}, {z_i})")
141-
# Load the data for this chunk
142-
loaded_zarr_store = load_zarr_data(all_files[flat_index])
150+
file_to_load = get_file_for_row_col(x_i, y_i)
151+
print(f"Processing {file_to_load} at coordinates ({x_i}, {y_i}, {z_i})")
152+
loaded_zarr_store = load_zarr_data(file_to_load)
143153
start = [x_i * chunk_shape[0], y_i * chunk_shape[1], z_i * chunk_shape[2]]
144154
end = [
145155
min((x_i + 1) * chunk_shape[0], shape[0]),

0 commit comments

Comments
 (0)