Coverage for pybeepop/beepop/nutrientcontaminationtable.py: 81%

31 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-30 13:34 +0000

1""" 

2Nutrient Contamination Module for BeePop+ Pesticide Exposure Simulation 

3 

4This module manages time-dependent contamination levels in honey bee nutrient 

5sources (pollen and nectar). It tracks daily contamination concentrations 

6for modeling exposure to pesticides. 

7 

8Classes: 

9 SNCElement: Single day's contamination data for pollen and nectar sources 

10 NutrientContaminationTable: Time-series contamination concentration manager 

11""" 

12 

13from dataclasses import dataclass 

14from datetime import datetime 

15from typing import List, Optional, Tuple 

16 

17 

18@dataclass 

19class SNCElement: 

20 """ 

21 Daily nutrient source contamination data for BeePop+ exposure simulation. 

22 

23 Represents contamination levels in honey bee nutrient sources (pollen and 

24 nectar) for a specific date. Enables modeling of time-varying exposure 

25 to environmental contaminants through foraging activities. 

26 

27 Attributes: 

28 nc_date (datetime): Date for this contamination measurement 

29 nc_pollen_cont (float): Pollen contamination concentration (default: 0.0) 

30 nc_nectar_cont (float): Nectar contamination concentration (default: 0.0) 

31 """ 

32 

33 nc_date: datetime 

34 nc_pollen_cont: float = 0.0 

35 nc_nectar_cont: float = 0.0 

36 

37 

38class NutrientContaminationTable: 

39 """ 

40 Time-series contamination concentration manager for BeePop+ exposure simulation. 

41 

42 Attributes: 

43 cont_date_array (List[SNCElement]): Time-series of daily contamination measurements 

44 nutrient_cont_enabled (bool): Whether contamination effects are active in simulation 

45 contaminant_file_name (str): Source filename for contamination data (default: "No File Loaded") 

46 """ 

47 

48 def __init__(self): 

49 self.cont_date_array: List[SNCElement] = [] 

50 self.nutrient_cont_enabled: bool = False 

51 self.contaminant_file_name: str = "No File Loaded" 

52 

53 def remove_all(self): 

54 self.cont_date_array.clear() 

55 

56 def add_contaminant_conc(self, element: SNCElement): 

57 self.cont_date_array.append(element) 

58 

59 def get_contaminant_conc(self, date: datetime) -> Tuple[float, float]: 

60 """ 

61 Returns (nectar_conc, pollen_conc) for the given date. If not found, returns (0.0, 0.0). 

62 """ 

63 for element in self.cont_date_array: 

64 if element.nc_date.date() == date.date(): 

65 return element.nc_nectar_cont, element.nc_pollen_cont 

66 return 0.0, 0.0 

67 

68 def copy_from(self, other: "NutrientContaminationTable"): 

69 self.remove_all() 

70 self.cont_date_array = [ 

71 SNCElement(e.nc_date, e.nc_pollen_cont, e.nc_nectar_cont) 

72 for e in other.cont_date_array 

73 ] 

74 self.nutrient_cont_enabled = other.nutrient_cont_enabled 

75 self.contaminant_file_name = other.contaminant_file_name 

76 

77 def get_file_name(self) -> str: 

78 return self.contaminant_file_name 

79 

80 def is_enabled(self) -> bool: 

81 return self.nutrient_cont_enabled