pytuflow.NCGrid

pytuflow.NCGrid#

class NCGrid(fpath)#

Bases: Grid

Class for reading netCDF grid outputs (NC) from TUFLOW, though any CF-compliant netCDF file should work.

The NCGrid class 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.ResultTypeError if the file does not look like a NCGrid file, 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

close

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.

open_reader

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_mesh

Converts the grid to a GridMesh object, essentially converting the grid data structure into a mesh data structure.

Attributes

ATTRIBUTE_TYPES

DOMAIN_TYPES

GEOMETRY_TYPES

ID_COLUMNS

dx

The grid cell size in the x-direction.

dy

The grid cell size in the y-direction.

ncol

The number of columns in the grid.

no_data_value

The no data value for the grid.

nrow

The number of rows in the grid.

ox

The x-origin of the grid.

oy

The y-origin of the grid.

time_units

The units of time in the netCDF file.

name

The result name

has_reference_time

Does the result have an inherent reference time.

reference_time

The reference time for the output