spatial.GeometryFM2D
spatial.GeometryFM2D(self, node_coordinates, element_table, codes=None, projection='LONG/LAT', dfsu_type=DfsuFileType.Dfsu2D, element_ids=None, node_ids=None, validate=True, reindex=False)
Attributes
Name | Description |
---|---|
boundary_codes | Unique list of boundary codes |
boundary_polylines | Lists of closed polylines defining domain outline |
codes | Node codes of all nodes (0=water, 1=land, 2…=open boundaries) |
element_coordinates | Center coordinates of each element |
geometry2d | Return self |
is_2d | Type is either mesh or Dfsu2D (2 horizontal dimensions) |
is_geo | Are coordinates geographical (LONG/LAT)? |
is_layered | Type is layered dfsu (3d, vertical profile or vertical column) |
is_local_coordinates | Are coordinates relative (NON-UTM)? |
is_spectral | Type is spectral dfsu (point, line or area spectrum) |
is_tri_only | Does the mesh consist of triangles only? |
max_nodes_per_element | The maximum number of nodes for an element |
n_elements | Number of elements |
n_nodes | Number of nodes |
projection | The projection |
projection_string | The projection string |
type_name | Type name, e.g. Mesh, Dfsu2D |
Methods
Name | Description |
---|---|
contains | test if a list of points are contained by mesh |
find_index | Find a set of element indicies for a number of points or within an area. |
find_nearest_elements | Find index of nearest elements (optionally for a list) |
get_2d_interpolant | IDW interpolant for list of coordinates |
get_element_area | Calculate the horizontal area of each element. |
get_node_centered_data | convert cell-centered data to node-centered by pseudo-laplacian method |
get_overset_grid | get a 2d grid that covers the domain by specifying spacing or shape |
interp2d | interp spatially in data (2d only) |
isel | export a selection of elements to a new geometry |
to_mesh | Export geometry to new mesh file |
to_shapely | Export mesh as shapely MultiPolygon |
contains
spatial.GeometryFM2D.contains(points)
test if a list of points are contained by mesh
Parameters
Name | Type | Description | Default |
---|---|---|---|
points |
array-like n-by-2 | x,y-coordinates of n points to be tested | required |
Returns
Type | Description |
---|---|
bool array | True for points inside, False otherwise |
find_index
spatial.GeometryFM2D.find_index(x=None, y=None, coords=None, area=None)
Find a set of element indicies for a number of points or within an area.
The returned indices returned are the unique, unordered set of element indices that contain the points or area.
This method will return elements containing the argument points/area, which is not necessarily the same as the nearest.
Typically not called directly, but by Dataset/DataArray’s sel() method.
Parameters
Name | Type | Description | Default |
---|---|---|---|
x |
float | numpy.numpy.ndarray | None | X coordinate(s) (easting or longitude) | None |
y |
float | numpy.numpy.ndarray | None | Y coordinate(s) (northing or latitude) | None |
coords |
numpy.numpy.array(float, float) | As an alternative to specifying x, and y individually, the argument coords can be used instead. (x,y)-coordinates of points to be found, by default None | None |
area |
(float, float, float, float) | Bounding box of coordinates (left lower and right upper) to be selected, by default None | None |
Returns
Type | Description |
---|---|
numpy.numpy.array | indicies of containing elements |
Raises
Type | Description |
---|---|
ValueError | if any point is outside the domain |
Examples
>>> g = dfs.geometry
>>> id = dfs.find_index(x=3.1, y=4.3)
See Also
isel : get subset geometry for specific indicies find_nearest_elements : find nearest instead of containing elements
find_nearest_elements
spatial.GeometryFM2D.find_nearest_elements(x, y=None, n_nearest=1, return_distances=False)
Find index of nearest elements (optionally for a list)
Parameters
Name | Type | Description | Default |
---|---|---|---|
x |
float | numpy.numpy.ndarray | X coordinate(s) (easting or longitude) | required |
y |
float | numpy.numpy.ndarray | None | Y coordinate(s) (northing or latitude) | None |
n_nearest |
int | return this many (horizontally) nearest points for each coordinate set, default=1 | 1 |
return_distances |
bool | should the horizontal distances to each point be returned? default=False | False |
Returns
Type | Description |
---|---|
numpy.numpy.array | element ids of nearest element(s) |
(numpy.numpy.array, optional) | horizontal distances |
Examples
>>> g = dfs.geometry
>>> id = g.find_nearest_elements(3, 4)
>>> ids = g.find_nearest_elements([3, 8], [4, 6])
>>> ids = g.find_nearest_elements(xy)
>>> ids = g.find_nearest_elements(3, 4, n_nearest=4)
>>> ids, d = g.find_nearest_elements(xy, return_distances=True)
See Also
find_index : find element indicies for points or an area
get_2d_interpolant
spatial.GeometryFM2D.get_2d_interpolant(xy, n_nearest=5, extrapolate=False, p=2, radius=None)
IDW interpolant for list of coordinates
Parameters
Name | Type | Description | Default |
---|---|---|---|
xy |
array - like | x,y coordinates of new points | required |
n_nearest |
int | number of nearest elements used for IDW, by default 5 | 5 |
extrapolate |
bool | allow extrapolation, by default False | False |
p |
float | power of inverse distance weighting, default=2 | 2 |
radius |
float | None | an alternative to extrapolate=False, only include elements within radius | None |
Returns
Type | Description |
---|---|
(numpy.numpy.array, numpy.numpy.array) | element ids and weights |
get_element_area
spatial.GeometryFM2D.get_element_area()
Calculate the horizontal area of each element.
Returns
Type | Description |
---|---|
numpy.numpy.array(float) | areas in m2 |
get_node_centered_data
spatial.GeometryFM2D.get_node_centered_data(data, extrapolate=True)
convert cell-centered data to node-centered by pseudo-laplacian method
Parameters
Name | Type | Description | Default |
---|---|---|---|
data |
numpy.numpy.array(float) | cell-centered data | required |
extrapolate |
bool | allow the method to extrapolate, default:True | True |
Returns
Type | Description |
---|---|
numpy.numpy.array(float) | node-centered data |
get_overset_grid
spatial.GeometryFM2D.get_overset_grid(dx=None, dy=None, nx=None, ny=None, buffer=0.0)
get a 2d grid that covers the domain by specifying spacing or shape
Parameters
Name | Type | Description | Default |
---|---|---|---|
dx |
float or (float, float) | grid resolution in x-direction (or in x- and y-direction) | None |
dy |
float | grid resolution in y-direction | None |
nx |
int | number of points in x-direction, by default None, (the value will be inferred) | None |
ny |
int | number of points in y-direction, by default None, (the value will be inferred) | None |
buffer |
float | positive to make the area larger, default=0 can be set to a small negative value to avoid NaN values all around the domain. | 0.0 |
Returns
Type | Description |
---|---|
<mikeio.Grid2D> | 2d grid |
interp2d
spatial.GeometryFM2D.interp2d(data, elem_ids, weights=None, shape=None)
interp spatially in data (2d only)
Parameters
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray or list(ndarray) | dfsu data | required |
elem_ids |
ndarray(int) | n sized array of 1 or more element ids used for interpolation | required |
weights |
ndarray(float) | weights with same size as elem_ids used for interpolation | None |
shape |
typing.Tuple[int, …] | None | reshape output | None |
Returns
Type | Description |
---|---|
ndarray or list(ndarray) | spatially interped data |
Examples
>>> ds = dfsu.read()
>>> g = dfs.get_overset_grid(shape=(50,40))
>>> elem_ids, weights = dfs.get_2d_interpolant(g.xy)
>>> dsi = dfs.interp2d(ds, elem_ids, weights)
isel
spatial.GeometryFM2D.isel(idx, keepdims=False, **kwargs)
export a selection of elements to a new geometry
Typically not called directly, but by Dataset/DataArray’s isel() or sel() methods.
Parameters
Name | Type | Description | Default |
---|---|---|---|
idx |
collection(int) | collection of element indicies | required |
keepdims |
bool | Should the original Geometry type be kept (keepdims=True) or should it be reduced e.g. to a GeometryPoint2D if possible (keepdims=False), by default False | False |
Returns
Type | Description |
---|---|
Geometry | geometry subset |
See Also
find_index : find element indicies for points or an area
to_mesh
spatial.GeometryFM2D.to_mesh(outfilename)
Export geometry to new mesh file
Parameters
Name | Type | Description | Default |
---|---|---|---|
outfilename |
str | path to file to be written | required |
to_shapely
spatial.GeometryFM2D.to_shapely()
Export mesh as shapely MultiPolygon
Returns
Type | Description |
---|---|
shapely.shapely.geometry.shapely.geometry.MultiPolygon | polygons with mesh elements |