pytuflow.Grid

pytuflow.Grid#

class Grid(fpath)#

Bases: MapOutput, LineStringMixin, PointMixin

Generic Grid result class. Can be used to load raster files that are supported by GDAL or rasterio. The raster data extracted from an input file is assumed to be static (i.e. no time dimension). Alternatively, it is possible to initialise the Grid class with a dictionary containing already extracted grid data in the form of an array. The dictionary should include metadata about the grid such as cell size, origin, and number of rows/columns. The data can be either static or temporal.

Parameters:

fpath (PathLike | dict) –

The file path to the grid file to load, or a dictionary containing grid data (as a np.ndarray) and metadata.

If using a dictionary, the following keys should be present:

  • dx : float

  • dy : float

  • ncol : int

  • nrow : int

  • ox : float : optional, default is 0.0

  • oy : float : optional, default is 0.0

  • nodatavalue : float, optional, default is np.nan

  • data : np.ndarray. Array can be 2D (static scalar, NRow,NCol), 3D (temporal scalar, NTime,NRow,NCol), 3D (static vector, NRow,NCol,2), or 4D (temporal vector, NTime,NRow,NCol,2). If data represents vector data, then the dtype key must also be set to "vector". If data is temporal, then the timesteps key must also be provided.

  • data_type : str, optional data type (result type) identifier

  • timesteps : list[float] | int, optional. If data is temporal, this should be a list of time values.

  • dtype : str, optional. Either "scalar" (default) or "vector".

Examples

Load a static grid from a GeoTIFF file:

>>> grid = Grid('path/to/static_grid.tif')
>>> grid.dx
10.0
>>> df = grid.surface()
                x           y  value  active
0       292723.75  6177421.25    NaN   False
1       292726.25  6177421.25    NaN   False
2       292728.75  6177421.25    NaN   False
3       292731.25  6177421.25    NaN   False
4       292733.75  6177421.25    NaN   False
...           ...         ...    ...     ...
197536  293768.75  6178586.25    NaN   False
197537  293771.25  6178586.25    NaN   False
197538  293773.75  6178586.25    NaN   False
197539  293776.25  6178586.25    NaN   False
197540  293778.75  6178586.25    NaN   False
__init__(fpath)#
Parameters:

fpath (Path | str | dict)

Methods

data_point

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

data_types

Returns all the available data types (result types) for the output given the context.

maximum

Returns the maximum values for the given data types.

minimum

Returns the minimum values for the given 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 all the available times for the given context.

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.

name

The result name

has_reference_time

Does the result have an inherent reference time.

reference_time

The reference time for the output