Project

General

Profile

CDO selgridcell function

Added by Pierre Kloppers almost 7 years ago

Hi, I am trying to select a single grid cell using the selgridcell function but am not sure how to specify the indexes correctly. The documentation says "The user has to give the indexes of each grid cell" and that the indexes parameter must be an INTEGER "Comma separated list of indexes". What does an example of this look like? How does one know if it has run correctly? I have tried running 'cdo selgridcell,1,1 test.nc singlecell.nc' but the output only has a west_east dimension so I'm a little unsure if it is correct.

Does anyone know if the selgridcell option would be faster than the remapnn hack to pull a single grid cell?


Replies (4)

RE: CDO selgridcell function - Added by Ralf Mueller almost 7 years ago

Please upload some sample of your data.

Lets create an example.

cdo -f nc selgridcell,1 -topo c.nc
This gives you the first cell of the data set
netcdf c {
dimensions:
        ncells = 1 ;
variables:
        float lon(ncells) ;
                lon:standard_name = "longitude" ;
                lon:long_name = "longitude" ;
                lon:units = "degrees_east" ;
        float lat(ncells) ;
                lat:standard_name = "latitude" ;
                lat:long_name = "latitude" ;
                lat:units = "degrees_north" ;
        float topo(ncells) ;
                topo:units = "m" ;
                topo:CDI_grid_type = "unstructured" ;
                topo:coordinates = "lat lon" ;

// global attributes:
                :CDI = "Climate Data Interface version 1.8.2 (http://mpimet.mpg.de/cdi)" ;
                :Conventions = "CF-1.6" ;
                :history = "Tue Jul 04 12:05:24 2017: cdo -C -f nc selgridcell,1 -topo c.nc" ;
                :CDO = "Climate Data Operators version 1.8.2 (http://mpimet.mpg.de/cdo)" ;
data:

 lon = -179.75 ;

 lat = -89.75 ;

 topo = 2783.333 ;
}
the somewhat lower left corner. If you want more cells, lets try the first 10
cdo -f nc selgridcell,1/10 -topo c.nc 
and you get
netcdf c {
dimensions:
        ncells = 10 ;
variables:
        float lon(ncells) ;
                lon:standard_name = "longitude" ;
                lon:long_name = "longitude" ;
                lon:units = "degrees_east" ;
        float lat(ncells) ;
                lat:standard_name = "latitude" ;
                lat:long_name = "latitude" ;
                lat:units = "degrees_north" ;
        float topo(ncells) ;
                topo:units = "m" ;
                topo:CDI_grid_type = "unstructured" ;
                topo:coordinates = "lat lon" ;

// global attributes:
                :CDI = "Climate Data Interface version 1.8.2 (http://mpimet.mpg.de/cdi)" ;
                :Conventions = "CF-1.6" ;
                :history = "Tue Jul 04 12:06:30 2017: cdo -C -f nc selgridcell,1/10 -topo c.nc" ;
                :CDO = "Climate Data Operators version 1.8.2 (http://mpimet.mpg.de/cdo)" ;
data:

 lon = -179.75, -179.25, -178.75, -178.25, -177.75, -177.25, -176.75, 
    -176.25, -175.75, -175.25 ;

 lat = -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, -89.75, 
    -89.75, -89.75 ;

 topo = 2783.333, 2783.333, 2783.333, 2783.333, 2783.333, 2783.333, 2784, 
    2784, 2784, 2784 ;
}
which is a row of ten longitudes for latitude -87.75. The result is always a new grid with a single dimension ncells. It has to be like that, because user should be able to select whatever points they want. Of cause the index strongly depends on your input grid.

hth
ralf

RE: CDO selgridcell function - Added by Ralf Mueller almost 7 years ago

there is some docu in the docu about how to set integer parameters

RE: CDO selgridcell function - Added by Pierre Kloppers almost 7 years ago

Ah I see, I was thinking you had to provide an index for both lat and lon but you just provide one.

Does the indexing always go from bottom left working it's way across the rows and then columns? Like:
7,8,9
4,5,6,
1,2,3,

In your example how would you go about finding the index for a gridcell using a lat lon coordinate, is there an easy way in CDO or would you manually calculate using the know length of lat and lon dimensions?

Thanks very much for your replies, I didn't know about selecting a range of integers using first/last so thanks for the useful tip.

RE: CDO selgridcell function - Added by Ralf Mueller almost 7 years ago

In the current release you just have to know it, next release will support the usage of a 0-1-mask file in addition to integer indices. This somewhat overlaps with the reducegrid operator - you might check that one out, too.

    (1-4/4)