pytuflow.NCMesh

pytuflow.NCMesh#

class NCMesh(fpath, driver='v1.1')#

Bases: Mesh

Class for handling TUFLOW FV style output files.

The NCMesh class supports both QGIS and Python drivers. The drivers are also split between geometry handling and data extraction.

If using Python libraries, the NCMesh class is initialised without loading the mesh geometry data. This makes the class cheap to initialise and allows querying of available data types and times without requiring mesh loading. The mesh geometry data is only loaded when required for spatial data extraction.

QGIS libraries can be used for geometry handling and Python libraries can be used for data extraction, this also allows for the cheap initialisation of the class. If QGIS libraries are used for both geometry and data extraction, the mesh geometry data is loaded at initialisation.

Parameters:
  • fpath (PathLike) – Path to the NetCDF file.

  • driver (str, optional) –

    The driver to use for reading the NCMesh file. Options are:

    • "v1.0": Use PyTUFLOW v1.0 NCMesh reader (legacy). This uses old QGIS geometry and extraction methods.

    • "v1.1": Use PyTUFLOW v1.1 NCMesh reader (default). Uses Python geometry handling if available, otherwise uses QGIS geometry. For data extraction, the order of preference is h5py, netcdf4, then QGIS.

    • "qgis geometry [data extractor]": Use QGIS libraries for geometry ("qgis geometry") and the optional use of QGIS for data extraction as well ("qgis geometry data extractor"). If only "qgis geometry" is provided, the data extraction can also use Python libraries if available e.g. "qgis geometry netcdf4" or "qgis geometry h5py". Using NetCDF4 or h5py for data extraction allows for cheap initialisation of the class.

    • "netcdf4": Use NetCDF4 library for extracting data. Can be used with "qgis geometry" otherwise

      uses Python libraries for geometry handling.

    • "h5py": Use h5py library for extracting data. Can be used with "qgis geometry" otherwise uses Python libraries for geometry handling.

Examples

>>> from pytuflow import NCMesh
>>> nc = NCMesh('./path/to/nc')

Get all the data types available in the NetCDF file:

>>> nc.data_types()
['bed level', 'velocity', 'water level', 'salinity', 'temperature']

Get all the times available in the NetCDF file:

>>> nc.times()
[0.0, 0.5, ..., 3.0]

Get the water level time-series data for a given point defined in a shapefile:

>>> nc.time_series('path/to/shapefile.shp', 'water level')
    time  pnt1/water level
0.000000               NaN
0.083333               NaN
0.166667               NaN
0.250000               NaN
0.333333               NaN
0.416667               NaN
0.500000               NaN
0.583333               NaN
0.666667         41.561204
0.750000         41.838923
...                    ...
2.666667         41.278006
2.750000         41.239387
2.833334         41.201996
2.916667         41.166462
3.000000         41.128152

Get the depth-averaged velocity time-series using the Sigma method:

>>> nc.time_series('path/to/shapefile.shp', 'velocity', averaging_method='sigma&0.1&0.9')
time      pnt1/velocity
0.000000       0.353553
0.016667       0.353553
0.033333       0.353553
0.050000       0.353553
0.066667       0.353553
0.083333       0.353553

Get water level section data using a shapefile:

>>> nc.section('path/to/shapefile.shp', 'water level', 1.0)
      line1
     offset water level
0  0.000000         0.1
1  0.605553         0.1
2  0.605553         0.2
3  1.614808         0.2
4  1.614808         0.3
5  2.220360         0.3

Get a velocity curtain plot using a shapefile:

>>> nc.curtain('path/to/shapefile.shp', 'velocity', 0.5)
       line1
           x    y  velocity
0   0.000000  0.0  0.282843
1   0.605553  0.0  0.282843
2   0.605553  0.5  0.282843
3   0.000000  0.5  0.282843
4   0.000000  0.5  0.424264
5   0.605553  0.5  0.424264
6   0.605553  1.0  0.424264
7   0.000000  1.0  0.424264
8   0.605553  0.0  0.565685
9   1.614808  0.0  0.565685
10  1.614808  0.5  0.565685
11  0.605553  0.5  0.565685
12  0.605553  0.5  0.707107
13  1.614808  0.5  0.707107
14  1.614808  1.0  0.707107
15  0.605553  1.0  0.707107
16  1.614808  0.0  0.848528
17  2.220360  0.0  0.848528
18  2.220360  0.5  0.848528
19  1.614808  0.5  0.848528
20  1.614808  0.5  0.989949
21  2.220360  0.5  0.989949
22  2.220360  1.0  0.989949
23  1.614808  1.0  0.989949

Get a velocity (vertical) profile plot using a point shapefile:

>>> nc.profile('path/to/shapefile.shp', 'velocity', 0.5)
       pnt1
  elevation  velocity
0       0.0  0.282843
1       0.5  0.282843
2       0.5  0.424264
3       1.0  0.424264
__init__(fpath, driver='v1.1')#
Parameters:
  • fpath (Path | str)

  • driver (str)

Methods

curtain

Extracts curtain data for the given locations and data types.

data_point

Extracts the data value for the given point locations and data types at the specified time.

data_types

Return the available data types for the given filter.

maximum

Returns the maximum values for the given data types.

minimum

Returns the minimum values for the given data types.

profile

Extracts vertical profile data for the given locations and data types.

section

Extracts section data for the given locations and data types.

surface

Returns the value for every cell/vertex at the specified time.

time_series

Extracts time-series data for the given locations and data types.

times

Returns a list of times for the given filter.

to_alembic

Exports the mesh to an Alembic file for visualisation in compatible software.

to_gltf

Exports the mesh to a glTF 2.0 file for visualisation in compatible software.

Attributes

ATTRIBUTE_TYPES

DOMAIN_TYPES

GEOMETRY_TYPES

ID_COLUMNS

spherical

Returns whether the mesh is in spherical coordinates.

name

The result name

has_reference_time

Does the result have an inherent reference time.

reference_time

The reference time for the output