Project

General

Profile

Read Data From CORDEX Netcdf file

Added by Hassan Sheidaee almost 6 years ago

Hi Guys
I've several NetCDF files of CORDEX. How can I extract data from cordex NetCDF files?
These are rotated pole grids. I want do it by matlab.
Thanks


Replies (6)

RE: Read Data From CORDEX Netcdf file - Added by Karin Meier-Fleischer almost 6 years ago

Hi Hassan,

what do you want to do? Do you want to use CDO to extract a variable from a netCDF file? See the documentation about the CDO operator selvar (or selname). But if you want to use matlab to do it, well, then this isn't the proper forum.

-Karin

RE: Read Data From CORDEX Netcdf file - Added by Hassan Sheidaee almost 6 years ago

Thank you Karin
I want use cordex NetCDF file in CDO or Matlab but I can't know, how can I do it for rotated pole grids? these files has lat/lon and rlat/rlon variables but the values of rlat/rlon is not similar by its domain.

RE: Read Data From CORDEX Netcdf file - Added by Karin Meier-Fleischer almost 6 years ago

The rotated data have rlat,rlon, lat and lon coordinate variables which have to be preserved. This can be done adding the variable attribute coordinates and set it to "lat lon", e.g. for variable pr

cdo setattribute,pr@coordinates="lat lon" infile tmpfile

Now, you can use CDO to extract variables, time steps, regions,.... (see https://code.mpimet.mpg.de/projects/cdo/wiki/Tutorial).

Examples

select variable pr

cdo -selname,pr tmpfile outfile

Select timesteps
cdo -seltimestep,1/12 tmpfile outfile

Select region
cdo -sellonlatbox,-5,15,45,55 tmpfile outfile

-Karin

RE: Read Data From CORDEX Netcdf file - Added by Sohrab Kolsoumi almost 6 years ago

Hi hasan
In cordex Netcdf files lat/lon is 2dimension variables. If you want use rlat/rlon for extract data, firstly, you should convert your regular coordinate to rotated coordinate based on your domain then you can extract data based on rlat/rlon in CDO or any language. If you want convert your data to rotated data you can use this converter:
https://agrimetsoft.com/Cordex%20Coordinate%20Rotation.aspx
GoodLuck

RE: Read Data From CORDEX Netcdf file - Added by Karin Meier-Fleischer almost 6 years ago

Hi Hassan and Sohrab,

CDO is exactly doing what you want and it handles the 2d-rlat/rlon grid correct. Maybe you are using an old CDO version, I'm using 1.9.2. I used to test an EUR-11 CORDEX file.
ncdump -h tas_EUR-11_ICHEC-EC-EARTH_rcp85_r12i1p1_SMHI-RCA4_v1_mon_2006-2100.nc

netcdf tas_EUR-11_ICHEC-EC-EARTH_rcp85_r12i1p1_SMHI-RCA4_v1_mon_2006-2100 {
dimensions:
    x = 424 ;
    y = 412 ;
    time = UNLIMITED ; // (1140 currently)
    nb2 = 2 ;
variables:
    double lon(y, x) ;
        lon:standard_name = "longitude" ;
        lon:long_name = "longitude" ;
        lon:units = "degrees_east" ;
        lon:_CoordinateAxisType = "Lon" ;
    double lat(y, x) ;
        lat:standard_name = "latitude" ;
        lat:long_name = "latitude" ;
        lat:units = "degrees_north" ;
        lat:_CoordinateAxisType = "Lat" ;
    double time(time) ;
        time:standard_name = "time" ;
        time:long_name = "time" ;
        time:bounds = "time_bnds" ;
        time:units = "days since 1949-12-01 00:00:00" ;
        time:calendar = "standard" ;
    double time_bnds(time, nb2) ;
        time_bnds:units = "days since 1949-12-01 00:00:00" ;
        time_bnds:calendar = "standard" ;
    float tas(time, y, x) ;
        tas:standard_name = "air_temperature" ;
        tas:long_name = "Near-Surface Air Temperature" ;
        tas:units = "K" ;
        tas:coordinates = "lon lat" ;
        tas:_FillValue = 1.e+20f ;
        tas:missing_value = 1.e+20f ;
        tas:cell_methods = "time: mean" ;

// global attributes:
    ....

It is required that the variable has the coordinates attribute set to lat lon. The variables lat and lon must be stored in the same file. If there is no coordinates attribute but lat and lon are stored in the file you can add the coordinate attribute to the variable by

cdo setattribute,tas@coordinates="lat lon" infile.nc infile_with_coordinates.nc

The following commands show how to work with CDO.

Select time step 1:

cdo -seltimestep,1 tas_EUR-11_ICHEC-EC-EARTH_rcp85_r12i1p1_SMHI-RCA4_v1_mon_2006-2100.nc tmp-0.nc

Select variable tas and only the first time step:

cdo -seltimestep,1 -selname,tas tas_EUR-11_ICHEC-EC-EARTH_rcp85_r12i1p1_SMHI-RCA4_v1_mon_2006-2100.nc tmp-1.nc

Select a sub-region which is in the range of the EUR-11 lat/lon area:

cdo -sellonlatbox,-5,15,45,55 tas_EUR-11_ICHEC-EC-EARTH_rcp85_r12i1p1_SMHI-RCA4_v1_mon_2006-2100.nc tmp-2.nc

-Karin

RE: Read Data From CORDEX Netcdf file - Added by Sohrab Kolsoumi almost 6 years ago

That's good
Thank you so much

    (1-6/6)