Skip to content

Commit 457ca26

Browse files
committed
doc updated
1 parent e065975 commit 457ca26

File tree

10 files changed

+247
-89
lines changed

10 files changed

+247
-89
lines changed

docs/_static/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
div.highlight pre {
2+
white-space: pre-wrap !important; /* Allows text wrapping */
3+
word-wrap: break-word !important; /* Ensures words break if needed */
4+
overflow-x: auto; /* Enables scrolling only if necessary */
5+
}

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ The core package contains 2 main module :
1717
`tools` module
1818
---------------
1919

20+
Methods vary depending on the type of input (e.g, country name vs energy data) and the output (e.g single value vs time series DataFrame). Most tools depend on the data from the `data` sub package.
21+
As a convention, methods that primarily accept DataFrame as an input (along with other parameters) and return a DataFrame are prefixed with `_df`.
22+
2023
.. automodule:: codegreen_core.tools
2124
:members:
2225

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
1414

1515
project = "codegreen_core"
16-
copyright = "2024, Dr. Anne Hartebrodt"
16+
copyright = "2025, Dr. Anne Hartebrodt"
1717
author = "Dr. Anne Hartebrodt"
1818

1919
# -- General configuration ---------------------------------------------------
@@ -46,6 +46,7 @@
4646

4747
html_theme = "alabaster"
4848
html_static_path = ["_static"]
49+
html_css_files = ["custom.css"]
4950

