As the title indicates, I want to compute the median of a .nc
file named sfcWind_1999.nc
. On each grid point (lat/lon combination) I want to compute the median in the time
dimension. Is there any nco attribute that does this?
Asked
Active
Viewed 890 times
2

ClimateUnboxed
- 7,106
- 3
- 41
- 86

David Halley
- 417
- 3
- 6
- 18
-
Does the solution have to be with NCO? CDO has a percentile function that can calculate the median. – ClimateUnboxed Mar 30 '18 at 12:48
2 Answers
3
The median is the 50th percentile, so you can use the percentile function in CDO to do this:
cdo timpctl,50 in.nc -timmin in.nc -timmax in.nc median.nc
The function needs to know the data bounding values to calculate the histogram, hence the piped min and max commands.

ClimateUnboxed
- 7,106
- 3
- 41
- 86
2
As described in the manual, NCO can report the median of a single variable, but not, in one step, all variables in the file. So you would have to create the loop over variables yourself, either in Bash or in ncap2 directly.
ncap2 -O -v -s "foo=gsl_stats_median_from_sorted_data(var_nm.sort());print(foo)" in.nc out.nc
or
ncmdn var_nm in.nc

Charlie Zender
- 5,929
- 14
- 19