data_url = server_stem_url + file_stem + str(d.year) + str(d.month).zfill(2) + str(d.day).zfill(2) + '.nc' # the utools class requires a mapping of specific model variable names (values) # to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ } # class instantiation creates a netCDF Dataset object as an attribute wfs = tri_grid.ugrid(data_url) # get longitude, latitude, and time variables print('Downloading data dimensions') wfs.get_dimensions(var_map) #display available time range for model output nctools.show_tbounds(wfs.Dataset.variables['time']) # get grid topo variables (nbe, nv) print('Downloading grid topo variables') wfs.get_grid_topo(var_map) # find and order the boundary print('Finding boundary segs') bnd = wfs.find_bndry_segs()
# -*- coding: utf-8 -*- from __future__ import print_function from libgoods import tri_grid from libgoods import data_files_dir import os import numpy as np nc_file = 'http://geoport.whoi.edu/thredds/dodsC/usgs/vault0/models/tides/FLsab_adcirc54.nc' var_map = {'latitude':'lat','longitude':'lon','nodes_surrounding_ele':'ele'} adcirc = tri_grid.ugrid(nc_file) adcirc.get_dimensions(var_map,get_time=False) adcirc.get_grid_topo(var_map) nl = 30.6; sl = 29 wl = -82; el = -80.6 adcirc.find_nodes_eles_in_ss(nl,sl,wl,el) bnd = adcirc.find_bndry_segs(subset=True) print('Size of boundary: ', len(bnd)) seg_types = [0] * len(bnd) adcirc.order_boundary(bnd,seg_types) #adcirc.update(os.path.join(data_files_dir,'vdatum','vdatum_fl_sab_adcirc54.nc')) def parse_string(name): lista = [e.decode().strip() for e in name.tolist()] return ''.join(lista) names = [] const = adcirc.Dataset.variables['tidenames'][:] for name in const:
# and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) #!!!!!!!!CREOFS output on server does not include eles_surrounding_ele info #I have it saved as a netcdf file included in libgoods data_files directory var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'ele',\ 'eles_surrounding_ele':'',\ } # class instantiation creates a netCDF Dataset object as an attribute # creofs = utools.ugrid(flist) #multiple files creofs = tri_grid.ugrid(data_url) #single file output # get longitude, latitude, and time variables print 'Downloading data dimensions' creofs.get_dimensions(var_map) #display available time range for model output nctools.show_tbounds(creofs.Dataset.variables['time']) # get grid topo variables (nbe, nv) print 'Downloading grid topo variables' creofs.get_grid_topo(var_map) creofs.atts['nbe']['order'] = 'ccw' creofs.find_nodes_eles_in_ss(nl,sl,wl,el)
'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ } firsttime = 1 for f in flist: if firsttime: firsttime = 0 # class instantiation creates a netCDF Dataset object as an attribute -- # use the first file in the list only ngofs = tri_grid.ugrid(f) # # get longitude, latitude, and time variables # print 'Downloading data dimensions' # ngofs.get_dimensions(var_map) # get grid topo variables (nbe, nv) print 'Downloading grid topo variables' ngofs.get_grid_topo(var_map) # GNOME needs to know whether the elements are ordered clockwise (FVCOM) or counter-clockwise (SELFE) ngofs.atts['nbe']['order'] = 'cw' # find and order the boundary print 'Finding boundary' bnd = ngofs.find_bndry_segs() print 'Ordering boundary'
# -*- coding: utf-8 -*- from __future__ import print_function from libgoods import tri_grid from libgoods import data_files_dir import os ncfile = os.path.join(data_files_dir,'vdatum','vdatum_fl_sab_adcirc54.nc') var_map = {'latitude':'lat','longitude':'lon','nodes_surrounding_ele':'ele'} adcirc = tri_grid.ugrid(ncfile) adcirc.get_dimensions(var_map,get_time=False) adcirc.get_grid_topo(var_map) # find and order the boundary print('Finding boundary') bnd = adcirc.find_bndry_segs() seg_types = [0] * len(bnd) print('Ordering boundary') adcirc.order_boundary(bnd,seg_types) adcirc.write_unstruc_grid_only(os.path.join(data_files_dir,'vdatum','fl_sab_grid.nc'))
'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'ele',\ 'eles_surrounding_ele':'',\ } firsttime = 1 for f in flist: if firsttime: firsttime = 0 # class instantiation creates a netCDF Dataset object as an attribute -- # use the first file in the list only creofs = tri_grid.ugrid(f) # # get longitude, latitude, and time variables # print 'Downloading data dimensions' # creofs.get_dimensions(var_map) # get grid topo variables (nbe, nv) print('Downloading grid topo variables') creofs.get_grid_topo(var_map) creofs.get_dimensions(var_map,get_time=False) # GNOME needs to know whether the elements are ordered clockwise (FVCOM) or counter-clockwise (SELFE) creofs.atts['nbe']['order'] = 'ccw' creofs.find_nodes_eles_in_ss(nl,sl,wl,el) # find and order the boundary
# to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ 'sigma':'siglay',\ 'depth':'h',\ } # class instantiation creates a netCDF Dataset object as an attribute nwgofs = tri_grid.ugrid(flist[0]) # get longitude, latitude print('Downloading data dimensions') nwgofs.get_dimensions(var_map,get_time=False) # get grid topo variables (nbe, nv) print('Downloading grid topo variables') nwgofs.get_grid_topo(var_map) # GNOME needs to know whether the elements are ordered clockwise (FVCOM) or counter-clockwise (SELFE) nwgofs.atts['nbe']['order'] = 'cw' # find and order the boundary print('Finding boundary') bnd = nwgofs.find_bndry_segs() print('Ordering boundary')
# to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) #!!!!!!!!txselfe output on server does not include eles_surrounding_ele info #I have it saved as a netcdf file included in libgoods data_files directory var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'ele',\ 'eles_surrounding_ele':'',\ } # class instantiation creates a netCDF Dataset object as an attribute txselfe = tri_grid.ugrid(data_file) # get longitude, latitude, and time variables print 'Downloading data dimensions' # Normally this would be a call to txself.get_dimensions(var_map) but # this file has no time info, and only UTM coordinates -- so we do it # manually #Enter actual model time here for particular file model_time = dt.datetime(2013,8,21,0,0,0) #I made this time up t_units = 'hours since 2012-01-01 00:00:00' txselfe.data['time'] = [date2num(model_time,t_units),] txselfe.atts['time'] = {'units':t_units} x = txselfe.Dataset.variables['x'][:] y = txselfe.Dataset.variables['y'][:]
# to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) #!!!!!!!!txsuntans output on server does not include eles_surrounding_ele info #I have it saved as a netcdf file included in libgoods data_files directory var_map = { 'time':'time',\ 'u_velocity':'uc', \ 'v_velocity':'vc', \ 'nodes_surrounding_ele':'cells',\ 'eles_surrounding_ele':'nbe',\ 'edge_node_connectivity':'edges',\ } # class instantiation creates a netCDF Dataset object as an attribute txsuntans = tri_grid.ugrid(data_file) # get longitude, latitude, and time variables print 'Downloading data dimensions' txsuntans.get_dimensions(var_map) # UTM coordinates -- calculate lat/lon x = txsuntans.Dataset.variables['xp'][:] y = txsuntans.Dataset.variables['yp'][:] lon = np.ones_like(x); lat = np.ones_like(x) for ii in range(len(x)): lat[ii], lon[ii] = nctools.utmToLatLng(14,x[ii],y[ii]) txsuntans.data['lon'] = lon txsuntans.data['lat'] = lat txsuntans.atts['lon'] = {'long_name': 'longitude'} txsuntans.atts['lat'] = {'long_name': 'latitude'}
grid = 'hecwfs' # the utools class requires a mapping of specific model variable names (values) # to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ } # class instantiation creates a netCDF Dataset object as an attribute stclair = tri_grid.ugrid(data_url) # get longitude, latitude, and time variables print('Downloading data dimensions') stclair.get_dimensions(var_map) #display available time range for model output nctools.show_tbounds(stclair.Dataset.variables['time']) # get grid topo variables (nbe, nv) print('Downloading grid topo variables') stclair.get_grid_topo(var_map) # GNOME needs to know whether the elements are ordered clockwise (FVCOM) or counter-clockwise (SELFE) stclair.atts['nbe']['order'] = 'cw' # find and order the boundary
# the utools class requires a mapping of specific model variable names (values) # to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ } # class instantiation creates a netCDF Dataset object as an attribute -- # use the first file in the list only ngofs = tri_grid.ugrid(flist[0]) #get longitude, latitude print('Downloading data dimensions') ngofs.get_dimensions(var_map, get_time=False) # get grid topo variables (nbe, nv) print('Downloading grid topo variables') ngofs.get_grid_topo(var_map) # subset bounding box nl = 30.7 sl = 28.6 wl = -89.643 el = -87.391 ngofs.find_nodes_eles_in_ss(nl, sl, wl, el)
# the utools clasalish_sea requires a mapping of specific model variable names (values) # to common names (keys) so that the clasalish_sea methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ } # clasalish_sea instantiation creates a netCDF Dataset object as an attribute salish_sea = tri_grid.ugrid(filenames) # get longitude, latitude, and time variables print 'Downloading data dimensions' salish_sea.get_dimensions(var_map) #fix time units salish_sea.atts['time']['units'] = 'seconds since 2006-01-01 00:00:00' #display available time range for model output #nctools.show_tbounds(salish_sea.Dataset.variables['time']) # UTM coordinates -- calculate lat/lon x = salish_sea.data['lon'] #these are actually UTM even though named lon/lat in file y = salish_sea.data['lat'] lon = np.ones_like(x); lat = np.ones_like(x) for ii in range(len(x)): lat[ii], lon[ii] = nctools.utmToLatLng(10,x[ii],y[ii]) salish_sea.data['lon'] = lon
# the utools clasalish_sea requires a mapping of specific model variable names (values) # to common names (keys) so that the clasalish_sea methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ } # clasalish_sea instantiation creates a netCDF Dataset object as an attribute salish_sea = tri_grid.ugrid(filenames) # get longitude, latitude, and time variables print 'Downloading data dimensions' salish_sea.get_dimensions(var_map) #fix time units salish_sea.atts['time']['units'] = 'seconds since 2006-01-01 00:00:00' #display available time range for model output #nctools.show_tbounds(salish_sea.Dataset.variables['time']) # UTM coordinates -- calculate lat/lon x = salish_sea.data[ 'lon'] #these are actually UTM even though named lon/lat in file y = salish_sea.data['lat'] lon = np.ones_like(x) lat = np.ones_like(x) for ii in range(len(x)):
grid = 'hecwfs' # the utools class requires a mapping of specific model variable names (values) # to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'time', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'nv',\ 'eles_surrounding_ele':'nbe',\ } # class instantiation creates a netCDF Dataset object as an attribute stclair = tri_grid.ugrid(data_url) # get longitude, latitude, and time variables print 'Downloading data dimensions' stclair.get_dimensions(var_map) #display available time range for model output nctools.show_tbounds(stclair.Dataset.variables['time']) # get grid topo variables (nbe, nv) print 'Downloading grid topo variables' stclair.get_grid_topo(var_map) # GNOME needs to know whether the elements are ordered clockwise (FVCOM) or counter-clockwise (SELFE) stclair.atts['nbe']['order'] = 'cw' # find and order the boundary
# to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) #!!!!!!!!txselfe output on server does not include eles_surrounding_ele info #I have it saved as a netcdf file included in libgoods data_files directory var_map = { 'longitude':'lon', \ 'latitude':'lat', \ 'time':'', \ 'u_velocity':'u', \ 'v_velocity':'v', \ 'nodes_surrounding_ele':'ele',\ 'eles_surrounding_ele':'',\ } # class instantiation creates a netCDF Dataset object as an attribute txselfe = tri_grid.ugrid(data_file) # get longitude, latitude, and time variables print 'Downloading data dimensions' # Normally this would be a call to txself.get_dimensions(var_map) but # this file has no time info, and only UTM coordinates -- so we do it # manually #Enter actual model time here for particular file model_time = dt.datetime(2013, 8, 21, 0, 0, 0) #I made this time up t_units = 'hours since 2012-01-01 00:00:00' txselfe.data['time'] = [ date2num(model_time, t_units), ] txselfe.atts['time'] = {'units': t_units}
# to common names (keys) so that the class methods can work with FVCOM, SELFE, # and ADCIRC which have different variable names # (This seemed easier than finding them by CF long_names etc) #!!!!!!!!txsuntans output on server does not include eles_surrounding_ele info #I have it saved as a netcdf file included in libgoods data_files directory var_map = { 'time':'time',\ 'u_velocity':'uc', \ 'v_velocity':'vc', \ 'nodes_surrounding_ele':'cells',\ 'eles_surrounding_ele':'nbe',\ 'edge_node_connectivity':'edges',\ } # class instantiation creates a netCDF Dataset object as an attribute txsuntans = tri_grid.ugrid(data_file) # get longitude, latitude, and time variables print 'Downloading data dimensions' txsuntans.get_dimensions(var_map) # UTM coordinates -- calculate lat/lon x = txsuntans.Dataset.variables['xp'][:] y = txsuntans.Dataset.variables['yp'][:] lon = np.ones_like(x) lat = np.ones_like(x) for ii in range(len(x)): lat[ii], lon[ii] = nctools.utmToLatLng(14, x[ii], y[ii]) txsuntans.data['lon'] = lon txsuntans.data['lat'] = lat txsuntans.atts['lon'] = {'long_name': 'longitude'}