Skip to content

Commit

Permalink
_regrid_area_weighted_array: move indices variable nearer to use (Sci…
Browse files Browse the repository at this point in the history
  • Loading branch information
abooton authored and pp-mo committed Jan 14, 2020
1 parent e9fcace commit d793977
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/iris/experimental/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ def _regrid_area_weighted_array(src_data, x_dim, y_dim,
# Assign to mask to explode it, allowing indexed assignment.
new_data.mask = False

indices = [slice(None)] * new_data.ndim

# Determine which grid bounds are within src extent.
y_within_bounds = _within_bounds(src_y_bounds, grid_y_bounds,
grid_y_decreasing)
Expand All @@ -511,6 +509,7 @@ def _regrid_area_weighted_array(src_data, x_dim, y_dim,
axis = tuple(axes)

# Simple for loop approach.
indices = [slice(None)] * new_data.ndim
for j, (y_0, y_1) in enumerate(grid_y_bounds):
# Reverse lower and upper if dest grid is decreasing.
if grid_y_decreasing:
Expand Down Expand Up @@ -542,14 +541,16 @@ def _regrid_area_weighted_array(src_data, x_dim, y_dim,
# Calculate weighted mean of data points.
# Slice out relevant data (this may or may not be a view()
# depending on x_indices being a slice or not).
if isinstance(x_indices, tuple) and isinstance(
y_indices, tuple
):
raise RuntimeError(
"Cannot handle split bounds " "in both x and y."
)
if x_dim is not None:
indices[x_dim] = x_indices
if y_dim is not None:
indices[y_dim] = y_indices
if isinstance(x_indices, tuple) and \
isinstance(y_indices, tuple):
raise RuntimeError('Cannot handle split bounds '
'in both x and y.')
data = src_data[tuple(indices)]

# Calculate weights based on areas of cropped bounds.
Expand Down

0 comments on commit d793977

Please sign in to comment.