Project

General

Profile

Subsetting SCRIP grid file

Added by Thiago dos Santos almost 6 years ago

Dear all,

I am trying to spatially subset one of the CESM surface datasets, which I am quite sure is a mask file encapsulated in a SCRIP grid file. This is the header of the file:

netcdf map_0.5x0.5_nomask_to_360x720_nomask_aave_da_c120830 {
dimensions:
    n_a = 259200 ;
    n_b = 259200 ;
    n_s = 259200 ;
    nv_a = 4 ;
    nv_b = 4 ;
    num_wgts = 1 ;
    src_grid_rank = 2 ;
    dst_grid_rank = 2 ;
variables:
    int src_grid_dims(src_grid_rank) ;
    int dst_grid_dims(dst_grid_rank) ;
    double yc_a(n_a) ;
        yc_a:units = "degrees" ;
    double yc_b(n_b) ;
        yc_b:units = "degrees" ;
    double xc_a(n_a) ;
        xc_a:units = "degrees" ;
    double xc_b(n_b) ;
        xc_b:units = "degrees" ;
    double yv_a(n_a, nv_a) ;
        yv_a:units = "degrees" ;
    double xv_a(n_a, nv_a) ;
        xv_a:units = "degrees" ;
    double yv_b(n_b, nv_b) ;
        yv_b:units = "degrees" ;
    double xv_b(n_b, nv_b) ;
        xv_b:units = "degrees" ;
    int mask_a(n_a) ;
        mask_a:units = "unitless" ;
    int mask_b(n_b) ;
        mask_b:units = "unitless" ;
    double area_a(n_a) ;
        area_a:units = "square radians" ;
    double area_b(n_b) ;
        area_b:units = "square radians" ;
    double frac_a(n_a) ;
        frac_a:units = "unitless" ;
    double frac_b(n_b) ;
        frac_b:units = "unitless" ;
    int col(n_s) ;
    int row(n_s) ;
    double S(n_s) ;

// global attributes:
        :title = "ESMF Offline Regridding Weight Generator" ;
        :normalization = "destarea" ;
        :map_method = "Conservative remapping" ;
        :conventions = "NCAR-CSM" ;
        :domain_a = "/glade/proj3/cseg/inputdata/lnd/clm2/mappingdata/grids/SCRIPgrid_0.5x0.5_nomask_c110308.nc" ;
        :domain_b = "/glade/proj3/cseg/inputdata/lnd/clm2/mappingdata/grids/SCRIPgrid_360x720_nomask_c120830.nc" ;
        :grid_file_src = "/glade/proj3/cseg/inputdata/lnd/clm2/mappingdata/grids/SCRIPgrid_0.5x0.5_nomask_c110308.nc" ;
        :grid_file_dst = "/glade/proj3/cseg/inputdata/lnd/clm2/mappingdata/grids/SCRIPgrid_360x720_nomask_c120830.nc" ;
        :CVS_revision = "5.2.0rp1 beta snapshot" ;
        :history = "Thu Aug 30 12:49:01 2012: ncatted -a history,global,a,c,/contrib/esmf-5.2.0rp1bs09-64/bin/ESMF_RegridWeightGen map_0.5x0.5_nomask_to_360x720_nomask_aave_da_c120830.nc\n",
            "/contrib/esmf-5.2.0rp1bs09-64/bin/ESMF_RegridWeightGen" ;
        :hostname = "be1005en.ucar.edu" ;
        :logname = "erik" ;
data:

 src_grid_dims = 720, 360 ;

 dst_grid_dims = 720, 360 ;

 yc_a = -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, 
    -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, 
    -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, 
    -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, 

(and so on). The full file is attached to this message and also available for download at https://nofile.io/f/23mudkozTSh/map_0.5x0.5_nomask_to_360x720_nomask_aave_da_c120830.nc.

The command I am trying to run is:

cdo sellonlatbox,-170,-53,25,84 map_0.5x0.5_nomask_to_360x720_nomask_aave_da_c120830.nc out.nc

but I get the infamous error message:

cdo sellonlatbox: Unsupported grid type: generic

cdo sellonlatbox (Abort): Unsupported grid type!

which makes me wonder that I have to add some dimension/attribute to the file before using CDO on it, but I don't what those would be.

Does anybody have any experience with a file like this? What dimensions or attributes do I need to add to the file in order to be able to subset a lon/lat box out of it?

Thanks in advance,
Thiago.


Replies (3)

RE: Subsetting SCRIP grid file - Added by Karin Meier-Fleischer almost 6 years ago

Hi Thiago,

I don't have much expirience working with SCRIP files directly but you should do

cdo -setattribute,yc_a@units="degrees_north" -setattribute,xc_a@units="degrees_east" \
    -setattribute,yc_b@units="degrees_north" -setattribute,xc_b@units="degrees_east" \
    -setattribute,yv_a@units="degrees_north" -setattribute,xv_a@units="degrees_east" \
    -setattribute,yv_b@units="degrees_north" -setattribute,xv_b@units="degrees_east" \
    map_0.5x0.5_nomask_to_360x720_nomask_aave_da_c120830.nc tmp.nc

cdo -setattribute,mask_a@coordinates="yc_a xc_a" -setattribute,mask_a@coordinates="yc_a xc_a" \
    -setattribute,mask_b@coordinates="yc_b xc_b" -setattribute,mask_b@coordinates="yc_b xc_b" \
    -setattribute,area_a@coordinates="yc_a xc_a" -setattribute,area_a@coordinates="yc_a xc_a" \
    -setattribute,area_b@coordinates="yc_b xc_b" -setattribute,area_b@coordinates="yc_b xc_b" \
    -setattribute,frac_a@coordinates="yc_a xc_a" -setattribute,frac_a@coordinates="yc_a xc_a" \
    -setattribute,frac_b@coordinates="yc_b xc_b" -setattribute,frac_b@coordinates="yc_b xc_b" \
    tmp.nc outfile.nc

You have to select the variable, e.g. mask_a

cdo -sellonlatbox,-170,-53,25,84 -selvar,mask_a outfile.nc outfile_sellonlatbox.nc

Because I don't know if mask, area and frac are going with yc, xc or with yv,xv you have to have a closer look at this yourself.

-Karin

RE: Subsetting SCRIP grid file - Added by Uwe Schulzweida almost 6 years ago

BTW: The CDO operator setattribute accepts more than one attribute and it supports wildcards:

cdo -setattribute,y?_?@units="degrees_north",x?_?@units="degrees_east",????_a@coordinates="yc_a xc_a",????_b@coordinates="yc_b xc_b" \         
     map_0.5x0.5_nomask_to_360x720_nomask_aave_da_c120830.nc  outfile.nc

RE: Subsetting SCRIP grid file - Added by Thiago dos Santos almost 6 years ago

Thanks Kari and Uwe for your replies. I ended up using another tool to process that file, but it's good to know about CDO's ability to easily set attributes.

    (1-3/3)