mnp.species_models package
Submodules
- class mnp.species_models.clustering.ClusterLocal(parameters: MNPParameters, species_code: str)
Bases:
ClusteringProcedure
- run(hsi_array: csr_array)
Run Local clustering procedure
- Parameters:
hsi_array (csr_array) – A sparse csr_array containing hsi map for this species
- class mnp.species_models.clustering.Clustering(parameters: MNPParameters, species_code: str)
Bases:
object
- class mnp.species_models.clustering.ClusteringProcedure(geospatial_profile, output_path: str = '')
Bases:
SpeciesGeoMap
,ABC
Abstract class for cluster procedures
- abstract run(hsi_array: csr_array)
- class mnp.species_models.environmental_factor.EnvironmentalFactor(parameters: MNPParameters, species_code: str)
Bases:
SpeciesGeoMap
- calculate(environmentals: dict)
Make habitat suitability map for this species model based on land type suitability map and abiotic maps. environmentals that are not within the species’ formula will be left out. This function first deconstructs the abiotic formula to know of which set of environmentals it should take pairwise minima before multiplication.
If no abiotic maps are used, this will return the input ltsi map.
- Parameters:
ltsi_array (sparse.csr_array) – sparse array with land type suitability index values (0-1)
environmentals (dict) – dictionary with ‘environmental name’: sparse array
- class mnp.species_models.habitat_suitability.HSI(parameters: MNPParameters, species_code: str)
Bases:
SpeciesGeoMap
Habitat type suitability class for making hsi maps for species. Sets itself using necessary parameters from parameter database. Most members are private to counteract people’s fiddling and errors.
- Parameters:
parameters (dict) –
species_code (str) –
- calculate(land_types: dict, environmentals: dict = None) sparray
Calculate land type suitability index map for this species based on the land type map, and land type suitabilities
- Parameters:
environmentals (dict or None) –
land_types (dict) – dict of LandType objects
- save_environmental_factor_raster()
you pass butter
- class mnp.species_models.habitat_suitability.HSIProcedure(hsi_threshold: float, suitabilities: dict)
Bases:
ABC
Abstract class for HSI procedures.
- Parameters:
hsi_threshold (float) – threshold below which to exclude land type, multiplied by environmental factor, from further computations.
suitabilities (dict) – Suitabilities of land types as: land type code (str) : suitability (float between 0 and 1).
- abstract run(land_types: dict, abiotic_factor_array: csr_array)
- class mnp.species_models.habitat_suitability.Nature(hsi_threshold: float, land_type_suitabilities: dict)
Bases:
HSIProcedure
- run(land_types: dict, environmental_factor_array: csr_array)
Calculate land type suitability for ‘Nature’ species; terrestrial species occurring in nature areas.
- Parameters:
land_types (dict) –
environmental_factor_array (sparse.csr_array or None) –
- class mnp.species_models.habitat_suitability.PreCalculated(hsi_threshold: float, suitabilities: dict)
Bases:
HSIProcedure
Procedure for when reading HSI from disk. Does nothing as HSI map is read from cover directory. An empty procedure is needed for this as having no procedure will result in KeyError when attempting to execute procedures from SpeciesModel
- Parameters:
land_types –
environmental_factor_array –
- run(land_types: dict, environmental_factor_array: csr_array)
- class mnp.species_models.polygon_habitat_maps.PolygonHabitatMap(gkpg_destination, species_code)
Bases:
SpeciesGeoMap
- build_template()
- write(metapopulation, evaluation)
- class mnp.species_models.species_evaluation.RegionalSpeciesEvaluation(species_code: str, parent_evaluation: SpeciesEvaluation, region_array: sparray, region_name: str, region_id: int)
Bases:
SpeciesEvaluation
Species evaluation object for a certain sub-region. Is a child of SpeciesEvaluation as it does the exact same thing, just for a smaller region and with a slightly different update_results_dictionary method.
- Parameters:
species_code (str) – Name says it all.
parent_evaluation (SpeciesEvaluation) – The evaluation of the entire area that the sub-region for this evaluation is a part of. Example evaluation of NL for a sub-evaluation of North-Holland.
region_name (str) – Name for the collection of sub-regions that the present sub-region is a part of.
region_id (int) – The ID that labels the sub-region for this regional evaluation in the sub-region raster.
- update_results_dictionary()
- class mnp.species_models.species_evaluation.SpeciesEvaluation(mnp_parameters: MNPParameters, species_code: str, hsi: HSI, clustering: ClusteringProcedure)
Bases:
object
- Parameters:
mnp_parameters –
species_code –
- calculate()
Calculate evaluation for this SpeciesModel.
The following results are calculated at species level : - populations = number of populations - populations_key_population = amount of populations that reach a key population in size - total_area_m = total area in meters - total_effective_area_m = total area in meters, corrected for suitability - total_effective_area_kp = total area in key populations, corrected for suitability - total_effective_area_kp_norm = total area in key populations, corrected for suitability, after normalisation - viability_class = viability class for this species: None, 1, 2 or 3 - viability_class_description = label for the corresponding viability class
- Parameters:
hsi (HSI) – HSI object with habitat suitability array expressed in effective area
clustering (Clustering object) –
- evaluate_metapopulations() None
Evaluate metapopulations for the
- Parameters:
metapopulation_ids –
hsi –
clustering –
- population_array(array_type: str, only_keypopulations=False) sparray
Make an array for this species evaluation, with some value in the cells of each population.
- Parameters:
only_keypopulations (bool) – retain only population of at least a key population in size
array_type ({'binary','nkeys'}) – The type of population array to make
- Returns:
array – array of this species’ populations
- Return type:
np.ndarray
- results()
Return result-dictionary.
- summary_table_to_file(output_path)
Write summary table with specifications of each population to *.tif.vat.dbf file, as sidecar file to the <cover>outputclustering<species_code>.tif files
- trait_info() dict[str, float]
Return the values of this species’ traits
- Return type:
Dictionary with trait info
- update_results_dictionary()
- update_viability_class()
Check if this species is viable and update the result dictionary. Note: sum_norm_keys = 0 –> 0 sum_norm_keys < possibly_viable_threshold –> 1 possibly_viable_threshold <= sum_norm_keys < viable_threshold –> 2 sum_norm_keys >= viable_threshold –> 3
- class mnp.species_models.species_evaluation.SpeciesEvaluationParameters(key_population_area: float = 1, possibly_viable_threshold: float = 1, viable_threshold: float = 1, small_pop_threshold_area: float = 500, small_pop_slope: float = 2, pxl_area: float = 0)
Bases:
object
- key_population_area: float = 1
- possibly_viable_threshold: float = 1
- pxl_area: float = 0
- small_pop_slope: float = 2
- small_pop_threshold_area: float = 500
- viable_threshold: float = 1
- class mnp.species_models.species_evaluation.SubRegion(raster: ClusteringProcedure, region_array: sparray, region_id: int)
Bases:
object
Holds a sub-region of a species cluster or hsi array.
- Parameters:
clustering (ClusterLocal or HSI) – Clustering object to take a sub-region from
region_array (sparse.csr_array) – Array with sub-regions as IDs.
region_id (int) – The ID for the region to take out of region_array.
- class mnp.species_models.species_geo_map.SpeciesGeoMap(geospatial_profile: DefaultGTiffProfile, output_path: str = '')
Bases:
object
Parent class for geospatial rasters pertaining to species. Implements loading the geospatial profile and saving as .tif
- Parameters:
output_path (str) – path to save or read raster fil from or to, without extension
- file_exists()
Check if file already exists and return True or False
- Return type:
boolean indicating file exists or not
- read_from_file()
Read raster from file.
- Parameters:
species_code – code of the species for which to read raster file
- save_raster(nodata_value='auto', band_description: str = None, **kwargs)
Save the hsi map for this species
- class mnp.species_models.species_geo_map.SpeciesGeomapLogger
Bases:
object
Class for holding log messages until the SpeciesModel asks for them. This is done because logging to a file does not go well when using multiple processes due to write conflicts.
- error(message: str)
- info(message: str)
- warning(message: str)
- class mnp.species_models.species_model.SpeciesModel(species_code: str, parameters: MNPParameters)
Bases:
object
Highest level class for controlling each species model. Contains the three overarching steps species models do: making an HSI map, clustering metapopulations and evaluating metapopulations. It does not do any work itself. For each major step in MNP it holds an instance of a subclass which implements the actual work.
It gets everything it needs to know to run and evaluate each model from the parameter database dictionary.
- Parameters:
species_code (str) – Code for this SpeciesModel (S0XXXXXXX)
parameters – Dictionary containing all parameters for this MNP run.
- evaluation_results() dict
You pass butter.
- get_populations_array(*args, **kwargs) csr_array
- Parameters:
array_type ({'binary','nkeys'}) – Specify which value should be in the cells of each population
- Return type:
array of this species’ populations
- log_messages()
- name_info() dict[str, str]
Return name info
- Returns:
species code
local name
scientific name
code of group that species belongs to
name of group that species belongs to
- region_evaluation_results() list[dict]
You pass butter
- run_clustering() None
Run each clustering procedure for this species model. Read it from disk if a raster file already exists.
- run_evaluation() None
Evaluate this species model. Save summary table of evaluation to .dbf.
- run_hsi(land_types: dict, environmentals: dict) None
Calculate land type suitability map for this species model
- Parameters:
environmentals –
land_types –
- run_regional_evaluation(sub_regions: dict) None
Evaluate species for a sub-region.
- Parameters:
parameters –
sub_regions –
- trait_info() dict[str, float]
Gives trait info on species model.
- mnp.species_models.species_model.run_species(species_model: SpeciesModel, land_types: dict, environmentals: dict, sub_regions: dict)
Run this species model.
- Parameters:
species_model –
land_types –
environmentals –
- mnp.species_models.species_model.run_species_models(species_models: list[SpeciesModel], land_types: dict, environmentals: dict, sub_regions: dict = 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
Prefect should not cache results as this keeps references to the species model list which prevents memory being released during garbage collection.
- 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 with a model object for each species in this run
- Return type:
list[SpeciesModel]
- mnp.species_models.species_specific_maps.produce_nkeys_map(species_model: SpeciesModel, parameters: MNPParameters)
Produce maps with population size in number of key populations for the given species model
- Parameters:
species_model (SpeciesModel) – Instance of SpeciesModel class
parameters (MNPParameters) – MNPParameters class instance
- mnp.species_models.species_specific_maps.produce_nkeys_maps(species_models: ReferenceType, parameters: MNPParameters)
Task for producing maps with population size in number of key populations for a species model
- Parameters:
species_models (List[SpeciesModel]) – List of SpeciesModel class instances
parameters (MNPParameters) – MNPParameters class instance