How do I calculate climatologies and climatological anomalies?
Question:
Subject: computing monthly anomalies
What I want to do is this:
Given 6 years of data  72 months
(1) compute the seasonal cycle ( 12 months  each an average of the 6 Jan, Febs ... etc.)
(2) compute the anomalies from the climatology  72 months of data  (eg jan 79 minus jan climo ....)
I can do (1) easily using the modulo regridding, so far any way of doing (2) has eluded me.
Quick example and explanation:
Compute the climatological anomaly for a time series of zonal winds.
(using the Ferret demo dataset monthly_navy_winds)
! Example data set: modelgenerated global winds ! (This data set included with standard Ferret distribution) yes? SET DATA monthly_navy_winds ! Get the climatological axis that you want to use ! Here we will use the predefined axis ("MONTH_REG") ! (If the SHOW AXIS returns nothing, see the note at the bottom of this page**) yes? SHOW AXIS month_reg name axis # pts start end MONTH_REG TIME 12mr 16JAN 06:00 16DEC 01:20 T0 = 01JAN0000 00:00:00 Axis span (to cell edges) = 8765.82 (modulo length = axis span) ! (optional) Set the time range of data to be used in the climatology yes? LET uwnd_of_interest = uwnd[T=15jan1983:15jan1991] yes? PLOT/X=180/Y=40 uwnd_of_interest
! Compute the climatology and plot over yes? LET uwnd_climatology = uwnd_of_interest[GT=month_reg@MOD] yes? PLOT/X=180/Y=40/OVERLAY uwnd_climatology[T=15jan1983:15jan1991]
! Subtract to get the anomaly ! Regrid the anomaly back to the original time axis using @asn to guarantee ! success (Subtle interpolation errors may occur on irregular time axes ! if the @asn regridding isn't done.) yes? LET uwnd_anomaly = uwnd  uwnd_climatology[gt=uwnd@asn] yes? PLOT/color=blue/X=180/Y=40/T=15jan1983:15jan1991 uwnd_anomaly
but wait, with my dataset, I get an error:
yes? use my_current_data yes? plot/X=180/Y=40 U yes? LET U_climatology = U[GT=month_reg@MOD] yes? PLOT/X=180/Y=40/OVERLAY U_climatology **ERROR: regridding: only @ASN, @LIN, or @NRST regridding between calendar types: NOLEAP, GREGORIAN
The incoming data is on a different calendar, so the regridding operation we defined is not valid. We'll need to use another climatological axis. These calendars are defined automatically in Ferret: MONTH_IRREG, MONTH_REG, MONTH_GREGORIAN, MONTH_NOLEAP, MONTH_360_DAY, MONTH_ALL_LEAP, MONTH_JULIAN. Choose a monthly climatological axis with the same calendar as the source data:
yes? say `U,return=calendar` !> MESSAGE/CONTINUE NOLEAP NOLEAP ! Define the climatology accordingly, yes? LET U_climatology = U[GT=month_noleap@MOD] yes? PLOT/X=180/Y=40/OVERLAY U_climatology
Detailed explanation to full question:
There are actually 4 steps to what you want to do:
1) Pick a time region over which you would like to compute a climatology
2) Compute a climatology with a compressed time axis (only 12 points)
3) regrid the climatology on the full time axis (72 points in your case)
4) subtract the original variable from the regrided climatology (at each of the 72 points)
I will walk you through this below. In order to do all this we need to tell ferret the name of the compressed time axis (climatology) grid and the name of the full time axis (72 point) grid.
> What I want to do is this.
> Given 6 years of data  72 months
Okay, so we have a variable, call it MY_VAR, in a dataset, call it MY_DATASET which has a certain time axis, call it MY_TIME_AXIS (which has 72 points) as part of a grid MY_GRID.
> (1) compute the seasonal cycle ( 12 months  each an average of the 6 Jan, Febs ... etc.)
Okay to do this we can use some regridding tools in FERRET, but first we need to choose the climatological axis:
yes? show axis month*
MONTH_IRREG has different sized boxes to reflect the fact that March has 31 days while April has only 30, etc... while MONTH_REG has 12 months of equal size (30 days each). Monthly calendar axes for nonGregorian calendars are also included.
Now that we have the appropriate time axis, we need to pick out the region of data that over which we would like to calculate the climatology. This is not strictly necessary  by default FERRET will compute the climatology over the entire range of the data set (despite whatever time region is set using SET REGION/T=). However, you may not want the climatology of ALL the data... for example, you might have 19461996 data but only want the climatology for the years 19461976.
So we set up an intermediate variable, MY_VAR_LIMITED_TIME_RANGE
yes? let MY_VAR_LIMITED_TIME_RANGE = MY_VAR[t="1jan1946":"31dec1976"]
Okay, now we can set up the climatology
yes? let MY_CLIMATOLOGY = MY_VAR_LIMITED_TIME_RANGE[gt=MONTH_IRREG@mod]
This uses the regridding tool gt=@mod which will average the months and put the result onto the compressed climatology time axis MONTH_IRREG that we set up earlier.
> (2) compute the anomalies from the climatology  72 months of data  (eg jan 79  jan climo ....)
Now in order to do this we need the climatology, MY_CLIMATOLOGY, to be on the full time axis of the orginal variable MY_VAR. So once again, we need to regrid, this time from the time axis MONTH_IRREG to the time axis of the full variable.We can use the name of the time variable MY_VAR to specify the full time axis.
So, type
yes? let @asn] ! or, if you like: yes? let MY_ANOMALY = MY_VAR_LIMITED_TIME_RANGE  MY_CLIMATOLOGY[gt=MY_VAR_LIMITED_TIME_RANGE@asn]
and you are done. MY_ANOMALY will be on the exact same grid as MY_VAR.
Note that we use the @asn regridding transformation to regrid the climatology time axis back onto the full time axis. The reason for doing this is subtle: The climatological axis and the actual year length may not quite match  for example in a Gregorian calendar the climatology contains 365.2425 days in its year, the actual year may be a leap year with 366 days or a nonleap year with 365 days. We use @asn to tell Ferret not to worry about this mismatch but to instead use the January value at each January etc... If you don't use the @asn transformation, Ferret will try to account for the different length months, etc... by interpolating which can lead to slightly different values being used for each January, etc...
Here is another detail regarding climatological regridding:
In addition, the commonplace (somewhat sloppy) way that most climatologies are computed is that all data falling within a particular calendar month boundary go into the computed average of that month of the climatological average. If we regard the climatological year as a representation of the earth's tilt relative to the sun (the solar year), then this way of computing climatological averages means that there are small alterations (up to ~3/4 day errors) in the mapping of the calendar months onto the climatological year based on leap year variations.
To do it more carefully, average in 2 stages:

average the original (say, daily) data onto a truemonth Gregorian calendar axis using @ave. This calculation will respect the calendar month boundaries, including leap years. The target climatology axis could be used, specifying the input date range, and using @ave rather than @mod. (To define truemonthly axes, see the sections on DEFINE AXIS/EDGES and the script def_monthaxis_days.jnl also discussed inthat section.

Now do the modulo regridding from this monthly average which takes into account the month lengths in each year.
**NOTE ! Prior to Ferret v6.9, needed to USE and CANCEL this dataset. The next two ! commands not needed in v6.9 and higher. ! The predefined climatological axes include all of the ! calendar definions (Gregorian, NOLEAP, LEAP, etc.) ! Or to use additional climatological axes, such as those in the definition datasets ! clim_axes_gregorian.nc. clim_axes_julian.nc, or clim_axes_noleap.nc , use this ! this same sequence: use and cancel the definition dataset. yes? USE climatological_axes yes? CANCEL DATA climatological_axes
Contributed by Sim Larkin
Last Modified: Feb 10 1997