metno / NWPdocs

Description of the numerical weather prediction products at MET Norway
GNU General Public License v3.0
14 stars 4 forks source link

X, Y = proj.transform(lat, lon) ? #21

Closed paapu88 closed 1 year ago

paapu88 commented 1 year ago

Dear developers, I have to change the order of lat lon in https://github.com/metno/NWPdocs/wiki/Examples#plotting-timeseries-for-the-nearest-neighbour-of-a-lonlat-point to get it work for Helsinki (MET Nordic dataset version3)

With code below helsinki position is ok (lat, lon order changed in transform compared to example above)

ds=xr.open_mfdataset("met_analysis_1_0km_nordic_20200912T12Z.nc")
lat=60.205791,
lon=24.929186,
crs= "+proj=lcc +lat_0=63 +lon_0=15 +lat_1=63 +lat_2=63 +no_defs +R=6.371e+06",
xname='x',
yname='y',
proj = pyproj.Proj.from_crs("4326", crs)
X, Y = proj.transform(lat, lon)
# Find nearest neighbour
x = ds.variables[xname].to_numpy()
y = ds.variables[yname].to_numpy()
Ix = np.argmin(np.abs(x - X))
Iy = np.argmin(np.abs(y - Y))
tnipen commented 1 year ago

Thanks for the feedback.Yes, I think with newer versions of pyproj, you either need to do as suggested, or use: proj = pyproj.Proj.from_crs("4326", crs, always_xy=True)

We will update the examples.

paapu88 commented 1 year ago

thanks! I guess there is nowadays options for using keywords like latitude, longitude for pyproj.Proj so there should be no room for confusion.

tnipen commented 1 year ago

Yes, that is true. Good point.