pytuflow.NCGrid#
- class NCGrid(fpath)#
Bases:
GridClass for reading netCDF grid outputs (NC) from TUFLOW, though any CF-compliant netCDF file should work.
The
NCGridclass will only load header information from the NC file on initialisation, this makes the class cheap to initialise.The netCDF4 library is required to use this class.
- Parameters:
fpath (PathLike) – Path to the netCDF file.
- Raises:
ResultTypeError – Raises
pytuflow.results.ResultTypeErrorif the file does not look like aNCGridfile, or if the file is empty or locked by another program.
Examples
>>> from pytuflow import NCGrid >>> nc = NCGrid('./path/to/nc')
Get all the data types available in the netCDF file:
>>> nc.data_types() ['water level', 'depth', 'velocity', 'z0', 'max water level', 'max depth', 'max velocity', 'max z0', 'tmax water level']
Get only the temporal data types:
>>> nc.data_types('temporal') ['water level', 'depth', 'velocity', 'z0']
Get only the vector data types:
>>> nc.data_types('vector') ['velocity', 'max velocity']
Get all the available times in the netCDF file:
>>> nc.times() [0.0, 0.08333, 0.1667, 0.25, 0.3333, 0.4167, 0.5]
Get the water level time-series data for a given point defined in a shapefile:
>>> nc.time_series('/path/to/point.shp', 'water level') time pnt1/water level 0.00000 NaN 0.08333 NaN 0.16670 NaN 0.25000 NaN 0.33330 44.125675 0.41670 44.642513 0.50000 45.672554 0.58330 46.877666
Get a water level section from a line defined in a shapefile at time 0.5 hrs:
>>> nc.section('/path/to/line.shp', 'water level', 0.5) offset Line 1/water level 0 0.000000 45.994362 1 1.495967 45.994362 2 1.495967 45.636654 3 4.159921 45.636654 4 4.159921 45.592628 5 6.804385 45.592628 6 6.804385 45.624744 7 6.823876 45.624744 8 6.823876 45.583813 9 9.487831 45.583813 10 9.487831 45.560959
- __init__(fpath)#
- Parameters:
fpath (Path | str)
Methods
Extracts the data value for the given point locations and data types at the specified time.
Return the available data types for the given filter.
Returns the maximum values for the given data types.
Returns the minimum values for the given data types.
Extracts section data for the given locations and data types.
Returns the value for every cell/vertex at the specified time.
Extracts time-series data for the given locations and data types.
Returns a list of times for the given filter.
Converts the grid to a
GridMeshobject, essentially converting the grid data structure into a mesh data structure.Attributes
The grid cell size in the x-direction.
The grid cell size in the y-direction.
The number of columns in the grid.
The no data value for the grid.
The number of rows in the grid.
The x-origin of the grid.
The y-origin of the grid.
The units of time in the netCDF file.
The result name
Does the result have an inherent reference time.
The reference time for the output