JISAO data nco

Using NetCDF Operators (NCOs) to calculate climatologies.


Simple and sophisticated.


Simple

The following uses all months in the input data set. The downside of this script is that time values of the climatology file don't make sense. They are something like the mean January value of the dataset, the mean February value of the data set, ..., actually I am not sure what they are.

foreach month ( 01 02 03 04 05 06 07 08 09 10 11 12 )
foreach? ncra -F -d time,$month,,12 file_with_years_and_months.nc temp$month.nc
foreach? end
ncrcat -h temp*nc monthly_climatology.nc  
/bin/rm temp??.nc
"foreach/end" is a UNIX command line construction to perform looping. "ncra" calculates the mean for each calendar month. "ncrcat" concatenates the monthly climatologies. "/bin/rm temp??.nc" deletes the temporary files.



Sophisticated

The 15th day of each calendar month (in non-Leap Years) is
15 46 74 105 135 166 196 227 258 288 319 349 Julian days
and one would like the time value of the output climatology to have those time values and units of days since January first.

The following calculates the 1971-2000 climatology of a dataset that begins in 1948. 276 = ( 1971 - 1948 ) * 12 and 636 = ( 2000 - 1948 + 1 ) * 12 . If I had more time, I'd make the first year of the input data and the first and last years of the climatologies inputs.

A key point in the following is that you cannot do albegra in the input arguments to the NCO routines, for example, "ncra."

foreach month ( 01 02 03 04 05 06 07 08 09 10 11 12 )
set mon1 = 276
@ mon1 = $mon1 + $month
echo $mon1

ncra -O -h -F -d time,$mon1,636,12 slp.mon.mean.nc temp.nc

# Change the time units to days since ...
ncatted -O -h -a units,time,m,c,"days since 1971-1-1 00:00:0.0" temp.nc
# Delete some of the extraneous time attributes.
ncatted -O -h -a actual_range,time,d,c,"" temp.nc
ncatted -O -h -a delta_t,time,d,c,"" temp.nc
ncatted -O -h -a prev_avg_period,time,d,c,"" temp.nc 

if ( $month == "01" ) then
ncap2 -O -h -s "time=time*0+14" temp.nc temp.nc
else if ( $month == "02" ) then
ncap2 -O -h -s "time=time*0+45" temp.nc temp.nc
else if ( $month == "03" ) then
ncap2 -O -h -s "time=time*0+73" temp.nc temp.nc
else if ( $month == "04" ) then
ncap2 -O -h -s "time=time*0+104" temp.nc temp.nc
else if ( $month == "05" ) then
ncap2 -O -h -s "time=time*0+134" temp.nc temp.nc
else if ( $month == "06" ) then
ncap2 -O -h -s "time=time*0+165" temp.nc temp.nc
else if ( $month == "07" ) then
ncap2 -O -h -s "time=time*0+195" temp.nc temp.nc
else if ( $month == "08" ) then
ncap2 -O -h -s "time=time*0+226" temp.nc temp.nc
else if ( $month == "09" ) then
ncap2 -O -h -s "time=time*0+257" temp.nc temp.nc
else if ( $month == "10" ) then
ncap2 -O -h -s "time=time*0+287" temp.nc temp.nc
else if ( $month == "11" ) then
ncap2 -O -h -s "time=time*0+318" temp.nc temp.nc
else 
ncap2 -O -h -s "time=time*0+348" temp.nc temp.nc
endif
/bin/mv temp.nc clim${month}.nc

end

ncrcat -O -h clim??.nc test.nc
/bin/rm clim??.nc


March 2009
Todd Mitchell ( mitchell@atmos.washington.edu )
JISAO data