[Thread Prev][Thread Next][Index]

Re: Distribution of annual data across months



Hi,
     This is an add up to Mick's mail. I modified his script ( his 
sampling idea was great)  to include the second variable - that repeats 12
monthly values for each year.   


!  define grid for three years annual data

	def axis/t=1-jul-2001:1-jul-2003/npoints=3 t_3year
	def grid/t=t_3year g_3year

! and load it with sample data {3,1,2}

	let ann_var=tsequence({3,1,2})
	let yr_var=ann_var[g=g_3year,gt=@asn]
        list yr_var

! define grid for 12 months monthly data 

	def axis/t=15-jan-0001:15-dec-0001/npoints=12 t_12mon
	def grid/t=t_12mon g_12mon

! and load it with sample data 

	let mon_var=tsequence({1,2,3,4,5,6,7,8,9,10,11,12})
	let mn_var=mon_var[g=g_12mon,gt=@asn]
        list mn_var

! now define grid (3yr*12mon ==> 36 months) for the final output data

	def axis/t=15-jan-2001:15-dec-2003/npoints=36 t_36mon
	def grid/t=t_36mon g_36mon

! now we need a "sample" function with 36 values: 12x1, 12x2, 12x3

	let yr_samp = int((l[g=g_36mon]-1)/12) + 1 ! to sample yearly
values
        let mon_samp = l[g=g_36mon] - int((l[g=g_36mon]-1)/12)*12
! to sample monthly values
 	list yr_samp, mon_samp

! those two with the SAMPLEL function gives us monthly and yearly data in 
! same grid hence can be multiplied to get the final answer        

        let yr_t36_dummy   = samplel(yr_var,yr_samp)  
        let mon_t36_dummy  = samplel(mn_var,mon_samp)

	let yr_t36  = yr_t36_dummy[g=g_36mon,gt=@asn]
        let mon_t36 = mon_t36_dummy[g=g_36mon,gt=@asn]

        let final_var = yr_t36 * mon_t36

	list yr_t36, mon_t36, final_var

Hope this helps

With Regards 

Jaison




On Tue, 16 Mar 2004 Mick.Spillane@noaa.gov wrote:

> Hi Barry,
> 	I think the SAMPLEL function may be of help in creating
> the first variable - that repeats each annual value 12 times.
> Here is a demo of what I have in mind (but for 3 years rather
> than 100 so the listings are shorter).
> 
> ! define grid for three years annual data
> def axis/t=1-jul-2001:1-jul-2003/npoints=3 tyear
> def grid/t=tyear gyear
> 
> ! and load it with sample data {2,3,1}
> let vsample=tsequence({2,3,1})
> let vyear=vsample[g=gyear,gt=@asn]
> list vyear
>  JUL-2001 / 1:  2.000
>  JUL-2002 / 2:  3.000
>  JUL-2003 / 3:  1.000
> 
> ! now define grid for the monthly data
> def axis/t=15-jan-2001:15-dec-2003/npoints=36 tmonth
> def grid/t=tmonth gmonth
> 
> ! now we need a "sample" function with 36 values: 12x1, 12x2, 12x3
> let lsamp = int((l[g=gmonth]-1)/12) + 1
> 
> ! which used with the SAMPLEL gives us what we need
> let vm=samplel(vyear,lsamp)     ! this has the values right but
>                                 ! lacks the calendar axis
> let vmonth=vm[g=gmonth,gt=@asn]
> list vmonth
>  15-JAN-2001 /  1:  2.000
>  14-FEB-2001 /  2:  2.000
>  16-MAR-2001 /  3:  2.000
>  16-APR-2001 /  4:  2.000
>  16-MAY-2001 /  5:  2.000
>  16-JUN-2001 /  6:  2.000
>  16-JUL-2001 /  7:  2.000
>  15-AUG-2001 /  8:  2.000
>  15-SEP-2001 /  9:  2.000
>  15-OCT-2001 / 10:  2.000
>  15-NOV-2001 / 11:  2.000
>  15-DEC-2001 / 12:  2.000
>  14-JAN-2002 / 13:  3.000
>  14-FEB-2002 / 14:  3.000
>  16-MAR-2002 / 15:  3.000
>  16-APR-2002 / 16:  3.000
>  16-MAY-2002 / 17:  3.000
>  15-JUN-2002 / 18:  3.000
>  16-JUL-2002 / 19:  3.000
>  15-AUG-2002 / 20:  3.000
>  15-SEP-2002 / 21:  3.000
>  15-OCT-2002 / 22:  3.000
>  14-NOV-2002 / 23:  3.000
>  15-DEC-2002 / 24:  3.000
>  14-JAN-2003 / 25:  1.000
>  14-FEB-2003 / 26:  1.000
>  16-MAR-2003 / 27:  1.000
>  15-APR-2003 / 28:  1.000
>  16-MAY-2003 / 29:  1.000
>  15-JUN-2003 / 30:  1.000
>  16-JUL-2003 / 31:  1.000
>  15-AUG-2003 / 32:  1.000
>  14-SEP-2003 / 33:  1.000
>  15-OCT-2003 / 34:  1.000
>  14-NOV-2003 / 35:  1.000
>  15-DEC-2003 / 36:  1.000
> 
> Your data seems to be ASCII so you are free to define your axes in
> a way similar to the above, but I think the scheme would work
> if "gyear", "gmonth" came from input netcdf files.
> 
> Hope this helps,
> Mick
> 
> |Please note NEW E-Mail Address|
> |!!! Mick.Spillane@noaa.gov !!!|
> |__Room 2070 Bldg#3 NOAA/PMEL__|
> |____Phone_:_(206)526-6780_____|
> 
> 



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement