pytuflow.NCGrid.section

Contents

pytuflow.NCGrid.section#

NCGrid.section(locations, data_types, time, **kwargs)#

Extracts section data for the given locations and data types.

The locations can be a list of x, y tuple points, or a Well Known Text (WKT) line string. It can also be a dictionary of key, line-string pairs where the key is the name that will be used in the column name in the resulting DataFrame.

The locations argument can also be a single GIS file path e.g. Shapefile or GPKG (but any format supported by GDAL is also supported). GPKG’s should follow the TUFLOW convention if specifying the layer name within the database database.gpkg >> layer. If the GIS layer has a field called name, label, or ID then this will be used as the column name in the resulting DataFrame.

The resulting DataFrame will use multi-index columns since the data is not guaranteed to have the same index. The level 1 index will be the label, and the level 2 index will be the data type. The offset will always be the first column within the level 2 index.

Parameters:
  • locations (list[Point] | str | PathLike) – The location to extract the section data for.

  • data_types (str | list[str]) – The data types to extract the section data for.

  • time (TimeLike) – The time to extract the section data for.

Returns:

The section data.

Return type:

pd.DataFrame

Examples

Get a water level section from a line defined in a shapefile at time 0.5 hrs:

>>> grid = ... # Assume grid is a loaded grid result instance
>>> grid.section('/path/to/line.shp', 'water level', 0.5)
       offset  water level/Line 1
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