11.07.2015 Views

PyClimate 1.1. A set of C and Python routines for the ... - Starship

PyClimate 1.1. A set of C and Python routines for the ... - Starship

PyClimate 1.1. A set of C and Python routines for the ... - Starship

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

so that <strong>the</strong> time values created this way can be correctly read <strong>and</strong> interpreted by <strong>the</strong>SDF interface in plotting programs as GrADS. The date arithmetic is carried out bymeans <strong>of</strong> Julian Days stored as double precision (Float64) numbers. Conversion functionsto date structures are provided by means <strong>of</strong> a C extension based on astronomicalalgorithms [6]. The file exjdtime.py provides some examples <strong>of</strong> <strong>the</strong> use <strong>of</strong> <strong>the</strong>sefunctions. The algorithm does not support dates be<strong>for</strong>e <strong>the</strong> start <strong>of</strong> <strong>the</strong> Gregorian calendar(1582-10-15). In particular, this means that you can not properly recover datesfrom some <strong>of</strong> <strong>the</strong> NCEP Reanalysis netCDF files, which start at 1–1–1, a date not includedin <strong>the</strong> Gregorian calendar.Class: JDTimeInteger members: year, month, day, hour, minute.Double member: second.The previous members can be directly accessed from <strong>Python</strong>.Function: def date2jd(jdt)From a JDTime structure jdt, get <strong>the</strong> Julian Day number as a double.Function: def jd2date(jd,jdt)Given a Julian Day jd, get <strong>the</strong> broken date structure jdt.Function: def monthlystep()Return <strong>the</strong> number <strong>of</strong> Julian Days in a month, that is, number <strong>of</strong> tropical days peryear (365.242198781) divided by twelve. This provides adequate accuracy <strong>for</strong> datesduring <strong>the</strong> instrumental part <strong>of</strong> <strong>the</strong> climate record. However, this approach poses aproblem because <strong>of</strong> <strong>the</strong> truncation problem that appears due to <strong>the</strong> different length <strong>of</strong><strong>the</strong> months. When using this approximation, some months are longer than o<strong>the</strong>rs <strong>and</strong>this means that one <strong>of</strong> <strong>the</strong> time steps may be in <strong>the</strong> first day <strong>of</strong> one month <strong>and</strong> <strong>the</strong> laststep on <strong>the</strong> last day <strong>of</strong> <strong>the</strong> same month (if month is longer than 30.43 days). To avoidthis truncation problem, <strong>the</strong> origin should be <strong>set</strong> to day 15th <strong>of</strong> <strong>the</strong> starting month. Thisway, <strong>for</strong> every record, <strong>the</strong> first two fields <strong>of</strong> <strong>the</strong> date structure (year <strong>and</strong> month) willbe adequately resolved by jd2date(). This can be easily explained with <strong>the</strong> nextexample, <strong>and</strong> its output.from pyclimate.JDTimeH<strong>and</strong>ler import *from pyclimate.JDTime import *a=JDTimeH<strong>and</strong>ler("hours since 1958-01-01")b=JDTimeH<strong>and</strong>ler("hours since 1958-01-15")mstep=monthlystep()*24print mstep," in hours = ",mstep/24.," days"print a.getdatefields(0.0,3)print b.getdatefields(0.0,3)print a.getdatefields(0.0+mstep,3)," Still in January"print b.getdatefields(0.0+mstep,3)," In February"730.484397562 in hours = 30.4368498984 days[1958, 1, 1][1958, 1, 15][1958, 1, 31] Still in January[1958, 2, 14] In FebruaryThere is a second file that allows <strong>the</strong> h<strong>and</strong>ling <strong>of</strong> COARDS compliant time variables innetCDF files, JDTimeH<strong>and</strong>ler.py.7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!