Skip to content

Use Ember's carbon intensity of the year the usage was billed in - #281

Merged
jnioche merged 3 commits into
mainfrom
280
Sep 11, 2026
Merged

jnioche merged 3 commits into
mainfrom
280

Conversation

@dpol1

@dpol1 dpol1 commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

One figure per region and year from 2022 on; each line uses the figure of the year it was billed in, as PWUE does: the latest earlier year when Ember has not published that one, the latest year when the row has no date.

The first commit regenerates the csv from the current Ember files. The third places usgovvirginia in Virginia, keeps Ember's "Washington, D.C." rows, which the parser split on the comma and dropped, and stops the script, csv untouched, when a region in the US or India would get the national figure.

The monthly figures stay on a branch for a later PR.

@dpol1

dpol1 commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

csv file too wide, draft for now

@dpol1
dpol1 marked this pull request as draft September 5, 2026 07:30
@dpol1

dpol1 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator Author

Reworked the monthly file, see the last commit. Ready for a look.

@dpol1
dpol1 marked this pull request as ready for review September 6, 2026 16:55
@dpol1
dpol1 requested a review from jnioche September 6, 2026 16:56
@dpol1 dpol1 self-assigned this Sep 6, 2026
@dpol1 dpol1 added the enhancement New feature or request label Sep 6, 2026
@dpol1 dpol1 added this to the 1.4 milestone Sep 6, 2026
@jnioche

jnioche commented Sep 7, 2026

Copy link
Copy Markdown
Member

Ember's yearly and monthly datasets are different series and disagree for some regions, Sweden is 35.35 yearly against 22-29 in every month since 2025, so a region shifts when its latest months are not out yet.

is there a difference in the methodology used by Ember for monthly vs yearly?

@jnioche

jnioche commented Sep 7, 2026

Copy link
Copy Markdown
Member

Should UsageDate be used in other parts of the code?

@jnioche

jnioche commented Sep 7, 2026

Copy link
Copy Markdown
Member

The carbon intensity is systematically lower than using yearly averages. We need to make sure that the datasets in Ember use the same methodology. I would expect that over a year the figures would be roughly the same.

@dpol1

dpol1 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

I would expect that over a year the figures would be roughly the same.

Agreed, this needs checking. Ember's methodology documents differences in sources and coverage: Sweden uses Eurostat yearly and mostly ENTSO-E monthly, with gross vs net generation for the EU data. I havent pinned down how much of the gap this explains.

I'll compare the monthly values weighted by electricity generation against the annual figure for the same country and year.

Should UsageDate be used in other parts of the code?

Yes, PWUE already uses it in this PR. That's where I extracted the lookup from, so both modules use the same date precedence. The other places need full timestamps or intervals.

@dpol1

dpol1 commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed the comparison, weighted by generation over 2022-2025: yearly / monthly falls within 0.9-1.1 in 63 of 64 US state-years and 99 of 131 country-years, the country gaps go both ways.

The script now keeps the months only for areas passing every complete year since 2022, the rest stay on the yearly figure; the ones left out are listed at the top of the CSV. Ireland just misses the cutoff at 0.898, 15% would keep it. Does 10% sound reasonable?

@jnioche

jnioche commented Sep 8, 2026

Copy link
Copy Markdown
Member

From https://files.ember-energy.org/public-downloads/ember_electricity_data_methodology.pdf

Estimating latest yearly data
Monthly data does not always align well with annual data: different types of generation may
be included in different scales, or coverage may differ. Where conflicts occur, annual data is
generally more accurate. As such, we project latest generation data by applying absolute
changes by fuel from available annualised monthly data to historical annual values. In the
few cases where a specific fuel is not available in monthly data, it is treated as having shown
no change in the annualised projection. As such, note that simply summing up monthly
values will not produce the same results as our annual values for any given year.

@jnioche jnioche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are here: update the documentation by linking to https://files.ember-energy.org/public-downloads/ember_electricity_data_methodology.pdf

and explain that the Ember figures

include full lifecycle
emissions including upstream methane, supply chain and manufacturing emissions, and include all gases, converted into CO2 equivalent over a 100-year timescale.

Comment thread src/main/java/com/digitalpebble/spruce/modules/ember/MonthlyCarbonIntensity.java Outdated
@dpol1
dpol1 requested a review from jnioche September 8, 2026 12:02
@jnioche

jnioche commented Sep 8, 2026

Copy link
Copy Markdown
Member

Still seeing a 20% drop for some regions (us-east-1 / eu-west-2) over a 12 months period.
Having mixed sources of intensities depending on the region is problematic as it makes things harder to explain (and each their own methodology etc...)
I need to think about it. If yearly data are available over several years, an intermediate step would be to keep yearly but take the year into account.

@dpol1

dpol1 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

feel free to provide changes on the branch

Regenerated with scripts/fetch_ember_co2_intensity.sh from the current
Ember release: 78 of the 157 regions move, most by a few gCO2/kWh. The
larger shift is us-east-1, from 384.4 to 327.17, which now matches the
Virginia figure used for the Azure region in the same state.
@dpol1

dpol1 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

@jnioche some investigation I would like to share: Ember has yearly figures back to 2000, so the middle step is trivial: all year from 2022 in the csv and keep the year of the usage (like PWUE) - Also tried scaling the monthly profile to annual figure: looks ok on past years, but monthly estimates would need validating. Something for a PR later? On the 20%: partly of it is the refresh rather than the monthly figures - us-east-1 on main was mapped to the US national figure instead of Virginia's (eastus in the same state already had the right one). The rest is the monthly series itself, which goes away with the yearly-per-year step anyway.

@jnioche

jnioche commented Sep 9, 2026

Copy link
Copy Markdown
Member

@jnioche some investigation I would like to share: Ember has yearly figures back to 2000, so the middle step is trivial: all year from 2022 in the csv and keep the year of the usage (like PWUE)

thanks @dpol1 let's do that for now

Also tried scaling the monthly profile to annual figure: looks ok on past years, but monthly estimates would need validating. Something for a PR later?

Can look at monthly again later in a separate PR

On the 20%: partly of it is the refresh rather than the monthly figures - us-east-1 on main was mapped to the US national figure instead of Virginia's (eastus in the same state already had the right one). The rest is the monthly series itself, which goes away with the yearly-per-year step anyway.

this formulation is not quite clear for me (maybe because it is AI generated?): refresh? yearly-per-year step?
I do miss human to human communication in open source projects ;-)

Anyway, the main point here is that us-east-1 should not be mapped to the US average, if it does it is a bug / regression in the fetch_ember_co2_intensity.sh script

@dpol1

dpol1 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

this formulation is not quite clear for me (maybe because it is AI generated?): refresh? yearly-per-year step?

Hand-typed, but drafted with an AI, hence the jargon ;-) Plain version: "yearly per year" = one figure per region and year, each line uses the one of its billing year. I will replace the commits on this branch with that and keep the monthly ones on a side branch.

Anyway, the main point here is that us-east-1 should not be mapped to the US average, if it does it is a bug / regression in the fetch_ember_co2_intensity.sh script

The csv in main was generated when cloud_regions.json still placed us-east-1 in Washington DC. Ember has no figure for DC, so the script used the US average, which is what it does when a state has no figure. The coordinates were corrected later, the csv was not regenerated. usgovvirginia still has the DC coordinates, I will fix that too.

To make this visible: the csv gets a column with the Ember area each region uses (us-east-1 → US-VA), and a test checks that every US and Indian region uses a state figure. OK with the extra column?

@jnioche

jnioche commented Sep 10, 2026

Copy link
Copy Markdown
Member

The csv in main was generated when cloud_regions.json still placed us-east-1 in Washington DC. Ember has no figure for DC, so the script used the US average, which is what it does when a state has no figure. The coordinates were corrected later, the csv was not regenerated. usgovvirginia still has the DC coordinates, I will fix that too.

To make this visible: the csv gets a column with the Ember area each region uses (us-east-1 → US-VA), and a test checks that every US and Indian region uses a state figure. OK with the extra column?

or change scripts/fetch_ember_co2_intensity.sh src/main/resources/cloud_regions.json so that an error message is displayed when no region data is found for the countries which have them. This will attract attention to a fix for cloud_regions.json or fetch_ember_co2_intensity.sh itself.

@dpol1

dpol1 commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Yep, fair point - let me think about it

The csv carries every year from 2022 on, one row per region and year,
and AverageCarbonIntensity picks the figure of the year the usage was
billed in, as PWUE does: the latest earlier year when Ember has not
published that one, the latest year when the row has no date. The usage
date lookup moves out of PWUE into UsageDate, and timestamps are read
in UTC instead of the JVM zone.
usgovvirginia gets coordinates in Virginia; cloud_regions.json placed it
in Washington DC. The script reads Ember's state files by counting
fields from the end of the line, so "Washington, D.C." no longer shifts
the columns and drops the state. When a region in a country with state
figures would get the national figure, the script lists the reasons and
leaves the csv unchanged. Failed Nominatim requests are not cached and
cached empty codes are ignored.
@dpol1 dpol1 changed the title Use Ember's monthly carbon intensity for the month of the usage Use Ember's carbon intensity of the year the usage was billed in Sep 10, 2026
@dpol1

dpol1 commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

or change scripts/fetch_ember_co2_intensity.sh so that an error message is displayed when no region data is found for the countries which have them.

Done: the script now stops, lists the US and Indian regions that would get the national figure with the reason, and leaves the csv untouched. One correction on DC: Ember does have a figure for it, the script split "Washington, D.C." on the comma and lost the row. Fixed, usgovvirginia too.

Branch replaced with approach we discussed. The monthly ones sit on a side branch for a later PR.

@jnioche

jnioche commented Sep 11, 2026

Copy link
Copy Markdown
Member

Thanks @dpol1

@jnioche
jnioche merged commit 43fa7c3 into main Sep 11, 2026
3 checks passed
@jnioche
jnioche deleted the 280 branch September 11, 2026 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants