API
FM2PROF Runner Module.
This module provides the main execution engine for FM2PROF, a tool for converting 2D dflowFM model results to 1D cross-sections for hydraulic modelling.
FM2PROF (dflowFM to Profile) extracts cross-sectional data from 2D hydrodynamic model outputs and generates 1D model inputs. The main workflow includes:
- Initialisation: Load configuration files and validate input data -. Data Import: Read dflowfm map files and cross-section location files -. Classification: Assign 2D model points to regions and cross-sections
- Generation: Create cross-section geometries and roughness tables
- Finalisation: Write output files in various formats (D-Flow 1D, SOBEK 3, etc.)
Classes:
Name | Description |
---|---|
InitializationError |
Custom exception for initialisation failures. |
Fm2ProfRunner |
Main class that orchestrates the FM2PROF workflow. |
Project |
Python API wrapper for programmatic access to FM2PROF functionality. |
The Project class is auto-imported when using the fm2prof package.
Example
Basic usage through the Project API:
from fm2prof import Project project = Project('config.ini') project.run()
Programmatic configuration:
project = Project() project.set_input_file('2DMapOutput', 'model_map.nc') project.set_input_file('CrossSectionLocationFile', 'crosssections.csv') project.set_output_directory('./output') project.run()
Note
This module requires FlowFM map files (NetCDF format) and cross-section location files as input. The output includes 1D model geometry and roughness data suitable for various hydraulic modelling software.
License
GPL-3.0-or-later AND LGPL-3.0-or-later
Fm2ProfRunner(ini_file_path='')
Bases: FM2ProfBase
Main class that executes all functionality.
Initialize the project.
ini_file_path (Path | str): path to configuration file.
Source code in fm2prof\fm2prof_runner.py
create_logger()
staticmethod
Create logger instance.
Source code in fm2prof\common.py
finish_log_task()
Use this method to finish task.
:param task_name: task name, will be displayed in log message
get_filelogformatter()
get_inifile()
get_logformatter()
get_logger()
load_configuration(ini_file_path)
Use this method to load a configuration file from path.
If no path is given, the default configuration is used.
ini_file_path (Path | str): path to configuration file
Source code in fm2prof\fm2prof_runner.py
run(*, overwrite=False)
Execute FM2PROF routines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overwrite
|
bool
|
if True, overwrites existing output. If False, exits if output detected. |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if run was successful, False if errors occurred. |
Source code in fm2prof\fm2prof_runner.py
set_inifile(inifile=None)
Use this method to set configuration file object.
For loading from file, use load_inifile
instead
inifile (IniFile): inifile object. Obtain using e.g. ``get_inifile``.
Source code in fm2prof\common.py
set_logfile(output_dir, filename='fm2prof.log')
Set log file.
output_dir (str): _description_
filename (str, optional): _description_. Defaults to "fm2prof.log".
Source code in fm2prof\common.py
set_logger(logger)
Use to set logger.
logger (Logger): Logger instance
Source code in fm2prof\common.py
set_logger_message(err_mssg='', level='info', *, header=False)
Set message to logger if this is set.
err_mssg (str, optional): Error message to log. Defaults to "".
level (str, optional): Log level. Defaults to "info".
header (bool, optional): Set error message as header. Defaults to False.
Source code in fm2prof\common.py
start_new_log_task(task_name='NOT DEFINED', pbar=None)
Use this method to start a new task. Will reset the internal clock.
:param task_name: task name, will be displayed in log message
Source code in fm2prof\common.py
InitializationError
Bases: Exception
Exception class for initialization errors.
Project(ini_file_path='')
Bases: Fm2ProfRunner
Provides the python API for running FM2PROF.
Instantiate by providing the path to a configuration file
Project('/path/to/config.ini')
Initialize the project.
ini_file_path (Path | str): path to configuration file.
Source code in fm2prof\fm2prof_runner.py
output_files: Generator[Path, None, None]
property
Get a generator object with the output files.
Generator[Path, None, None]: generator of output files.
create_logger()
staticmethod
Create logger instance.
Source code in fm2prof\common.py
finish_log_task()
Use this method to finish task.
:param task_name: task name, will be displayed in log message
get_filelogformatter()
get_inifile()
get_input_file(name)
Use this method to retrieve the path to an input file.
name (str): case-insensitive key of the input file (e.g.'2dmapoutput')
Source code in fm2prof\fm2prof_runner.py
get_logformatter()
get_logger()
get_output_directory()
get_parameter(name)
Use this method to get the value of a parameter.
name (str): name of the parameter (case insensitive)
(str | float): The current value of the parameter
Source code in fm2prof\fm2prof_runner.py
load_configuration(ini_file_path)
Use this method to load a configuration file from path.
If no path is given, the default configuration is used.
ini_file_path (Path | str): path to configuration file
Source code in fm2prof\fm2prof_runner.py
print_configuration()
Use this method to obtain string representation of the configuration.
Use this string to write to file, e.g.:
>> with open('EmptyProject.ini', 'w') as f:
>> f.write(project.print_configuration())
(str): string representation of the configuration
Source code in fm2prof\fm2prof_runner.py
run(*, overwrite=False)
Execute FM2PROF routines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
overwrite
|
bool
|
if True, overwrites existing output. If False, exits if output detected. |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if run was successful, False if errors occurred. |
Source code in fm2prof\fm2prof_runner.py
set_inifile(inifile=None)
Use this method to set configuration file object.
For loading from file, use load_inifile
instead
inifile (IniFile): inifile object. Obtain using e.g. ``get_inifile``.
Source code in fm2prof\common.py
set_input_file(name, value)
Use this method to set the path to an input file.
name: name of the input file in the configuration (case insensitive).
value: path to the inputfile
Source code in fm2prof\fm2prof_runner.py
set_logfile(output_dir, filename='fm2prof.log')
Set log file.
output_dir (str): _description_
filename (str, optional): _description_. Defaults to "fm2prof.log".
Source code in fm2prof\common.py
set_logger(logger)
Use to set logger.
logger (Logger): Logger instance
Source code in fm2prof\common.py
set_logger_message(err_mssg='', level='info', *, header=False)
Set message to logger if this is set.
err_mssg (str, optional): Error message to log. Defaults to "".
level (str, optional): Log level. Defaults to "info".
header (bool, optional): Set error message as header. Defaults to False.
Source code in fm2prof\common.py
set_output_directory(path)
Use this method to set the output directory.
.. warning:: calling this function will also create the output directory, if it does not already exists!
path (path | str): path to the output path
Source code in fm2prof\fm2prof_runner.py
set_parameter(name, value)
Use this method to set the value of a parameter.
name (str): name of the parameter (case insensitive).
value (str | float): value of the parameter.
An error will be given if the value has the wrong type (e.g. string if int was expected).
Source code in fm2prof\fm2prof_runner.py
start_new_log_task(task_name='NOT DEFINED', pbar=None)
Use this method to start a new task. Will reset the internal clock.
:param task_name: task name, will be displayed in log message
Source code in fm2prof\common.py
Region and Section Polygon File Module.
This module provides functionality for handling polygon files used in FM2PROF for spatial classification of 2D model data into regions and sections.
The module supports GeoJSON format polygon files and provides efficient spatial indexing and point-in-polygon classification algorithms. It handles two main types of polygon files:
- Region Polygons: Define geographical regions for grouping cross-sections
- Section Polygons: Define hydraulic sections (main channel, floodplains)
Key Features
- GeoJSON file parsing and validation
- Spatial indexing using MeshKernel for efficient point classification
- Overlap detection and validation
Classes:
Name | Description |
---|---|
Polygon |
Named tuple representing a polygon with geometry and properties. |
PolygonFile |
Base class for polygon file handling with classification methods. |
RegionPolygonFile |
Specialised class for region polygon files. |
SectionPolygonFile |
Specialised class for section polygon files with hydraulic validation. |
Note
Polygon files must be in GeoJSON format with specific property requirements: - Region polygons: require 'name' and 'id' properties - Section polygons: require 'name' and 'section' properties ('main', 'floodplain1', 'floodplain2')
GridPointsInPolygonResults
Bases: NamedTuple
Named tuple for grid points in polygon results.
MultiPolygon(logger)
Bases: FM2ProfBase
MultiPolygon file class.
This class handles MultiPolygon files used in FM2PROF for spatial classification of 2D model data into regions and sections. It supports GeoJSON format polygon files and provides methods for reading, validating, and classifying points within the polygons.
We use a base MultiPolygon class to leverage MeshKernel and Shapely functionality
within a common framework. E.g. MultiPolygon.as_meshkernel()
outputs a MeshKernel GeometryList
object that can be used for spatial classification, while MultiPolygon.as_shapely()
outputs
a list of Shapely Polygon objects for geometric operations.
Not all geojson geometry types are supported:
- Only 'Polygon' and 'MultiPolygon' are supported.
- Polygons with holes are not supported.
- MultiPolygons with multiple polygons are not supported.
- Properties must contain a 'name' key-word.
- Properties must be unique, otherwise overlap checking will produce bugs.
- SectionPolygon properties must contain a 'section' key-word.
- RegionPolygon properties must contain a 'region' key-word.
Instantiate a MultiPolygon object.
Source code in fm2prof\polygon_file.py
polygons: list[Polygon]
property
writable
Polygons.
as_meshkernel()
Convert polygons to MeshKernel GeometryList.
Note
MeshKernel GeometryList supports multiple polygons, separated by some int (default -999). However, to keep track of polygon properties (e.g. name), we create a list of single polygon GeometryList objects.
Returns:
Name | Type | Description |
---|---|---|
GeometryList |
list[GeometryList]
|
MeshKernel GeometryList object containing all polygons. |
Source code in fm2prof\polygon_file.py
as_shapely()
Convert polygons to list of Shapely Polygon objects.
Returns:
Type | Description |
---|---|
list[Polygon]
|
list[shapely.geometry.Polygon]: List of Shapely Polygon objects. |
Source code in fm2prof\polygon_file.py
check_overlap()
Check if polygons overlap and log a warning if they do.
Source code in fm2prof\polygon_file.py
create_logger()
staticmethod
Create logger instance.
Source code in fm2prof\common.py
finish_log_task()
Use this method to finish task.
:param task_name: task name, will be displayed in log message
from_file(file_path)
Read data from geojson file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path | str
|
path to geojson file |
required |
Source code in fm2prof\polygon_file.py
get_filelogformatter()
get_gridpoints_in_polygon(res_file, *, property_name, force_cache_invalidation=False)
Method to get faces and edges in region.
This method performs caching of the in-polygon classification results
to avoid recalculating if the region file has not changed. The cache
is invalidated if the region file is modified or if force_cache_invalidation
is set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res_file
|
str | Path
|
path to result (map) netcdf file. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
force_cache_invalidation
|
bool
|
Force cache invalidation even if region file has not changed. |
False
|
Returns:
Type | Description |
---|---|
GridPointsInPolygonResults
|
GridPointsInPolygonResults |
Source code in fm2prof\polygon_file.py
get_inifile()
get_logformatter()
get_logger()
get_points_in_polygon(points, property_name)
Method to determine in which polygon input points are.
Warning
This method is not applicable for large number of points. Only use for small number of points (e.g. cross-section locations).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
ndarray
|
Array of shape (n_points, 2) containing x,y coordinates of points to classify. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of polygon names in which the points are located. If a point is not located in any polygon, it is classified as 'undefined'. |
Source code in fm2prof\polygon_file.py
meshkernel_inpolygon(res_file, dtype, property_name)
Get grid points in polygon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res_file
|
str | Path
|
Path to result (map) netcdf file. |
required |
dtype
|
Literal['face', 'edge', 'node']
|
Type of grid points to retrieve. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
pd.DataFrame | dict: DataFrame or dictionary containing grid points in polygon. |
Source code in fm2prof\polygon_file.py
set_inifile(inifile=None)
Use this method to set configuration file object.
For loading from file, use load_inifile
instead
inifile (IniFile): inifile object. Obtain using e.g. ``get_inifile``.
Source code in fm2prof\common.py
set_logfile(output_dir, filename='fm2prof.log')
Set log file.
output_dir (str): _description_
filename (str, optional): _description_. Defaults to "fm2prof.log".
Source code in fm2prof\common.py
set_logger(logger)
Use to set logger.
logger (Logger): Logger instance
Source code in fm2prof\common.py
set_logger_message(err_mssg='', level='info', *, header=False)
Set message to logger if this is set.
err_mssg (str, optional): Error message to log. Defaults to "".
level (str, optional): Log level. Defaults to "info".
header (bool, optional): Set error message as header. Defaults to False.
Source code in fm2prof\common.py
start_new_log_task(task_name='NOT DEFINED', pbar=None)
Use this method to start a new task. Will reset the internal clock.
:param task_name: task name, will be displayed in log message
Source code in fm2prof\common.py
Polygon(coordinates, properties)
Polygon class.
This class represents a single polygon with its geometry and properties. It is used by the MultiPolygon class to store individual polygons.
Attributes:
Name | Type | Description |
---|---|---|
coordinates |
list[list[float]]
|
List of [x, y] coordinates defining the polygon. |
properties |
dict
|
Dictionary of properties associated with the polygon. |
Instantiate a Polygon object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coordinates
|
list[list[float]]
|
List of [x, y] coordinates defining the polygon. |
required |
properties
|
dict
|
Dictionary of properties associated with the polygon. |
required |
Source code in fm2prof\polygon_file.py
x: list[float]
property
X coordinates of the polygon.
y: list[float]
property
Y coordinates of the polygon.
PolygonError(message)
RegionPolygon(region_file_path, logger, default_value='undefined')
Bases: MultiPolygon
RegionPolygonFile class.
Instantiate a RegionPolygonFile object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
region_file_path
|
str | Path
|
path to region polygon file. |
required |
logger
|
Logger
|
logger |
required |
default_value
|
str
|
default region name to use in cells not covered by a region polygon |
'undefined'
|
Source code in fm2prof\polygon_file.py
polygons: list[Polygon]
property
writable
Polygons.
regions: list[Polygon]
property
Region polygons.
as_meshkernel()
Convert polygons to MeshKernel GeometryList.
Note
MeshKernel GeometryList supports multiple polygons, separated by some int (default -999). However, to keep track of polygon properties (e.g. name), we create a list of single polygon GeometryList objects.
Returns:
Name | Type | Description |
---|---|---|
GeometryList |
list[GeometryList]
|
MeshKernel GeometryList object containing all polygons. |
Source code in fm2prof\polygon_file.py
as_shapely()
Convert polygons to list of Shapely Polygon objects.
Returns:
Type | Description |
---|---|
list[Polygon]
|
list[shapely.geometry.Polygon]: List of Shapely Polygon objects. |
Source code in fm2prof\polygon_file.py
check_overlap()
Check if polygons overlap and log a warning if they do.
Source code in fm2prof\polygon_file.py
create_logger()
staticmethod
Create logger instance.
Source code in fm2prof\common.py
finish_log_task()
Use this method to finish task.
:param task_name: task name, will be displayed in log message
from_file(file_path)
Read geojson file and performs validation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
Path | str
|
region file path |
required |
get_filelogformatter()
get_gridpoints_in_polygon(res_file, *, property_name='region', force_cache_invalidation=False)
Method to get faces and edges in region.
This method performs caching of the in-polygon classification results
to avoid recalculating if the region file has not changed. The cache
is invalidated if the region file is modified or if force_cache_invalidation
is set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res_file
|
str | Path
|
path to result (map) netcdf file. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. Defaults to region |
'region'
|
force_cache_invalidation
|
bool
|
Force cache invalidation even if region file has not changed. |
False
|
Returns:
Type | Description |
---|---|
GridPointsInPolygonResults
|
GridPointsInPolygonResults |
Source code in fm2prof\polygon_file.py
get_inifile()
get_logformatter()
get_logger()
get_points_in_polygon(points, property_name)
Method to determine in which polygon input points are.
Warning
This method is not applicable for large number of points. Only use for small number of points (e.g. cross-section locations).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
ndarray
|
Array of shape (n_points, 2) containing x,y coordinates of points to classify. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of polygon names in which the points are located. If a point is not located in any polygon, it is classified as 'undefined'. |
Source code in fm2prof\polygon_file.py
meshkernel_inpolygon(res_file, dtype, property_name)
Get grid points in polygon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res_file
|
str | Path
|
Path to result (map) netcdf file. |
required |
dtype
|
Literal['face', 'edge', 'node']
|
Type of grid points to retrieve. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
pd.DataFrame | dict: DataFrame or dictionary containing grid points in polygon. |
Source code in fm2prof\polygon_file.py
set_inifile(inifile=None)
Use this method to set configuration file object.
For loading from file, use load_inifile
instead
inifile (IniFile): inifile object. Obtain using e.g. ``get_inifile``.
Source code in fm2prof\common.py
set_logfile(output_dir, filename='fm2prof.log')
Set log file.
output_dir (str): _description_
filename (str, optional): _description_. Defaults to "fm2prof.log".
Source code in fm2prof\common.py
set_logger(logger)
Use to set logger.
logger (Logger): Logger instance
Source code in fm2prof\common.py
set_logger_message(err_mssg='', level='info', *, header=False)
Set message to logger if this is set.
err_mssg (str, optional): Error message to log. Defaults to "".
level (str, optional): Log level. Defaults to "info".
header (bool, optional): Set error message as header. Defaults to False.
Source code in fm2prof\common.py
start_new_log_task(task_name='NOT DEFINED', pbar=None)
Use this method to start a new task. Will reset the internal clock.
:param task_name: task name, will be displayed in log message
Source code in fm2prof\common.py
SectionPolygon(section_file_path, logger, default_value='floodplain1')
Bases: MultiPolygon
SectionPolygonFile class.
Instantiate a SectionPolygonFile object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
section_file_path
|
str | Path
|
path to section polygon file. |
required |
logger
|
Logger
|
logger |
required |
default_value
|
str
|
default section name to use in cells not covered by a section polygon. |
'floodplain1'
|
Source code in fm2prof\polygon_file.py
polygons: list[Polygon]
property
writable
Polygons.
sections: list[Polygon]
property
Section polygons.
as_meshkernel()
Convert polygons to MeshKernel GeometryList.
Note
MeshKernel GeometryList supports multiple polygons, separated by some int (default -999). However, to keep track of polygon properties (e.g. name), we create a list of single polygon GeometryList objects.
Returns:
Name | Type | Description |
---|---|---|
GeometryList |
list[GeometryList]
|
MeshKernel GeometryList object containing all polygons. |
Source code in fm2prof\polygon_file.py
as_shapely()
Convert polygons to list of Shapely Polygon objects.
Returns:
Type | Description |
---|---|
list[Polygon]
|
list[shapely.geometry.Polygon]: List of Shapely Polygon objects. |
Source code in fm2prof\polygon_file.py
check_overlap()
Check if polygons overlap and log a warning if they do.
Source code in fm2prof\polygon_file.py
create_logger()
staticmethod
Create logger instance.
Source code in fm2prof\common.py
finish_log_task()
Use this method to finish task.
:param task_name: task name, will be displayed in log message
from_file(file_path)
Read section polygon file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str | Path
|
path to section polygon file. |
required |
get_filelogformatter()
get_gridpoints_in_polygon(res_file, *, property_name='section', force_cache_invalidation=False)
Method to get faces and edges in section.
This method performs caching of the in-polygon classification results
to avoid recalculating if the section file has not changed. The cache
is invalidated if the section file is modified or if force_cache_invalidation
is set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res_file
|
str | Path
|
path to result (map) netcdf file. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. Defaults to section |
'section'
|
force_cache_invalidation
|
bool
|
Force cache invalidation even if section file has not changed. |
False
|
Returns:
Type | Description |
---|---|
GridPointsInPolygonResults
|
GridPointsInPolygonResults |
Source code in fm2prof\polygon_file.py
get_inifile()
get_logformatter()
get_logger()
get_points_in_polygon(points, property_name)
Method to determine in which polygon input points are.
Warning
This method is not applicable for large number of points. Only use for small number of points (e.g. cross-section locations).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
points
|
ndarray
|
Array of shape (n_points, 2) containing x,y coordinates of points to classify. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: List of polygon names in which the points are located. If a point is not located in any polygon, it is classified as 'undefined'. |
Source code in fm2prof\polygon_file.py
meshkernel_inpolygon(res_file, dtype, property_name)
Get grid points in polygon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
res_file
|
str | Path
|
Path to result (map) netcdf file. |
required |
dtype
|
Literal['face', 'edge', 'node']
|
Type of grid points to retrieve. |
required |
property_name
|
Literal['region', 'section']
|
Property to use for classification. |
required |
Returns:
Type | Description |
---|---|
list[str]
|
pd.DataFrame | dict: DataFrame or dictionary containing grid points in polygon. |
Source code in fm2prof\polygon_file.py
set_inifile(inifile=None)
Use this method to set configuration file object.
For loading from file, use load_inifile
instead
inifile (IniFile): inifile object. Obtain using e.g. ``get_inifile``.
Source code in fm2prof\common.py
set_logfile(output_dir, filename='fm2prof.log')
Set log file.
output_dir (str): _description_
filename (str, optional): _description_. Defaults to "fm2prof.log".
Source code in fm2prof\common.py
set_logger(logger)
Use to set logger.
logger (Logger): Logger instance
Source code in fm2prof\common.py
set_logger_message(err_mssg='', level='info', *, header=False)
Set message to logger if this is set.
err_mssg (str, optional): Error message to log. Defaults to "".
level (str, optional): Log level. Defaults to "info".
header (bool, optional): Set error message as header. Defaults to False.
Source code in fm2prof\common.py
start_new_log_task(task_name='NOT DEFINED', pbar=None)
Use this method to start a new task. Will reset the internal clock.
:param task_name: task name, will be displayed in log message
Source code in fm2prof\common.py
Base classes and data containers.
ElapsedFileFormatter()
Bases: ElapsedFormatter
Elapsed file formatter class.
Instantiate an ElapsedFileFormatter object.
Source code in fm2prof\common.py
pbar: None | tqdm.tqdm | tqdm.std.tqdm
property
writable
Progress bar.
finish_task()
format(record)
Format log record.
Source code in fm2prof\common.py
get_elapsed_time()
new_task()
set_intro(flag=True)
set_number_of_iterations(n)
start_new_iteration(pbar=None)
ElapsedFormatter()
ElapsedFormatter class.
Instantiate an ElapsedFormatter object.
Source code in fm2prof\common.py
pbar: None | tqdm.tqdm | tqdm.std.tqdm
property
writable
Progress bar.
finish_task()
format(record)
Format log record.
Source code in fm2prof\common.py
get_elapsed_time()
new_task()
set_intro(flag=True)
set_number_of_iterations(n)
start_new_iteration(pbar=None)
FM2ProfBase(logger=None, inifile=None)
Base class for FM2PROF types.
Implements methods for logging, project specific parameters
Instatiate a FM2ProfBase object.
logger (Logger | None, optional): Logger . Defaults to None.
inifile (IniFile | None, optional): IniFile instance. Defaults to None.
Source code in fm2prof\common.py
create_logger()
staticmethod
Create logger instance.
Source code in fm2prof\common.py
finish_log_task()
Use this method to finish task.
:param task_name: task name, will be displayed in log message
get_filelogformatter()
get_inifile()
get_logformatter()
get_logger()
set_inifile(inifile=None)
Use this method to set configuration file object.
For loading from file, use load_inifile
instead
inifile (IniFile): inifile object. Obtain using e.g. ``get_inifile``.
Source code in fm2prof\common.py
set_logfile(output_dir, filename='fm2prof.log')
Set log file.
output_dir (str): _description_
filename (str, optional): _description_. Defaults to "fm2prof.log".
Source code in fm2prof\common.py
set_logger(logger)
Use to set logger.
logger (Logger): Logger instance
Source code in fm2prof\common.py
set_logger_message(err_mssg='', level='info', *, header=False)
Set message to logger if this is set.
err_mssg (str, optional): Error message to log. Defaults to "".
level (str, optional): Log level. Defaults to "info".
header (bool, optional): Set error message as header. Defaults to False.
Source code in fm2prof\common.py
start_new_log_task(task_name='NOT DEFINED', pbar=None)
Use this method to start a new task. Will reset the internal clock.
:param task_name: task name, will be displayed in log message
Source code in fm2prof\common.py
FrictionTable(level, friction)
Container for friction table.
Instantiate a FrictionTable object.
Source code in fm2prof\common.py
interpolate(new_z)
Interpolate friction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_z
|
ndarray
|
description |
required |
TqdmLoggingHandler()
Bases: StreamHandler
Logging handler for tqdm package.
Instantiate a TqdmLoggingHandler.
Source code in fm2prof\common.py
emit(record)
Write progressbar to logstream.
Source code in fm2prof\common.py
Contains functions used for the emulation/reduction of 2D models to 1D models for Delft3D FM (D-Hydro).
classify_with_regions(cssdata, time_independent_data, edge_data, css_regions)
Assign cross-section id's based on region polygons.
Within a region, assignment will be done by k nearest neighbour
Source code in fm2prof\nearest_neighbour.py
classify_without_regions(cssdata, time_independent_data, edge_data)
Classify without regions.
Source code in fm2prof\nearest_neighbour.py
get_centre_values(location, x, y, waterdepth, waterlevel)
Find output point closest to x,y location, output depth and water level as nd arrays.