[Thread Prev][Thread Next][Index]
Summary to Distributing annual data across months
Hello
All,
A big thanks needs
to go out to Jaison, Ansley, and Mick as well as all of the rest of you who
responded to my emails regarding "do loops" and "distributing annual data across
months."
The
Question:
I am trying to manipulate two files, one has annual data for
100 years (ann_var). The other has monthly data for 1 year (norm_var which
is created from the NC file I read in). I want to distribute the 100
annual values over 12 months such that the value for each month in a year
is the same as the annual value (a total of twelve hundred values). For
the second file I want to distribute
the monthly values over the 100 years such that the value for January in
year one is the same as January in year 100.
Here is a generic
example of what finally worked.
Mick Spillane
suggested the following code for distributing annual data values across
months. The example uses 3 years and 36 months.
---------------------------------------------------------
! 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
.
.
14-JAN-2002 / 13:
3.000
14-FEB-2002 / 14: 3.000
.
14-JAN-2003 /
25: 1.000
14-FEB-2003 / 26: 1.000
-------------------------------------------------------------------------------------------------------------
As for the second
problem distributing monthly values over 100 years such that the
value for a single month is the same in every year, I borrowed some
code from the "how to create a climatology" and advice from Jaison and
Ansley.
! define axis
and grid
!-----------------------------
define
axis/t="15-jan-2001:12:00":"15-dec-2100:12:00"/np=1200 t1200
set
axis/modulo t1200
define grid/x=lon/y=lat/t=t1200
gt1200
! Read in monthly
data
(i=1:720,j=1:360,t=1:12)
!-----------------------------
use
"input.nc"
list var
14-JAN-2080
/ 1: 19.00
14-FEB-2080 / 2:
23.60
15-MAR-2080 / 3: 10.00
14-APR-2080 /
4: -2.70
15-MAY-2080 / 5: -10.00
14-JUN-2080
/ 6: -17.20
15-JUL-2080 / 7:
-6.30
14-AUG-2080 / 8: -7.40
14-SEP-2080 /
9: -11.40
14-OCT-2080 / 10: 1.50
14-NOV-2080 /
11: 12.60
14-DEC-2080 / 12: 29.00
! Get the
climatological_axis
!----------------------------
use
climatological_axes
cancel data climatological_axes
! Get rid of the
Year
!----------------------------
let new_var =
var[gt=month_reg@mod]
list new_var
16-JAN /
1: 19.00
15-FEB / 2:
23.60
17-MAR / 3:
10.00
16-APR / 4:
-2.70
16-MAY / 5:
-10.00
16-JUN / 6:
-17.20
16-JUL / 7:
-6.30
16-AUG / 8:
-7.40
15-SEP / 9:
-11.40
16-OCT / 10:
1.50
15-NOV / 11:
12.60
16-DEC / 12:
29.00
! Set up the new
grid to map monthly values onto
! (there probably is a more elagant
solution)
!----------------------------
let temp = 0*x[gx=lon]
+ 0*y[gy=lat] + 0*t[gt=t1200]
! Regrid the monthly
values across all 100 years
!----------------------------
let
final_var = temp + new_var[gt=t1200@asn]
list
final_var
15-JAN-2001 /
1: 19.00
14-FEB-2001 / 2: 23.60
.
.
15-JAN-2002 /
13: 19.00
14-FEB-2002 / 14: 23.60
.
.
14-JAN-2100
/ 1189: 19.00
14-FEB-2100 / 1190:
23.60
.
------------------------------------------------------------------------------------------------------------------------------------
Once again a big
thanks to Jaison, Ansley, Mick, and everyone else who took the time to help me
get this!
All the
best,
Barry
Barry B.
Baker, Ph.D. Climate Change
Modeler
bbaker@tnc.org (303) 541-0322 (Phone) (303)
449-4328 (Fax) nature.org\tncscience\scientists\misc\baker.html |
|
The Nature
Conservancy Global Climate Change
Initiative
2424 Spruce
Street Suite 100 Boulder, CO 80302 nature.org
|
|
|
"A reverence for uncertainty is
one of the unrecognized implications of systems thinking" Peter
Senge |
[Thread Prev][Thread Next][Index]
Dept of Commerce /
NOAA /
OAR /
PMEL /
TMAP
Contact Us | Privacy Policy | Disclaimer | Accessibility Statement