PyFVCOM is a collection of various tools and utilities which can be used to extract, analyse and plot input and output files from FVCOM.
Easiest way is to install with pip/pip3:
pip install PyFVCOMIf you want to install the development version, checkout the `dev' branch and then from within the top-level directory:
pip install --user -e .We are targeting Python 3.6+. PyFVCOM no longer supports Python 2.
We recommend Jupyter (formerly iPython) for interactive use of PyFVCOM (and python generally).
-
buoy- read data from an SQLite3 database of BODC buoy data.Buoy- class to hold a range of time series data from buoys.get_buoy_metadataget_buoy_data
-
coast- work with coastlinesread_ESRI_shapefileread_arc_MIKEread_CSTwrite_CST
-
coordinate- convert from spherical and cartesian (UTM) coordinates. Also work with British National Grid coordinates and spherical.utm_from_lonlatlonlat_from_utmbritish_national_grid_to_lonlat
-
ctd- interrogate an SQLite data base of CTD casts.CTD- class to hold a range of time series data from many different CTD formats we (PML) encounter.get_CTD_metadataget_CTD_dataget_ferrybox_data
-
current- tools related to processing currentsResidualsscalar2vectorvector2scalarresidual_flowvorticityebb_floodprincipal_axis
-
grid- tools to parse SMS, DHI MIKE, GMSH and FVCOM unstructured grids. Also provides functionality to add coasts and clip triangulations to a given domain. Functions to parse FVCOM river files are also included, as is a function to resample an unstructured grid onto a regular grid (without interpolation, simply finding the nearest point within a threshold distance). This module contains a number of generally useful tools related to unstructured grids (node and element lookups, grid connectivity, grid metrics, area tools).Domain- class to abstract loading different grid types away. Theread_*_meshmethods below are now slighly redundant.Domain.closest_nodeDomain.closest_elementDomain.horizontal_transect_nodesDomain.horizontal_transect_elementsDomain.calculate_areasOpenBoundary- class to handle model open boundaries.OpenBoundary.add_sponge_layerOpenBoundary.add_tpxo_tidesOpenBoundary.add_nested_forcingread_sms_meshread_fvcom_meshread_mike_meshread_gmsh_meshwrite_sms_meshwrite_sms_bathywrite_mike_meshfind_nearest_pointelement_side_lengthsclip_triangulationget_river_configget_riversmesh2gridline_sampleelement_sampleconnectivityfind_connected_nodesfind_connected_elementsget_areafind_bad_nodetrigradientrotate_pointsget_boundary_polygonsget_attached_unique_nodesgrid_metricscontrol_volumesnode_control_areaelement_control_areaunstructured_grid_volumeunstructured_grid_depthselems2nodesnodes2elemsvincenty_distancehaversine_distanceshape_coefficientsreduce_triangulationgetcrossectiontrianglesisintriangle
-
ocean- a number of routines to convert between combinations of temperature, salinity, pressure, depth and density.pressure2depthdepth2pressuredT_adiab_swtheta_swcp_swsw_smowsw_dens0sw_secksw_denssw_svansw_sal78dens_jackettcond2saltzbarpeasimpsonhuntermixedlayerdepthstokesdissipationcalculate_rhum
-
plot- plotting class for FVCOM outputs.Time.plot_lineTime.plot_scatterTime.plot_quiverTime.plot_surfacePlotter.plot_fieldPlotter.plot_quiverPlotter.plot_linesPlotter.remove_line_plotsPlotter.plot_scatter
-
preproc- class for creating input files for FVCOM model runs.Model.write_gridModel.write_coriolisModel.add_bed_roughnessModel.write_bed_roughnessModel.interp_sst_assimilationModel.write_sstgrdModel.add_sigma_coordinatesModel.sigma_generalizedModel.sigma_geometricModel.sigma_tanhModel.hybrid_sigma_coordinateModel.write_sigmaModel.add_open_boundariesModel.write_spongeModel.add_grid_metricsModel.write_tidesModel.add_riversModel.check_riversModel.write_river_forcingModel.write_river_namelistModel.read_nemo_riversModel.add_probesModel.write_probesModel.read_regularWriteForcing.add_variableWriteForcing.write_fvcom_timeRegularReader- likePyFVCOM.read.FileReader, but for regularly gridded data.read_regular- load multiple regularly gridded files.HYCOMReader- likePyFVCOM.read.FileReader, but for HYCOM data.read_hycom- load multiple regularly gridded files.
-
read- parse the netCDF model output and extract a subset of the variables.FileReaderMFileReaderFileReaderFromDictncwritencreadread_probeswrite_probes
-
stats- some basic statistics tools.calculate_regressioncalculate_polyfitrmsecalculate_coefficient
-
tidal_ellipse- Python version of the Tidal Ellipse MATLAB toolbox http://woodshole.er.usgs.gov/operations/sea-mat/tidal_ellipse-html/index.html.ap2epep2apcBEpmget_BEsub2indplot_elldo_the_plotprep_plot
-
tide- tools to use and abuse tidal data from an SQLite database of tidal time series.HarmonicOutputadd_harmonic_resultsget_observed_dataget_observed_metadataclean_observed_dataparse_TAPPY_XMLget_harmonicsread_POLPREDgrid_POLPREDget_harmonics_POLPREDmake_water_columnLanczos- Lanczos time filter.lanczos- As above, but not a class.
-
utilities- general utilities (including time utilities)general.fix_rangegeneral.ind2subgeneral.flatten_listgrid.StubFiletime.julian_daytime.gregorian_datetime.overlaptime.common_time
-
validation- post-processing and validation utilities. Some of these are currently incomplete.validation_dbvalidation_db.execute_sqlvalidation_db.create_tablevalidation_db.insert_into_tablevalidation_db.select_qryvalidation_db.table_existsvalidation_db.close_conndt_to_epochsecepochsec_to_dtplot_mapplot_tidesdb_tidedb_tide.make_bodc_tablesdb_tide.insert_tide_filedb_tide.get_tidal_seriesdb_tide.get_gauge_locationsdb_tide.get_nearest_gauge_idbodc_annual_tide_filedb_wcodb_wco.make_wco_tablesdb_wco.insert_CTD_filedb_wco.insert_buoy_filedb_wco.insert_CTD_dirdb_wco.insert_csv_filedb_wco.get_observationsWCO_obs_filecsv_formattedcomp_datacomp_data.retrieve_file_datacomp_data.retrieve_obs_datacomp_data.get_comp_data_interpolatedcomp_data.comp_data_nearestcomp_data.model_closest_timecomp_data_filereadercomp_data_filereader.retrieve_file_datacomp_data_filereader.model_closest_timecomp_data_probecomp_data_probe.retrieve_file_dataICES_compICES_comp.get_var_comp
The examples directory includes some Jupyter notebooks of some brief examples of how to use PyFVCOM. There are also sample scripts of those notebooks.
- Read an SMS unstructured grid:
mesh = PyFVCOM.grid.Domain('mesh.2dm') - Read an FVCOM unstructured grid:
mesh = PyFVCOM.grid.Domain('mesh.dat') - Find elements connected to node:
elements = PyFVCOM.grid.find_connected_elements(n, mesh.grid.triangles) - Find nodes connected to node:
nodes = PyFVCOM.grid.find_connected_nodes(n, mesh.grid.triangles) - Find model boundary from a grid:
coast = PyFVCOM.grid.get_boundary_polygons(mesh.grid.triangles) - Calculate element areas:
mesh.calculate_areas() - Calculate node control areas:
node_control_area = [PyFVCOM.grid.node_control_area(n) for n in range(len(mesh.dims.node))] - Calculate element control areas:
element_control_area = [PyFVCOM.grid.element_control_area(e, mesh.grid.triangles, area) for e in range(len(fvcom.dims.nele))] - Move a field from elements to nodes:
on_nodes = elems2nodes(fvcom.data.field, mesh.grid.triangles) - Move a field from nodes to elements:
on_elements = nodes2elems(fvcom.data.field, mesh.grid.triangles)
- Read model output:
fvcom = PyFVCOM.read.FileReader('casename_0001.nc', variables=['temp', 'salinity']) - Calculate density from temperature and salinity:
density = PyFVCOM.ocean.dens_jackett(fvcom.data.temp, fvcom.data.salinity)
- Make an array of datetime objects:
times = PyFVCOM.utilities.date_range(start, end, inc=0.5)
- Use 4 spaces per indentation level
- Never mix tabs and spaces
- Imports should usually be on separate lines
from module import *is not OK; rather, usefrom module import name- Imports are always put at the top of the file
- Avoid extraneous whitespace
- Use parentheses sparingly
- Don't put an if/for/while with a small body on a single line
- Do not terminate your lines with semi-colons and do not use semi-colons to put two commands on the same line
- If a class inherits from no other base classes, explicitly inherit from object. This also applies to nested classes.
- Function names should be lowercase, underscore separated. Class names should be of the form `MyClass'.
- Names of members considered private shall start with two underscores
- Use lambda expressions only for one-liners (else: hard to read and to debug)
- Use properties for accessing or setting data where you would normally have used simple, lightweight getter or setter methods
- Use
withwhen opening files or explicitly close files and sockets when done with them - Use TODO comments for code that is temporary, a short-term solution, or good-enough but not perfect
Cazenave, P. W. and Bedington, M. (2018). PyFVCOM (version x.x.x) [software]. Plymouth, Devon, United Kingdom: Plymouth Marine Laboratory. https://doi.org/10.5281/zenodo.1422462