@@ -215,16 +215,9 @@ def bin_to_grid_numpy(ds: xr.Dataset, bands: Iterable[str], grid: Grid,*, super_
215215 bin_idx_row = np .divide ((lat - grid .lat [0 ]), pixel_size , out = bin_idx_buf ).astype (int )
216216 bin_idx_col = np .divide ((lon - grid .lon [0 ]), pixel_size , out = bin_idx_buf ).astype (int )
217217
218- bin_idx = bin_idx_row * width
219- bin_idx += bin_idx_col
220-
221-
218+ bin_idx = bin_idx_row * width + bin_idx_col
222219
223220 bin_idx [(bin_idx_row < 0 ) | (bin_idx_row > height ) | (bin_idx_col < 0 ) | (bin_idx_col > width )] = - 1
224- #bin_idx[(bin_idx_row < 0)] = -1
225- #bin_idx[(bin_idx_row > height)] = -1
226- #bin_idx[(bin_idx_col < 0)] = -1
227- #bin_idx[(bin_idx_col > width)] = -1
228221
229222 counts , _ = np .histogram (bin_idx , width * height , range = (0 , width * height ))
230223
@@ -241,6 +234,7 @@ def bin_to_grid_numpy(ds: xr.Dataset, bands: Iterable[str], grid: Grid,*, super_
241234 else :
242235 sampled_data = data
243236
237+ # Promote datatype to avoid overflows
244238 hist , _ = np .histogram (bin_idx , range (width * height + 1 ), weights = sampled_data .astype (np .int32 ).reshape (- 1 ), range = (0 , width * height ))
245239 means = np .divide (hist , counts , out = means )
246240 scaled_means = means .reshape (height , width ) * SCALE_FACTOR
0 commit comments