Issue with Implementing Carbon Emission Constraints in PyPSA

168 views
Skip to first unread message

Tuo ZHANG

unread,
Nov 8, 2023, 9:18:48 PM11/8/23
to pypsa

---



Hello PyPSA Community,

I am experiencing an issue with adding carbon emission constraints for each investment period in my PyPSA model. My code looks as follows:

```python
base_emission_limit = 2e+9  # The emission limit in the base year, in tons of CO2
end_emission_limit = 1e+9  # The emission limit in the end year, in tons of CO2

# Calculate the annual decrease in emission limit
annual_decrease = (base_emission_limit - end_emission_limit) / (end_year - base_year)

for year in range(base_year, end_year + 1):
    # Calculate the emission limit for this year
    emission_limit = base_emission_limit - annual_decrease * (year - base_year)
    print(f"CO2-Emission-limit-{year}                  {emission_limit} ton")
   
    # Add the global constraint
    network_temp.add("GlobalConstraint", f"CO2-Emission-limit-{year}",
                     investment_period=year,
                     carrier_attribute="co2_emissions",
                     sense="<=",
                     constant=emission_limit)
```

After adding these constraints, I made sure that they were successfully implemented. For instance:
I could find the constraints in the exported csv files as follows:
name 
investment_period sense constant

CO2-Emission-limit-2023 
2023 <= 2000000000

CO2-Emission-limit-2024 
2024 <= 1666666667

CO2-Emission-limit-2025 
2025 <= 1333333333

CO2-Emission-limit-2026 
2026 <= 1000000000


To solve for optimization, I use the following command:

```python
network_temp  .lopf(solver_name="gurobi", solver_options=solver_options)
```

However, after adding the constraints, there seems to be no change in the optimization results, and the annual carbon emissions are still exceeding the limits I have set. Moreover, if I set the emission limits to a very low number, Gurobi reports that there is no feasible solution.

Could anyone suggest how to address this issue?

Thank you in advance for your assistance!

---

Johannes Hampp

unread,
Nov 9, 2023, 1:59:19 AM11/9/23
to Tuo ZHANG, pypsa
Hi there,

Have you checked whether the co2_emissions attribute for the carriers
you are using are set?

(Carrier has co2_emissions, carrier is assigned to generators, through
the co2_emissions attribute the constraint is realised)

Best,
Johannes
> --
> You received this message because you are subscribed to the Google
> Groups "pypsa" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pypsa+un...@googlegroups.com
> <mailto:pypsa+un...@googlegroups.com>.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/pypsa/41e9a57b-db4e-42c8-8519-15bf4d8e1de9n%40googlegroups.com <https://groups.google.com/d/msgid/pypsa/41e9a57b-db4e-42c8-8519-15bf4d8e1de9n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages