{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example usage\n", "\n", "To use `optigob` in a project:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "OptiGob Budget Model Input Combinations\n", "\n", "Input type: forest\n", "{'affor_rate_kha-yr': 2, 'broadleaf_frac': 0.5, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'high'}\n", "{'affor_rate_kha-yr': 8, 'broadleaf_frac': 0.5, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'high'}\n", "{'affor_rate_kha-yr': 8, 'broadleaf_frac': 0.5, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'low'}\n", "{'affor_rate_kha-yr': 8, 'broadleaf_frac': 0.3, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'high'}\n", "{'affor_rate_kha-yr': 8, 'broadleaf_frac': 0.3, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'low'}\n", "{'affor_rate_kha-yr': 16, 'broadleaf_frac': 0.5, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'low'}\n", "{'affor_rate_kha-yr': 16, 'broadleaf_frac': 0.3, 'organic_soil_frac': 0.0, 'forest_harvest_intensity': 'high'}\n", "{'affor_rate_kha-yr': 16, 'broadleaf_frac': 0.3, 'organic_soil_frac': 0.0, 'forest_harvest_intensity': 'low'}\n", "{'affor_rate_kha-yr': 25, 'broadleaf_frac': 0.5, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'high'}\n", "{'affor_rate_kha-yr': 25, 'broadleaf_frac': 0.5, 'organic_soil_frac': 0.15, 'forest_harvest_intensity': 'low'}\n", "{'affor_rate_kha-yr': 25, 'broadleaf_frac': 0.3, 'organic_soil_frac': 0.0, 'forest_harvest_intensity': 'high'}\n", "{'affor_rate_kha-yr': 25, 'broadleaf_frac': 0.3, 'organic_soil_frac': 0.0, 'forest_harvest_intensity': 'low'}\n", "\n", "Input type: organic_soil\n", "{'wetland_restored_frac': 0.5, 'organic_soil_under_grass_frac': 0.0}\n", "{'wetland_restored_frac': 0.9, 'organic_soil_under_grass_frac': 0.5}\n", "{'wetland_restored_frac': 0.9, 'organic_soil_under_grass_frac': 0.9}\n", "\n", "Input type: abatement_and_productivity\n", "{'abatement': 'baseline', 'scenario': 1}\n", "{'abatement': 'baseline', 'scenario': 2}\n", "{'abatement': 'baseline', 'scenario': 3}\n", "{'abatement': 'macc', 'scenario': 4}\n", "{'abatement': 'macc', 'scenario': 5}\n", "{'abatement': 'macc', 'scenario': 6}\n", "{'abatement': 'frontier', 'scenario': 7}\n", "{'abatement': 'frontier', 'scenario': 8}\n", "{'abatement': 'frontier', 'scenario': 9}\n" ] } ], "source": [ "from optigob import Optigob\n", "from optigob import OptiGobDataManager\n", "from optigob import InputHelper\n", "\n", "print(\"OptiGob Budget Model Input Combinations\")\n", "\n", "# Initialize the input helper\n", "helper = InputHelper()\n", "helper.print_all_combos()" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "data = './data/sip.yaml'\n", "# Initialize the data manager\n", "data_manager = OptiGobDataManager(data)\n", "\n", "# Create an instance of Optigob\n", "optigob = Optigob(data_manager)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GHG Emissions by Sector\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'baseline': {'agriculture': 21147.772800304, 'existing_forest': -2082.0, 'afforestation': 0, 'hwp': 0, 'other_land_use': 5947, 'ad': 0, 'beccs': 0}, 'scenario': {'agriculture': 12273.079795069938, 'existing_forest': 2057.0, 'afforestation': -4757.436304, 'hwp': -1198, 'other_land_use': 6546, 'ad': 141.1, 'beccs': -2315.2028127000003}}\n", " baseline scenario\n", "agriculture 21147.7728 12273.079795\n", "existing_forest -2082.0000 2057.000000\n", "afforestation 0.0000 -4757.436304\n", "hwp 0.0000 -1198.000000\n", "other_land_use 5947.0000 6546.000000\n", "ad 0.0000 141.100000\n", "beccs 0.0000 -2315.202813\n" ] } ], "source": [ "print(\"GHG Emissions by Sector\")\n", "print(optigob.get_total_emissions_co2e_by_sector())\n", "print(optigob.get_total_emissions_co2e_by_sector_df())" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Aggregated Total Land Area by Sector\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'baseline': {'agriculture': 4225153.146096, 'afforested': 0, 'existing_forest': 773254, 'other_land_use': 1433000, 'ad': 0, 'protein_crops': 0, 'beccs_willow': 0}, 'scenario': {'agriculture': 2794622.2815562123, 'afforested': 368640, 'existing_forest': 781254, 'other_land_use': 1433000, 'ad': 130000.0, 'protein_crops': 0, 'beccs_willow': 150000.0}}\n", " baseline scenario\n", "agriculture 4.225153e+06 2.794622e+06\n", "afforested 0.000000e+00 3.686400e+05\n", "existing_forest 7.732540e+05 7.812540e+05\n", "other_land_use 1.433000e+06 1.433000e+06\n", "ad 0.000000e+00 1.300000e+05\n", "protein_crops 0.000000e+00 0.000000e+00\n", "beccs_willow 0.000000e+00 1.500000e+05\n" ] } ], "source": [ "print(\"Aggregated Total Land Area by Sector\")\n", "print(optigob.get_aggregated_total_land_area_by_sector())\n", "print(optigob.get_aggregated_total_land_area_by_sector_df())" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Protein by Sector\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'baseline': {'pig_and_poultry': 132000000.0, 'sheep': 14332176.614848224, 'beef': 155417070.62386402, 'milk': 297463320.00000006, 'protein_crops': 0}, 'scenario': {'pig_and_poultry': 158400000.0, 'sheep': 14332176.614848224, 'beef': 114726990.82573089, 'milk': 450223532.97514117, 'protein_crops': 0}}\n", " baseline scenario\n", "pig_and_poultry 1.320000e+08 1.584000e+08\n", "sheep 1.433218e+07 1.433218e+07\n", "beef 1.554171e+08 1.147270e+08\n", "milk 2.974633e+08 4.502235e+08\n", "protein_crops 0.000000e+00 0.000000e+00\n" ] } ], "source": [ "print(\"Protein by Sector\")\n", "print(optigob.get_total_protein_by_sector())\n", "print(optigob.get_total_protein_by_sector_df())" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Area by Sector\n", "{'baseline': {'dairy': 980841.4292544001, 'beef': 2066291.4368416, 'sheep': 828020.28, 'pig_and_poultry': 0.0, 'static_crops': 350000, 'protein_crops': 0, 'beccs_willow': 0, 'anaerobic_digestion': 0, 'managed forest': 773254, 'afforestation': 0, 'other_land_use': 1433000, 'available_area': 0}, 'scenario': {'dairy': 1082977.7200910388, 'beef': 765997.4414651733, 'sheep': 595647.12, 'pig_and_poultry': 0.0, 'static_crops': 350000.0, 'protein_crops': 0, 'beccs_willow': 150000.0, 'anaerobic_digestion': 130000.0, 'managed forest': 781254, 'afforestation': 368640, 'other_land_use': 1433000, 'available_area': 773890.8645397881}}\n", " baseline scenario\n", "dairy 9.808414e+05 1.082978e+06\n", "beef 2.066291e+06 7.659974e+05\n", "sheep 8.280203e+05 5.956471e+05\n", "pig_and_poultry 0.000000e+00 0.000000e+00\n", "static_crops 3.500000e+05 3.500000e+05\n", "protein_crops 0.000000e+00 0.000000e+00\n", "beccs_willow 0.000000e+00 1.500000e+05\n", "anaerobic_digestion 0.000000e+00 1.300000e+05\n", "managed forest 7.732540e+05 7.812540e+05\n", "afforestation 0.000000e+00 3.686400e+05\n", "other_land_use 1.433000e+06 1.433000e+06\n", "available_area 0.000000e+00 7.738909e+05\n" ] } ], "source": [ "print(\"Area by Sector\")\n", "print(optigob.get_disaggregated_total_land_area_by_sector())\n", "print(optigob.get_disaggregated_total_land_area_by_sector_df())" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "High Nature Value (HNV) Land Area by Sector\n", "{'baseline': {'agriculture': 681876.1741560001, 'afforested': 0, 'existing_forest': 255174, 'wetland': 884000, 'rewetted_wetland': 85000, 'organic_soil': 85000, 'beccs': 0}, 'scenario': {'agriculture': 252779.15563495315, 'afforested': 110592.0, 'existing_forest': 257814, 'wetland': 884000, 'rewetted_wetland': 198000, 'organic_soil': 198000, 'beccs': 150000.0}}\n", " baseline scenario\n", "agriculture 681876.174156 252779.155635\n", "afforested 0.000000 110592.000000\n", "existing_forest 255174.000000 257814.000000\n", "wetland 884000.000000 884000.000000\n", "rewetted_wetland 85000.000000 198000.000000\n", "organic_soil 85000.000000 198000.000000\n", "beccs 0.000000 150000.000000\n" ] } ], "source": [ "print(\"High Nature Value (HNV) Land Area by Sector\")\n", "print(optigob.get_total_hnv_land_area_by_sector())\n", "print(optigob.get_total_hnv_land_area_by_sector_df())" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Bioenergy by Sector\n", "{'baseline': {'ad': 0, 'willow_biomass': 0, 'forest_biomass': 0}, 'scenario': {'ad': 5700000, 'willow_biomass': 6605280.0, 'forest_biomass': 9144547.727}}\n", " baseline scenario\n", "ad 0 5700000.000\n", "willow_biomass 0 6605280.000\n", "forest_biomass 0 9144547.727\n" ] } ], "source": [ "print(\"Bioenergy by Sector\")\n", "print(optigob.get_bioenergy_by_sector())\n", "print(optigob.get_bioenergy_by_sector_df())" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "HWP\n", "{'baseline': {'hwp': 0}, 'scenario': {'hwp': 6407181}}\n", " baseline scenario\n", "hwp 0 6407181\n" ] } ], "source": [ "print(\"HWP\")\n", "print(optigob.get_hwp_volume())\n", "print(optigob.get_hwp_volume_df())" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Substitution\n", "{'ad_substitution': -417.1257789, 'forest_substitution': -3034, 'willow_substitution': -496.3207392}\n", " scenario\n", "ad_substitution -417.125779\n", "forest_substitution -3034.000000\n", "willow_substitution -496.320739\n" ] } ], "source": [ "print(\"Substitution\")\n", "print(optigob.get_substitution_emission_by_sector_co2e())\n", "print(optigob.get_substitution_emission_by_sector_co2e_df())" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NZ Status\n", "True\n", "total emissions co2e: 12746.540678369938 kt\n" ] } ], "source": [ "print(\"NZ Status\")\n", "print(optigob.check_net_zero_status())\n", "print(f\"total emissions co2e: {optigob.total_emission_co2e()} kt\")" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Livestock Population\n", "{'baseline': {'dairy': 1568000.0, 'beef': 984000.0}, 'scenario': {'dairy': 1832228.3887815578, 'beef': 183222.8388781558}}\n", " baseline scenario\n", "dairy 1568000.0 1.832228e+06\n", "beef 984000.0 1.832228e+05\n" ] } ], "source": [ "print(\"Livestock Population\")\n", "print(optigob.get_livestock_population())\n", "print(optigob.get_livestock_population_df())" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Livestock CH4 Emissions budget\n", "293.11946640400004\n" ] } ], "source": [ "print(\"Livestock CH4 Emissions budget\")\n", "print(optigob.get_livestock_split_gas_ch4_emission_budget())" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Livestock CO2e Emissions budget\n", "-3259.6335684200003\n" ] } ], "source": [ "print(\"Livestock CO2e Emissions budget\")\n", "print(optigob.get_livestock_co2e_emission_budget())" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AREA comparison\n", " baseline scenario\n", "dairy 9.808414e+05 1.082978e+06\n", "beef 2.066291e+06 7.659974e+05\n", "sheep 8.280203e+05 5.956471e+05\n", "pig_and_poultry 0.000000e+00 0.000000e+00\n", "static_crops 3.500000e+05 3.500000e+05\n", "protein_crops 0.000000e+00 0.000000e+00\n", "beccs_willow 0.000000e+00 1.500000e+05\n", "anaerobic_digestion 0.000000e+00 1.300000e+05\n", "managed forest 7.732540e+05 7.812540e+05\n", "afforestation 0.000000e+00 3.686400e+05\n", "other_land_use 1.433000e+06 1.433000e+06\n", "available_area 0.000000e+00 7.738909e+05\n", "\n", "Sum of each column:\n", "baseline 6.431407e+06\n", "scenario 6.431407e+06\n", "dtype: float64\n" ] } ], "source": [ "print(\"AREA comparison\")\n", "df = optigob.get_disaggregated_total_land_area_by_sector_df()\n", "print(df)\n", "print(\"\\nSum of each column:\")\n", "print(df.sum())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.9" } }, "nbformat": 4, "nbformat_minor": 4 }