def get_pasap_plot_title(dset,
    varname = 'hr24_prcp',
    timestep= 0,
    ):
    """ Given an open pydap object, and some extra information, return a nice
        plot title.
    """
    header = "PASAP: Dynamical Seasonal Outlooks for the Pacific."
    subheader1 = "Outlook based on POAMA 1.5 CGCM adjusted for historical skill"
    subheader2 = "Experimental outlook for demonstration and research only"
    time_var = dset['time']

    if 'units' in time_var.attributes.keys():
        time_units = time_var.attributes['units']
    else:
        time_units = ''
    if 'units' in dset[varname].attributes.keys():
        units = dset[varname].attributes['units']
    else:
        units = ''
    valid_time = datetime.datetime.strftime(
        num2date(time_var[timestep],time_units),"%Y%m%d")
    start_date = datetime.datetime.strftime(
        num2date(dset['init_date'][0],time_units),"%Y%m%d")

    period_label = str(dset['time_label'][timestep])
    titlestring = header + '\n' \
                  + subheader1 + '\n'  \
                  + subheader2 + '\n'  \
                  + "Variable: " + varname + ' (' + units + ')' + '\n' \
                  + 'Model initialised ' + start_date + '\n' \
                  # + 'Forecast period: ' + period_label 

    return titlestring
Ejemplo n.º 2
0
    def __get_plot_title(self):
        """" Returns the title for the full figure request"""
        header = "PASAP: Dynamical Seasonal Outlooks for the Pacific."
        subheader1 = "Outlook based on POAMA 1.5 CGCM adjusted for "\
                     "historical skill"
        subheader2 = "Experimental outlook for demonstration and research only"
        
        title = header + '\n' + \
                subheader1 + '\n' + \
                subheader2 + '\n'
        try:
            start_date = datetime.datetime.strftime( \
                            num2date( self.dset.get_init_date()[0], \
                                      self.dset.get_time_units()), \
                                      "%Y%m%d")
        except:
            start_date = "Cannot compute start_date."
        
        try:
            title = title + \
                'Variable: ' + self.parameters['layers'][0] + \
                ' (' + self.dset.get_var_unit() + ')\n' + \
                'Model initlialised ' + start_date + '\n' + \
                'Forecast period: ' + str(self.dset.get_time_label())
        except:
            title = "Can not compute title."

        return title
Ejemplo n.º 3
0
def create_daily_calendar(origin='days since 1998-01-01 00:00:00',cal_length=3652):
	'''
	create a daily calendar given origin and number of days ... 
	'''
	import numpy as np
	from mpl_toolkits.basemap import num2date	
	time = np.arange(0,cal_length)
	origin =  origin
	fdates = num2date(time[:],origin)
	years  = np.asarray([fdate.year for fdate in fdates])[...,np.newaxis]
	months  = np.asarray([fdate.month for fdate in fdates])[...,np.newaxis]
	days  = np.asarray([fdate.day for fdate in fdates])[...,np.newaxis]
	daily_calendar = np.concatenate((years,months,days),axis=1)
	return daily_calendar
Ejemplo n.º 4
0
    except:
        msg = """
opendap server not providing the requested data.
Try another date by providing YYYYMMDD on command line."""
        raise IOError, msg

# read lats,lons,times.

print data.variables.keys()
latitudes = data.variables['lat']
longitudes = data.variables['lon']
fcsttimes = data.variables['time']
times = fcsttimes[0:6]  # first 6 forecast times.
ntimes = len(times)
# convert times for datetime instances.
fdates = num2date(times, units=fcsttimes.units, calendar='standard')
# make a list of YYYYMMDDHH strings.
verifdates = [fdate.strftime('%Y%m%d%H') for fdate in fdates]
# convert times to forecast hours.
fcsthrs = []
for fdate in fdates:
    fdiff = fdate - fdates[0]
    fcsthrs.append(fdiff.days * 24. + fdiff.seconds / 3600.)
print fcsthrs
print verifdates
lats = latitudes[:]
nlats = len(lats)
lons1 = longitudes[:]
nlons = len(lons1)

# unpack 2-meter temp forecast data.
Ejemplo n.º 5
0
        msg = """
opendap server not providing the requested data.
Try another date by providing YYYYMMDD on command line."""
        raise IOError, msg


# read lats,lons,times.

print data.variables.keys()
latitudes = data.variables['lat']
longitudes = data.variables['lon']
fcsttimes = data.variables['time']
times = fcsttimes[0:6] # first 6 forecast times.
ntimes = len(times)
# convert times for datetime instances.
fdates = num2date(times,units=fcsttimes.units,calendar='standard')
# make a list of YYYYMMDDHH strings.
verifdates = [fdate.strftime('%Y%m%d%H') for fdate in fdates]
# convert times to forecast hours.
fcsthrs = []
for fdate in fdates:
    fdiff = fdate-fdates[0]
    fcsthrs.append(fdiff.days*24. + fdiff.seconds/3600.)
print fcsthrs
print verifdates
lats = latitudes[:]
nlats = len(lats)
lons1 = longitudes[:]
nlons = len(lons1)

# unpack 2-meter temp forecast data.
Ejemplo n.º 6
0
# read in sea-surface temperature and ice data
# can be a local file, a URL for a remote opendap dataset,
if len(sys.argv) == 1:
    date = '20071215'
