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)
Run the clustering procedure.
- Parameters:
hsi_array (sparse.csr_array) – HSI 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.
- Parameters:
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.
- 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()
Save the environmental factor raster to a file.
- class mnp.species_models.habitat_suitability.HSIProcedure(hsi_threshold: float, suitabilities: dict)
Bases:
ABC
Abstract class for HSI procedures.
- abstract run(land_types: dict, abiotic_factor_array: csr_array)
Run the HSI procedure on a given set of land types and (optionally) abiotic factor array.
- Parameters:
land_types (dict) – Land types as: land type code (str) : suitability (float between 0 and 1).
abiotic_factor_array (sparse.csr_array or None) – Abiotic factor array for the species. If None, no abiotic factors are considered.
- class mnp.species_models.habitat_suitability.Nature(hsi_threshold: float, 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) –
- Returns:
hsi
- Return type:
sparse.csr_array
- 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)
Run the HSI procedure on a given set of land types and (optionally) abiotic factor array.
- Parameters:
land_types (dict) – Land types as: land type code (str) : suitability (float between 0 and 1).
abiotic_factor_array (sparse.csr_array or None) – Abiotic factor array for the species. If None, no abiotic factors are considered.
- class mnp.species_models.species_evaluation.SpeciesEvaluation(mnp_parameters: MNPParameters, species_code: str, hsi: HSI, clustering: ClusteringProcedure)
Bases:
object
- 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 species
- population_array(array_type: str, only_keypopulations=False) sparray | int
Make an array for this species evaluation, with some value in the cells of each population.
- Parameters:
array_type ({'binary','nkeys'}) – The type of population array to make
only_keypopulations (bool) – retain only population of at least a key population in size
- 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
Dataclass for holding parameters for species evaluation.
- 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_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
- 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.
- Return type:
boolean indicating raster was read or not
- save_raster(nodata_value='auto', band_description: str = None, **kwargs)
Save the hsi map for this species
- Parameters:
nodata_value (str or int, optional) – NoData value for the raster. If ‘auto’, it will be determined based on the array contents.
band_description (str, optional) – Description of the band in the raster file.
**kwargs (dict) – Additional keyword arguments to pass to the update_tags method of the rasterio dataset.
- 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 (MNPParameters) – MNPParameters 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:
dictionary containing name information for the species model such as
species code
local name
scientific name
code of group that species belongs to
name of group that species belongs to
- 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 –
- trait_info() dict[str, float]
Gives trait info on species model.
- Return type:
dictionary containing ‘key_population_area_ha’, ‘possibly_viable_threshold’ and ‘viable_threshold’
- mnp.species_models.species_model.run_species(species_model: SpeciesModel, land_types: dict, environmentals: 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)
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
Prefect should not cache results as this keeps references to the species model list which prevents memory being released during garbage collection.
- Parameters:
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]