This script calls routines from the utools library by Amy MacFadyen (NOAA ERL) to convert FVCOM datasets to GNOME compabible format for particle tracking. GNOME is available here: http://response.restoration.noaa.gov/oil-and-chemical-spills/oil-spills/response-tools/gnome.html. This script could be modified to read other FVCOM data sources very easily, but currently it requires a boundary file unique to a particular grid as input. From Amy's e-mail, it's not yet possible to create automatically in this script. Here we are reading an archive of NECOFS MassBay Forecast data using a boundary file that Amy provided.
To create a gnome dataset for downloading, modify the time values below, and then when the script is completed, download the data using this link:
http://geoport.whoi.edu/thredds/fileServer/usgs/data2/notebook/MassBay_depave.nc
Note that a week of data is about 220MB, so you probably don't want to specify the entire range.
You can watch the video below for how to use this script and use the results in GNOME, although for legibility of text you may prefer to watch in HD here: http://www.youtube.com/v/qZhLcm_xspc
In [29]:
from IPython.lib.display import YouTubeVideo
YouTubeVideo('qZhLcm_xspc')
Out[29]:
In [16]:
import utools
import netCDF4
import datetime as dt
In [17]:
data_url = 'http://www.smast.umassd.edu:8080/thredds/dodsC/fvcom/archives/necofs_mb'
bndry_file = 'MassB.bry'
nc = netCDF4.Dataset(data_url)
In [18]:
print nc.variables['ua']
In [19]:
time_var = nc.variables['time']
dtime = netCDF4.num2date(time_var[:],time_var.units)
print 'Dataset start time: %s' % dtime[0]
print 'Dataset stop time: %s' % dtime[-1]
In [20]:
# modify these time values:
start = dt.datetime(2011,7,10,0,0,0)
stop = dt.datetime(2011,7,17,0,0,0)
istart = netCDF4.date2index(start,time_var,select='nearest')
istop = netCDF4.date2index(stop,time_var,select='nearest')
print istart,istop
In [21]:
# lets see what variables are available
nc.variables.keys()
Out[21]:
In [22]:
# Let's take a look at a variable
print nc.variables['ua']
In [23]:
# Use a mapping of FVCOM variable names to common names so that the class methods can also
#work with SELFE and ADCIRC which have different var names
#This seemed easier than finding them by CF long_names etc
var_map = { 'longitude':'lon', \
'latitude':'lat', \
'time':'time', \
'u_velocity':'ua', \
'v_velocity':'va', \
'nodes_surrounding_ele':'nv',\
'eles_surrounding_ele':'nbe',\
}
necofs = utools.ugrid(data_url)
In [24]:
print 'Downloading data'
necofs.get_data(var_map,tindex=[istart,istop,1]) # get all time steps in range
#necofs.get_data(var_map) #All time steps in file
In [25]:
necofs.adjust_time() #GNOME can't handle pre 1980 start dates (in units)
In [26]:
necofs.get_bndry(bndry_file)
#This file was pre-generated for this grid (somewhat manually as open water/land boundaries
#are not specified in the model output
In [27]:
necofs.atts['nbe']['order'] = 'cw'
#GNOME needs to know whether the elements are ordered clockwise (FVCOM) or counter-clockwise (SELFE)
In [28]:
print 'Writing to GNOME file'
necofs.write_unstruc_grid('MassBay_depave.nc')