use sciforge::hub::prelude::biology::ecology::{
shannon_diversity, simpson_diversity, species_area,
};
pub struct Ecosystem {
pub name: &'static str,
pub area_km2: f64,
pub species_counts: Vec<u64>,
pub net_primary_productivity_gc_m2_yr: f64,
pub mean_temperature_c: f64,
pub annual_precipitation_mm: f64,
}
impl Ecosystem {
pub fn total_species(&self) -> u64 {
self.species_counts.len() as u64
}
pub fn total_individuals(&self) -> u64 {
self.species_counts.iter().sum()
}
pub fn shannon_index(&self) -> f64 {
let proportions: Vec<f64> = self
.species_counts
.iter()
.map(|&c| c as f64 / self.total_individuals() as f64)
.collect();
shannon_diversity(&proportions)
}
pub fn simpson_diversity(&self) -> f64 {
let proportions: Vec<f64> = self
.species_counts
.iter()
.map(|&c| c as f64 / self.total_individuals() as f64)
.collect();
simpson_diversity(&proportions)
}
pub fn expected_species_from_area(&self, z: f64, c: f64) -> f64 {
species_area(c, z, self.area_km2)
}
pub fn total_npp_gc_yr(&self) -> f64 {
self.net_primary_productivity_gc_m2_yr * self.area_km2 * 1e6
}
pub fn biomass_turnover_time_yr(&self, biomass_gc_m2: f64) -> f64 {
biomass_gc_m2 / self.net_primary_productivity_gc_m2_yr
}
}
pub fn tropical_rainforest() -> Ecosystem {
Ecosystem {
name: "Tropical Rainforest",
area_km2: 17_000_000.0,
species_counts: vec![1000, 800, 600, 500, 400, 300, 200, 150, 100, 80],
net_primary_productivity_gc_m2_yr: 2200.0,
mean_temperature_c: 25.0,
annual_precipitation_mm: 2500.0,
}
}
pub fn boreal_forest() -> Ecosystem {
Ecosystem {
name: "Boreal Forest",
area_km2: 15_000_000.0,
species_counts: vec![500, 400, 300, 200, 100, 50],
net_primary_productivity_gc_m2_yr: 800.0,
mean_temperature_c: -5.0,
annual_precipitation_mm: 500.0,
}
}
pub fn coral_reef() -> Ecosystem {
Ecosystem {
name: "Coral Reef",
area_km2: 284_300.0,
species_counts: vec![2000, 1500, 1000, 800, 600, 400, 300, 200, 100, 50],
net_primary_productivity_gc_m2_yr: 2500.0,
mean_temperature_c: 26.0,
annual_precipitation_mm: 0.0,
}
}