-
Hi all! I am wondering if you have any tips/tricks on how to convert GeoX and GeoY coordinates to lat/lon? My goal is to take a slice of the RTMA data for a region rather than downloading the complete dataset for all across the country. I've looked online and I haven't found any good tutorials on this topic so I figured I'd ask here. Thanks! Regards, Eric |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @edrewitz This should be relatively straightforward using some of the accessors we have available in MetPy. Below is some example code that will read RTMA data available on the Unidata THREDDS server, but this should also work with local data. The key is that we need to first parse the coordinate reference system before we can add the latitude/longitude values. import xarray as xr
from metpy.units import units
ds = xr.open_dataset(
'https://thredds-jumbo.unidata.ucar.edu/thredds/dodsC/grib/NCEP/'
'RTMA/CONUS_2p5km/RTMA_CONUS_2p5km_20230830_1500.grib2'
).metpy.parse_cf().metpy.assign_latitude_longitude() This will then add two new variables to each DataArray: latitude, longitude. You could then be able to subset the dataset using latitude and longitude. ds_subset = ds.metpy.sel(y=((ds.latitude > 30) & (ds.latitude < 50)).y,
x=((ds.longitude > -125) & (ds.longitude < -90)).x) Currently, our magic is not recognizing everything it needs to to be able to directly subset via latitude and longitude directly, but the above will work. You should be able to change that to the desired domain to help facilitate only bringing in the desired data instead of the full array. |
Beta Was this translation helpful? Give feedback.
Hi @edrewitz
This should be relatively straightforward using some of the accessors we have available in MetPy. Below is some example code that will read RTMA data available on the Unidata THREDDS server, but this should also work with local data. The key is that we need to first parse the coordinate reference system before we can add the latitude/longitude values.
This will then add two new variables to each DataArray: latitude, long…