mlco2 / codecarbon

Track emissions from Compute and recommend ways to reduce their impact on the environment.
https://mlco2.github.io/codecarbon
MIT License
1.18k stars 178 forks source link

Dynamic Energy mix per country #513

Open bourdeet opened 8 months ago

bourdeet commented 8 months ago

Hello!

I have noticed in Denmark that the national electricity grid manager provides an API to track, among other things, the evolution of the energy mix in realtime: https://www.energidataservice.dk/tso-electricity/DeclarationGridmix

I was thinking of using this data source as a replacement for global_energy_mix.json, when computing CO2 emissions.

Have you already considered a method for people to include different APIs of this kind as plugins? I noticed another related question regarding using ElectricityMap, but it would be interesting to incorporate data from freely accessible API than rely on commercial ones.

cheers,

Étienne

LuisBlanche commented 8 months ago

Hi Etienne, thanks for using CodeCarbon. It would mean a lot of maintenance to handle a different API for each country unless they all have the same standardized way of querying. On improvement I could imagine though would be to use this API to enrich a more detailed static file with evolution of mix across seasons or lets be crazy the hours of the day. Another option would be to allow any API to provide electricity data but you would need to implement a "middle man" API to ensure standardisation so that code carbon could call it the same way it does the electricitymaps API

There is a free tier access to ElectricityMaps that can acomodate small use cases.

bourdeet commented 8 months ago

Hi Luis,

Thanks for the reply. I was indeed thinking of a middle man structure, where one could wrap different APIs into a unified call to code carbon. So I think I'll fork and explore a bit :)

have a great weekend,

Étienne

benoit-cty commented 8 months ago

Hello, CodeCarbon already support this with co2_signal_api_token , see https://github.com/mlco2/codecarbon/blob/fad87d7acb11d54fa67e9af17c899d0752e3163a/codecarbon/core/co2_signal.py#L12C53-L12C73 for the code.

Indeed, like Luis said, https://www.co2signal.com/ has now moved to a free ElectricityMaps API so it will be nice to switch to it.