@@ -132,8 +132,10 @@ def _downsample_by_one_level(
132
132
level = coarse_level
133
133
fine_level = level - 1
134
134
lev_shape = self ._get_level_shape (level )
135
+
135
136
field1 = zarr .open (self .zarr_store_path )[zarr_field ]
136
- field1 .empty (level , shape = lev_shape , chunks = self .chunks )
137
+ dtype = field1 [fine_level ].dtype
138
+ field1 .empty (level , shape = lev_shape , chunks = self .chunks , dtype = dtype )
137
139
138
140
numchunks = field1 [str (level )].nchunks
139
141
@@ -197,7 +199,8 @@ def _write_chunk_values(
197
199
)
198
200
199
201
coarse_zarr = zarr .open (zarr_file )[zarr_field ][str (level )]
200
- coarse_zarr [si [0 ] : ei [0 ], si [1 ] : ei [1 ] :, si [2 ] : ei [2 ]] = outvals
202
+ dtype = coarse_zarr .dtype
203
+ coarse_zarr [si [0 ] : ei [0 ], si [1 ] : ei [1 ] :, si [2 ] : ei [2 ]] = outvals .astype (dtype )
201
204
202
205
return 1
203
206
@@ -208,15 +211,27 @@ def initialize_test_image(
208
211
base_resolution : tuple [int , int , int ],
209
212
chunks : int | tuple [int , int , int ] | None = None ,
210
213
overwrite_field : bool = True ,
214
+ dtype : str | type | None = None ,
211
215
) -> None :
216
+ if dtype is None :
217
+ dtype = np .float64
212
218
field1 = zarr_store .create_group (zarr_field , overwrite = overwrite_field )
213
219
214
220
if chunks is None :
215
221
chunks = (64 , 64 , 64 )
216
- lev0 = da .random .random (base_resolution , chunks = chunks )
222
+ fac : int | float
223
+ if np .issubdtype (dtype , np .integer ):
224
+ fac = 100
225
+ elif np .issubdtype (dtype , np .floating ):
226
+ fac = 1.0
227
+ else :
228
+ msg = f"Unexpected dtype of { dtype } "
229
+ raise RuntimeError (msg )
230
+ lev0 = fac * da .random .random (base_resolution , chunks = chunks )
231
+ lev0 = lev0 .astype (dtype )
217
232
halfway = np .asarray (base_resolution ) // 2
218
233
lev0 [0 : halfway [0 ], 0 : halfway [1 ], 0 : halfway [2 ]] = (
219
- lev0 [0 : halfway [0 ], 0 : halfway [1 ], 0 : halfway [2 ]] + 0.5
234
+ lev0 [0 : halfway [0 ], 0 : halfway [1 ], 0 : halfway [2 ]] + 0.5 * fac
220
235
)
221
- field1 .empty (0 , shape = base_resolution , chunks = chunks )
236
+ field1 .empty (0 , shape = base_resolution , chunks = chunks , dtype = dtype )
222
237
da .to_zarr (lev0 , field1 ["0" ])
0 commit comments