Livestock Module Example
Imports
We will start by importing AnimalData
and the Exports
classes, along with a few others.
from livestock_generation.livestock import AnimalData
from livestock_generation.livestock_exports import Exports
import pandas as pd
import os
Now, we set the path to our data and we will import our scenario dataframe
path = "../tests/data/"
scenario_dataframe = pd.read_csv(os.path.join(path, "scenario_input_dataframe.csv"))
Our Scenario Data frame looks like this …
print(scenario_dataframe)
index Scenarios Dairy pop Beef pop Upland sheep pop Lowland sheep pop \
0 0 0 1060000 0 0 0
1 1 0 0 1000 0 0
2 2 0 0 0 3000 0
3 3 0 0 0 0 50000
4 4 1 1060000 0 0 0
5 5 1 0 1000 0 0
6 6 1 0 0 0 0
7 7 1 0 0 0 0
Dairy prod Beef prod Upland sheep prod Lowland sheep prod ... \
0 0 0 0 0 ...
1 0 0 0 0 ...
2 0 0 0 0 ...
3 0 0 0 0 ...
4 0 0 0 0 ...
5 0 0 0 0 ...
6 0 0 0 0 ...
7 0 0 0 0 ...
Crop area Wetland area Forest area Conifer proportion \
0 0 0 1 0.7
1 0 0 1 0.7
2 0 0 1 0.7
3 0 0 1 0.7
4 0 0 1 0.7
5 0 0 1 0.7
6 0 0 1 0.7
7 0 0 1 0.7
Broadleaf proportion Conifer harvest Broadleaf harvest Conifer thinned \
0 0.3 0.05 0 0.1
1 0.3 0.05 0 0.1
2 0.3 0.05 0 0.1
3 0.3 0.05 0 0.1
4 0.3 0.05 0 0.8
5 0.3 0.05 0 0.8
6 0.3 0.05 0 0.8
7 0.3 0.05 0 0.8
Afforest year Cattle systems
0 2080 Dairy
1 2080 Beef
2 2080 Upland sheep
3 2080 Lowland sheep
4 2080 Dairy
5 2080 Beef
6 2080 Upland sheep
7 2080 Lowland sheep
[8 rows x 29 columns]
Define additional variables
We also need to define the calibration_year
, which is the year reference year, the target_year
, which is the year the scenarios run to, and the ef_country
, which is the emissions factor country.
baseline_year = 2020
target_year = 2050
ef_country = "ireland"
Class instances
Now we set our classes, and use the methods to generate our data.
animal_class = AnimalData(ef_country, baseline_year, target_year, scenario_dataframe)
export_class = Exports(ef_country, baseline_year, target_year, scenario_dataframe)
# create dataframe for baseline year animals
baseline_data = animal_class.create_baseline_animal_dataframe()
baseline_data
ef_country | farm_id | Scenarios | year | cohort | pop | daily_milk | weight | forage | grazing | con_type | con_amount | wool | t_outdoors | t_indoors | t_stabled | mm_storage | daily_spreading | n_sold | n_bought | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ireland | 2020.0 | -1.0 | 2020.0 | dairy_cows | 1.511850e+06 | 14.953000 | 538.000 | irish_grass | pasture | concentrate | 2.992828 | 0.0 | 13.589041 | 10.410959 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
1 | ireland | 2020.0 | -1.0 | 2020.0 | suckler_cows | 9.530000e+05 | 1.410959 | 600.000 | irish_grass | pasture | concentrate | 0.842752 | 0.0 | 12.219178 | 11.780822 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
2 | ireland | 2020.0 | -1.0 | 2020.0 | bulls | 5.095000e+04 | 0.000000 | 773.000 | irish_grass | pasture | concentrate | 0.654141 | 0.0 | 11.506849 | 12.493151 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
3 | ireland | 2020.0 | -1.0 | 2020.0 | DxD_calves_m | 2.486034e+05 | 0.000000 | 171.400 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
4 | ireland | 2020.0 | -1.0 | 2020.0 | DxD_calves_f | 3.537366e+05 | 0.000000 | 138.550 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
5 | ireland | 2020.0 | -1.0 | 2020.0 | DxB_calves_m | 3.201623e+05 | 0.000000 | 176.875 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
6 | ireland | 2020.0 | -1.0 | 2020.0 | DxB_calves_f | 3.189379e+05 | 0.000000 | 158.625 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
7 | ireland | 2020.0 | -1.0 | 2020.0 | BxB_calves_m | 4.059952e+05 | 0.000000 | 211.550 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
8 | ireland | 2020.0 | -1.0 | 2020.0 | BxB_calves_f | 4.041513e+05 | 0.000000 | 175.050 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
9 | ireland | 2020.0 | -1.0 | 2020.0 | DxD_heifers_less_2_yr | 3.465882e+05 | 0.000000 | 335.650 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 11.506849 | 12.493151 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
10 | ireland | 2020.0 | -1.0 | 2020.0 | DxD_steers_less_2_yr | 2.394694e+05 | 0.000000 | 434.200 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 18.465753 | 5.534247 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
11 | ireland | 2020.0 | -1.0 | 2020.0 | DxB_heifers_less_2_yr | 3.083219e+05 | 0.000000 | 395.875 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 11.506849 | 12.493151 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
12 | ireland | 2020.0 | -1.0 | 2020.0 | DxB_steers_less_2_yr | 3.092563e+05 | 0.000000 | 450.625 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 18.465753 | 5.534247 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
13 | ireland | 2020.0 | -1.0 | 2020.0 | BxB_heifers_less_2_yr | 3.908495e+05 | 0.000000 | 445.150 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 11.506849 | 12.493151 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
14 | ireland | 2020.0 | -1.0 | 2020.0 | BxB_steers_less_2_yr | 3.923286e+05 | 0.000000 | 554.650 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 18.465753 | 5.534247 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
15 | ireland | 2020.0 | -1.0 | 2020.0 | DxD_heifers_more_2_yr | 1.046702e+04 | 0.000000 | 481.650 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 12.765090 | 11.234910 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
16 | ireland | 2020.0 | -1.0 | 2020.0 | DxD_steers_more_2_yr | 5.823657e+04 | 0.000000 | 592.975 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 18.465753 | 5.534247 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
17 | ireland | 2020.0 | -1.0 | 2020.0 | DxB_heifers_more_2_yr | 2.021479e+04 | 0.000000 | 527.275 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 12.765090 | 11.234910 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
18 | ireland | 2020.0 | -1.0 | 2020.0 | DxB_steers_more_2_yr | 7.121757e+04 | 0.000000 | 624.000 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 18.465753 | 5.534247 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
19 | ireland | 2020.0 | -1.0 | 2020.0 | BxB_heifers_more_2_yr | 5.656799e+04 | 0.000000 | 603.925 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 12.765090 | 11.234910 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
20 | ireland | 2020.0 | -1.0 | 2020.0 | BxB_steers_more_2_yr | 6.266367e+04 | 0.000000 | 751.750 | irish_grass | pasture | concentrate | 0.000000 | 0.0 | 18.465753 | 5.534247 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
21 | ireland | 2020.0 | -1.0 | 2020.0 | ewes | 2.137040e+06 | 0.000000 | 68.000 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
22 | ireland | 2020.0 | -1.0 | 2020.0 | ewes | 5.342600e+05 | 0.000000 | 68.000 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
23 | ireland | 2020.0 | -1.0 | 2020.0 | lamb_less_1_yr | 9.603852e+05 | 0.000000 | 37.000 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
24 | ireland | 2020.0 | -1.0 | 2020.0 | lamb_less_1_yr | 2.400963e+05 | 0.000000 | 37.000 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
25 | ireland | 2020.0 | -1.0 | 2020.0 | lamb_more_1_yr | 1.027081e+05 | 0.000000 | 68.000 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
26 | ireland | 2020.0 | -1.0 | 2020.0 | lamb_more_1_yr | 2.567702e+04 | 0.000000 | 68.000 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
27 | ireland | 2020.0 | -1.0 | 2020.0 | male_less_1_yr | 2.400963e+05 | 0.000000 | 37.000 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
28 | ireland | 2020.0 | -1.0 | 2020.0 | male_less_1_yr | 9.603852e+05 | 0.000000 | 37.000 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
29 | ireland | 2020.0 | -1.0 | 2020.0 | ram | 6.876000e+04 | 0.000000 | 86.000 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
30 | ireland | 2020.0 | -1.0 | 2020.0 | ram | 1.719000e+04 | 0.000000 | 86.000 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
# create dataframe for scenarios animals
scenario_data = animal_class.create_animal_dataframe()
scenario_data
ef_country | farm_id | Scenarios | year | cohort | pop | daily_milk | weight | forage | grazing | con_type | con_amount | wool | t_outdoors | t_indoors | t_stabled | mm_storage | daily_spreading | n_sold | n_bought | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | ireland | 0.0 | 0.0 | 2050.0 | dairy_cows | 1.060000e+06 | 13.800000 | 538.00 | irish_grass | pasture | concentrate | 2.762056 | 0.0 | 13.589041 | 10.410959 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
1 | ireland | 0.0 | 0.0 | 2050.0 | suckler_cows | 0.000000e+00 | 1.410959 | 600.00 | irish_grass | pasture | concentrate | 0.842752 | 0.0 | 12.219178 | 11.780822 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
2 | ireland | 0.0 | 0.0 | 2050.0 | bulls | 2.191087e+04 | 0.000000 | 773.00 | irish_grass | pasture | concentrate | 0.654141 | 0.0 | 11.506849 | 12.493151 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
3 | ireland | 0.0 | 0.0 | 2050.0 | DxD_calves_m | 1.743027e+05 | 0.000000 | 171.40 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
4 | ireland | 0.0 | 0.0 | 2050.0 | DxD_calves_f | 2.480145e+05 | 0.000000 | 138.55 | irish_grass | pasture | concentrate | 1.000000 | 0.0 | 7.890411 | 16.109589 | 0.0 | tank liquid | broadcast | 0.0 | 0.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
119 | ireland | 7.0 | 1.0 | 2050.0 | lamb_more_1_yr | 0.000000e+00 | 0.000000 | 68.00 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
120 | ireland | 7.0 | 1.0 | 2050.0 | male_less_1_yr | 0.000000e+00 | 0.000000 | 37.00 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
121 | ireland | 7.0 | 1.0 | 2050.0 | male_less_1_yr | 0.000000e+00 | 0.000000 | 37.00 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
122 | ireland | 7.0 | 1.0 | 2050.0 | ram | 0.000000e+00 | 0.000000 | 86.00 | average | flat_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
123 | ireland | 7.0 | 1.0 | 2050.0 | ram | 0.000000e+00 | 0.000000 | 86.00 | average | hilly_pasture | concentrate | 0.000000 | 4.5 | 21.360000 | 2.640000 | 0.0 | solid | broadcast | 0.0 | 0.0 |
124 rows × 20 columns
# Create dataframes for beef and milk output
beef_outputs = export_class.compute_system_protien_exports(scenario_data, baseline_data)
dairy_outputs = export_class.compute_system_milk_exports(scenario_data, baseline_data)
protein_outputs = export_class.compute_system_total_protein_exports(scenario_data, baseline_data)
/home/colmduff/Dropbox/projects/FORESIGHT/packages/livestock_generation/src/livestock_generation/livestock_exports.py:77: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '8251442963.25' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
milk_system_export.loc[sc, "total_milk_kg"] = daily_milk * pop * 365
/home/colmduff/Dropbox/projects/FORESIGHT/packages/livestock_generation/src/livestock_generation/livestock_exports.py:77: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '8251442963.25' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
milk_system_export.loc[sc, "total_milk_kg"] = daily_milk * pop * 365
/home/colmduff/Dropbox/projects/FORESIGHT/packages/livestock_generation/src/livestock_generation/livestock_exports.py:77: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '8251442963.25' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
milk_system_export.loc[sc, "total_milk_kg"] = daily_milk * pop * 365
/home/colmduff/Dropbox/projects/FORESIGHT/packages/livestock_generation/src/livestock_generation/livestock_exports.py:77: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise in a future error of pandas. Value '8251442963.25' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.
milk_system_export.loc[sc, "total_milk_kg"] = daily_milk * pop * 365
print(beef_outputs)
Scenarios carcass_weight_kg DxD_m DxD_f \
-1.0 -1.0 652803287.105261 77397063.2663 95540884.900078
0.0 0.0 256991209.428068 54265229.395958 66986366.368411
1.0 1.0 256991209.428068 54265229.395958 66986366.368411
DxB_m DxB_f BxB_m BxB_f
-1.0 106421442.081876 86751315.047085 158882596.689614 127809985.120308
0.0 74615027.024366 60823754.969018 166718.35959 134113.310724
1.0 74615027.024366 60823754.969018 166718.35959 134113.310724
print(dairy_outputs)
Scenarios total_milk_kg
-1.0 -1 8.251443e+09
0.0 0 5.339220e+09
1.0 1 5.339220e+09
print(protein_outputs)
total_protein milk_protein beef_protein
-1.0 438945259.74796 288800503.71375 150144756.03421
0.0 245980678.168456 186872700.0 59107978.168456
1.0 245980678.168456 186872700.0 59107978.168456