%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-dvt 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_dvt import *
*** Star *** here means all. Usually this form of statements would import the entire library. In the case of PySeidon-dvt, 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-dvt 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* defines a specific spatial region to work with, as such:
*tx* defines for a specific temporal period to work with, as such:
Note that these options permit to extract partial data from the overall file and therefore reduce memory and cpu use.
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 from /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc ... Initialisation...
ax=[-65.77, -65.75, 44.675, 44.685]
ax2=[-64.4221, -64.4284, -64.4029, -64.3977, 45.3713, 45.3614, 45.3566, 45.3662]
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)
fvcomPartial3=FVCOM('http://ecoii.acadiau.ca/thredds/dodsC/ecoii/test/FVCOM3D_dngrid_BF_20130619_20130621.nc', ax=ax2, tx=tx2)
Retrieving data from /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc ... Initialisation... Re-indexing may take some time... -Now working in bounding box- -Now working in time box- Retrieving data from /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc ... Initialisation... Re-indexing may take some time... -Now working in bounding box- -Now working in time box- Retrieving data from /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc ... 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 /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc', 'Bounding box =[-65.77, -65.75, 44.675, 44.685]', 'Temporal domain from 2011-09-02 12:00:00 to 2011-09-02 18:00:00']
fvcomPartial1 += fvcomPartial2
fvcomPartial1.History
['Created from /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc', 'Bounding box =[-65.77, -65.75, 44.675, 44.685]', 'Temporal domain from 2011-09-02 12:00:00 to 2011-09-02 18:00:00', 'Data from acadia_BoF_2011-09-02_2011-09-04.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)
fvcomPartial3.Plots.colormap_var(fvcomPartial3.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 /home/grumpynounours/Desktop/test/acadia_BoF_2011-09-02_2011-09-04.nc', 'Bounding box =[-65.77, -65.75, 44.675, 44.685]', 'Temporal domain from 2011-09-02 12:00:00 to 2011-09-02 18:00:00', 'Data from acadia_BoF_2011-09-02_2011-09-04.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-dvt's 2D functionality is gathered in Util2D and composed of 12 functions:
and 7 methods:
*Exercise 7: *
*Example*
fvcomOD.Util2D.degree2metric_coordinates?
x, y = fvcomOD.Util2D.degree2metric_coordinates(pointA[0], pointA[1])
print x, y
-95425.7547239 315615.675451
*Exercise 8: *
fvcomPartial1.Util2D.depth?
fvcomPartial1.Util2D.depth()
fvcomPartial1.Grid.depth2D.shape
-Depth 2D added to FVCOM.Variables.-
(110, 982)
PySeidon-dvt's 2D functionality is gathered in Util2D and composed of 9 functions:
and 6 methods:
*Exercise 9: *
PySeidon-dvt 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-dvt 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...