Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

What does wrf-python function ll_to_xy() returns?

SunJianping

New member
I'm trying to interpolate some data based on the projection coordinate system, and I find that the output of ll_to_xy() function is different from which returned by cartopy method cartopy.crs.Projection.transform_point(). Here is an example:
Python:
from netCDF4 import Dataset
from wrf import getvar, CoordPair, xy_to_ll, ll_to_xy, get_cartopy, latlon_coords
import cartopy.crs as ccrs

wrfout = Dataset('wrfout_d01_2019-08-07_00_00_00')
slp = getvar(wrfout, 'slp', timeidx=0)
cart_proj = get_cartopy(slp)
xy_cartopy = cart_proj.transform_point(122, 30, ccrs.PlateCarree())
xy_wrfpy = ll_to_xy(wrfout, 30, 122, as_int=False)
print(xy_cartopy)
print(xy_wrfpy)

Result:
Python:
(204023.2701774671, 70339.28035986092)
<xarray.DataArray 'xy' (x_y: 2)>
array([121.50213256, 119.3614694 ])
Coordinates:
    latlon_coord  object CoordPair(lat=30, lon=122)
  * x_y           (x_y) <U1 'x' 'y'

I've tried other map projection calculators and have confirmed that the result given by cartopy is correct. So what excactly does ll_to_xy returns? Looking forward to any replies.
 
Last edited:
I'm trying to interpolate some data based on the projection coordinate system, and I find that the output of ll_to_xy() function is different from which returned by cartopy method cartopy.crs.Projection.transform_point(). Here is an example:
Python:
from netCDF4 import Dataset
from wrf import getvar, CoordPair, xy_to_ll, ll_to_xy, get_cartopy, latlon_coords
import cartopy.crs as ccrs

wrfout = Dataset('wrfout_d01_2019-08-07_00_00_00')
slp = getvar(wrfout, 'slp', timeidx=0)
cart_proj = get_cartopy(slp)
xy_cartopy = cart_proj.transform_point(122, 30, ccrs.PlateCarree())
xy_wrfpy = ll_to_xy(wrfout, 30, 122, as_int=False)
print(xy_cartopy)
print(xy_wrfpy)

Result:
Python:
(204023.2701774671, 70339.28035986092)
<xarray.DataArray 'xy' (x_y: 2)>
array([121.50213256, 119.3614694 ])
Coordinates:
    latlon_coord  object CoordPair(lat=30, lon=122)
  * x_y           (x_y) <U1 'x' 'y'

I've tried other map pprojection caculators and have confirmed that the result given by cartopy is correct. So what excactly does ll_to_xy returns? Looking forward to any replies.
OK, I get it. What ll_to_xy returns is not the xy coordinate itself but the grid index starting from 0.
 
Top