5051
html_theme_options = {
5152
"github_user": "codegreen-framework",

docs/features.rst

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
Features of `codegreen-core`
2+
=============================
3+
4+
**Gather energy production data**
5+
6+
Energy is produced from multiple sources, some of these sources are non-renewable, such as fossil fuels and coal, and others are renewable, like wind and solar. The combination of energy produced from different sources (or the energy mix) varies from country to country and season to season. The amount of carbon emissions generated from energy production depends on this energy mix. When more energy is derived from renewable sources, carbon emissions are lower, making the energy more 'green.' (and vice versa). This relationship is measured by carbon intensity, which quantifies the amount of carbon dioxide emitted per unit of energy produced.
7+
8+
The codegreen-core package offers tools to collect time series data of the energy mix for various countries, which can also be used to calculate the carbon intensity of energy.
9+
10+
.. image:: _static/DE_1.png
11+
:alt: Germany example 1
12+
:width: 600px
13+
:align: center
14+
15+
The figure above shows the percentage of energy generated from renewable (green) and non renewable (red) sources in Germany on 1st and 2nd June 2024.
16+
17+
This data helps analyze the energy production in a country over a period of time to identify patterns and compare energy data for multiple countries.
18+
19+
.. image:: _static/multiple_2.png
20+
:alt: Multiple example 1
21+
:width: 800px
22+
:align: center
23+
24+
The figure above shows the percentage of energy generated from renewable sources in four countries (Germany, France, Italy, and Spain) from June 1 to June 24, 2024.
25+
26+
An interesting observation is that the amount of green energy changes almost every hour. This presents two approaches to reducing carbon emissions:
27+
28+
- **Time Shifting**: Adjusting the timing of computations to align with periods of greater availability of green energy.
29+
- **Location Shifting**: Moving computational tasks to locations that utilize more green energy.
30+
31+
32+
**Calculating carbon emission of a computational task**
33+
34+
Given the time taken by a computational task, the location where it was performed, and the hardware specifications (number of cores/GPUs used and size of memory), the codegreen-core package provides an estimate of the carbon emissions produced by the task
35+
36+
37+
.. image:: _static/CE_DE_1.png
38+
:alt: CE DE example 1
39+
:width: 600px
40+
:align: center
41+
42+
The figure above shows the carbon emissions produced by a 12-hour computational task performed on 124 cores with 64 GB of memory in Germany
43+
44+
45+
**Predicting the optimal time/location to start the computational task**
46+
47+
Given the approximate run time of the task, the hardware specifications, the location, and a specified criteria, `codegreen-core` predicts an optimal time based on energy production forecast data. It is designed to be fault-tolerant, and if no optimal time exists, the current time is returned. The user provides a criteria, such as the minimum percentage of renewable energy for the entire duration, which is used to predict the optimal time.
48+
49+
.. image:: _static/optimal_it_1.png
50+
:alt: optimal eg 1
51+
:width: 800px
52+
:align: center
53+
54+
The figure above shows the carbon emissions produced by an 8-hour computational task performed on 124 cores with 64 GB of memory in Italy, along with the potential savings in carbon emissions when the computation is started at suggested times using three different criteria (values of percentage renewable energy).
55+
56+
..
57+
// Challenges and future plans
58+
// One of the main challenges is the availability of time series of energy produced using renewable and non renewable sources for different coutnreis. The current energy forecasts are also limited to the next 24 hours which limits the optimal time decitions within the next 24 hours. In future, we plan to integrate data for Non EU counties as well as train predication models that can generate time series forecasts of for longer periods of time.

docs/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Welcome to codegreen_core's documentation!
1111
:caption: Contents:
1212

1313
introduction
14-
methodology
15-
getting_started
16-
api
14+
features
15+
installation
16+
setup
17+
api
1718
status
19+
methodology
1820
references
19-
version_history
20-
21-
21+
version_history

docs/installation.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Installation
2+
==============
3+
4+
You can install the package using pip :
5+
6+
.. code-block:: python
7+
8+
pip install codegreen_core
9+
10+
Alternatively, you can clone the Git repository and install the package manually:
11+
12+
.. code-block:: bash
13+
14+
git clone https://github.com/codegreen-framework/codegreen-core.git
15+
pip install -e .

docs/introduction.rst

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,3 @@ The carbon footprint of a computer depends on two main factors : its hardware sp
1111

1212
The `codegreen-core` package is a comprehensive tool that enables users to calculate the carbon emissions of a computational task and provides strategies for minimizing those emissions.
1313

14-
Features of `codegreen-core`
15-
-----------------------------
16-
17-
**Gather energy production data**
18-
19-
Energy is produced from multiple sources, some of these sources are non-renewable, such as fossil fuels and coal, and others are renewable, like wind and solar. The combination of energy produced from different sources (or the energy mix) varies from country to country and season to season. The amount of carbon emissions generated from energy production depends on this energy mix. When more energy is derived from renewable sources, carbon emissions are lower, making the energy more 'green.' (and vice versa). This relationship is measured by carbon intensity, which quantifies the amount of carbon dioxide emitted per unit of energy produced.
20-
21-
The codegreen-core package offers tools to collect time series data of the energy mix for various countries, which can also be used to calculate the carbon intensity of energy.
22-
23-
.. image:: _static/DE_1.png
24-
:alt: Germany example 1
25-
:width: 600px
26-
:align: center
27-
28-
The figure above shows the percentage of energy generated from renewable (green) and non renewable (red) sources in Germany on 1st and 2nd June 2024.
29-
30-
This data helps analyze the energy production in a country over a period of time to identify patterns and compare energy data for multiple countries.
31-
32-
.. image:: _static/multiple_2.png
33-
:alt: Multiple example 1
34-
:width: 800px
35-
:align: center
36-
37-
The figure above shows the percentage of energy generated from renewable sources in four countries (Germany, France, Italy, and Spain) from June 1 to June 24, 2024.
38-
39-
An interesting observation is that the amount of green energy changes almost every hour. This presents two approaches to reducing carbon emissions:
40-
41-
- **Time Shifting**: Adjusting the timing of computations to align with periods of greater availability of green energy.
42-
- **Location Shifting**: Moving computational tasks to locations that utilize more green energy.
43-
44-
45-
**Calculating carbon emission of a computational task**
46-
47-
Given the time taken by a computational task, the location where it was performed, and the hardware specifications (number of cores/GPUs used and size of memory), the codegreen-core package provides an estimate of the carbon emissions produced by the task
48-
49-
50-
.. image:: _static/CE_DE_1.png
51-
:alt: CE DE example 1
52-
:width: 600px
53-
:align: center
54-
55-
The figure above shows the carbon emissions produced by a 12-hour computational task performed on 124 cores with 64 GB of memory in Germany
56-
57-
58-
**Predicting the optimal time/location to start the computational task**
59-
60-
Given the approximate run time of the task, the hardware specifications, the location, and a specified criteria, `codegreen-core` predicts an optimal time based on energy production forecast data. It is designed to be fault-tolerant, and if no optimal time exists, the current time is returned. The user provides a criteria, such as the minimum percentage of renewable energy for the entire duration, which is used to predict the optimal time.
61-
62-
.. image:: _static/optimal_it_1.png
63-
:alt: optimal eg 1
64-
:width: 800px
65-
:align: center
66-
67-
The figure above shows the carbon emissions produced by an 8-hour computational task performed on 124 cores with 64 GB of memory in Italy, along with the potential savings in carbon emissions when the computation is started at suggested times using three different criteria (values of percentage renewable energy).
68-
69-
70-
71-
..
72-
// Challenges and future plans
73-
// One of the main challenges is the availablilty of time series of energy produced using renewable and non renewable sources for different coutnreis. The current energy forecasts are also limited to the next 24 hours which limits the optimal time decitions within the next 24 hours. In future, we plan to integrate data for Non EU counties as well as train predication models that can generate time series forecasts of for longer periods of time.
74-
75-
Next step
76-
----------
77-
78-
See the Getting started guide for installation and setup.

docs/methodology.rst

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,7 @@
11
Methodology
22
============
33

4-
Here we describe how we calcualte stuff
5-
6-
7-
8-
``tools`` Module
9-
------------------
10-
11-
This subpackage provides tools and methods for tasks like calculating the carbon intensity of energy production and calculating the emissions produced due to a computation.
12-
13-
Each tool is implemented in a separate module and must be imported individually (See below).
14-
15-
..
16-
Methods vary depending on the type of input (e.g, country name vs energy data) and the output (e.g single value vs time series DataFrame). Most tools depend on the data from the `data` sub package.
17-
As a convention, methods that primarily accept DataFrame as an input (along with other parameters) and return a DataFrame are prefixed with `_df`.
18-
19-
20-
4+
This page describes the working of various tools and how they compute values.
215

226
Carbon Intensity of Energy
237
---------------------------

docs/setup.rst

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
Setting up the package
2+
=======================
3+
4+
The package requires a configuration file where all settings are defined.
5+
Create a new file named `.codegreencore.config` in your root directory or project root.
6+
This file will contain all the configurations required to run the package successfully.
7+
8+
This section describes how to set up the package.
9+
10+
Configuration options available
11+
--------------------------------
12+
13+
The table below summarizes all available configs :
14+
15+
.. list-table:: Available Configuration Options
16+
:header-rows: 1
17+
:widths: 20 50 10 20
18+
19+
* - Name
20+
- Description
21+
- Default
22+
- Possible Values
23+
* - `ENTSOE_token`
24+
- The token required to fetch data from the ENTSO-E portal. Follow the steps at https://transparency.entsoe.eu to create a free account and obtain an API token.
25+
- None
26+
- String
27+
* - `default_energy_mode`
28+
- Defines the source of energy forecasts to be used for making optimal time predictions
29+
- public_data
30+
- public_data / local_prediction
31+
* - `enable_energy_caching`
32+
- Enables or disables local caching of energy data
33+
- false
34+
- true/false
35+
* - `energy_redis_path`
36+
- Path to Redis instance for caching
37+
- None
38+
- String (Redis URL, redis://localhost:6379 )
39+
* - `enable_offline_energy_generation`
40+
- To enable storing and periodic update of historical energy in csv files
41+
- false
42+
- true/false
43+
* - `offline_data_dir_path`
44+
- Path to the folder where historical energy data will be stored
45+
- None
46+
- String
47+
* - `offline_data_start_date`
48+
- The start date from which historical energy data must be downloaded and stored
49+
- None
50+
- String (`YYYY-mm-dd` format)
51+
52+
53+
54+
Basic Configuration
55+
--------------------
56+
Below is the template for the basic configuration
57+
58+
.. code-block:: bash
59+
60+
[codegreen]
61+
ENTSOE_token = token-here
62+
63+
This configuration will allow you to fetch data online and use it.
64+
It is recommended to start with the basic setup and explore the available APIs before making advanced customizations.
65+
Please refer to the above table for details about the configuration options.
66+
67+
Using predication models for energy forecasts
68+
-----------------------------------------------
69+
70+
By default we use energy data that is available from public sources. While this data is very useful, it may sometimes by inadequate to make better decisions.
71+
72+
The codegreen_core package includes built in predication models that generate energy forecasts. One advantage of our models is that we have trained different models for each country. They also provide forecasts for more that 24 hours in the future.
73+
74+
To enable the use prediction model where the package requires energy forecast data, set the `default_energy_mode` to `local_prediction`
75+
76+
Note : This feature is still under development and models may not be available for all countries. If a model is unavailable, the system will fall back to using publicly available energy data.
77+
78+
Setting up energy data caching
79+
---------------------------
80+
81+
Some methods in the tools module rely of energy data provided by the data module.
82+
By default, every time a method is called, data is fetched from online sources.
83+
To avoid repeatedly fetching the same data, the package allows storing recent energy data in a Redis cache.
84+
85+
**To enable this feature**
86+
87+
- Set `enable_energy_caching` to `true`
88+
- Provide the path to Redis cache in `energy_redis_path` configuration
89+
- Ensure that the Redis cache is running ; otherwise an exception will be thrown.
90+
91+
**How caching works**
92+
93+
Forecast data is synced in the cache whenever a method request data. The first request may take some time as it triggers the cache sync process.
94+
95+
To sync energy generation data run the following piece of code (either manually or via a CRON Job):
96+
97+
.. code-block:: python
98+
99+
from codegreen_core.data import sync_offline_data
100+
sync_offline_data(cache=True)
101+
102+
Cached data includes :
103+
104+
- Recent energy forecasts for all available countries (up to 24 hours ahead)
105+
- Recent energy production data ( last 72 hours up until 5 hours before the last sync time since different countries have different upload schedules)
106+
- Recent forecast data generated by the predication models (up to 72 hours ahead in time, if that option is enabled)
107+
108+
109+
Setting offline storage of energy data
110+
---------------------------------------
111+
112+
If you work with energy generation data for longer periods , you have the option to store it offline for quick access.
113+
The package supports long term storage of generation data only.
114+
115+
**To enable this feature**
116+
117+
- Set `enable_offline_energy_generation` to `true`
118+
- Provide a folder path in `offline_data_dir_path` where data will be stored.
119+
- Specify the start date from which data should be stored using `offline_data_start_date` configuration in `YYYY-MM-DD` format.
120+
121+
After configuring these settings , manually start the initial sync using following code :
122+
123+
.. code-block:: python
124+
125+
from codegreen_core.data import sync_offline_data
126+
sync_offline_data(file=True)
127+
128+
**How Offline Storage Works**
129+
130+
This setup will create initial files for each available country.
131+
Each country will have two files : A CSV file with the data and JSON containing metadata for easier syncing.
132+
Syncing may take time depending on the selected start date.
133+
134+
If you want to back fill data from an earlier time, modify `offline_data_start_date`
135+
136+
137+
**Keeping offline storage up-to-date**
138+
139+
Date files needs to be updated with latest data regularly. You can update them manually (by running the above command) or set up a CRON job to call the sync method periodically
140+
141+
142+
143+
**Using Preprocessed Data for Faster Setup**
144+
145+
Since initial setup can take a long time, you can also download preprocessed data from our Github repo and use it as a starting point.
146+
147+
Steps :
148+
149+
- Download the zip file
150+
- Extract the folder and place the data in the desired location
151+
- Update the config file if required (`offline_data_dir_path` and `offline_data_start_date`)
152+
- Run the sync code to ensure the files are updated with the latest available data.
153+
154+
Available preprocessed data:
155+
156+
- Data since Jan 1, 2025 : Link to the zip file https://github.com/codegreen-framework/energy-data/raw/refs/heads/main/2025.zip
157+
- Data since Jan 1, 2020 : Under development
File renamed without changes.

0 commit comments

Comments
 (0)