Coverage for pybeepop/engine_interface.py: 58%

26 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-19 20:58 +0000

1""" 

2Engine interface protocol for PyBeePop. 

3 

4This module defines the BeepopEngineInterface protocol that a BeePop+ simulation 

5engine must implement to be compatible with the PyBeePop wrapper. 

6""" 

7 

8from typing import Protocol, Dict, Optional 

9import pandas as pd 

10 

11 

12class BeepopEngineInterface(Protocol): 

13 """ 

14 Protocol defining the interface that a BeePop simulation engine must implement. 

15 

16 Implemented by PythonEngineAdapter, which wraps the pure Python engine 

17 (beepop.BeePop). 

18 

19 Note: Initialization happens in __init__(), not via a separate initialize_model() method. 

20 """ 

21 

22 engine_type: str 

23 

24 def set_parameters(self, parameters: Dict[str, str]) -> Dict[str, str]: 

25 """ 

26 Set simulation parameters from a dictionary. 

27 

28 Args: 

29 parameters: Dictionary of parameter name -> value pairs. 

30 Example: {"ICWorkerAdults": "10000", "SimStart": "04/01/2023"} 

31 

32 Returns: 

33 Dict[str, str]: Dictionary of parameters that were successfully set. 

34 """ 

35 ... 

36 

37 def get_parameters(self) -> Dict[str, str]: 

38 """ 

39 Get currently set parameters. 

40 

41 Returns: 

42 Dict[str, str]: Dictionary of current parameter values. 

43 """ 

44 ... 

45 

46 def load_parameter_file(self, file_path: str) -> bool: 

47 """ 

48 Load parameters from a text file. 

49 

50 Args: 

51 file_path: Path to parameter file (format: parameter=value per line). 

52 

53 Returns: 

54 bool: True if file loaded successfully, False otherwise. 

55 """ 

56 ... 

57 

58 def load_weather_file(self, file_path: str) -> bool: 

59 """ 

60 Load weather data from a CSV or text file. 

61 

62 Args: 

63 file_path: Path to weather file. 

64 

65 Returns: 

66 bool: True if file loaded successfully, False otherwise. 

67 """ 

68 ... 

69 

70 def load_residue_file(self, file_path: str) -> bool: 

71 """ 

72 Load pesticide residue/contamination data from a file. 

73 

74 Args: 

75 file_path: Path to residue file. 

76 

77 Returns: 

78 bool: True if file loaded successfully, False otherwise. 

79 """ 

80 ... 

81 

82 def set_latitude(self, latitude: float) -> bool: 

83 """ 

84 Set geographic latitude for daylight calculations. 

85 

86 Args: 

87 latitude: Latitude in decimal degrees (-90 to 90). 

88 

89 Returns: 

90 bool: True if latitude set successfully, False otherwise. 

91 """ 

92 ... 

93 

94 def run_simulation(self) -> Optional[pd.DataFrame]: 

95 """ 

96 Execute the simulation and return results. 

97 

98 Returns: 

99 pd.DataFrame: DataFrame with simulation results (44 columns), or None if failed. 

100 """ 

101 ... 

102 

103 def get_error_log(self) -> str: 

104 """ 

105 Get error messages from the simulation session. 

106 

107 Returns: 

108 str: Error log as newline-separated string. 

109 """ 

110 ... 

111 

112 def get_info_log(self) -> str: 

113 """ 

114 Get informational messages from the simulation session. 

115 

116 Returns: 

117 str: Info log as newline-separated string. 

118 """ 

119 ... 

120 

121 def get_version(self) -> str: 

122 """ 

123 Get the engine version string. 

124 

125 Returns: 

126 str: Version string (e.g., "1.15.25"). 

127 """ 

128 ... 

129 

130 def cleanup(self) -> None: 

131 """ 

132 Clean up resources and close connections. 

133 

134 This method should be idempotent and safe to call multiple times. 

135 """ 

136 ...