Flowmeshreader api-doc
Contents
Flowmeshreader api-doc#
load_mesh#
- flowmeshreader.load_mesh(input_file_path: str) Tuple[numpy.ndarray, numpy.ndarray] [source]#
Retrieves the mesh nodes faces’ x and y-coordinates from the netCDF file at input_file_path
- Parameters
input_file_path (str) – path to the input file
- Returns
node_x (np.ndarray) – x-coordinates of the mesh nodes faces
node_y (np.ndarray) – y-coordinates of the mesh nodes faces
load_meta_data#
load_data#
- flowmeshreader.load_data(input_file_path: str, variable: str) numpy.ndarray [source]#
Retrieves the selected mesh data (i.e. variable) from the netCDF file at input_file_path
- Parameters
input_file_path (str) – path to the input file
variable (str) – variable to return
- Returns
data (np.ndarray) – data at the mesh nodes
load_fou_data#
- flowmeshreader.load_fou_data(input_file_path: str, variable: str) numpy.ndarray [source]#
Retrieves the selected mesh data (i.e. variable) from the netCDF file at input_file_path
- Parameters
input_file_path (str) – path to the input file
variable (str) – variable to return
- Returns
data (np.ndarray) – data at the mesh nodes
load_map_data#
- flowmeshreader.load_map_data(input_file_path: str, variable: str) numpy.ndarray [source]#
Retrieves the selected mesh data (i.e. variable) from the netCDF file at input_file_path. Also restores original dimensions
- Parameters
input_file_path (str) – path to the input file
variable (str) – variable to return
- Returns
map_data (np.ndarray) – data at the mesh nodes (time, spatial)
load_classmap_data#
- flowmeshreader.load_classmap_data(input_file_path: str, variable: str, method: str = 'average', ret_map_data=True) Tuple[numpy.ndarray, numpy.ndarray] [source]#
Retrieves the selected mesh data (i.e. variable) from the .clm netCDF file at input_file_path Returns (1) the raw data (clm_data) at mesh locations and (2) the filled data (map_data), using class definitions Optional: provide method for replacing class numbers with bin values (lower bound, upper bound, average). Default is average
- Parameters
input_file_path (str) – path to the input file
variable (str) – variable to return
method (str) – method to use when replacing classes with values. “lower” replaces class numbers with lower bound; “upper” replaces class numbers with upper bound; “average” replaces class numbers with average of upper and lower bounds. Regardless, the lass class will take the lower bound as it goes to infinity
- Returns
clm_data (np.ndarray) – classmap data at the mesh nodes (time, spatial)
map_data (np.ndarray) – filled classmap data at the mesh nodes, using class definition (time, spatial)
create_raster#
- flowmeshreader.create_raster(node_x: numpy.ndarray, node_y: numpy.ndarray, resolution: float, margin: float = 1.05) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] [source]#
Creates a raster that spans from min(node_x) to max(node_x) and from min(node_y) to max(node_y) with user defined resolution
- Parameters
node_x (np.ndarray) – x-coordinates of the mesh nodes
node_y (np.ndarray) – y-coordinates of the mesh nodes
resolution (float) – resolution of the raster
margin (float) – margin around the node face center that the raster covers, in percentage. A value of 1 corresponds to 100%, the default value of 1.05 corresponds to 105% of the extend of the nodes face coordinates
- Returns
grid_x (np.ndarray) – x-coordinates of the raster points
grid_y (np.ndarray) – y-coordinates of the raster points
bounds (np.ndarray) – outermost coordinates of the raster (west, east, south, north)
get_bounds#
- flowmeshreader.get_bounds(node_x: numpy.ndarray, node_y: numpy.ndarray, resolution: float, margin: float) numpy.ndarray [source]#
Determines the raster bounds based on given resolution and margin. Guarantees that the resolution is maintained and extends span if the span in a direction is not an exact multiple of resolution.
- Parameters
node_x (np.ndarray) – x-coordinates of the mesh nodes
node_y (np.ndarray) – y-coordinates of the mesh nodes
resolution (float) – resolution of the raster
margin (float) – margin around the node face center that the raster covers, in percentage. A value of 1 corresponds to 100%, the default value of 1.05 corresponds to 105% of the extend of the nodes face coordinates
- Returns
bounds (np.ndarray) – outermost coordinates of the raster (west, east, south, north)
n_cells (np.ndarray) – number of cells in x and y direction (x, y)
mesh_data_to_raster#
- flowmeshreader.mesh_data_to_raster(node_x: numpy.ndarray, node_y: numpy.ndarray, node_data: numpy.ndarray, grid_x: numpy.ndarray, grid_y: numpy.ndarray, interpolation: str = 'nearest', distance_tol: float = - 999) numpy.ndarray [source]#
Maps the data at the mesh nodes to the raster points. see e.g. https://hatarilabs.com/ih-en/how-to-create-a-geospatial-raster-from-xy-data-with-python-pandas-and-rasterio-tutorial
Sets raster points to NaN if further away than distance_tol from a mesh node. This allows ‘holes’ in grids and other funky shapes to exist in the raster. Otherwise the convex hull of the mesh is interpolated, resulting in potentially unwanted results.
- Parameters
node_x (np.ndarray) – x-coordinates of the mesh nodes
node_y (np.ndarray) – y-coordinates of the mesh nodes
node_data (np.ndarray) – data at the mesh nodes
grid_x (np.ndarray) – x-coordinates of the raster points
grid_y (np.ndarray) – y-coordinates of the raster points
interpolation (str) – interpolation method for scipy.spatial.griddata. (1. “linear”, 2. “nearest”, 3. “cubic”)
distance_tol (float) – maximum distance for raster points from mesh nodes. If distance is larger, raster point will be set to NaN
- Returns
new_grid_data/grid_data (np.ndarray) – data at raster points. Is NaN at points further from mesh node than distance_tol, if distance_tol > 0. Otherwise, raster points are interpolated according to scipy.spatial.griddata, stopping at the mesh’s convex hull
write_tiff#
- flowmeshreader.write_tiff(output_file_path: str, new_grid_data: numpy.ndarray, bounds: numpy.ndarray, epsg: int) None [source]#
Saves new_grid_data to a tiff file. new_grid_data should be a raster.
- Parameters
output_file_path (str) – location of the output file
new_grid_data (np.ndarray) – data at grid points
bounds (np.ndarray) – outermost coordinates of the raster (west, east, south, north)
epsg (int) – coordinate reference system (CPS) that is stored in the tiff-file
- Returns
None
mesh_to_tiff#
- flowmeshreader.mesh_to_tiff(data: numpy.ndarray, input_file_path: str, output_file_path: str, resolution: float, distance_tol: float, interpolation: str = 'nearest') None [source]#
Wrapper function that turns mesh data into a tiff. The mesh data should be a 1D array, with the same size as the coordinates in the netCDF input file.
- Parameters
data (np.ndarray) – data at the mesh nodes.
input_file_path (str) – location of the input file
output_file_path (str) – location of the output file
resolution (float) – resolution of the raster
distance_tol (float) – maximum distance for raster points from mesh nodes. If distance is larger, raster point will be set to NaN
interpolation (str) – interpolation method for scipy.spatial.griddata. (1. “linear”, 2. “nearest”, 3. “cubic”)
- Returns
grid_x (np.ndarray) – grid with x-coordinates of raster
grid_y (np.ndarray) – grid with y-coordinates of raster
new_grid_data (np.ndarray) – new_grid_data