Beispiel #1
0
 #print count,months
 if months in [1, 3, 5, 7, 8, 10, 12]:
     monthendday = 31
     hrs = 12
 elif months in [4, 6, 9, 11]:
     monthendday = 30
     hrs = 0
 elif isleap(int(1984)):
     monthendday = 29
     hrs = 12
 else:
     monthendday = 28
     hrs = 0
 times.append(
     cdt.componenttime(
         1984, months, np.int(monthendday / 2.),
         hrs).torel('days since 1955-1-1').value)
 # WOA13v2 extends from 1955 to 2012
 #                    times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1'),
 #                                       cdt.componenttime(2012,months,monthendday,12,59,59).torel('days since 1955-1-1')])
 if months < 12:
     times_bnds.append([
         cdt.componenttime(
             1955, months, 1, 0, 0,
             0).torel('days since 1955-1-1').value,
         cdt.componenttime(
             2012, months + 1, 1, 0, 0,
             0).torel('days since 1955-1-1').value
     ])
 else:
     times_bnds.append([
Beispiel #2
0
result, newwts = averager(x, axis='x', weight=aw, returned=1)
new_result = averager(result, axis='y', weight='equal')
result = averager(x, axis='21', weight=aw)

result = averager(x, axis=0)

#******************************************************************************************
# Now a real world check!!
#******************************************************************************************

#
# The values in this file were calculated using old routines in CDAT2.4
#
fcheck = cdms2.open(
    os.path.join(cdat_info.get_sampledata_path(), 'tas_gavg_rnl_ecm.nc'))
start = cdtime.componenttime(1979, 1, 1)
end = cdtime.componenttime(1979, 12, 1)
correct = fcheck('tas', time=(start, end))

#
# The source for the averages in the above file is the raw data in the file below.
# The difference in units (degrees C and degrees K) should be the obvious answer.
#
f = cdms2.open(os.path.join(cdat_info.get_sampledata_path(),
                            'tas_ecm_1979.nc'))

#
# I can invoke averager by passing the f('tas') as the variable instead of first extracting
# the variable...... Youcan obviously get more fancy with the kind of selected variables you pass.
#
result = averager(f('tas'), axis='xy', weight=['generate', 'generate'])
Beispiel #3
0
    error = True
if error == False:
    raise Exception,"Error it should have failed here!"


s=f('ta',slice(0,1),genutil.picker(level=levels,match=0))

if s.shape[1]!=3:
    raise "Error did not return 3 levels!"
if (s.getLevel()[:]!=levels).any():
    raise Exception,"Error did not retrieve the right levels!"

print "folowing plot should show all missing values, since 800 does not exisits!"
x=vcs.init()
x.plot(s[0,-1],bg=bg)
vcs.test.support.check_plot(x)

levels = [1000,700,850]
s3=f('ta',genutil.picker(time=['1987-7','1988-1',cdtime.comptime(1988,3)],level=[1000,700,850]))

if s3.shape!=(3, 3, 73, 144):
    raise Exception,"Did not retrieve the right slab"
t1= cdtime.componenttime(1987,7)
t2= cdtime.componenttime(1988,1)
t3= cdtime.componenttime(1988,3)
if s3.getTime().asComponentTime()!=[t1,t2,t3]:
    raise Exception,"Error did not get the right times"
test = s3.getLevel()[:]!=levels
if test.any():
    raise Exception,"Error did not get the right levels"
                times = [] ; times_bnds = []
                for count,months in enumerate(range(1,13)):
                    #print count,months
                    if months in [1,3,5,7,8,10,12]:
                        monthendday = 31
                        hrs = 12
                    elif months in [4,6,9,11]:
                        monthendday = 30
                        hrs = 0
                    elif isleap(int(1984)):
                        monthendday = 29
                        hrs = 12
                    else:
                        monthendday = 28
                        hrs = 0
                    times.append(cdt.componenttime(1984,months,np.int(monthendday/2.),hrs).torel('days since 1955-1-1').value)
                    # WOA13v2 extends from 1955 to 2012
#                    times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1'),
#                                       cdt.componenttime(2012,months,monthendday,12,59,59).torel('days since 1955-1-1')])
                    if months < 12:
                        times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1').value,
                                           cdt.componenttime(2012,months+1,1,0,0,0).torel('days since 1955-1-1').value])
                    else:
                        times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1').value,
                                           cdt.componenttime(2013,1,1,0,0,0).torel('days since 1955-1-1').value])
                time = cdm.createAxis(times,np.array(times_bnds),id='time')
                time.units = 'days since 1955-01-01 0.0.0'
                timeAx = {'table_entry': 'time2',
                          'units': time.units,
                          'coord_vals': time
                         }
Beispiel #5
0
try:
    result = averager(x, axis=0) 
except AveragerError:
    print 'Failure! 35'


