diff --git a/public/_redirects b/public/_redirects index 718072d..a7035b4 100644 --- a/public/_redirects +++ b/public/_redirects @@ -1,2 +1,3 @@ -/carbon.txt / 404 -/.well-known/carbon.txt / 404 +/co2js/explainer/methodologies-for-calculating-website-carbon/ /co2js/models/overview/ 301 +/co2js/methods/ /co2js/functions/overview/ 301 +/co2js/data/ /co2js/data/overview/ 301 diff --git a/src/_includes/layouts/default.njk b/src/_includes/layouts/default.njk index 5e7627a..1398e2a 100644 --- a/src/_includes/layouts/default.njk +++ b/src/_includes/layouts/default.njk @@ -107,7 +107,7 @@ {%- for entry in navPages %} {% if sectionTitle != entry.sectionTitle %} {% set sectionTitle = entry.sectionTitle %} - {% endif %} @@ -175,4 +175,4 @@ {% analytics %} - \ No newline at end of file + diff --git a/src/docs/co2js/data/average-intensity.md b/src/docs/co2js/data/average-intensity.md new file mode 100644 index 0000000..55cc942 --- /dev/null +++ b/src/docs/co2js/data/average-intensity.md @@ -0,0 +1,36 @@ +--- +title: Data - Average intensity +description: This guide will show you how find and use country-level grid intensity data available in CO2.js. +eleventyNavigation: + key: data-average-intensity + title: Average intensity + sectionTitle: Data + order: 6.2 +--- + +# Data - Average intensity + +You can import annual, country-level average grid intensity data from [Ember Climate](https://ember-climate.org/data/data-explorer/) into your projects directly from CO2.js. For example, if you wanted to use the average grid intensity for Australia in a project, then you can do so by using the code below: + +```js +import { averageIntensity } from '@tgwf/co2/data'; +const { data, type, year } = averageIntensity; + +const { AUS } = data; +console.log({ AUS }) +``` + +All countries are represented by their respective [Alpha-3 ISO country code](https://www.iso.org/obp/ui/#search). + +### Using CO2.js v0.16 and older + +If you are using CO2.js v0.16 or older in your code, then you should import data using the code sample below: + +```js +// Import data from CO2.js +import { marginalIntensity } from "@tgwf/co2" +``` + +## Licenses + +The carbon intensity data from Ember is published under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa)) diff --git a/src/docs/co2js/data/electricity-maps.md b/src/docs/co2js/data/electricity-maps.md new file mode 100644 index 0000000..9aca13e --- /dev/null +++ b/src/docs/co2js/data/electricity-maps.md @@ -0,0 +1,48 @@ +--- +title: Data - Electricity Maps +description: This guide will show you how find and use country-level grid intensity data available in CO2.js. +eleventyNavigation: + key: data-electricity-maps + title: Electricity Maps + sectionTitle: Data + order: 6.1 +--- + +# Data - Electricity Maps + +You can import annual, country-level average grid intensity data from [Electricity Maps](https://www.electricitymaps.com) into your projects directly from CO2.js. For example, if you wanted to use the average grid intensity for **Australia for all available years** in a project, then you can do so by using the code below: + +```js +import { yearly2025, yearly2024, yearly2023, yearly2022, yearly2021 } from '@tgwf/co2/data/electricity-maps'; + +const data2025 = yearly2025.data["AU"] +const data2024 = yearly2024.data["AU"] +const data2023 = yearly2023.data["AU"] +const data2022 = yearly2022.data["AU"] +const data2021 = yearly2021.data["AU"] + +console.log({ data2025, data2024, data2023, data2022, data2021 }) +``` + +Electricity Maps also provides information for some grid regions (for example CAISO in the United States, or Northern India). To access these regions, developers should use the appropriate zone ID for the region they wish to access. + +Data is available for: + +- All Electricity Maps zones (see the [full list of available zones](https://github.com/thegreenwebfoundation/co2.js/blob/main/data/fixtures/electricity-maps-zones.js)) +- The calendar years 2021, 2022, 2023, 2024, and 2025 + +### Accessing other Electricity Maps data + +While we are able to provide annual grid data from Electricity Maps in CO2.js, users wishing to utilise data at higher-than-yearly resolution (e.g monthly, hourly etc.), or [other historical and forecasted datapoints](https://www.electricitymaps.com/data) should contact Electricity Maps to access this data via their paid API. To do so, visit the Electricity Maps website for [pricing and details](https://www.electricitymaps.com/pricing). + + +## Licenses + +The annual grid intensity data is republished from Electricity Maps under the [Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/summary/). Users of this data through CO2.js must: + +- Attribute: Credit Electricity Maps as the source +- Share-Alike: Keep derivative works under the same license +- Keep open: Provide unrestricted versions if using DRM + +For full details on Electricity Maps methodology see: [https://www.electricitymaps.com/data/methodology](https://www.electricitymaps.com/data/methodology) +For full detail on the ODbL see: [https://opendatacommons.org/licenses/odbl/summary/](https://opendatacommons.org/licenses/odbl/summary/) diff --git a/src/docs/co2js/data/marginal-intensity.md b/src/docs/co2js/data/marginal-intensity.md new file mode 100644 index 0000000..3c5391a --- /dev/null +++ b/src/docs/co2js/data/marginal-intensity.md @@ -0,0 +1,36 @@ +--- +title: Data - Marginal intensity +description: This guide will show you how find and use country-level grid intensity data available in CO2.js. +eleventyNavigation: + key: data-marginal-intensity + title: Marginal intensity + sectionTitle: Data + order: 6.3 +--- + +# Data - Marginal intensity + +You can import annual, country-level marginal grid intensity data from the [UNFCCC](https://unfccc.int/) (United Nations Framework Convention on Climate Change) into your projects directly from CO2.js. For example, if you wanted to use the marginal grid intensity for Australia in a project, then you can do so by using the code below: + +```js +import { marginalIntensity } from '@tgwf/co2/data'; +const { data, type, year } = marginalIntensity; + +const { AUS } = data; +console.log({ AUS }) +``` + +All countries are represented by their respective [Alpha-3 ISO country code](https://www.iso.org/obp/ui/#search). + +### Using CO2.js v0.16 and older + +If you are using CO2.js v0.16 or older in your code, then you should import data using the code sample below: + +```js +// Import data from CO2.js +import { marginalIntensity } from "@tgwf/co2" +``` + +## Licenses + +The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa)) diff --git a/src/docs/co2js/data.md b/src/docs/co2js/data/overview.md similarity index 60% rename from src/docs/co2js/data.md rename to src/docs/co2js/data/overview.md index 5d0ed57..18dbd97 100644 --- a/src/docs/co2js/data.md +++ b/src/docs/co2js/data/overview.md @@ -1,15 +1,16 @@ --- -title: Data +title: Data - Overview description: This guide will show you how find and use country-level grid intensity data available in CO2.js. eleventyNavigation: - key: data - title: Data - order: 5 + key: data-overview + title: Overview + sectionTitle: Data + order: 6 --- # Data -Sourcing carbon intensity data shouldn’t be the remit of developers. For that reason, CO2.js now includes yearly average grid intensity data from [Ember](https://ember-climate.org/data/data-explorer/), as well as marginal intensity data from the [UNFCCC](https://unfccc.int/) (United Nations Framework Convention on Climate Change). +Sourcing carbon intensity data shouldn’t be the remit of developers. For that reason, CO2.js now includes yearly average grid intensity data from [Electricity Maps](electricitymaps.com), [Ember](https://ember-climate.org/data/data-explorer/), as well as marginal intensity data from the [UNFCCC](https://unfccc.int/) (United Nations Framework Convention on Climate Change). ## Average and marginal intensity explained @@ -19,40 +20,14 @@ Marginal intensity, on the other hand, looks at where the additional electricity If you want to learn more about the differences between average or marginal grid intensity data, the team over at Electricity Maps have two great blog posts [explaining both concepts](https://electricitymaps.com/blog/marginal-emissions-what-they-are-and-when-to-use-them/) and why you [might use one over the other](https://electricitymaps.com/blog/marginal-vs-average-real-time-decision-making/). -## Where to find the data +## Using the data to your projects -The raw data files (in CSV) format, can be found in the `data` folder in the [CO2.js repository](https://github.com/thegreenwebfoundation/co2.js/tree/main/data). We have written a generation script that parses the raw data files, and outputs grid intensity data in unminified JSON and CommonJS formats. The generated output can be found in the `data/output` folder of the CO2.js repository. - -## Using emissions intensity data - -You can also import annual, country-level marginal or average grid intensity data into your projects directly from CO2.js. For example, if you wanted to use the average grid intensity for Australia in a project, then you can do so by using the code below: - -```js -import { averageIntensity } from '@tgwf/co2/data'; -const { data, type, year } = averageIntensity; - -const { AUS } = data; -console.log({ AUS }) -``` +You can also import annual, country-level marginal or average grid intensity data into your projects directly from CO2.js. For code examples, see the specific pages for the data source you are using: -Likewise, if you want to use annual marginal intensity for Australia: +- [Electricity Maps](/co2js/data/electricity-maps/) +- [Ember (average intensity)](/co2js/data/average-intensity/) +- [UNFCC (marginal intensity)](/co2js/data/marginal-intensity/) -```js -import { marginalIntensity } from '@tgwf/co2/data'; -const { data, type, year } = marginalIntensity; +## Where to find the raw data -const { AUS } = data; -console.log({ AUS }) -``` - -All countries are represented by their respective [Alpha-3 ISO country code](https://www.iso.org/obp/ui/#search). - -### Using CO2.js v0.16 and older - -If you are using CO2.js v0.16 or older in your code, then you can import data using the code sample below: - -```js -// Import data from CO2.js -import { averageIntensity } from "@tgwf/co2" -import { marginalIntensity } from "@tgwf/co2" -``` +The raw data files (in CSV) format, can be found in the `data` folder in the [CO2.js repository](https://github.com/thegreenwebfoundation/co2.js/tree/main/data). We have written a generation script that parses the raw data files, and outputs grid intensity data in unminified JSON and CommonJS formats. The generated output can be found in the `data/output` folder of the CO2.js repository. diff --git a/src/docs/co2js/functions/overview.md b/src/docs/co2js/functions/overview.md new file mode 100644 index 0000000..ed69e12 --- /dev/null +++ b/src/docs/co2js/functions/overview.md @@ -0,0 +1,18 @@ +--- +title: Functions +description: This guide will show you how to use the different functions to calculate carbon emissions that are available in CO2.js. +eleventyNavigation: + key: functions-overview + title: Overview + sectionTitle: Functions + order: 5 +--- + +# Functions + +CO2.js exposes four functions that developers can use to return CO2 estimates. This guide will show you how to use the different methods to calculate carbon emissions, and give a brief explanation for each. + +- [`perByte`](/co2js/functions/perbyte/) +- [`perVisit`](/co2js/functions/pervisit/) +- [`perByteTrace`](/co2js/functions/perbyte-trace/) +- [`perVisitTrace`](/co2js/functions/pervisit-trace/) diff --git a/src/docs/co2js/functions/perbyte-trace.md b/src/docs/co2js/functions/perbyte-trace.md new file mode 100644 index 0000000..d5100f5 --- /dev/null +++ b/src/docs/co2js/functions/perbyte-trace.md @@ -0,0 +1,61 @@ +--- +title: Functions - perByteTrace +description: This guide will show you how to use the perByteTrace function to calculate carbon emissions that are available in CO2.js. +eleventyNavigation: + key: functions-perbyte-trace + title: perByteTrace + sectionTitle: Functions + order: 5.2 +--- + +# Functions - perByteTrace
Sustainable Web Design Model only
+ +The `perByteTrace()` function is an extension of `perByte()` which allows for certain inputs to be adjusted. This allows for more accurate, scenario specific estimates to be produced using the Sustainable Web Design Model. + + + +## Accepted parameters + +The `perByteTrace()` function accepts the following parameters: + +- **bytes** `number`
Required
: The value of bytes to estimate emissions for. +- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. +- **options**: `object` Optional - A JavaScript object containing any Sustainable Web Design specific variables to be change. + +### The `options` parameter + +The `options` parameter can contain any of the following keys. These can be used to adjust the values used by the Sustainable Web Design Model's calculation. + +- `greenHostingFactor`
Sustainable Web Design Model v4 only
- A `number` representing the portion of hosting services powered by renewable or zero-carbon energy, between 0 and 1. If the `green hosting` boolean above is set to `true` then the `greenHostingFactor` will always be `1`. +- `gridIntensity` Optional – an `object` that can contain the following keys: + - `device` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. + - `dataCenter` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. + - `networks` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. + +Below is an example which shows both kinds of accepted inputs in use. + +```js +const options = { + gridIntensity: { + device: 565.629, // Here we have set the grid intensity at the device location using a number. + dataCenter: { country: "TWN" }, // Here we have set the data center grid intensity using a country code. + networks: 442, + }, +}; +``` + +## Result + +The `perByteTrace()` function returns an object with the following keys: + +- `co2` - A `number` representing the carbon emissions calculated in grams +- `green` - A `boolean` indicating whether the calculation was based on data being hosted in a green data center +- `variables` - An `object`` that details all the other variables used in the calculation. This object will include: + - `description` - A static `string` explaining what is being shown. + - `bytes` - A `number` showing the bytes that were passed into the function. + - `greenHostingFactor` Sustainable Web Design Model v4 only - A `number` representing the portion of hosting services powered by renewable or zero-carbon energy. + - `gridIntensity` – an `object` that can contain the following keys: + - `device` – A `number` representing the carbon intensity (in grams per kilowatt-hour) used in the calculation. + - `dataCenter` – A `number` representing the carbon intensity (in grams per kilowatt-hour) used in the calculation. + - `networks` – A `number` representing the carbon intensity (in grams per kilowatt-hour) used in the calculation. diff --git a/src/docs/co2js/functions/perbyte.md b/src/docs/co2js/functions/perbyte.md new file mode 100644 index 0000000..012ea1b --- /dev/null +++ b/src/docs/co2js/functions/perbyte.md @@ -0,0 +1,37 @@ +--- +title: Functions - perByte +description: This guide will show you how to use the perByte function to calculate carbon emissions that are available in CO2.js. +eleventyNavigation: + key: functions-perbyte + title: perByte + sectionTitle: Functions + order: 5.1 +--- + +# Functions - perByte() + +The `perByte()` function can be used with both the [OneByte and Sustainable Web Design Models](/co2js/models/). We recommend using this function, as it will return a CO2 value (in grams) for raw data transfer using a given model. It can be used for calculating emissions from websites, file uploads, streaming etc. + + + +```js +import { co2 } from "@tgwf/co2"; + +const oneByte = new co2({ model: "1byte" }); + +const emissions = oneByte.perByte(1000000); +``` + +Here we are using the OneByte model, and using the `perByte()` function to check the carbon emissions for transferring 1 million bytes. + +## Accepted parameters + +The `perByte()` function accepts the following parameters: + +- **bytes** `number`
Required
: The value of bytes to estimate emissions for. +- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. + +## Result + +The `perByte()` function returns a floating point decimal value which is the amount of CO2e (in grams) calculated using the function. diff --git a/src/docs/co2js/functions/pervisit-trace.md b/src/docs/co2js/functions/pervisit-trace.md new file mode 100644 index 0000000..ebd7554 --- /dev/null +++ b/src/docs/co2js/functions/pervisit-trace.md @@ -0,0 +1,71 @@ +--- +title: Functions - perVisitTrace +description: This guide will show you how to use the perVisitTrace function to calculate carbon emissions that are available in CO2.js. +eleventyNavigation: + key: functions-pervisit-trace + title: perVisitTrace + sectionTitle: Functions + order: 5.4 +--- + +# Functions - perVisitTrace
Sustainable Web Design only
+ +The `perVisitTrace()` function is an extension of `perVisit()` which allows for certain inputs to be adjusted. This allows for more accurate, scenario specific estimates to be produced using the Sustainable Web Design Model. + + + +## Accepted parameters + +The `perVisitTrace()` function accepts the following parameters: + +- **bytes** `number`
Required
: The value of bytes to estimate emissions for. +- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. +- **options**: `object` Optional - A JavaScript object containing any Sustainable Web Design specific variables to be change. + +### The `options` parameter + +The `options` parameter can contain any of the following keys. These can be used to adjust the values used by the Sustainable Web Design Model's calculation. + +- `dataReloadRatio` Optional – a `number` between 0 and 1 representing the percentage of data that is downloaded by return visitors. This is the complement of the data cache ratio from the Sustainable Web Design model, i.e. dataReloadRatio = 1 - dataCacheRatio. +- `firstVisitPercentage` Optional – a `number` between 0 and 1 representing the percentage of new visitors. +- `returnVisitPercentage` Optional – a `number` between 0 and 1 representing the percentage of returning visitors. +- `greenHostingFactor`
Sustainable Web Design Model v4 only
- The portion of hosting services powered by renewable or zero-carbon energy, between 0 and 1. If the `green hosting` boolean above is set to `true` then the `greenHostingFactor` will always be `1`. +- `gridIntensity` Optional – an `object` that can contain the following keys: + - `device` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. + - `dataCenter` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. + - `networks` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. + +Below is an example which shows both kinds of accepted inputs in use. + +```js +const options = { + dataReloadRatio: 0.6, + firstVisitPercentage: 0.9, + returnVisitPercentage: 0.1, + gridIntensity: { + device: 565.629, // Here we have set the grid intensity at the device location using a number. + dataCenter: { country: "TWN" }, // Here we have set the data center grid intensity using a country code. + networks: 442, + }, +}; +``` + +## Result + +The `perVisitTrace()` function returns an object with the following keys: + +- `co2` - A `number` representing the carbon emissions calculated in grams +- `green` - A `boolean` indicating whether the calculation was based on data being hosted in a green data center +- `variables` - An `object`` that details all the other variables used in the calculation. This object will include: + - `description` - A static `string` explaining what is being shown. + - `bytes` - A `number` showing the bytes that were passed into the function. + - `greenHostingFactor` Sustainable Web Design Model v4 only - A `number` representing the portion of hosting services powered by renewable or zero-carbon energy. + - `gridIntensity` – an `object` that can contain the following keys: + - `device` – A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. + - `dataCenter` – A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. + - `networks` – A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. + - `production` - A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. + - `dataReloadRatio` – a `number` between 0 and 1 representing the percentage of data that is downloaded by return visitors. This is the complement of the data cache ratio from the Sustainable Web Design model, i.e. dataReloadRatio = 1 - dataCacheRatio. + - `firstVisitPercentage` – a `number` between 0 and 1 representing the percentage of new visitors. + - `returnVisitPercentage` – a `number` between 0 and 1 representing the percentage of returning visitors. diff --git a/src/docs/co2js/functions/pervisit.md b/src/docs/co2js/functions/pervisit.md new file mode 100644 index 0000000..b38230b --- /dev/null +++ b/src/docs/co2js/functions/pervisit.md @@ -0,0 +1,37 @@ +--- +title: Functions - perVisit +description: This guide will show you how to use the perVisit function to calculate carbon emissions that are available in CO2.js. +eleventyNavigation: + key: functions-pervisit + title: perVisit + sectionTitle: Functions + order: 5.3 +--- + +# Functions - perVisit
Sustainable Web Design Model only
+ +The `perVisit()` function can only be used with the Sustainable Web Design Models. This function includes assumptions the model authors have made [about website visitors and caching](https://sustainablewebdesign.org/calculating-digital-emissions/#:~:text=Returning%20visitors%20are%20assumed%20to%20be%2025%25%2C%20loading%202%25%20of%20data.) as part its calculation. For that reason, we recommend only using it if you are comfortable with those assumptions. The `perVisit()` function is best used for calculating website carbon emissions. + + + +```js +import { co2 } from "@tgwf/co2"; + +const swd = new co2({ model: "swd" }); + +const emissions = swd.perVisit(1000000); +``` + +Here we are using the Sustainable Web Design Model, and using the `perVisit()` function to check the carbon emissions for transferring 1 million bytes. + +### Accepted parameters + +The `perVisit()` function accepts the following parameters: + +- **bytes** `number`
Required
: The value of bytes to estimate emissions for. +- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. + +## Result + +The `perVisit()` function returns a floating point decimal value which is the amount of CO2e (in grams) calculated using the function. diff --git a/src/docs/co2js/methods.md b/src/docs/co2js/methods.md deleted file mode 100644 index 34e734d..0000000 --- a/src/docs/co2js/methods.md +++ /dev/null @@ -1,180 +0,0 @@ ---- -title: Methods -description: This guide will show you how to use the different methods to calculate carbon emissions that are available in CO2.js. -eleventyNavigation: - key: methods - title: Methods - order: 4 ---- - -# Methods - -CO2.js exposes two functions that developers can use to return CO2 estimates. This guide will show you how to use the different methods to calculate carbon emissions, and give a brief explanation for each. - -{% include 'partials/swdmv4-update.njk' %} - -## perByte() - -The `perByte()` function can be used with both the [OneByte and Sustainable Web Design Models](/co2js/models/). We recommend using this function, as it will return a CO2 value (in grams) for raw data transfer using a given model. It can be used for calculating emissions from websites, file uploads, streaming etc. - - - -```js -import { co2 } from "@tgwf/co2"; - -const oneByte = new co2({ model: "1byte" }); - -const emissions = oneByte.perByte(1000000); -``` - -Here we are using the OneByte model, and using the `perByte()` function to check the carbon emissions for transferring 1 million bytes. - -### Accepted parameters - -The `perByte()` function accepts the following parameters: - -- **bytes** `number`
Required
: The value of bytes to estimate emissions for. -- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. - -### Result - -The `perByte()` function returns a floating point decimal value which is the amount of CO2e (in grams) calculated using the function. - -## perByteTrace
Sustainable Web Design Model only
- -The `perByteTrace()` function is an extension of `perByte()` which allows for certain inputs to be adjusted. This allows for more accurate, scenario specific estimates to be produced using the Sustainable Web Design Model. - - - -### Accepted parameters - -The `perByteTrace()` function accepts the following parameters: - -- **bytes** `number`
Required
: The value of bytes to estimate emissions for. -- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. -- **options**: `object` Optional - A JavaScript object containing any Sustainable Web Design specific variables to be change. - -#### The `options` parameter - -The `options` parameter can contain any of the following keys. These can be used to adjust the values used by the Sustainable Web Design Model's calculation. - -- `greenHostingFactor`
Sustainable Web Design Model v4 only
- A `number` representing the portion of hosting services powered by renewable or zero-carbon energy, between 0 and 1. If the `green hosting` boolean above is set to `true` then the `greenHostingFactor` will always be `1`. -- `gridIntensity` Optional – an `object` that can contain the following keys: - - `device` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. - - `dataCenter` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. - - `networks` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. - -Below is an example which shows both kinds of accepted inputs in use. - -```js -const options = { - gridIntensity: { - device: 565.629, // Here we have set the grid intensity at the device location using a number. - dataCenter: { country: "TWN" }, // Here we have set the data center grid intensity using a country code. - networks: 442, - }, -}; -``` - -### Result - -The `perByteTrace()` function returns an object with the following keys: - -- `co2` - A `number` representing the carbon emissions calculated in grams -- `green` - A `boolean` indicating whether the calculation was based on data being hosted in a green data center -- `variables` - An `object`` that details all the other variables used in the calculation. This object will include: - - `description` - A static `string` explaining what is being shown. - - `bytes` - A `number` showing the bytes that were passed into the function. - - `greenHostingFactor` Sustainable Web Design Model v4 only - A `number` representing the portion of hosting services powered by renewable or zero-carbon energy. - - `gridIntensity` – an `object` that can contain the following keys: - - `device` – A `number` representing the carbon intensity (in grams per kilowatt-hour) used in the calculation. - - `dataCenter` – A `number` representing the carbon intensity (in grams per kilowatt-hour) used in the calculation. - - `networks` – A `number` representing the carbon intensity (in grams per kilowatt-hour) used in the calculation. - -## perVisit
Sustainable Web Design Model only
- -The `perVisit()` function can only be used with the Sustainable Web Design Models. This function includes assumptions the model authors have made [about website visitors and caching](https://sustainablewebdesign.org/calculating-digital-emissions/#:~:text=Returning%20visitors%20are%20assumed%20to%20be%2025%25%2C%20loading%202%25%20of%20data.) as part its calculation. For that reason, we recommend only using it if you are comfortable with those assumptions. The `perVisit()` function is best used for calculating website carbon emissions. - - - -```js -import { co2 } from "@tgwf/co2"; - -const swd = new co2({ model: "swd" }); - -const emissions = swd.perVisit(1000000); -``` - -Here we are using the Sustainable Web Design Model, and using the `perVisit()` function to check the carbon emissions for transferring 1 million bytes. - -### Accepted parameters - -The `perVisit()` function accepts the following parameters: - -- **bytes** `number`
Required
: The value of bytes to estimate emissions for. -- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. - -## perVisitTrace
Sustainable Web Design only
- -The `perVisitTrace()` function is an extension of `perVisit()` which allows for certain inputs to be adjusted. This allows for more accurate, scenario specific estimates to be produced using the Sustainable Web Design Model. - - - -### Accepted parameters - -The `perVisitTrace()` function accepts the following parameters: - -- **bytes** `number`
Required
: The value of bytes to estimate emissions for. -- **green hosting** `boolean` Optional: if the data being measured is served from a green web host. -- **options**: `object` Optional - A JavaScript object containing any Sustainable Web Design specific variables to be change. - -#### The `options` parameter - -The `options` parameter can contain any of the following keys. These can be used to adjust the values used by the Sustainable Web Design Model's calculation. - -- `dataReloadRatio` Optional – a `number` between 0 and 1 representing the percentage of data that is downloaded by return visitors. This is the complement of the data cache ratio from the Sustainable Web Design model, i.e. dataReloadRatio = 1 - dataCacheRatio. -- `firstVisitPercentage` Optional – a `number` between 0 and 1 representing the percentage of new visitors. -- `returnVisitPercentage` Optional – a `number` between 0 and 1 representing the percentage of returning visitors. -- `greenHostingFactor`
Sustainable Web Design Model v4 only
- The portion of hosting services powered by renewable or zero-carbon energy, between 0 and 1. If the `green hosting` boolean above is set to `true` then the `greenHostingFactor` will always be `1`. -- `gridIntensity` Optional – an `object` that can contain the following keys: - - `device` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. - - `dataCenter` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. - - `networks` Optional – A `number` representing the carbon intensity for the given segment (in grams per kilowatt-hour). Or, an `object`, which contains a key of country and a value that is an Alpha-3 ISO country code. - -Below is an example which shows both kinds of accepted inputs in use. - -```js -const options = { - dataReloadRatio: 0.6, - firstVisitPercentage: 0.9, - returnVisitPercentage: 0.1, - gridIntensity: { - device: 565.629, // Here we have set the grid intensity at the device location using a number. - dataCenter: { country: "TWN" }, // Here we have set the data center grid intensity using a country code. - networks: 442, - }, -}; -``` - -### Result - -The `perVisitTrace()` function returns an object with the following keys: - -- `co2` - A `number` representing the carbon emissions calculated in grams -- `green` - A `boolean` indicating whether the calculation was based on data being hosted in a green data center -- `variables` - An `object`` that details all the other variables used in the calculation. This object will include: - - `description` - A static `string` explaining what is being shown. - - `bytes` - A `number` showing the bytes that were passed into the function. - - `greenHostingFactor` Sustainable Web Design Model v4 only - A `number` representing the portion of hosting services powered by renewable or zero-carbon energy. - - `gridIntensity` – an `object` that can contain the following keys: - - `device` – A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. - - `dataCenter` – A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. - - `networks` – A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. - - `production` - A `number` representing the carbon intensity for this segment (in grams per kilowatt-hour) used in the calculation. - - `dataReloadRatio` – a `number` between 0 and 1 representing the percentage of data that is downloaded by return visitors. This is the complement of the data cache ratio from the Sustainable Web Design model, i.e. dataReloadRatio = 1 - dataCacheRatio. - - `firstVisitPercentage` – a `number` between 0 and 1 representing the percentage of new visitors. - - `returnVisitPercentage` – a `number` between 0 and 1 representing the percentage of returning visitors. diff --git a/src/docs/co2js/models.md b/src/docs/co2js/models.md deleted file mode 100644 index b0a081c..0000000 --- a/src/docs/co2js/models.md +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: Models -description: This guide will show you how use the different carbon estimation models available in CO2.js. -eleventyNavigation: - key: models - title: Models - order: 3 ---- - -# Models - -There are a few different models that can be used to measure digital carbon emissions. CO2.js includes two of these - the [OneByte][soberDigital] model, and the [Sustainable Web Design Model][swd]. This guide will show you how use the different carbon estimation models available in CO2.js. - -This guide will not go into the details of each model. If you'd like to learn more about the OneByte or Sustainable Web Design Models then take a look at [Methodologies for calculating website carbon](/co2js/explainer/methodologies-for-calculating-website-carbon/). - -## Using the Sustainable Web Design Model Default - v0.11.0 - -Since v0.11.0, CO2.js uses the Sustainable Web Design Model by default. After importing CO2.js into your project, you can start using this model right away by initiating a `co2()` object. Alternately, you can pass in the `model: "swd"` option. This will use [version 3 of the Sustainable Web Design Model](https://sustainablewebdesign.org/estimating-digital-emissions-version-3) by default. - -```js -import { co2 } from "@tgwf/co2"; - -const swd = new co2(); -// You can also explicitly declare the model -const declaredSwd = new co2({ model: "swd" }); -``` - -{% include 'partials/swdmv4-update.njk' %} - -### Using Sustainable Web Design Model version 3 - -You can explicitly set the Sustainable Web Design Model version 3 when initiating the a new instance of the `co2()` object. - -```js -import { co2 } from "@tgwf/co2"; - -const swdmV3 = new co2({ model: "swd", version: 3 }); -``` - -### Using Sustainable Web Design Model version 4 Since v0.16.0 - -In May 2024, version 4 of the Sustainable Web Design Model was published for initial community feedback. The update includes a change to the estimation formula, introduces separation between operational and embodied emissions, and updates the underlying data that forms the foundation of the model. We have covered the changes made in [this helpful blog post](https://www.thegreenwebfoundation.org/news/understanding-the-latest-sustainable-web-design-model-update/). - -CO2.js v0.16 sees the inclusion of Sustainable Web Design Model version 4 as one of the models that can be used in CO2.js. Developers will be required to explicitly opt-in to using Sustainable Web Design Model version 4, but will have access to all the same functions that can be accessed in version 3. Switching to version 4 should create minimal disruption for most developers, with only the returned values when using `perByteTrace` and `perVisitTrace` functions changing. - -The code sample below shows how to use SWDM version 4 in CO2.js to estimate 1000 bytes using the `perByte` function. Note that the version number has been explicitly declared (`version: 4`) when initiating a new `co2()` instance. - -```js -import { co2 } from "@tgwf/co2"; - -const swdmV4 = new co2({ model: "swd", version: 4 }); -const bytes = 1000; - -const estimate = version4.perByte(1000); -``` - -Learn more about the [different methods available when using the Sustainable Web Design Model](/co2js/methods/), including how to adjust variables used within the model. - -## Using the OneByte model - -If you want to use the OneByte model, then you'll need to let CO2.js know. This can be done by passing in a `model` parameter with a value of `"1byte"` when you initiate a new `co2()` object. - -```js -import { co2 } from "@tgwf/co2"; - -const oneByte = new co2({ model: "1byte" }); -``` - -[soberDigital]: https://theshiftproject.org/en/lean-ict-2/ -[swd]: https://sustainablewebdesign.org/estimating-digital-emissions diff --git a/src/docs/co2js/explainer/methodologies-for-calculating-website-carbon.md b/src/docs/co2js/models/overview.md similarity index 64% rename from src/docs/co2js/explainer/methodologies-for-calculating-website-carbon.md rename to src/docs/co2js/models/overview.md index c4cf3ab..303f2f3 100644 --- a/src/docs/co2js/explainer/methodologies-for-calculating-website-carbon.md +++ b/src/docs/co2js/models/overview.md @@ -1,29 +1,47 @@ --- -title: Methodologies for calculating website carbon -description: CO2.js offers two models for understanding the environmental impact of compute - the OneByte model, and the Sustainable Web Design Model. +title: Models +description: This guide will show you how use the different carbon estimation models available in CO2.js. eleventyNavigation: - key: website-carbon-methodologies + key: models-overview + title: Overview # parent: overview - title: Methodologies for calculating website carbon - sectionTitle: Explanations - order: 30 + sectionTitle: Estimation Models + order: 4 --- -# {{ title }} +# Models -CO2.js offers two models for understanding the environmental impact of compute - the OneByte model (`1byte.js`), and the Sustainable Web Design Model (`swd.js`). +There are a few different models that can be used to measure digital carbon emissions. CO2.js includes two of these - the [OneByte][soberDigital] model, and the [Sustainable Web Design Model][swd]. This guide will show you how use the different carbon estimation models available in CO2.js. -## Default +## Default estimation model -Since v0.11.0, CO2.js uses the Sustainable Web Design (SWDM) model as the default when calculating carbon emissions. +CO2.js uses the **Sustainable Web Design (SWDM) Model version 4** as the default when calculating carbon emissions. ## Carbon estimation models ### The Sustainable Web Design Model -By default, CO2.js uses the [Sustainable Web Design Model][swd] for calculating emissions from digital services. As the name suggests, this has been designed for helping understand the environmental impact of websites. Further details are available on the [Sustainable Web Design website explaining the model](https://sustainablewebdesign.org/calculating-digital-emissions/), but for convenience, a short summary is below. +After importing CO2.js into your project, you can start using this model right away by initiating a `co2()` object. Alternately, you can pass in the `model: "swd"` option. This will use [version 4 of the Sustainable Web Design Model](https://sustainablewebdesign.org/estimating-digital-emissions) by default. -#### How the SWDM works +```js +import { co2 } from "@tgwf/co2"; + +const swd = new co2(); +// You can also explicitly declare the model +const declaredSwd = new co2({ model: "swd" }); +``` + +#### Using Sustainable Web Design Model version 3 + +By default, CO2.js will use the Sustainable Web Design Model version 4 calculations. To use Sustainable Web Design Model version 3, you can explicitly set it as the model version when initiating the a new instance of the `co2()` object. + +```js +import { co2 } from "@tgwf/co2"; + +const swdmV3 = new co2({ model: "swd", version: 3 }); +``` + +#### Explainer: How the SWDM works This model uses data transfer as an proxy indicator for total resource usage, and uses this number to extrapolate energy usage numbers for your application as a fraction of the energy used by the total system comprised of: @@ -44,11 +62,18 @@ This follows the approach used by the IPCC 5th Assessment Report Annex 3 (2014), ### The OneByte model -Additionally, CO2.js also allows developers to use the OneByte model as introduced by The Shift Project in their report on CO2 emissions from digital infrastructure, [Lean ICT: for a sober digital][soberDigital]. + +Additionally, CO2.js also allows developers to use the OneByte model as introduced by The Shift Project in their report on CO2 emissions from digital infrastructure, [Lean ICT: for a sober digital][soberDigital].If you want to use the OneByte model, then you'll need to let CO2.js know. This can be done by passing in a `model` parameter with a value of `"1byte"` when you initiate a new `co2()` object. + +```js +import { co2 } from "@tgwf/co2"; + +const oneByte = new co2({ model: "1byte" }); +``` This returns a number for the estimated CO2 emissions for the corresponding number of bytes sent over the wire, and has been used for video streaming, file downloads and websites. -### How the models differ +## How the models differ These models return slightly different results, since they apply different system boundaries as part of their calculations. Tom Greenwood has written [a terrific blog post](https://www.wholegraindigital.com/blog/website-energy-consumption/) explaining system boundaries and how they impact carbon estimates. @@ -56,20 +81,21 @@ The OneByte model, as it has been implemented in CO2.js, applies narrow system b On the other hand, the Sustainable Web Design Model has a broader system boundary (explained above). It takes a more complex, but detailed, bottom up approach. By using a wider system boundary, the Sustainable Web Design Model provides a more comprehensive carbon estimate. This also means that segmented estimates can be produced for each part of the system, allowing for greater granularity and flexibility. -As a result, the `perByte` carbon estimates returned when using the OneByte model will be lower than those from Sustainable Web Design for the same amount of data transfer. - ## Switching between models -To use the Sustainable Web Design Model in CO2.js, pass in the `{ model: 'swd' }` parameter when initiating a new CO2.js object. +To use the Sustainable Web Design Model in CO2.js, pass in the `{ model: 'swd' }` or `{ model: '1byte' }` parameter when initiating a new CO2.js object. ```js import { co2 } from "@tgwf/co2"; -// Use the default Sustainable Web Design Model +// Use the default Sustainable Web Design Model v4 const swd = new co2(); // Use the OneByte model const oneByte = new co2({ model: "1byte" }); + +// Use the Sustainable Web Design Model v3 +const swdmV3 = new co2({ model: "swd", version: 3 }); ``` [ember-methodology]: https://ember-climate.org/app/uploads/2022/03/GER22-Methodology.pdf diff --git a/src/docs/co2js/overview.md b/src/docs/co2js/overview.md index cb09364..ef325c8 100644 --- a/src/docs/co2js/overview.md +++ b/src/docs/co2js/overview.md @@ -83,3 +83,14 @@ The code for CO2.js is licensed [Apache 2.0](https://github.com/thegreenwebfound The carbon intensity data from Ember is published under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa)) The marginal intensity data is published by the Green Web Foundation, under the Creative Commons ShareAlike Attribution Licence ([CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)). ([What does this mean?](https://www.tldrlegal.com/license/creative-commons-attribution-share-alike-cc-sa)) + +Electricity Maps Grid Intensity Data - The annual grid intensity data is republished from Electricity Maps under the [Open Database License (ODbL)](https://opendatacommons.org/licenses/odbl/summary/). Users of this data through CO2.js must: + +- Attribute: Credit Electricity Maps as the source +- Share-Alike: Keep derivative works under the same license +- Keep open: Provide unrestricted versions if using DRM + +For full details on Electricity Maps methodology see: [https://www.electricitymaps.com/data/methodology](https://www.electricitymaps.com/data/methodology) +For full detail on the ODbL see: [https://opendatacommons.org/licenses/odbl/summary/](https://opendatacommons.org/licenses/odbl/summary/) + +Data at higher-than-yearly resolution (e.g monthly, hourly etc.), or [other historical and forecasted datapoints](https://www.electricitymaps.com/data) are available through Electricity Maps as a paid service. Users requiring this data should visit the Electricity Maps website for [pricing and details](https://www.electricitymaps.com/pricing). diff --git a/src/docs/co2js/roadmap.md b/src/docs/co2js/roadmap.md index 031445e..5026c34 100644 --- a/src/docs/co2js/roadmap.md +++ b/src/docs/co2js/roadmap.md @@ -4,7 +4,7 @@ description: This page contains links to different Github issues that track the eleventyNavigation: key: roadmap title: Roadmap - order: 6 + order: 3 --- # CO2.js - Roadmap