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

regression bug in cartopy 0.20?, as_geocentric() not functionning as expected #2032

Closed
dja001 opened this issue Apr 4, 2022 · 4 comments · Fixed by #2077
Closed

regression bug in cartopy 0.20?, as_geocentric() not functionning as expected #2032

dja001 opened this issue Apr 4, 2022 · 4 comments · Fixed by #2077

Comments

@dja001
Copy link

dja001 commented Apr 4, 2022

Description

I use cartopy.crs.Geodetic().as_geocentric() to get x,y,z coordinates from lat/lon. Since the introduction of cartopy 0.20, this functionality appears to be broken with the returned z-component always zero.

Code to reproduce

The problem can be reproduced with a few lines of code:

import numpy as np
import cartopy

crs = cartopy.crs.Geodetic()
geo_cent = crs.as_geocentric()

out = geo_cent.transform_points(crs, np.array([0.]), np.array([45.]))
print('[x,y,z] from lon=0, lat=45 : ', out)

In cartopy 0.19, output is :


[x,y,z] from  lon=0, lat=45 :  [[4517590.87884893       0.         4487348.40886592]]

as expected.

In cartopy 0.20 output is:


[x,y,z] from lon=0, lat=45 :  [[4517590.87884893       0.               0.        ]]

with the z component equal to zero while it should not.

Operating system

linux

Cartopy version

Problem in 0.20

conda list

Test environments created with:
conda create -n cartopy19 -c conda-forge cartopy=0.19.0.post1
and
conda create -n cartopy20 -c conda-forge cartopy

@guziy
Copy link
Contributor

guziy commented Sep 1, 2022

It seems like in 0.20 z computed only if z is provided as input...

In [18]: import numpy as np
    ...: import cartopy
    ...:
    ...: crs = cartopy.crs.Geodetic()
    ...: geo_cent = crs.as_geocentric()
    ...:
    ...: out = geo_cent.transform_points(crs, np.array([0.]), np.array([45.]), np.array([0]))
    ...: print('[x,y,z] from lon=0, lat=45 : ', out)
[x,y,z] from lon=0, lat=45 :  [[4517590.87884893       0.         4487348.40886592]]

@guziy
Copy link
Contributor

guziy commented Sep 1, 2022

I agree with Dominik, It should be computed every time it is returned...

@greglucas
Copy link
Contributor

Likely because of this check:

if z is None:
xx, yy = transformed_coords
zz = 0

A PR to update this would be welcome!

@dja001
Copy link
Author

dja001 commented Sep 8, 2022

Thanks a lot everyone for contributing to fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants