Skip to content

Commit

Permalink
GH#2013 Make img_transform.regrid API consistent with img_transform.w…
Browse files Browse the repository at this point in the history
…rap_array
  • Loading branch information
ellequelle committed Mar 10, 2022
1 parent 22cdafc commit 2b2b48c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/cartopy/img_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def _determine_bounds(x_coords, y_coords, source_cs):
return bounds


def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj,
target_x_points, target_y_points, mask_extrapolated=False):
def regrid(array, source_x_coords, source_y_coords, source_proj, target_proj,
target_x_points, target_y_points, mask_extrapolated=False, source_cs=None):
"""
Regrid the data array from the source projection to the target projection.
Expand All @@ -235,9 +235,9 @@ def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj,
source_y_coords
A 2-dimensional source projection :class:`numpy.ndarray` of
y-direction sample points.
source_cs
source_proj
The source :class:`~cartopy.crs.Projection` instance.
target_cs
target_proj
The target :class:`~cartopy.crs.Projection` instance.
target_x_points
A 2-dimensional target projection :class:`numpy.ndarray` of
Expand All @@ -249,19 +249,25 @@ def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj,
Assume that the source coordinate is rectilinear and so mask the
resulting target grid values which lie outside the source grid domain.
Defaults to False.
source_cs
Deprecated, please use source_proj instead.
Returns
-------
new_array
The data array regridded in the target projection.
"""
if source_cs is not None:
warnings.warn("The source_cs keyword argument is deprecated. Please use source_proj instead.")
source_proj = source_cs

# Stack our original xyz array, this will also wrap coords when necessary
xyz = source_cs.transform_points(source_cs,
xyz = source_proj.transform_points(source_proj,
source_x_coords.flatten(),
source_y_coords.flatten())
# Transform the target points into the source projection
target_xyz = source_cs.transform_points(target_proj,
target_xyz = source_proj.transform_points(target_proj,
target_x_points.flatten(),
target_y_points.flatten())

Expand Down Expand Up @@ -293,7 +299,7 @@ def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj,
# to the same point to within a fixed fractional offset.
# NOTE: This only needs to be done for (pseudo-)cylindrical projections,
# or any others which have the concept of wrapping
back_to_target_xyz = target_proj.transform_points(source_cs,
back_to_target_xyz = target_proj.transform_points(source_proj,
target_xyz[:, 0],
target_xyz[:, 1])
back_to_target_x = back_to_target_xyz[:, 0].reshape(desired_ny,
Expand Down Expand Up @@ -323,7 +329,7 @@ def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj,
target_in_source_y = target_xyz[:, 1].reshape(desired_ny,
desired_nx)

bounds = _determine_bounds(source_x_coords, source_y_coords, source_cs)
bounds = _determine_bounds(source_x_coords, source_y_coords, source_proj)

outside_source_domain = ((target_in_source_y >= bounds['y'][1]) |
(target_in_source_y <= bounds['y'][0]))
Expand Down

0 comments on commit 2b2b48c

Please sign in to comment.