Calculating annual means for the six lowest monthly values in each year
Added by Thomas Moore over 2 years ago
I'd like to calculate two values from HadISST data: 1) mean annual SST and 2) mean annual SST for the coolest 6 months.
(dataset here: https://www.metoffice.gov.uk/hadobs/hadisst/data/HadISST_sst.nc.gz)
For various reasons, my current workflow is this:
i) set missing values to nan
ii) cut timeseries to 2010-2019
iii) set missing values to distance-weighted average
iv) regrid to a 0.5x0.5 degree grid using bilinear interpolation
For calculating mean annual SST the following code works perfectly:
cdo -L -O -yearmean -select,name=sst -remapbil,global_0.5 -setmisstonn -selyear,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019 -select,name=sst -setmissval,nan HadISST_sst.nc HadISST_baseline_SST_ts_annual.nc
For calculating the mean annual SST for only the coolest 6 months of the year, I've been using the following code:
cdo -L -O -select,name=sst -remapbil,global_0.5 -setmisstonn -selyear,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019 -select,name=sst -setmissval,nan HadISST_sst.nc HadISST_baseline_SST_ts_monthly.nc
Then importing to R tidyverse and using slice_min(n=6) to select the minimum SST values in each year, then group_by() and summarise() to calculate annual means.
This workflow (CDO to R) is massively( inefficient as R/tidyverse takes a *long time to process the data.
I'm sure there's a better approach, but I'm not familiar enough with CDO to figure out how to do this!
In summary, here's the missing step in CDO
monthly SST > cut to 6 lowest monthly SST in each year > average to annual
Can I calculate this step directly in CDO, and if so, how to approach this?
Replies (2)
RE: Calculating annual means for the six lowest monthly values in each year - Added by Thomas Moore over 2 years ago
At the risk of answering my own question, can I use TIMSELPCTL to select the lowest nth percentile?
RE: Calculating annual means for the six lowest monthly values in each year - Added by Thomas Moore over 2 years ago
Figured this out from the CDO documentation, so I'll answer my own question in case anyone else comes across this.
The correct approach is to calculate percentiles. So, for the 4 lowest months:
cdo yearpctl,30 infile -yearmin infile -yearmax infile outfile