PyFVCOM is a collection of various tools and utilities which can be used to extract, analyse and plot input and output files from FVCOM as well as generate model inputs.
If you wish to cite PyFVCOM, please use the following:
Cazenave, P. W. et al. (2018). PyFVCOM (version x.x.x) [software]. Plymouth, Devon, United Kingdom: Plymouth Marine Laboratory. https://doi.org/10.5281/zenodo.1422462
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).
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(mesh.dims.node)] - Calculate element control areas:
element_control_area = [PyFVCOM.grid.element_control_area(e, mesh.grid.triangles, area) for e in range(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.time.date_range(start, end, inc=0.5)
-
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
-
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_lonlatlonlat_decimal_from_degminseclonlat_decimal_from_degminsec_wco
-
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_flowprogressive_vectorsvorticityebb_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_areasmp_interp_funcOpenBoundary- class to handle model open boundaries.OpenBoundary.add_sponge_layerOpenBoundary.add_typeOpenBoundary.add_tpxo_tidesOpenBoundary.add_fvcom_tidesOpenBoundary.add_nest_levelOpenBoundary.add_nest_weightsOpenBoundary.add_nested_forcingOpenBoundary.avg_nest_force_velNest- subclass of OpenBoundary to hold model nested level stripes. Used by the OpenBoundary methods.read_sms_meshread_fvcom_meshread_smesh_meshread_mike_meshread_gmsh_meshread_fvcom_obcparse_obc_sectionsread_sms_cstwrite_sms_meshwrite_sms_bathywrite_mike_meshwrite_sms_cstshp2cstMIKEarc2cstfind_nearest_pointelement_side_lengthsclip_triangulationget_river_configget_riversmesh2gridline_sampleelement_sampleconnectivityfind_connected_nodesfind_connected_elementsexpand_connected_nodesget_areafind_bad_nodetrigradientrotate_pointsget_boundary_polygonsget_attached_unique_nodesgrid_metricscontrol_volumesnode_control_areaclockwiseelement_control_areaunstructured_grid_volumeunstructured_grid_depthselems2nodesnodes2elemsvincenty_distancehaversine_distanceshape_coefficientsreduce_triangulationgetcrossectiontrianglesisintrianglesubset_domainmodel_exteriorfvcom2ugridpoint_in_pixelnode_to_centreGraph- class to hold an unstructured grid as a graphReducedFVCOMdist- class to query a grid graph for distance-based metricsGraphFVCOMdepth- class to query a grid graph for depth-based metrics
-
interpolate- a class to handle interpolation between unstructured and regular grids.mask_to_fvcommask_to_fvcom_meshgridMPIRegularInterpolateWorkerMPIRegularInterpolateWorker.InitialiseGridMPIRegularInterpolateWorker.InterpolateRegular
-
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.Depth- for plotting vertical slicesDepth.plot_sliceTime- for plotting timer series of dataTime.plot_lineTime.plot_scatterTime.plot_quiverTime.plot_surfacePlotter- for plotting horizontal mapsPlotter.plot_fieldPlotter.plot_quiverPlotter.plot_linesPlotter.remove_line_plotsPlotter.plot_scatterPlotter.plot_streamlinesCrossPlotter- for plotting cross-sectionsCrossPlotter.cross_section_initCrossPlotter.plot_pcolor_fieldCrossPlotter.plot_quiverMPIWorker- for plotting in parallel with MPIMPIWorker.plot_fieldMPIWorker.plot_streamlinesPlayer- for interactive animation of horizontal mapsplot_domain- to quickly plot a FileReader.colourbar_extensioncm2inch
-
preproc- class for creating input files for FVCOM model runs.Model- hold everything needed to generate new model inputsModel.write_gridModel.write_coriolisModel.add_bed_roughnessModel.write_bed_roughnessModel.interp_sst_assimilationModel.write_sstgrdModel.interp_adyModel.interp_ady_climatologyModel.write_adygrdModel.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.mask_river_estuaryModel.write_river_forcingModel.write_river_namelistModel.read_nemo_riversModel.read_ea_river_temperature_climatologyModel.add_probesModel.write_probesModel.add_stationsModel.write_stationsModel.add_nestsModel.add_nests_harmonicsModel.add_nests_regularModel.avg_nest_force_velModel.load_nested_forcingModel.write_nested_forcingModel.add_obc_typesModel.write_obcModel.add_groundwaterModel.write_groundwaterModel.read_regularModel.subset_existing_nestModel.load_elevtideModel.write_tsobcNameListEntry- class for holding entries in a NameList classNameListEntry.stringNameListEntry.tolistNameList- class for creating FVCOM model namelistsNameList.indexNameList.valueNameList.updateNameList.update_nudgingNameList.update_nesting_intervalNameList.valid_nesting_timescaleNameList.update_rampNameList.write_model_namelistwrite_model_namelistWriteForcing- actually a fairly generic class to write netCDFs with a concise syntaxWriteForcing.add_variableWriteForcing.write_fvcom_timeRegularReader- likePyFVCOM.read.FileReader, but for regularly gridded dataRegularReader.closest_elementRegularReader.closest_noderead_regular- load multiple regularly gridded filesHYCOMReader- likePyFVCOM.read.FileReader, but for HYCOM dataHYCOMReader.load_dataread_hycom- load multiple regularly gridded filesNEMOReader- likeRegularReader, but specifically for NEMO outputsNEMOReader.loadNemoRestartRegularReaderRegular2DReaderRestart- class to interact/modify FVCOM restart filesRestart.replace_variableRestart.replace_variable_with_regularRestart.write_restartRestart.read_regular
-
read- parse the netCDF model output and extract a subset of the variables.FileReader- read in FVCOM outputsFileReader.addFileReader.subtractFileReader.multiplyFileReader.divideFileReader.powerFileReader.load_dataFileReader.closest_timeFileReader.grid_volumeFileReader.total_volume_varFileReader.avg_volume_varFileReader.time_to_indexFileReader.time_average- `FileReader.add_river_flow
FileReader.to_excelFileReader.to_csvread_nesting_nodesapply_maskMFileReader- read in multiple FVCOM outputsSubDomainReader- subset a model domain in spaceSubDomainReader.add_evap_precipSubDomainReader.add_river_dataSubDomainReader.aopen_integralSubDomainReader.volume_integralSubDomainReader.surface_integraltime_to_indexFileReaderFromDict- have a go at converting fromncreadoutput toFileReaderformatncwritencread- read netCDF data to a dictionaryread_probeswrite_probesWriteFVCOM- write a FileReader object to a netCDF file in FVCOM format
-
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.PassiveStore- our template class for lots of other classesgeneral.fix_rangegeneral.ind2subgeneral.flatten_listgeneral.split_stringgeneral.ObjectFromDictgeneral.clean_htmlgeneral.cart2polgeneral.pol2carttime.julian_daytime.gregorian_datetime.overlaptime.common_timetime.make_signaltime.ramped_signal
-
validation- post-processing and validation utilities. Some of these are currently incomplete.ValidationDBValidationDB.execute_sqlValidationDB.create_tableValidationDB.insert_into_tableValidationDB.select_qryValidationDB.table_existsValidationDB.close_conndt_to_epochsecepochsec_to_dtplot_mapplot_tidesTideDBTideDB.make_bodc_tablesTideDB.insert_tide_fileTideDB.get_tidal_seriesTideDB.get_gauge_locationsTideDB.get_nearest_gauge_idBODCAnnualTideFileWCODBWCODB.make_wco_tablesWCODB.insert_CTD_fileWCODB.insert_buoy_fileWCODB.insert_CTD_dirWCODB.insert_csv_fileWCODB.get_observationsWCOParseFileCSVFormatterCompareDataCompareData.retrieve_file_dataCompareData.retrieve_obs_dataCompareData.get_comp_data_interpolatedCompareData.comp_data_nearestCompareData.model_closest_timeCompareDataFileReaderCompareDataFileReader.retrieve_file_dataCompareDataFileReader.model_closest_timeCompareDataProbeCompareDataProbe.retrieve_file_dataCompareICESCompareICES.get_var_comp
- 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
- Verbose output should be off by default