%pylab inline
Populating the interactive namespace from numpy and matplotlib
Similarly to the "Station class", the "FVCOM class" is a numerical-model-based object.
As any other library in Python, PySeidon has to be first imported before to be used. Here we will use an alternative import statement compared to the one previoulsy presented:
from pyseidon import *
*** Star *** here means all. Usually this form of statements would import the entire library. In the case of PySeidon, this statement will import the following object classes: FVCOM, Station, Validation, ADCP, Tidegauge and Drifter. Only the FVCOM class will be tackle in this tutorial. However note should note that the architecture design and functioning between each classes are very similar.
Python is by definition an object oriented language...and so is matlab. PySeidon is based on this notion of object, so let us define our first "FVCOM" object.
*Exercise 1: *
*Answer: *
FVCOM?
According to the documentation, in order to define a FVCOM object, the only required input is a *filename. This string input represents path to a file (e.g. testFvcom=FVCOM('./path_to_FVOM_output_file/filename') and whose file can be a pickle file (i.e. .p) or a netcdf file (i.e. .nc). Additionally, either a local file path or a OpenDap url could be used.
Optionally, one can extract spatial and/or temporal data from the designated file by respectively defining *ax* and *tx keywords. *ax* can be defined as a list of min/max longitudes and latitudes (e.g. ax = [minimum longitude, maximum longitude, minimum latitude, maximum latitude]) or as a pre-defined region tag (e.g. ax = 'GP', 'PP', 'DG' or 'MP'). Whereas *tx* can be defined as a list of date (e.g. tx = ['2012-11-07T12:00:00','2012.11.09T12:00:00']).
One should note that throughout the package, the following conventions apply:
*Exercise 2: *
*Answer: *
fvcomOD=FVCOM('http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc')
Retrieving data through OpenDap server... Initialisation...
ax=[-65.77, -65.75, 44.675, 44.685]
tx1=['2013-06-20 12:00:00', '2013-06-21 12:00:00']
tx2=['2013-06-21 12:00:00', '2013-06-21 18:00:00']
fvcomPartial1=FVCOM('http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc', ax=ax, tx=tx1)
fvcomPartial2=FVCOM('http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc', ax=ax, tx=tx2)
Retrieving data through OpenDap server... Initialisation... Re-indexing may take some time... -Now working in bounding box- -Now working in time box- Retrieving data through OpenDap server... Initialisation... Re-indexing may take some time... -Now working in bounding box- -Now working in time box-
The FVCOM object possesses 4 attributes, 4 methods (or 3 for 2D simulations) and 1 special method. They would appear by typing *fvcomOD. Tab* for instance.
An attribute is a quantity intrinsic to its object. A method is an intrinsic function which changes an attribute of its object. Contrarily a function will generate its own output:
The FVCOM attributes are:
The FVCOM methods & functions are:
The special FVCOM method permits to *stack* two FVCOM objects (e.g. fvcom1 and fvcom2) through a simple addition, as such:
However, fvcom1 and fvcom2 must share the exact same spatial domain and be consecutive in time (e.g. fvcom1 before in time compared to fvcom2).
*Exercise 3: *
*Answer: *
fvcomPartial1.History
['Created from http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc', 'Bounding box =[-65.77, -65.75, 44.675, 44.685]', 'Temporal domain from 2013-06-20 12:00:00 to 2013-06-21 12:00:00']
fvcomPartial1 += fvcomPartial2
fvcomPartial1.History
['Created from http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc', 'Bounding box =[-65.77, -65.75, 44.675, 44.685]', 'Temporal domain from 2013-06-20 12:00:00 to 2013-06-21 12:00:00', 'Data from FVCOM3D_dngrid_BF_20130619_20130621.nc has been stacked']
Note how the *History* attribute has changed
*Exercise 4: *
*Answer: *
fvcomPartial1.Plots.colormap_var(fvcomPartial1.Grid.h, title='Bathymetry (m)', mesh=False)
fvcomOD.Plots.colormap_var(fvcomOD.Grid.h, title='Bathymetry (m)', isoline='none')
*Exercise 5: *
*Answer: *
refPoint=[-65.761, 44.68]
pointA=[-65.76178, 44.68057]
pointB=[-65.76053, 44.68023]
pointC=[-65.76123, 44.67942]
pointD=[-65.76246, 44.67976]
fI, eI, pa, pav= fvcomPartial1.Util2D.ebb_flood_split_at_point(refPoint[0], refPoint[1])
fvcomPartial1.Util3D.velo_norm()
ebbNorm = np.mean(fvcomPartial1.Variables.velo_norm[eI,:,:], 0)
floodNorm = np.mean(fvcomPartial1.Variables.velo_norm[fI,:,:], 0)
fvcomPartial1.Plots.vertical_slice(ebbNorm, pointD, pointB, title='Time-averaged velocity norm (m/s)')
fvcomPartial1.Plots.vertical_slice(floodNorm, pointA, pointC, title='Time-averaged velocity norm (m/s)')
fvcomPartial1.History
-Velocity norm added to FVCOM.Variables.-
['Created from http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc', 'Bounding box =[-65.77, -65.75, 44.675, 44.685]', 'Temporal domain from 2013-06-20 12:00:00 to 2013-06-21 12:00:00', 'Data from FVCOM3D_dngrid_BF_20130619_20130621.nc has been stacked', 'Velocity norm computed']
*Exercise 6: *
*Answer: *
point = [-66.0, 45.0] #refPoint
fI, eI, pa, pav= fvcomOD.Util2D.ebb_flood_split_at_point(point[0], point[1])
vp = fvcomOD.Util3D.verti_shear_at_point(point[0], point[1], time_ind=eI, graph=True)
fD, norm = fvcomOD.Util2D.flow_dir_at_point(point[0], point[1], exceedance=True)
fvcomOD.Util2D.speed_histogram(point[0], point[1])
fvcomOD.Plots.colormap_var(fvcomOD.Grid.h, title='Bathmetry (m)', mesh=False)
fvcomOD.Plots.add_points(point[0], point[1], label='Location')
PySeidon can easily be coupled to any other Python library and package. For instance, the following script creates a series of *.png which could be then easily turn into an animated GIF with GIMP:
fvcomPartial1.Util2D.hori_velo_norm()
import matplotlib.pyplot as plt
for i in range(fvcomPartial1.Grid.ntime):
fvcomPartial1.Plots.colormap_var(fvcomPartial1.Variables.hori_velo_norm[i,:], title='Flow speed (m/s)')
saveName = 'anim{0}.png'.format(i)
plt.savefig(saveName, bbox_inches=0)
plt.close()
As beta tester, your first assignement is to report bugs...yet not everything is a bug. The first thing to check before to report a bug is to verify that your version of PySeidon is up-to-date. The best way to keep up with the package evolution is to *git* to *clone* the repository, use *pull* to update it and *re-install* it if needed.
The second thing to check before to report a bug is to verify that the bug is *reproducible. When running into a bug, double check that your inputs fit the description of the documentation then turn the debug flag on* (e.g. output = fvcomobject.function(inputs, debug=True)) and submit the command again. If the error re-occurs then report it (i.e. copy entire error message + command and send it to package administrator)
Your second role as beta-tester is to submit suggestions and critics to the developpers regarding the functioning and functionality of the package. Beta testing phase is the best opportunity to steer a project towards the applications you would like to be tackled...