#******************************************************************************************
# Now a real world check!!
#******************************************************************************************

#
# The values in this file were calculated using old routines in CDAT2.4
#
fcheck = cdms2.open(os.path.join(cdms2.__path__[0],'..','..','..','..','sample_data','tas_gavg_rnl_ecm.nc'))
start = cdtime.componenttime(1979, 1, 1)
end =  cdtime.componenttime(1979, 12, 1)
correct = fcheck('tas', time=(start, end))

#
# The source for the averages in the above file is the raw data in the file below.
# The difference in units (degrees C and degrees K) should be the obvious answer.
#
f = cdms2.open(os.path.join(cdms2.__path__[0],'..','..','..','..','sample_data','tas_ecm_1979.nc'))

#
# I can invoke averager by passing the f('tas') as the variable instead of first extracting
# the variable...... Youcan obviously get more fancy with the kind of selected variables you pass.
#
result = averager(f('tas'), axis='xy', weight=['generate', 'generate'])
Beispiel #6
0
xlonAxis = var_sub5.getLongitude()
ncols = len(xlonAxis)
nrows = len(ylatAxis)
## print some diagnostics
print "opened bound subsetting through cdms Selectors:"
print "Xlon: "
print "\t# elements: %d, range: %.1f -- %.1f" \
      %(ncols, xlonAxis.getValue()[0], xlonAxis.getValue()[-1])
print "Ylat: "
print "\t# elements: %d, range: %.1f -- %.1f" \
      %(nrows, ylatAxis.getValue()[0], ylatAxis.getValue()[-1])
print ""

## Could also subset time, etc
## Note: time cdtime object and level is a sigma value
date1 = cdtime.componenttime(2001, 6, 1, 12)
sel = cdms.selectors.Selector(time = date1, level = 1., \
                              latitude = (lat1,lat2, "ccb"), \
                              longitude = (lon1, lon2, "ccb"))

var_sub6 = var(sel)

## get  axes
timeAxis = var_sub6.getTime()
levAxis = var_sub6.getLevel()
ylatAxis = var_sub6.getLatitude()
xlonAxis = var_sub6.getLongitude()
ncols = len(xlonAxis)
nrows = len(ylatAxis)

print "Selector in time, level, and space:"
Beispiel #7
0
ncols = len(xlonAxis)
nrows = len(ylatAxis)
## print some diagnostics
print "opened bound subsetting through cdms Selectors:"
print "Xlon: "
print "\t# elements: %d, range: %.1f -- %.1f" \
      %(ncols, xlonAxis.getValue()[0], xlonAxis.getValue()[-1])
print "Ylat: "
print "\t# elements: %d, range: %.1f -- %.1f" \
      %(nrows, ylatAxis.getValue()[0], ylatAxis.getValue()[-1])
print ""


## Could also subset time, etc
## Note: time cdtime object and level is a sigma value
date1 = cdtime.componenttime(2001,6,1,12)
sel = cdms.selectors.Selector(time = date1, level = 1., \
                              latitude = (lat1,lat2, "ccb"), \
                              longitude = (lon1, lon2, "ccb"))

var_sub6 = var(sel)

## get  axes
timeAxis = var_sub6.getTime()
levAxis = var_sub6.getLevel()
ylatAxis = var_sub6.getLatitude()
xlonAxis = var_sub6.getLongitude()
ncols = len(xlonAxis)
nrows = len(ylatAxis)

print "Selector in time, level, and space:"
Beispiel #8
0
                times = [] ; times_bnds = []
                for count,months in enumerate(range(1,13)):
                    #print count,months
                    if months in [1,3,5,7,8,10,12]:
                        monthendday = 31
                        hrs = 12
                    elif months in [4,6,9,11]:
                        monthendday = 30
                        hrs = 0
                    elif isleap(int(1984)):
                        monthendday = 29
                        hrs = 12
                    else:
                        monthendday = 28
                        hrs = 0
                    times.append(cdt.componenttime(1984,months,np.int(monthendday/2.),hrs).torel('days since 1955-1-1').value)
                    # WOA13v2 extends from 1955 to 2012
#                    times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1'),
#                                       cdt.componenttime(2012,months,monthendday,12,59,59).torel('days since 1955-1-1')])
                    if months < 12:
                        times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1').value,
                                           cdt.componenttime(2012,months+1,1,0,0,0).torel('days since 1955-1-1').value])
                    else:
                        times_bnds.append([cdt.componenttime(1955,months,1,0,0,0).torel('days since 1955-1-1').value,
                                           cdt.componenttime(2013,1,1,0,0,0).torel('days since 1955-1-1').value])
                time = cdm.createAxis(times,np.array(times_bnds),id='time')
                time.units = 'days since 1955-01-01 0.0.0'
                timeAx = {'table_entry': 'time2',
                          'units': time.units,
                          'coord_vals': time
                         }