Regrid grid_mapping = "latitude_longitude" to normal regular lat-lon grid?
Added by Bang AA over 1 year ago
I've this netCDF file which has this latitude_longitude grid mapping ( lat(y, x) and lon(y, x) )
which I would like to regrid it to regular netCDF file with cdo.
Please help me with this command as I don't know how to do that.
Here is the output of ncdump -h
dimensions:
time = UNLIMITED ; // (1 currently)
x = 194 ;
y = 200 ;
height_2m = 1 ;
variables:
double time(time) ;
time:standard_name = "time" ;
time:units = "days since 2006-01-01" ;
time:calendar = "proleptic_gregorian" ;
time:axis = "T" ;
float lon(y, x) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:_CoordinateAxisType = "Lon" ;
float lat(y, x) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:_CoordinateAxisType = "Lat" ;
int64 latitude_longitude ;
latitude_longitude:semi_major_axis = 6371229. ;
latitude_longitude:grid_mapping_name = "latitude_longitude" ;
float height_2m(height_2m) ;
height_2m:standard_name = "height" ;
height_2m:long_name = "height above the surface" ;
height_2m:units = "m" ;
height_2m:positive = "up" ;
height_2m:axis = "Z" ;
float T_2M(time, height_2m, y, x) ;
T_2M:standard_name = "air_temperature" ;
T_2M:long_name = "2m temperature" ;
T_2M:units = "K" ;
T_2M:grid_mapping = "latitude_longitude" ;
T_2M:coordinates = "lat lon" ;
T_2M:_FillValue = NaNf ;
T_2M:missing_value = NaNf ;
float TOT_PREC(time, y, x) ;
TOT_PREC:standard_name = "precipitation_amount" ;
TOT_PREC:long_name = "total precipitation amount" ;
TOT_PREC:units = "kg m-2" ;
TOT_PREC:grid_mapping = "latitude_longitude" ;
TOT_PREC:coordinates = "lat lon" ;
TOT_PREC:_FillValue = NaNf ;
TOT_PREC:missing_value = NaNf ;
TOT_PREC:cell_methods = "time: sum" ;
Replies (5)
RE: Regrid grid_mapping = "latitude_longitude" to normal regular lat-lon grid? - Added by Karin Meier-Fleischer over 1 year ago
Hi Bang,
to remap you can use one of the remap operators, e.g. remapnn.
Remap to global 1x1 degree grid:
cdo -remapnn,global_1 test_clima_COSMO_subset.nc outfile.nc
RE: Regrid grid_mapping = "latitude_longitude" to normal regular lat-lon grid? - Added by Bang AA over 1 year ago
Hi Karin,
Thanks for your reply. However, this file test_clima_COSMO_subset.nc is not global data but somewhere around Italy. Please see the output of
cdo griddes test_clima_COSMO_subset.nc > /tmp/test.txt
https://privatebin.net/?6c5a27100c00c1fe#HvLCaFr4X8HZjmfB7u41PGZwkCZ6wGk3GNuQ8p1aLUhF
RE: Regrid grid_mapping = "latitude_longitude" to normal regular lat-lon grid? - Added by Karin Meier-Fleischer over 1 year ago
There are many post in the forum about regridding a subregion. You can find a simple example in our FAQ, see https://code.mpimet.mpg.de/projects/cdo/wiki/FAQ#How-to-interpolateremap-my-data-to-another-grid
RE: Regrid grid_mapping = "latitude_longitude" to normal regular lat-lon grid? - Added by Bang AA over 1 year ago
@Karin: so I prepared gridfile.txt like below:
gridtype = lonlat
xsize = 194
ysize = 200
xfirst = 3.475573
xinc = 0.033333333
yfirst = 36.03576
yinc = 0.033333333
With the values (xsize, ysize), xfirst from first value of xvals and yfrist from first value yvals
copied from https://privatebin.net/?6c5a27100c00c1fe#HvLCaFr4X8HZjmfB7u41PGZwkCZ6wGk3GNuQ8p1aLUhF
and xinc and yinc (can be something else) copied from https://code.mpimet.mpg.de/projects/cdo/wiki/FAQ#How-to-interpolateremap-my-data-to-another-grid
Please check if I'm correct when I created gridfile.txt with this content.
Thanks!
RE: Regrid grid_mapping = "latitude_longitude" to normal regular lat-lon grid? - Added by Bang AA over 1 year ago
Ok, I created the python code to get these values properly.
# import netCDF4 as nc # ds = nc.Dataset("test_clima_COSMO_subset.nc") gridtype = lonlat xsize = 194 # ds['lon'].shape[1] ysize = 200 # ds['lon'].shape[0] xfirst = 1.5041884 # np.min(ds['lon'][:]) xinc = 0.11094939831605892 # ( np.max(ds['lon'][:]) - np.min(ds['lon'][:]) ) / ds['lon'].shape[1] yfirst = 35.710938 # np.min(ds['lat'][:]) yinc = 0.07395030975341797 # ( np.max(ds['lat'][:]) - np.min(ds['lat'][:]) ) / ds['lat'].shape[0]