David Halley
David Halley

Reputation: 457

dump netcdf variable within a range

I am using the following command to dump the content of the variable 'tas' within a netcdf file tas_EUR-44_historical.nc

ncdump -v tas tas_EUR-44_historical.nc

tas is a variable of three dimensions consisting of time, latitude and longitude tas(time, rlat, rlon)

Now I need to dump the first value of time ,0, for rlat ranging from 0 to 5 and rlon ranging from 0 to 5.

Does anyone know how this can be done?

Thanks!

Upvotes: 1

Views: 1643

Answers (2)

Charlie Zender
Charlie Zender

Reputation: 6332

You can use ncks

ncks -d time,0 -d rlat,0,5 -d rlon,0,5 in.nc out.nc

Upvotes: 1

Bart
Bart

Reputation: 10248

Strongly depends on what kind of tools you want to use. This is a very trivial task with most programming languages ("Python/R/..."), if you want a command line tool you might want to look at NCO and especially its ncks (NetCDF Kitchen Sink) command.

For example, if I have a NetCDF file (output ncdump -h)

netcdf u.xz {
dimensions:
    xh = 256 ;
    y = 1 ;
    z = 160 ;
    time = UNLIMITED ; // (481 currently)
variables:
    float time(time) ;
        string time:units = "Seconds since start of experiment" ;
    float xh(xh) ;
    float y(y) ;
    float z(z) ;
    float u(time, z, xh, y) ;
}

I can extract for example the first time record using:

ncks -d time,0,0 u.xz.nc test.nc

Or, something closer to your question, select the first time record and slice the spatial dimensions:

ncks -d time,0,0 -d xh,0,5 -d z,0,5 u.xz.nc test.nc

Each time the manipulated NetCDF file is written to a new file. You can leave out the last argument test.nc to dump the output to screen, or simply dump the output of test.nc with ncdump.

Upvotes: 1

Related Questions