In [1]:
from pylab import *
import datetime as dt
import iris
In [2]:
#box=[-74.4751, 40.3890, -73.7432, 40.9397]
box=[-76.4751, 38.3890, -71.7432, 42.9397]
#box=[-180, -90, 180, 90]
# specific specific times (UTC) ...
# hurricane sandy
jd_start = dt.datetime(2012,10,26)
jd_stop = dt.datetime(2012,11,2)
# 2014 feb 10-15 storm
jd_start = dt.datetime(2014,2,10)
jd_stop = dt.datetime(2014,2,15)
# 2014 recent
jd_start = dt.datetime(2014,3,8)
jd_stop = dt.datetime(2014,3,11)
# 2011
#jd_start = dt.datetime(2013,4,20)
#jd_stop = dt.datetime(2013,4,24)
# ... or relative to now
jd_start = dt.datetime.utcnow()- dt.timedelta(days=3)
jd_stop = dt.datetime.utcnow() + dt.timedelta(days=3)
start_date = jd_start.strftime('%Y-%m-%d %H:00')
stop_date = jd_stop.strftime('%Y-%m-%d %H:00')
jd_start = dt.datetime.strptime(start_date,'%Y-%m-%d %H:%M')
jd_stop = dt.datetime.strptime(stop_date,'%Y-%m-%d %H:%M')
print start_date,'to',stop_date
sos_name = 'water_surface_height_above_reference_datum'
In [3]:
url='http://sos.maracoos.org/stable/dodsC/stationHRMARPH-agg.ncml'
url='http://geoport-dev.whoi.edu/thredds/dodsC/usgs/data2/rsignell/foo.ncml'
#url='http://opendap.co-ops.nos.noaa.gov/thredds/dodsC/DBOFS/fmrc/Aggregated_7_day_DBOFS_Fields_Forecast_best.ncd'
In [4]:
std_name_list=['water_surface_height_above_reference_datum',
'sea_surface_height_above_geoid','sea_surface_elevation',
'sea_surface_height_above_reference_ellipsoid','sea_surface_height_above_sea_level',
'sea_surface_height','water level']
In [5]:
print std_name_list
def name_in_list(cube):
return cube.standard_name in std_name_list
constraint = iris.Constraint(cube_func=name_in_list)
In [6]:
a = iris.load_cube(url,constraint)
In [7]:
print a
In [8]:
a.convert_units('m')
In [9]:
a.coord('time')
Out[9]:
In [10]:
def find_timevar(cube):
"""
return the time variable from Iris. This is a workaround for
Iris having problems with FMRC aggregations, which produce two time coordinates
"""
try:
cube.coord(axis='T').rename('time')
except:
pass
timevar = cube.coord('time')
return timevar
In [11]:
mod_name = a.attributes['title'][0:20]
r = shape(a)
timevar = find_timevar(a)
lat = a.coord(axis='Y').points
lon = a.coord(axis='X').points
jd = timevar.units.num2date(timevar.points)
istart = timevar.nearest_neighbour_index(timevar.units.date2num(jd_start))
istop = timevar.nearest_neighbour_index(timevar.units.date2num(jd_stop))
In [12]:
t=timevar.points
In [13]:
t.max()
Out[13]:
In [ ]: