pyholos 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyholos might be problematic. Click here for more details.

Files changed (55) hide show
  1. pyholos/__init__.py +0 -0
  2. pyholos/common.py +141 -0
  3. pyholos/common2.py +157 -0
  4. pyholos/components/__init__.py +0 -0
  5. pyholos/components/animals/__init__.py +0 -0
  6. pyholos/components/animals/beef.py +766 -0
  7. pyholos/components/animals/common.py +2301 -0
  8. pyholos/components/animals/dairy.py +341 -0
  9. pyholos/components/animals/sheep.py +412 -0
  10. pyholos/components/common.py +170 -0
  11. pyholos/components/land_management/__init__.py +0 -0
  12. pyholos/components/land_management/carbon/__init__.py +0 -0
  13. pyholos/components/land_management/carbon/climate.py +863 -0
  14. pyholos/components/land_management/carbon/management.py +21 -0
  15. pyholos/components/land_management/carbon/relative_biomass_information.py +410 -0
  16. pyholos/components/land_management/carbon/tillage.py +88 -0
  17. pyholos/components/land_management/common.py +220 -0
  18. pyholos/components/land_management/crop.py +1233 -0
  19. pyholos/components/land_management/field_system.py +458 -0
  20. pyholos/components/land_management/utils.py +66 -0
  21. pyholos/config.py +49 -0
  22. pyholos/core_constants.py +20 -0
  23. pyholos/defaults.py +116 -0
  24. pyholos/farm/__init__.py +0 -0
  25. pyholos/farm/enums.py +54 -0
  26. pyholos/farm/farm.py +101 -0
  27. pyholos/farm/farm_inputs.py +633 -0
  28. pyholos/farm/farm_settings.py +542 -0
  29. pyholos/launching.py +86 -0
  30. pyholos/postprocessing/__init__.py +0 -0
  31. pyholos/postprocessing/plots.py +164 -0
  32. pyholos/postprocessing/postprocessing.py +38 -0
  33. pyholos/resources/holos/Table_16_Livestock_Coefficients_BeefAndDairy_Cattle_Provider.csv +21 -0
  34. pyholos/resources/holos/Table_21_Average_Milk_Production_For_Dairy_Cows_By_Province.csv +23 -0
  35. pyholos/resources/holos/Table_22_Livestock_Coefficients_For_Sheep.csv +28 -0
  36. pyholos/resources/holos/Table_29_Percentage_Total_Manure_Produced_In_Systems.csv +56 -0
  37. pyholos/resources/holos/Table_30_Default_Bedding_Material_Composition_Provider.csv +28 -0
  38. pyholos/resources/holos/Table_50_Fuel_Energy_Requirement_Estimates_By_Region.csv +81 -0
  39. pyholos/resources/holos/Table_51_Herbicide_Energy_Requirement_Estimates_By_Region.csv +81 -0
  40. pyholos/resources/holos/Table_61_Fractions_of_dairy_cattle_N_volatilized.csv +25 -0
  41. pyholos/resources/holos/Table_62_Fractions_of_swine_N_volatilized.csv +25 -0
  42. pyholos/resources/holos/Table_6_Manure_Types_And_Default_Composition.csv +126 -0
  43. pyholos/resources/holos/Table_7_Relative_Biomass_Information.csv +112 -0
  44. pyholos/resources/holos/Table_9_Default_Values_For_Nitrogen_Lignin_In_Crops.csv +72 -0
  45. pyholos/resources/holos/Table_Tillage_Factor.csv +13 -0
  46. pyholos/resources/holos/feeds.csv +223 -0
  47. pyholos/resources/holos/main_tables.py +493 -0
  48. pyholos/resources/holos/small_area_yields.csv +167159 -0
  49. pyholos/resources/soil_landscapes_of_canada_v3r2.zip +0 -0
  50. pyholos/soil.py +439 -0
  51. pyholos/utils.py +83 -0
  52. pyholos-0.0.1.dist-info/METADATA +16 -0
  53. pyholos-0.0.1.dist-info/RECORD +55 -0
  54. pyholos-0.0.1.dist-info/WHEEL +4 -0
  55. pyholos-0.0.1.dist-info/licenses/LICENSE +677 -0
@@ -0,0 +1,412 @@
1
+ from datetime import date
2
+ from enum import Enum
3
+
4
+ from pyholos import utils
5
+ from pyholos.common import Component, HolosVar
6
+ from pyholos.components.animals.common import (
7
+ AnimalType, Bedding, BeddingMaterialType, Diet, DietAdditiveType,
8
+ HousingType, LivestockEmissionConversionFactorsData, ManureStateType,
9
+ ProductionStage, convert_animal_type_name,
10
+ get_default_manure_composition_data,
11
+ get_default_methane_producing_capacity_of_manure,
12
+ get_manure_excretion_rate)
13
+ from pyholos.components.common import ComponentType
14
+ from pyholos.config import DATE_FMT, PathsHolosResources
15
+
16
+
17
+ def get_feeding_activity_coefficient(
18
+ housing_type: HousingType
19
+ ) -> float:
20
+ """Returns the feeding activity coefficient of feeding situation (CA) for sheep
21
+ (Table_23_Feeding_Activity_Coefficient_Sheep_Provider)
22
+
23
+ Args:
24
+ housing_type: Housing type class instance
25
+
26
+ Returns:
27
+ (MJ d-1 kg-1) activity coefficient of feeding situation (CA)
28
+
29
+ Notes:
30
+ 1. Animals are confined due to pregnancy in final trimester (50 days) (IPCC, 2019)
31
+ 2. Animals housed for fattening
32
+
33
+ Holos Source Code:
34
+ https://github.com/holos-aafc/Holos/blob/97331845af308fe8aab6267edad4bbda6f5938b6/H.Core/Providers/Animals/Table_23_Feeding_Activity_Coefficient_Sheep_Provider.cs#L17
35
+
36
+ """
37
+ match housing_type:
38
+ # Footnote 1
39
+ case HousingType.housed_ewes:
40
+ return 0.0096
41
+
42
+ # Footnote 2
43
+ case HousingType.confined:
44
+ return 0.0067
45
+
46
+ case HousingType.pasture | HousingType.flat_pasture:
47
+ return 0.0107
48
+
49
+ case HousingType.hilly_pasture_or_open_range:
50
+ return 0.024
51
+
52
+ case _:
53
+ raise ValueError(f"unable to get data for housing type: {housing_type}. Returning default value of 0.")
54
+ # return 0
55
+
56
+
57
+ class GroupNames(Enum):
58
+ sheep_feedlot: str = "Sheep feedlot"
59
+ rams: str = "Rams"
60
+ ewes: str = "Ewes"
61
+ lambs: str = "Lambs"
62
+ lambs_and_ewes: str = "Lambs & ewes"
63
+
64
+
65
+ class AnimalCoefficientData:
66
+ def __init__(
67
+ self,
68
+ maintenance_coefficient: float = 0,
69
+ coefficient_a: float = 0,
70
+ coefficient_b: float = 0,
71
+ initial_weight: float = 0,
72
+ final_weight: float = 0,
73
+ wool_production: float = 0
74
+ ):
75
+ """Table_22_Livestock_Coefficients_For_Sheep.csv
76
+
77
+ Args:
78
+ maintenance_coefficient: (MJ d-1 kg-1) maintenance coefficient (cf)
79
+ coefficient_a: (MJ kg-1)
80
+ coefficient_b: (MJ kg-2)
81
+ initial_weight: (kg)
82
+ final_weight: (kg)
83
+ wool_production: : (kg year-1)
84
+ """
85
+ self.baseline_maintenance_coefficient = maintenance_coefficient
86
+ self.coefficient_a = coefficient_a
87
+ self.coefficient_b = coefficient_b
88
+ self.initial_weight = initial_weight
89
+ self.final_weight = final_weight
90
+ self.wool_production = wool_production
91
+
92
+
93
+ class SheepBase(Component):
94
+ def __init__(self):
95
+ super().__init__()
96
+
97
+ self.name = HolosVar(name="Name", value="Sheep")
98
+ self.component_type = HolosVar(name="Component Type", value="H.Core.Models.Animals.Sheep")
99
+ self.group_name = HolosVar(name="Group Name", value=None)
100
+ self.group_type = HolosVar(name="Group Type", value=None)
101
+ self.management_period_name = HolosVar(name="Management Period Name", value=None)
102
+ self.group_pairing_number = HolosVar(name="Group Pairing Number", value=None)
103
+ self.management_period_start_date = HolosVar(name="Management Period Start Date", value=None)
104
+ self.management_period_days = HolosVar(name="Management Period Days", value=None)
105
+ self.number_of_animals = HolosVar(name="Number Of Animals", value=None)
106
+ self.production_stage = HolosVar(name="Production Stage", value=None)
107
+ self.number_of_young_animals = HolosVar(name="Number Of Young Animals", value=None)
108
+ self.start_weight = HolosVar(name="Start Weight", value=None)
109
+ self.end_weight = HolosVar(name="End Weight", value=None)
110
+ self.average_daily_gain = HolosVar(name="Average Daily Gain", value=None)
111
+
112
+ self.energy_required_to_produce_wool = HolosVar(name="Energy Required To Produce Wool", value=24)
113
+ """(MJ kg-1)
114
+ Holos Source Code:
115
+ https://github.com/holos-aafc/Holos/blob/97331845af308fe8aab6267edad4bbda6f5938b6/H.Core/Services/Initialization/Animals/AnimalInitializationService.Sheep.cs#L28
116
+ """
117
+
118
+ self.wool_production = HolosVar(name="Wool Production", value=None)
119
+
120
+ self.energy_required_to_produce_milk = HolosVar(name="Energy Required To Produce Milk", value=4.6)
121
+ """(MJ kg-1)
122
+ Holos Source Code:
123
+ https://github.com/holos-aafc/Holos/blob/97331845af308fe8aab6267edad4bbda6f5938b6/H.Core/Services/Initialization/Animals/AnimalInitializationService.Sheep.cs#L28
124
+ """
125
+
126
+ self.diet_additive_type = HolosVar(name="Diet Additive Type", value=None)
127
+
128
+ self.methane_conversion_factor_of_diet = HolosVar(name="Methane Conversion Factor Of Diet", value=None)
129
+
130
+ self.methane_conversion_factor_adjusted = HolosVar(name="Methane Conversion Factor Adjusted", value=0)
131
+ """deprecated"""
132
+
133
+ self.feed_intake = HolosVar(name="Feed Intake", value=0)
134
+ """only for swine"""
135
+
136
+ self.crude_protein = HolosVar(name="Crude Protein", value=None)
137
+ self.forage = HolosVar(name="Forage", value=None)
138
+ self.tdn = HolosVar(name="TDN", value=None)
139
+ self.ash_content_of_diet = HolosVar(name="Ash Content Of Diet", value=None)
140
+ self.starch = HolosVar(name="Starch", value=None)
141
+ self.fat = HolosVar(name="Fat", value=None)
142
+ self.me = HolosVar(name="ME", value=None)
143
+ self.ndf = HolosVar(name="NDF", value=None)
144
+ self.gain_coefficient_a = HolosVar(name="Gain Coefficient A", value=None)
145
+ self.gain_coefficient_b = HolosVar(name="Gain Coefficient B", value=None)
146
+ self.activity_coefficient_of_feeding_situation = HolosVar(name="Activity Coefficient Of Feeding Situation",
147
+ value=None)
148
+ self.maintenance_coefficient = HolosVar(name="Maintenance Coefficient", value=None)
149
+ self.user_defined_bedding_rate = HolosVar(name="User Defined Bedding Rate", value=None)
150
+ self.total_carbon_kilograms_dry_matter_for_bedding = HolosVar(
151
+ name="Total Carbon Kilograms Dry Matter For Bedding", value=None)
152
+ self.total_nitrogen_kilograms_dry_matter_for_bedding = HolosVar(
153
+ name="Total Nitrogen Kilograms Dry Matter For Bedding", value=None)
154
+ self.moisture_content_of_bedding_material = HolosVar(name="Moisture Content Of Bedding Material", value=None)
155
+ self.methane_conversion_factor_of_manure = HolosVar(name="Methane Conversion Factor Of Manure", value=None)
156
+ self.n2o_direct_emission_factor = HolosVar(name="N2O Direct Emission Factor", value=None)
157
+ self.emission_factor_volatilization = HolosVar(name="Emission Factor Volatilization", value=None)
158
+ self.volatilization_fraction = HolosVar(name="Volatilization Fraction", value=None)
159
+ self.emission_factor_leaching = HolosVar(name="Emission Factor Leaching", value=None)
160
+ self.fraction_leaching = HolosVar(name="Fraction Leaching", value=None)
161
+
162
+ self.ash_content = HolosVar(name="Ash Content", value=8.0)
163
+ """deprecated"""
164
+
165
+ self.methane_producing_capacity_of_manure = HolosVar(name="Methane Producing Capacity Of Manure", value=None)
166
+ self.manure_excretion_rate = HolosVar(name="Manure Excretion Rate", value=None)
167
+ self.fraction_of_carbon_in_manure = HolosVar(name="Fraction Of Carbon In Manure", value=None)
168
+
169
+ def update_component_type(self, component_type: str):
170
+ self.component_type.value = '.'.join((self.component_type.value, component_type))
171
+
172
+ def get_animal_coefficient_data(self) -> AnimalCoefficientData:
173
+ df = utils.read_holos_resource_table(
174
+ path_file=PathsHolosResources.Table_22_Livestock_Coefficients_For_Sheep)
175
+ df.set_index(df.pop("Sheep Class").apply(lambda x: convert_animal_type_name(name=x)), inplace=True)
176
+
177
+ animal_type = convert_animal_type_name(name=self.group_name.value)
178
+ lookup_type = AnimalType.ram if animal_type == AnimalType.sheep_feedlot else animal_type
179
+
180
+ if lookup_type in df.index:
181
+ _df = df.loc[lookup_type]
182
+ res = AnimalCoefficientData(
183
+ maintenance_coefficient=_df['cf'],
184
+ coefficient_a=_df['a'],
185
+ coefficient_b=_df['b'],
186
+ initial_weight=_df['Initial Weight'],
187
+ final_weight=_df['Final Weight'],
188
+ wool_production=_df['Wool Production'])
189
+ else:
190
+ res = AnimalCoefficientData()
191
+ return res
192
+
193
+
194
+ class Sheep(SheepBase):
195
+ def __init__(
196
+ self,
197
+ name: str,
198
+ animal_type: AnimalType,
199
+ group_name: str,
200
+ component_type: ComponentType,
201
+ management_period_name: str,
202
+ group_pairing_number: int,
203
+ management_period_start_date: date,
204
+ management_period_days: int,
205
+ number_of_animals: int,
206
+ production_stage: ProductionStage,
207
+ number_of_young_animals: int,
208
+
209
+ diet: Diet,
210
+ housing_type: HousingType,
211
+ manure_emission_factors: LivestockEmissionConversionFactorsData,
212
+ manure_handling_system: ManureStateType,
213
+
214
+ start_weight: float = None,
215
+ end_weight: float = None,
216
+
217
+ diet_additive_type: DietAdditiveType = DietAdditiveType.NONE,
218
+ bedding_material_type: BeddingMaterialType = BeddingMaterialType.NONE,
219
+ ):
220
+ super().__init__()
221
+
222
+ # group_name = GroupNames.sheep_feedlot.value
223
+ # animal_type: AnimalType = AnimalType.sheep_feedlot
224
+
225
+ self.name.value = name
226
+ self.update_component_type(component_type=component_type.to_str())
227
+ self.group_name.value = group_name
228
+ self.group_type.value = animal_type.value
229
+ self.management_period_name.value = management_period_name
230
+ self.group_pairing_number.value = group_pairing_number
231
+ self.management_period_start_date.value = management_period_start_date.strftime(DATE_FMT)
232
+ self.management_period_days.value = management_period_days
233
+ self.number_of_animals.value = number_of_animals
234
+ self.production_stage.value = production_stage.value
235
+ self.number_of_young_animals.value = number_of_young_animals
236
+
237
+ _animal_coefficient_data = self.get_animal_coefficient_data()
238
+
239
+ self.maintenance_coefficient.value = _animal_coefficient_data.baseline_maintenance_coefficient
240
+ self.start_weight.value = _animal_coefficient_data.initial_weight if start_weight is None else start_weight
241
+ self.end_weight.value = _animal_coefficient_data.final_weight if end_weight is None else end_weight
242
+ self.gain_coefficient_a.value = _animal_coefficient_data.coefficient_a
243
+ self.gain_coefficient_b.value = _animal_coefficient_data.coefficient_b
244
+ self.wool_production.value = _animal_coefficient_data.wool_production
245
+
246
+ self.average_daily_gain.value = (self.end_weight.value - self.start_weight.value) / management_period_days
247
+
248
+ self.diet_additive_type.value = diet_additive_type.value
249
+
250
+ self.crude_protein.value = diet.crude_protein_percentage
251
+ self.forage.value = diet.forage_percentage
252
+ self.tdn.value = diet.total_digestible_nutrient_percentage
253
+ self.ash_content_of_diet.value = diet.ash_percentage
254
+ self.starch.value = diet.starch_percentage
255
+ self.fat.value = diet.fat_percentage
256
+ self.me.value = diet.metabolizable_energy
257
+ self.ndf.value = diet.neutral_detergent_fiber_percentage
258
+
259
+ self.activity_coefficient_of_feeding_situation.value = get_feeding_activity_coefficient(
260
+ housing_type=housing_type)
261
+
262
+ bedding = Bedding(
263
+ housing_type=housing_type,
264
+ bedding_material_type=bedding_material_type,
265
+ animal_type=animal_type)
266
+
267
+ self.user_defined_bedding_rate.value = bedding.user_defined_bedding_rate.value
268
+ self.total_carbon_kilograms_dry_matter_for_bedding.value = bedding.total_carbon_kilograms_dry_matter_for_bedding.value
269
+ self.total_nitrogen_kilograms_dry_matter_for_bedding.value = bedding.total_nitrogen_kilograms_dry_matter_for_bedding.value
270
+ self.moisture_content_of_bedding_material.value = bedding.moisture_content_of_bedding_material.value
271
+
272
+ self.methane_conversion_factor_of_manure.value = manure_emission_factors.MethaneConversionFactor
273
+ self.n2o_direct_emission_factor.value = manure_emission_factors.N2ODirectEmissionFactor
274
+ self.volatilization_fraction.value = manure_emission_factors.VolatilizationFraction
275
+ self.emission_factor_volatilization.value = manure_emission_factors.EmissionFactorVolatilization
276
+ self.fraction_leaching.value = manure_emission_factors.LeachingFraction
277
+ self.emission_factor_leaching.value = manure_emission_factors.EmissionFactorLeach
278
+
279
+ self.methane_conversion_factor_of_diet.value = diet.calc_methane_conversion_factor(animal_type=animal_type)
280
+ self.methane_producing_capacity_of_manure.value = get_default_methane_producing_capacity_of_manure(
281
+ is_pasture=housing_type.is_pasture(),
282
+ animal_type=animal_type)
283
+
284
+ self.manure_excretion_rate.value = get_manure_excretion_rate(animal_type=animal_type)
285
+ self.fraction_of_carbon_in_manure.value = get_default_manure_composition_data(
286
+ animal_type=animal_type,
287
+ manure_state_type=manure_handling_system).carbon_content
288
+
289
+
290
+ class SheepFeedlot(Sheep):
291
+ animal_type = AnimalType.sheep_feedlot
292
+ def __init__(
293
+ self,
294
+ management_period_name: str,
295
+ group_pairing_number: int,
296
+ management_period_start_date: date,
297
+ management_period_days: int,
298
+ number_of_animals: int,
299
+ production_stage: ProductionStage,
300
+ number_of_young_animals: int,
301
+ diet: Diet,
302
+ housing_type: HousingType,
303
+ manure_emission_factors: LivestockEmissionConversionFactorsData,
304
+ manure_handling_system: ManureStateType,
305
+ start_weight: float = None,
306
+ end_weight: float = None,
307
+ diet_additive_type: DietAdditiveType = DietAdditiveType.NONE,
308
+ bedding_material_type: BeddingMaterialType = BeddingMaterialType.NONE,
309
+ ):
310
+ _group_name = GroupNames.sheep_feedlot.value
311
+ super().__init__(
312
+ name=_group_name,
313
+ animal_type=self.animal_type,
314
+ group_name=_group_name,
315
+ component_type=ComponentType.sheep_feedlot,
316
+
317
+ **utils.get_local_args(locals())
318
+ )
319
+
320
+
321
+ class Rams(Sheep):
322
+ animal_type = AnimalType.ram
323
+ def __init__(
324
+ self,
325
+ management_period_name: str,
326
+ group_pairing_number: int,
327
+ management_period_start_date: date,
328
+ management_period_days: int,
329
+ number_of_animals: int,
330
+ production_stage: ProductionStage,
331
+ number_of_young_animals: int,
332
+ diet: Diet,
333
+ housing_type: HousingType,
334
+ manure_emission_factors: LivestockEmissionConversionFactorsData,
335
+ manure_handling_system: ManureStateType,
336
+ start_weight: float = None,
337
+ end_weight: float = None,
338
+ diet_additive_type: DietAdditiveType = DietAdditiveType.NONE,
339
+ bedding_material_type: BeddingMaterialType = BeddingMaterialType.NONE,
340
+ ):
341
+ _group_name = GroupNames.rams.value
342
+
343
+ super().__init__(
344
+ name=_group_name,
345
+ animal_type=self.animal_type,
346
+ group_name=_group_name,
347
+ component_type=ComponentType.rams,
348
+
349
+ **utils.get_local_args(locals())
350
+ )
351
+
352
+
353
+ class Ewes(Sheep):
354
+ animal_type = AnimalType.ewes
355
+
356
+ def __init__(
357
+ self,
358
+ management_period_name: str,
359
+ group_pairing_number: int,
360
+ management_period_start_date: date,
361
+ management_period_days: int,
362
+ number_of_animals: int,
363
+ production_stage: ProductionStage,
364
+ number_of_young_animals: int,
365
+ diet: Diet,
366
+ housing_type: HousingType,
367
+ manure_emission_factors: LivestockEmissionConversionFactorsData,
368
+ manure_handling_system: ManureStateType,
369
+ start_weight: float = None,
370
+ end_weight: float = None,
371
+ diet_additive_type: DietAdditiveType = DietAdditiveType.NONE,
372
+ bedding_material_type: BeddingMaterialType = BeddingMaterialType.NONE,
373
+ ):
374
+ super().__init__(
375
+ name=GroupNames.lambs_and_ewes.value,
376
+ animal_type=self.animal_type,
377
+ group_name=GroupNames.ewes.value,
378
+ component_type=ComponentType.ewes_and_lambs,
379
+
380
+ **utils.get_local_args(locals())
381
+ )
382
+
383
+
384
+ class Lambs(Sheep):
385
+ animal_type = AnimalType.lambs
386
+
387
+ def __init__(
388
+ self,
389
+ management_period_name: str,
390
+ group_pairing_number: int,
391
+ management_period_start_date: date,
392
+ management_period_days: int,
393
+ number_of_animals: int,
394
+ production_stage: ProductionStage,
395
+ number_of_young_animals: int,
396
+ diet: Diet,
397
+ housing_type: HousingType,
398
+ manure_emission_factors: LivestockEmissionConversionFactorsData,
399
+ manure_handling_system: ManureStateType,
400
+ start_weight: float = None,
401
+ end_weight: float = None,
402
+ diet_additive_type: DietAdditiveType = DietAdditiveType.NONE,
403
+ bedding_material_type: BeddingMaterialType = BeddingMaterialType.NONE,
404
+ ):
405
+ super().__init__(
406
+ name=GroupNames.lambs_and_ewes.value,
407
+ animal_type=self.animal_type,
408
+ group_name=GroupNames.lambs.value,
409
+ component_type=ComponentType.ewes_and_lambs,
410
+
411
+ **utils.get_local_args(locals())
412
+ )
@@ -0,0 +1,170 @@
1
+ from enum import StrEnum, auto, unique
2
+
3
+ from pyholos.common import EnumGeneric
4
+ from pyholos.common2 import CanadianProvince
5
+
6
+
7
+ @unique
8
+ class ComponentCategory(StrEnum):
9
+ LandManagement = auto()
10
+ BeefProduction = auto()
11
+ Dairy = auto()
12
+ Swine = auto()
13
+ Poultry = auto()
14
+ OtherLivestock = auto()
15
+ Sheep = auto()
16
+ Infrastructure = auto()
17
+
18
+
19
+ class ComponentType(EnumGeneric):
20
+ """Holos component types
21
+
22
+ References:
23
+ Source code: https://github.com/holos-aafc/Holos/blob/396f1ab9bc7247e6d78766f9445c14d2eb7c0d9d/H.Core/Models/ComponentType.cs#L5
24
+
25
+ """
26
+ rotation: str = "Rotation"
27
+ pasture: str = "Pasture"
28
+ range: str = "Range"
29
+ shelterbelt: str = "Shelterbelt"
30
+ field: str = "Field"
31
+ cow_calf: str = "CowCalf"
32
+ backgrounding: str = "Backgrounding"
33
+ finishing: str = "Finishing"
34
+ grassland: str = "Grassland"
35
+ dairy: str = "Dairy"
36
+ dairy_lactating: str = "DairyLactating"
37
+ dairy_heifer: str = "DairyHeifer"
38
+ dairy_dry: str = "DairyDry"
39
+ dairy_calf: str = "DairyCalf"
40
+ dairy_bulls: str = "DairyBulls"
41
+ swine: str = "Swine"
42
+ boar: str = "Boar"
43
+ swine_finishers: str = "SwineFinishers"
44
+ swine_starters: str = "SwineStarters"
45
+ swine_lactating_sows: str = "SwineLactatingSows"
46
+ swine_dry_sows: str = "SwineDrySows"
47
+ swine_growers: str = "SwineGrowers"
48
+ poultry: str = "Poultry"
49
+ poultry_layers_wet: str = "PoultryLayersWet"
50
+ poultry_turkeys: str = "PoultryTurkeys"
51
+ poultry_geese: str = "PoultryGeese"
52
+ poultry_broilers: str = "PoultryBroilers"
53
+ poultry_ducks: str = "PoultryDucks"
54
+ poultry_layers_dry: str = "PoultryLayersDry"
55
+ sheep: str = "Sheep"
56
+ sheep_feedlot: str = "SheepFeedlot"
57
+ rams: str = "Rams"
58
+ lambs_and_ewes: str = "LambsAndEwes"
59
+ ewes_and_lambs: str = "EwesAndLambs" # added to the original code for convenience
60
+ other_livestock: str = "OtherLivestock"
61
+ alpaca: str = "Alpaca"
62
+ elk: str = "Elk"
63
+ goats: str = "Goats"
64
+ deer: str = "Deer"
65
+ horses: str = "Horses"
66
+ mules: str = "Mules"
67
+ bison: str = "Bison"
68
+ llamas: str = "Llamas"
69
+ farrow_to_wean: str = "FarrowToWean"
70
+ iso_wean: str = "IsoWean"
71
+ farrow_to_finish: str = "FarrowToFinish"
72
+ chicken_pullet_farm: str = "ChickenPulletFarm"
73
+ chicken_multiplier_breeder: str = "ChickenMultiplierBreeder"
74
+ chicken_meat_production: str = "ChickenMeatProduction"
75
+ turkey_multiplier_breeder: str = "TurkeyMultiplierBreeder"
76
+ turkey_meat_production: str = "TurkeyMeatProduction"
77
+ chicken_egg_production: str = "ChickenEggProduction"
78
+ chicken_multiplier_hatchery: str = "ChickenMultiplierHatchery"
79
+ anaerobic_digestion: str = "AnaerobicDigestion"
80
+
81
+ def to_str(self):
82
+ return f'{self.value}Component'
83
+
84
+
85
+ def calculate_fraction_of_nitrogen_lost_by_leaching_and_runoff(
86
+ growing_season_precipitation: float,
87
+ growing_season_evapotranspiration: float
88
+ ) -> float:
89
+ """Calculates the nitrogen loss due to leaching and runoff
90
+
91
+ Args:
92
+ growing_season_precipitation: Growing season precipitation, by ecodistrict (May – October)</param>
93
+ growing_season_evapotranspiration: Growing season potential evapotranspiration, by ecodistrict (May – October)
94
+
95
+ Returns:
96
+ (kg N (kg N)^-1) fraction of N lost by leaching and runoff
97
+
98
+ Holos Source Code:
99
+ https://github.com/RamiALBASHA/Holos/blob/71638efd97c84c6ded45e342ce664477df6f803f/H.Core/Calculators/Nitrogen/NitrogenInputCalculatorBase.cs#L15
100
+
101
+ """
102
+ fraction_of_nitrogen_lost_by_leaching_and_runoff = 0.3247 * (
103
+ growing_season_precipitation / growing_season_evapotranspiration) - 0.0247
104
+ return min(0.3, max(0.05, fraction_of_nitrogen_lost_by_leaching_and_runoff))
105
+
106
+
107
+ def convert_province_name(name: str) -> CanadianProvince:
108
+ """Returns a CanadianProvince instance based on the given name or abbreviation.
109
+
110
+ Args:
111
+ name: name of abbreviation of the canadian province
112
+
113
+ Returns:
114
+ CanadianProvince member
115
+
116
+ Holos source code:
117
+ https://github.com/holos-aafc/Holos/blob/b183dab99d211158d1fed9da5370ce599ac7c914/H.Core/Converters/ProvinceStringConverter.cs#L9
118
+
119
+ Notes:
120
+ The province name "Newfoundland" in the original holos source code was changed to
121
+ "NewfoundlandAndLabrador" to that to agree with the official name of the Province
122
+
123
+ """
124
+ match name.lower():
125
+ case "alberta" | "ab" | "alta" | "alb":
126
+ return CanadianProvince.Alberta
127
+ case "britishcolumbia" | "colombiebritannique" | "bc" | "cb":
128
+ return CanadianProvince.BritishColumbia
129
+ case "saskatchewan" | "sk" | "sask":
130
+ return CanadianProvince.Saskatchewan
131
+ case "manitoba" | "mb" | "man":
132
+ return CanadianProvince.Manitoba
133
+ case "ontario" | "on" | "ont":
134
+ return CanadianProvince.Ontario
135
+ case "quebec" | "québec" | "qc" | "que":
136
+ return CanadianProvince.Quebec
137
+ case "newbrunswick" | "nouveaubrunswick" | "nb":
138
+ return CanadianProvince.NewBrunswick
139
+ case "novascotia" | "nouvelleécosse" | "nouvelleecosse" | "ns" | "né" | "ne":
140
+ return CanadianProvince.NovaScotia
141
+ case "princeedwardisland" | "îleduprinceédouard" | "îleduprinceedouard" | "ileduprinceédouard" | "ileduprinceedouard" | "pe" | "pei" | "ipe" | "ipé" | "îpe" | "îpé":
142
+ return CanadianProvince.PrinceEdwardIsland
143
+ case "newfoundlandandlabrador" | "terreneuveetlabrador" | "nl" | "nf" | "tnl" | "nfld" | "newfoundland":
144
+ return CanadianProvince.NewfoundlandAndLabrador
145
+ case "yukon" | "yt" | "yk" | "yuk" | "yn":
146
+ return CanadianProvince.Yukon
147
+ case "northwestterritories" | "territoiresdunordouest" | "nt" | "tno":
148
+ return CanadianProvince.NorthwestTerritories
149
+ case "nunavut" | "nu" | "nvt":
150
+ return CanadianProvince.Nunavut
151
+ case _:
152
+ # Trace.TraceError($"{nameof(ProvinceStringConverter)}.{nameof(ProvinceStringConverter.Convert)}: unknown input '{input}'. Returning default value of {Province.Alberta.GetDescription()}");
153
+ return CanadianProvince.Alberta
154
+
155
+
156
+ def calc_default_irrigation_amount(
157
+ precipitation: float,
158
+ evapotranspiration: float
159
+ ) -> float:
160
+ """Calculates the default irrigation amount as the gap between water offer and demand.
161
+
162
+ Args:
163
+ precipitation: (mm) precipitation amount
164
+ evapotranspiration: (mm) evapotranspiration amount
165
+
166
+ Returns:
167
+ (mm) default irrigation amount
168
+
169
+ """
170
+ return max(0., evapotranspiration - precipitation)
File without changes
File without changes