mnp package
Subpackages
- mnp.evaluation package
- Submodules
EnvironmentalFactorTemplate
HSITemplate
LandTypeMapTemplate
PopulationMapTemplate
QgisLayerTemplate
get_land_type_color()
rand_web_color_hex()
SubselectionEvaluation
create_output()
AssignedSpeciesMap
BiggestBottleneckMap
DetailedTable
EnvironmentalBottleneckMap
EnvironmentalFactorHotspotMap
HotSpotsMap
KeyPopulationsCountMap
LandTypeMap
QGisLayers
RegionalContributionTable
SubselectionMap
SubselectionOutput
SummaryTable
Table
add_output_to_subselection()
identify_land_types_per_species()
make_bottleneck_map()
- Submodules
- mnp.preparation package
- Submodules
LandTypeMap
aggregate_land_type_map()
aggregate_row()
read_aggregated_map()
filter_incomplete_cells()
csv_is_readable()
directory_contains()
is_directory()
is_geospatial_raster()
is_valid_csv()
occurs_in_formula()
path_exists()
raster_has_resolution()
rasters_have_identical_bounds()
verify_local_distance()
verify_parameters()
ErrorMessage
InputPathway
OutputPathway
VerificationProcedure
VerifyEnvironmentalTable
VerifyHSIFromDisk
VerifyHasEnvironmentalFactors
VerifyIsGeospatialRasterAndResolution
VerifyLandTypeDirectory
VerifyMetadataComment
VerifyParameters
VerifyRasterAndGeospatialProfileBounds
VerifyRasterBounds
VerifySpeciesSubselection
VerifySpeciesTraits
VerifyTable
verify_user_input()
read_rasters_from_cover()
get_valid_species()
get_valid_species_selections()
melt_boolean_dataframe()
SpeciesDataBase
save_spatial_mask()
verify_spatial_data_coverage()
- Submodules
- mnp.species_models package
- Submodules
ClusterLocal
Clustering
ClusteringProcedure
EnvironmentalFactor
HSI
HSIProcedure
Nature
PreCalculated
PolygonHabitatMap
RegionalSpeciesEvaluation
SpeciesEvaluation
SpeciesEvaluation.calculate()
SpeciesEvaluation.evaluate_metapopulations()
SpeciesEvaluation.population_array()
SpeciesEvaluation.results()
SpeciesEvaluation.summary_table_to_file()
SpeciesEvaluation.trait_info()
SpeciesEvaluation.update_results_dictionary()
SpeciesEvaluation.update_viability_class()
SpeciesEvaluationParameters
SubRegion
SpeciesGeoMap
SpeciesGeomapLogger
SpeciesModel
SpeciesModel.evaluation_results()
SpeciesModel.get_populations_array()
SpeciesModel.log_messages()
SpeciesModel.name_info()
SpeciesModel.region_evaluation_results()
SpeciesModel.run_clustering()
SpeciesModel.run_evaluation()
SpeciesModel.run_hsi()
SpeciesModel.run_regional_evaluation()
SpeciesModel.trait_info()
run_species()
run_species_models()
produce_nkeys_map()
produce_nkeys_maps()
- Submodules
Submodules
- mnp.MNP.bottleneck_analysis(land_types: dict[str, sparray] | None, environmentals: dict[str, sparray] | None, parameters: MNPParameters, subselection_evaluations: list[SubselectionEvaluation])
- mnp.MNP.evaluate_models(output_pathway: OutputPathway, parameters: MNPParameters, species_models: ReferenceType, land_types: dict[str, sparray])
Generate all additional output aside from the standard tables.
- Parameters:
output_pathway (OutputPathway) – class describing which output to generate
species_models (list[SpeciesModel]) – list with a model object for each species in this run
subselection_evaluation (list[SubselectionEvaluation]) – list with an evaluation object for each species in this run
parameters (dict) – databases containing all domain parameters, like species traits and group traits
land_types (dict) – The land type map as a dictionary with land type codes as key and arrays as values
- mnp.MNP.mnp(config: ConfigParser)
Run the Model for Nature Policy on the given configuration.
- Parameters:
config (ConfigParser) – Configuration for current run
- mnp.MNP.prepare_input(parameters: ~mnp.config.MNPParameters, input_pathway: ~mnp.preparation.io_pathways.InputPathway) -> (dict[str, scipy.sparse._base.sparray] | None, dict[str, scipy.sparse._base.sparray] | None, dict[str, scipy.sparse._base.sparray] | None, <class 'set'>)
Subflow to prepare input for processing. - creates directories - copies all input files - reads land type map and environmental factor maps - determines overlap between all provided rasters (except region raster) - creates geospatial profile when running with precalculated HSI rasters - makes the parameter database
- Parameters:
config (ConfigParser) – Configuration for current run
input_pathway (InputPathway) – the input pathway describing the operations to be done on the provided input
- Returns:
land_types (dict) – The land type map as a dictionary with land type codes as key and arrays as values
environmentals – Dictionary with the name of the environmental factor as keys and their corresponding arrays as values
complying_species (set) – which species have all the needed information required for running
parameters (dict) – databases containing all domain parameters, like species traits and group traits
- mnp.MNP.run_and_evaluate(land_types: dict[str, ~scipy.sparse._base.sparray] | None, environmentals: dict[str, ~scipy.sparse._base.sparray] | None, sub_regions: dict[str, ~scipy.sparse._base.sparray] | None, parameters: ~mnp.config.MNPParameters, output_pathway: ~mnp.preparation.io_pathways.OutputPathway) -> (list[mnp.species_models.species_model.SpeciesModel], dict[list[slice(<class 'str'>, <class 'mnp.species_models.species_model.SpeciesModel'>, None)]])
Run and evaluate species models and evaluate species subselections.
Running a model is: 1. make HSI map 2. do clustering (make populations) 3. evaluate clusters 4. evaluatie contribution of sub-regions
- Parameters:
sub_regions (dict) – Dictionary with the name of the sub-regions as keys and their corresponding arrays as values
land_types (dict) – The land type map as a dictionary with land type codes as key and arrays as values
environmentals – Dictionary with the name of the environmental factor as keys and their corresponding arrays as values
parameters –
- Returns:
species_models (list[SpeciesModel]) – list with a model object for each species in this run
subselection_evaluation (list[SubselectionEvaluation]) – list with an evaluation object for each species in this run
- mnp.MNP.save_config_and_log(parameters: MNPParameters, config: ConfigParser)
- class mnp.config.MNPParameters(config: ConfigParser, folders: dict, geospatial_profile: dict, species_names: DataFrame, species_traits: DataFrame, group_traits: DataFrame, subselection_tables: dict[str, DataFrame], region_names: list | None = None, land_type_suitabilities: DataFrame | None = None, environmental_response_tables: dict[str, DataFrame] | None = None, save_rasters: bool = True, force_species_model_recalculation: bool = False, response_020: float = 0, response_080: float = 0.5, response_100: float = 1, hsi_threshold: float = 0.1, small_pop_threshold_area: float = 500, small_pop_slope: float = 2, pxl_area: float = 0, environmental_factor_hotspot_statistic: str = 'mean', complying_species: set | None = None, valid_species_subselections: dict[str, set] | None = None)
Bases:
object
This class holds all parameter and config information needed to tun the Model for Nature Policy
- complying_species: set | None = None
- config: ConfigParser
- environmental_factor_hotspot_statistic: str = 'mean'
- environmental_response_tables: dict[str, DataFrame] | None = None
- folders: dict
- force_species_model_recalculation: bool = False
- classmethod from_configparser(config: ConfigParser)
Factory method to create class from ConfigParser
- Parameters:
config (ConfigParser) – Instance to create parameter class from
- Returns:
cls – This class holds all information needed to run MNP
- Return type:
- geospatial_profile: dict
- get_complying_species()
- get_valid_species_selections()
- group_traits: DataFrame
- hsi_threshold: float = 0.1
- land_type_suitabilities: DataFrame | None = None
- pxl_area: float = 0
- read_geospatial_profile()
- region_names: list | None = None
- response_020: float = 0
- response_080: float = 0.5
- response_100: float = 1
- save_rasters: bool = True
- small_pop_slope: float = 2
- small_pop_threshold_area: float = 500
- species_names: DataFrame
- species_traits: DataFrame
- subselection_tables: dict[str, DataFrame]
- valid_species_subselections: dict[str, set] | None = None
- class mnp.utils.CustomFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)
Bases:
Formatter
For coloring cli outputs, thanks to: https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output
- FORMATS = {10: '%(asctime)s | %(levelname)s | %(funcName)s - %(message)s', 20: '%(asctime)s | \x1b[38;5;33m%(levelname)s\x1b[0m | %(funcName)s - %(message)s', 30: '%(asctime)s | \x1b[38;5;214m%(levelname)s\x1b[0m | %(funcName)s - %(message)s', 40: '%(asctime)s | \x1b[31;20m%(levelname)s\x1b[0m | %(funcName)s - %(message)s', 50: '%(asctime)s | \x1b[31;1m%(levelname)s\x1b[0m | %(funcName)s - %(message)s'}
- bold_red = '\x1b[31;1m'
- cyan = '\x1b[38;5;33m'
- format(record)
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- funcname = '%(funcName)s'
- grey = '\x1b[38;20m'
- levelname = '%(levelname)s'
- message = '%(message)s'
- red = '\x1b[31;20m'
- reset = '\x1b[0m'
- time = '%(asctime)s'
- yellow = '\x1b[38;5;214m'
- class mnp.utils.List(iterable=(), /)
Bases:
list
Child of list to make a weak referencable list. See https://docs.python.org/3/library/weakref.html This is used to make weak references to the species model lists.
- mnp.utils.add_dynamics_to_config(configuration: ConfigParser)
- mnp.utils.clear_temp()
Clear all files temporarly stored
- mnp.utils.config_info_to_temp(configuration: ConfigParser, section: str, key: str, dest: str) bool
Store a section from the configuration to a pkl file in a temporary location
- Parameters:
configuration (output from read_ini) –
- mnp.utils.config_section_to_cover(configuration: ConfigParser, section: str, cover_dir: str)
Save a section in the parameters to a csv file with key value pairs.
- mnp.utils.copy_input_file(source: str, destination: str)
copy input file
- Parameters:
destination (str) – Path of the destination file
source (str) – Path for the source file
- mnp.utils.create_directories(folders: dict) None
create scenario cover based on the cover design
- Return type:
directory tree in cover root
- mnp.utils.geo_profile_from_hsi(folders: dict)
Make geospatial profile from one of the HSI input rasters.
- mnp.utils.get_logger()
- mnp.utils.list_sources_destinations(input_pathway, folders: dict, configuration: ConfigParser) tuple
list source and destination paths of input rasters and tables.
- Parameters:
configuration – The configuration for this mnp run as provided by user
folders – Dictionary of folders in cover for this mnp run
input_pathway (InputPathway) – Class defining which input steps to take
- Return type:
([src1, src2, .. src_n], [dest1, dest2, .. dest_n])
- mnp.utils.log_file_to_cover(folders: dict)
Copy log file from temporary storing location to cover location
- mnp.utils.log_start_completed(func)
- mnp.utils.slugify(value, allow_unicode=False)
Taken from https://github.com/django/django/blob/master/django/utils/text.py Convert to ASCII if ‘allow_unicode’ is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren’t alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.