[Thread Prev][Thread Next][Index]

Re: [ferret_users] How can I produce a time series of JJA averages (orother intervals) from a monthly time series?



Hi Yun,
You're right. The trouble with my script is that the axis in the monthy_navy_winds dataset is defined in units of hours, so the t0 used there isn't really the one we'd want to use to define a monthly time series -- putting t0 in January of the first year means that for a monthly axis, 0=January, 1=February, and so on, so the script has 6=July when it should be 7=July.

If you're running v6.0 of Ferret, there are some new time axis functions which would let us construct the correct time axis origin. The function tax_year returns the year of any date. We know we want the time axis origin to be the middle of December of the year before the dataset's time axis starts. So, get the year of the first data point of the variable uwnd

yes? show function tax_year
   TAX_YEAR(A,B)
    Returns years of time axis coordinate values
    A: time steps to convert
    B: variable with reference time axis
yes? show function tax*

! Define a calendar axis containing these months, and starting
! with the month before the first month in the original dataset.

yes? let year0 = tax_year(t[gt=uwnd,L=1], uwnd) - 1
yes? def axis/t0="15-Dec-`year0`"/units="months" tsummer = just_summer[l=1:`nja`]

 !-> def axis/t0="15-Dec-1981"/units="months" tsummer = just_summer[l=1:33]

Here just to illustrate, I've put the time origin at 15-Dec, and left off the hours:minutes - I think the specification within the month should be thought about more carefully; probably using the date, hours, and minutes from the monthly_navy_winds data for December values; the monthly_navy_winds data set has a regularly-spaced monthly time axis and we should match the dates it uses.

yes? let day0 = tax_day(t[gt=uwnd,L=12], uwnd)

yes? let dfrac = tax_dayfrac(t[gt=uwnd,L=12], uwnd)
yes? let hour0 = INT(dfrac*24)
yes? let minute0 = INT(60*(dfrac*24 - hour0))


yes? define axis/t0="`day0`-DEC-`year0` `hour0`:`minute0`"/units=months tsummer = just_summer[l=1:33]

(Or one could call the TAX_DATESTRING function for data at time step 12, and use string-editing functions to change the year from 1982 to 1981.)

And to have a completely automatic script, the script should check that the first time step is in January.

Here's a corrected version of my script:

! Create a time series containing only June,July, Augst data
! from a monthly data set.

use monthly_navy_winds

! Get a list of the month numbers representing June ,July, August
! This is correct since the data start in January, otherwise we
! would need an offset

let nmon = `uwnd,return=Lend`
let tt = t[t=1:`nmon`]
let june = if mod(tt,12) ge 6 then tt
let june_aug = if mod(june,12) le 8 then june
list june_aug

let nja = `june_aug[t=@ngd]`

let just_summer = compressl(june_aug)
list just_summer[L=1:`nja`]

! Now sample the Lth point of uwnd for summer months
let uwnd_jja = samplel(uwnd,just_summer[l=1:`nja`])

! Define a calendar axis containing these months, and starting
! with the month before the first month in the original dataset.

let year0 = tax_year(t[gt=uwnd,L=1], uwnd) - 1
def axis/t0="15-Dec-`year0`"/units="months" tsummer = just_summer[l=1:`nja`]

! Refine this, setting the Day and Hour as for December points of the original data.
let day0 = tax_day(t[gt=uwnd,L=12], uwnd)

let dfrac = tax_dayfrac(t[gt=uwnd,L=12], uwnd)
let hour0 = INT(dfrac*24)
let minute0 = INT(60*(dfrac*24 - hour0))


define axis/t0="`day0`-DEC-`year0` `hour0`:`minute0`"/units=months tsummer = just_summer[l=1:33]

! Put the sampled summer data on the calendar axis
let uwnd_summer = uwnd_jja[gt=tsummer@asn]
list/x=180/y=0 uwnd_summer






[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement