electricitymaps / electricitymaps-contrib

A real-time visualisation of the CO2 emissions of electricity consumption
https://app.electricitymaps.com
GNU Affero General Public License v3.0
3.48k stars 925 forks source link

The apps is potentially showing the wrong co2intentity for aggregated zones #5156

Open VIKTORVAV99 opened 1 year ago

VIKTORVAV99 commented 1 year ago

Description

The co2intensity value that is shown to users in the app when looking at aggregated zones does not always represent the value used internally.

I'll try and describe what is going on in a simplified view of what is going on across the app, app-backend and API but some steps will be deliberately simplified or omitted.

So in order to do this I'm going to use the solar production values and co2 factors for Sweden as they are different for the subzones and are easy to replicate but this applies for all aggregated zones where the subzones have individual regional co2 emission factors.

Stand alone flow for SE-SE4 (Correct)

flowchart RL
    config[(Database)]
    AB <-->|get co2intensity factor '36'| config
    subgraph app-graph [App]
    A[App] -->|request co2intnsity| AB(App backend)
    AB -->|return co2 intensity '36'| A
    end
    api[API] -->|get co2intensity factor 36| config
    subgraph api-graph [API]
    api
    end

Current flow for aggregated SE (incorrect)

flowchart RL
    config[(Database)]
    AB <-->|get co2intensity factor for SE '41'| config
    subgraph app-graph [App]
    A[App] -->|request co2intnsity SE| AB(App backend)
    AB -->|return co2 intensity SE '41'| A
    end
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE4 '36 & 100 MW'| config
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE3 '38' & 150 MW| config
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE2 '45' & 5 MW| config
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE1 '45' & 0 MW| config
    subgraph api-graph [API]
    average -->|return weighted average to API '37,35'| api[API]
    end

Proposed flow for SE (correct)

flowchart RL
    config[(Database)]
    AB <-->|get co2intensity factor for SE '37,35'| average
    subgraph app-graph [App]
    A[App] -->|request co2intnsity SE| AB(App backend)
    AB -->|return co2 intensity SE '37,35'| A
    end
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE4 '36 & 100 MW'| config
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE3 '38' & 150 MW| config
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE2 '45' & 5 MW| config
    average{Weighted average} <-->|get co2intensity factor and production for zone SE-SE1 '45' & 0 MW| config
    subgraph api-graph [API]
    average -->|return weighted average to API '37,35'| api[API]
    end
VIKTORVAV99 commented 1 year ago

CC @madsnedergaard @tonypls @pierresegonne

Hopefully this makes sense to you guys 😅

pierresegonne commented 1 year ago

Hey @VIKTORVAV99 thanks for raising this. To be honest I did not spend the time to fully undestand your charts but indeed if we are returning somewhere that the co2 intensity for solar for SE as a whole is not the weighted average of the subzones wrt production and / or consumption, we're providing a slightly incorrect value.

We are doing it like this because I guess it only affects the UI of the app.

I think we should create an internal issue for this as we would have to shape a solution to it.

VIKTORVAV99 commented 1 year ago

Hey @VIKTORVAV99 thanks for raising this. To be honest I did not spend the time to fully undestand your charts but indeed if we are returning somewhere that the co2 intensity for solar for SE as a whole is not the weighted average of the subzones wrt production and / or consumption, we're providing a slightly incorrect value.

We are doing it like this because I guess it only affects the UI of the app.

I think we should create an internal issue for this as we would have to shape a solution to it.

Correct, this is only for the co2intensity value shown in the app. Me, Mads and Tony talked a little about it at our Friday meeting and they suggested I open a issue here first so everyone is on the same page on what the issue is and to be transparent with that we are aware of the issue.

I'll create an internal issue later today. This would also be needed to support the data structure I suggested in https://github.com/electricitymaps/electricitymaps-contrib/discussions/4219#discussioncomment-3110126 as that would apply to every zone and not just aggregated ones.