Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate vertical coord, even if not explicitely requested #2077

Merged
merged 3 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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