NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: [netcdfgroup] simple commandline query of data-variable statistics to stdout?

Kokron, Daniel S. Thu, 6 Sep 2012 20:15:31 -0500
>> Have a look at the 'grdinfo' utility which is part of GMT5.

>> http://www.soest.hawaii.edu/gmt5/

GMT looks interesting (and is available as a debian package) but
`grdinfo` seems to only work with 2d data (Am I missing something?)
E.g., for

$ ncdump -h ./GEIA_N2O_oceanic.nc
> netcdf GEIA_N2O_oceanic {
> dimensions:
>       lon = 360 ;
>       lat = 180 ;
>       time = UNLIMITED ; // (1 currently)
> variables:
...
>       double emi_n2o(time, lat, lon) ;
>              emi_n2o:units = "ton N2O-N/yr" ;
>              emi_n2o:missing_value = -999. ;
>              emi_n2o:long_name = "N2O emissions" ;
>              emi_n2o:_FillValue = -999.f ;
...
$ GMT grdinfo ./GEIA_N2O_oceanic.nc
> grdinfo: No 2-D variable in file [./GEIA_N2O_oceanic.nc]

Alas.

Charlie Zender Fri, 07 Sep 2012 10:16:19 -0700
> Your query matches a category of commands which I call filters[,
> e.g.] http://nco.sf.net/nco.html#filters [. Since] ncap2 [is]
> better for arbitrarily complex and longer filters

... I went with that, even though the bigot in me rails against the
requirement to write a file as a side effect. (Fortunately he was
appeased by use of tempfiles :-) `source`able bash follows my .sig.

your assistance is appreciated, Tom Roche <Tom_Roche@xxxxxxxxx>
---------------------code follows to end of post---------------------

# bash functions for NCO "filters", as suggested by Charlie Zender @
# 
http://www.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/2012/msg00286.html
# http://nco.sourceforge.net/nco.html#filters
# All use `ncap2` and take input like $1=datavar name, $2=filename

# Prints maximum
function ncmax {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s "foo=${1}.max();print(foo)" ${2} ${TMPFILE} | cut -f 3- -d 
' '
}

function ncmin {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s "foo=${1}.min();print(foo)" ${2} ${TMPFILE} | cut -f 3- -d 
' '
}

# Prints mean
function ncmean {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s "foo=${1}.avg();print(foo)" ${2} ${TMPFILE} | cut -f 3- -d 
' '
}

# median not currently available?

# Prints RMS (root-mean-square, normalized by N)
function ncRMS {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s "foo=${1}.rms();print(foo)" ${2} ${TMPFILE} | cut -f 3- -d 
' '
}

# Prints range (of values in datavar)
function ncrange {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s \
    "foo=${1}.min();bar=${1}.max();print(foo,\"%f\");print(\" to 
\");print(bar,\"%f\")"\
     ${2} ${TMPFILE}
}

# Prints number of elements in datavar (including NA)
function ncsize {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s "foo=${1}.size();print(foo)" ${2} ${TMPFILE} | cut -f 3- -d 
' '
}

# Prints total
function nctotal {
  TMPFILE="$(mktemp)"
  ncap2 -O -C -v -s "foo=${1}.total();print(foo)" ${2} ${TMPFILE} | cut -f 3- 
-d ' '
}



  • 2012 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: