diff --git a/lib/cartopy/img_transform.py b/lib/cartopy/img_transform.py index 2ddf61641..21c4e7fd2 100644 --- a/lib/cartopy/img_transform.py +++ b/lib/cartopy/img_transform.py @@ -219,7 +219,7 @@ def _determine_bounds(x_coords, y_coords, source_cs): return bounds -def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj, +def regrid(array, source_x_coords, source_y_coords, source_proj, target_proj, target_x_points, target_y_points, mask_extrapolated=False): """ Regrid the data array from the source projection to the target projection. @@ -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 @@ -256,12 +256,13 @@ def regrid(array, source_x_coords, source_y_coords, source_cs, target_proj, The data array regridded in the target projection. """ + # 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()) @@ -293,7 +294,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, @@ -323,7 +324,8 @@ 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]))