else:
    date = sys.argv[1]
# convert datestring to datetime object.
date = datetime.datetime(int(date[0:4]), int(date[4:6]), int(date[6:8]))
print date
# open dataset.
dataset =\
NetCDFFile('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst2/totalAmsrAgg')
# find index of desired time.
time = dataset.variables['time']
nt = date2index(date, time, calendar='standard')
print num2date(time[nt], time.units, calendar='standard')
# read sst.  Will automatically create a masked array using
# missing_value variable attribute.
sst = dataset.variables['sst'][nt]
# read ice.
ice = dataset.variables['ice'][nt]
# read lats and lons (representing centers of grid boxes).
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
# shift lats, lons so values represent edges of grid boxes
# (as pcolor expects).
delon = lons[1] - lons[0]
delat = lats[1] - lats[0]
lons = (lons - 0.5 * delon).tolist()
lons.append(lons[-1] + delon)
lons = np.array(lons, np.float64)
Ejemplo n.º 7
0
# read in sea-surface temperature and ice data
# can be a local file, a URL for a remote opendap dataset,
if len(sys.argv) == 1:
    date = '20071215'
else:
    date = sys.argv[1]
# convert datestring to datetime object.
date = datetime.datetime(int(date[0:4]),int(date[4:6]),int(date[6:8]))
print date
# open dataset.
dataset =\
NetCDFFile('http://nomads.ncdc.noaa.gov/thredds/dodsC/oisst2/totalAmsrAgg')
# find index of desired time.
time = dataset.variables['time']
nt = date2index(date, time, calendar='standard')
print num2date(time[nt],time.units, calendar='standard')
# read sst.  Will automatically create a masked array using
# missing_value variable attribute.
sst = dataset.variables['sst'][nt]
# read ice.
ice = dataset.variables['ice'][nt]
# read lats and lons (representing centers of grid boxes).
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
# shift lats, lons so values represent edges of grid boxes
# (as pcolor expects).
delon = lons[1]-lons[0]
delat = lats[1]-lats[0]
lons = (lons - 0.5*delon).tolist()
lons.append(lons[-1]+delon)
lons = np.array(lons,np.float64)
Ejemplo n.º 8
0
URL="http://nomad1.ncep.noaa.gov:9090/dods/reanalyses/reanalysis-2/6hr/pgb/pgb"
print URL
try:
    data = NetCDFFile(URL)
except:
    raise IOError, 'opendap server not providing the requested data'

# read lats,lons,times.
print data.variables.keys()
latitudes = data.variables['lat'][:]
longitudes = data.variables['lon'][:].tolist()
times = data.variables['time']
ntime1 = date2index(date1,times,calendar='standard')
ntime2 = date2index(date2,times,calendar='standard')
print 'ntime1,ntime2:',ntime1,ntime2
print num2date(times[ntime1],times.units,calendar='standard'), num2date(times[ntime2],times.units,calendar='standard')
# get sea level pressure and 10-m wind data.
slpdata = data.variables['presmsl']
udata = data.variables['ugrdprs']
vdata = data.variables['vgrdprs']
# mult slp by 0.01 to put in units of millibars.
slpin = 0.01*slpdata[ntime1:ntime2+1,:,:]
uin = udata[ntime1:ntime2+1,0,:,:] 
vin = vdata[ntime1:ntime2+1,0,:,:] 
dates = num2date(times[ntime1:ntime2+1], times.units, calendar='standard')
# add cyclic points
slp = np.zeros((slpin.shape[0],slpin.shape[1],slpin.shape[2]+1),np.float64)
slp[:,:,0:-1] = slpin; slp[:,:,-1] = slpin[:,:,0]
u = np.zeros((uin.shape[0],uin.shape[1],uin.shape[2]+1),np.float64)
u[:,:,0:-1] = uin; u[:,:,-1] = uin[:,:,0]
v = np.zeros((vin.shape[0],vin.shape[1],vin.shape[2]+1),np.float64)
Ejemplo n.º 9
0
print URL
try:
    data = NetCDFFile(URL)
except:
    raise IOError, 'opendap server not providing the requested data'

# read lats,lons,times.
print data.variables.keys()
latitudes = data.variables['lat'][:]
longitudes = data.variables['lon'][:].tolist()
times = data.variables['time']
ntime1 = date2index(date1, times, calendar='standard')
ntime2 = date2index(date2, times, calendar='standard')
print 'ntime1,ntime2:', ntime1, ntime2
print num2date(times[ntime1], times.units,
               calendar='standard'), num2date(times[ntime2],
                                              times.units,
                                              calendar='standard')
# get sea level pressure and 10-m wind data.
slpdata = data.variables['presmsl']
udata = data.variables['ugrdprs']
vdata = data.variables['vgrdprs']
# mult slp by 0.01 to put in units of millibars.
slpin = 0.01 * slpdata[ntime1:ntime2 + 1, :, :]
uin = udata[ntime1:ntime2 + 1, 0, :, :]
vin = vdata[ntime1:ntime2 + 1, 0, :, :]
dates = num2date(times[ntime1:ntime2 + 1], times.units, calendar='standard')
# add cyclic points
slp = np.zeros((slpin.shape[0], slpin.shape[1], slpin.shape[2] + 1),
               np.float64)
slp[:, :, 0:-1] = slpin
slp[:, :, -1] = slpin[:, :, 0]