Skip to content

Commit

Permalink
Merge pull request #2077 from guziy/z-coord-for-crs
Browse files Browse the repository at this point in the history
Calculate vertical coord, even if not explicitely requested
  • Loading branch information
dopplershift authored Sep 7, 2022
2 parents 8c31a15 + 71c4f7b commit 8124fcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def _get_transformer_from_crs(src_crs, tgt_crs):

def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True):
transformer = _get_transformer_from_crs(src_crs, tgt_crs)
transformed_coords = transformer.transform(x, y, z, errcheck=trap)

# if a projection is essentially 2d there
# should be no harm in setting its z to 0
if z is None:
xx, yy = transformed_coords
zz = 0
else:
xx, yy, zz = transformed_coords
return xx, yy, zz
z = np.zeros_like(x)

return transformer.transform(x, y, z, errcheck=trap)


class Globe:
Expand Down
3 changes: 1 addition & 2 deletions lib/cartopy/tests/test_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ def test_transform_points_outside_domain():
crs = ccrs.Orthographic()
result = crs.transform_points(ccrs.PlateCarree(),
np.array([-120]), np.array([80]))
assert np.all(np.isnan(result[..., :2]))
assert result[..., -1] == 0
assert np.all(np.isnan(result))
result = crs.transform_points(ccrs.PlateCarree(),
np.array([-120]), np.array([80]),
trap=True)
Expand Down

0 comments on commit 8124fcb

Please sign in to comment.