|
1 | 1 | .. getting_started:
|
2 | 2 |
|
3 | 3 |
|
4 |
| -Getting Started |
5 |
| -=============== |
| 4 | +How to use codegreen |
| 5 | +===================== |
6 | 6 |
|
7 |
| -Welcome to the guide for getting started with `codegreen_core`. This document provides installation instructions and the initial steps required to get the package up and running. It also outlines the package structure, which will help you choose the appropriate tools based on your needs. |
| 7 | +Welcome to the guide for getting started with the `codegreen` framework. |
| 8 | +There are four main ways to setup and use Codegreen based on your requirements. |
| 9 | +This document describes in detail the steps involved in each method. |
8 | 10 |
|
9 |
| -Installation |
10 |
| -------------- |
| 11 | +The four ways to use codegreen: |
11 | 12 |
|
12 |
| -Using pip : |
| 13 | +1. Using `codegreen.world` |
| 14 | +2. Setting up and using the `codegreen_core` package |
| 15 | +3. Setting up your own web server |
| 16 | +4. Deploying the web service using the docker container |
| 17 | + |
| 18 | + |
| 19 | +Using codegreen.world |
| 20 | +---------------------- |
| 21 | + |
| 22 | +The simplest and fastest way to use Codegreen is through our web service. |
| 23 | +This is ideal for beginners and new users looking for an easy way to reduce the carbon emissions of their computations. |
| 24 | + |
| 25 | +1. Visit `www.codegreen.world <https://www.codegreen.world>`_ |
| 26 | +2. Create and account and log in |
| 27 | +3. Generate an API token for your location and server details |
| 28 | +4. Use the "Predict Optimal Time" form to get a time prediction for starting a computation in your selected location and server. |
| 29 | + |
| 30 | + |
| 31 | +Additionally, we provide `codegreen_client`, a Python package that can automatically start your Python scripts at the optimal time. Please refer to for installation and setup guide for more details. |
| 32 | + |
| 33 | + |
| 34 | +The web service also includes a dashboard where you can track how much carbon emission you have saved in each registered location. |
| 35 | + |
| 36 | + |
| 37 | +Installing the `codegreen_core` package |
| 38 | +----------------------------------------- |
| 39 | + |
| 40 | +The `codegreen_core` Python package contains all the core functionalities of the Codegreen framework and can be used as a standalone tool. |
| 41 | +This is ideal for researchers and developers who need to gather energy data for a country and perform calculations such as carbon intensity analysis. |
| 42 | + |
| 43 | +**Step 1: Installation** |
| 44 | + |
| 45 | +You can install the package using pip : |
13 | 46 |
|
14 | 47 | .. code-block:: python
|
15 | 48 |
|
16 | 49 | pip install codegreen_core
|
17 | 50 |
|
18 |
| -You can also use clone the git repository and install the package : |
| 51 | +Alternatively, you can clone the Git repository and install the package manually: |
19 | 52 |
|
20 | 53 | .. code-block:: bash
|
21 | 54 |
|
22 | 55 | git clone https://github.com/bionetslab/codegreen-core.git
|
23 | 56 | pip install -e .
|
24 | 57 |
|
| 58 | +**Step 2 : Setting up the configuration file** |
25 | 59 |
|
26 |
| -Setup |
27 |
| -------- |
| 60 | +The package requires a configuration file where all settings are defined. Create a new file named `.codegreencore.config`` in your root directory. This file will contain all the configurations required to run the package successfully. |
28 | 61 |
|
29 |
| -After successfully installing the package, the next step is to create a configuration file: |
| 62 | +The next section describes how to set up the package based on your requirements. |
30 | 63 |
|
31 |
| -- Create a new file named `.codegreencore.config`` in your root directory. |
32 |
| -- This file will contain all the configurations required to run the package successfully. |
33 |
| -- Below is a template for the configuration file:" |
| 64 | + |
| 65 | +Configuring the `codegreen_core` package |
| 66 | +----------------------------------------- |
| 67 | + |
| 68 | +The codegreen_core package offers a wide range of functionalities and can be used in many applications. |
| 69 | + |
| 70 | +Below is the template for the basic configuration |
34 | 71 |
|
35 | 72 | .. code-block:: bash
|
36 | 73 |
|
37 | 74 | [codegreen]
|
38 | 75 | ENTSOE_token = <token>
|
39 |
| - enable_energy_caching = false |
40 |
| - energy_redis_path = <redis_path> |
41 | 76 |
|
| 77 | +This configuration allows you to fetch data online and use it. |
| 78 | +It is recommended to start with the basic setup and explore the available APIs before making advanced customizations. |
42 | 79 |
|
43 |
| -Description of the fields in configuration file: |
| 80 | +The API of the package is available :doc:`here <api>` |
44 | 81 |
|
45 |
| -- `ENTSOE_token``: The token required to fetch data from the ENTSO-E portal. Please follow the steps at https://transparency.entsoe.eu to create a free account and obtain an API token. |
46 |
| -- `enable_energy_caching``: (boolean) Indicates whether energy data used for optimal time predictions should be cached. |
47 |
| -- `energy_redis_path``: The path to the Redis server where energy data will be stored. This field is required if caching is enabled using the above option. |
| 82 | +The table below summarizes all available configs : |
48 | 83 |
|
| 84 | +.. list-table:: Available Configuration Options |
| 85 | + :header-rows: 1 |
| 86 | + :widths: 20 50 10 20 |
49 | 87 |
|
50 |
| -Package Organization |
51 |
| ---------------------- |
| 88 | + * - Name |
| 89 | + - Description |
| 90 | + - Default |
| 91 | + - Possible Values |
| 92 | + * - `ENTSOE_token` |
| 93 | + - The token required to fetch data from the ENTSO-E portal. Please follow the steps at https://transparency.entsoe.eu to create a free account and obtain an API token. |
| 94 | + - None |
| 95 | + - String |
| 96 | + * - `default_energy_mode` |
| 97 | + - To decide the source of energy forecasts to be used for making optimal time predictions |
| 98 | + - public_data |
| 99 | + - public_data / local_prediction |
| 100 | + * - `enable_energy_caching` |
| 101 | + - Enables or disables local caching of energy data |
| 102 | + - false |
| 103 | + - true/false |
| 104 | + * - `energy_redis_path` |
| 105 | + - Path to Redis instance for caching |
| 106 | + - None |
| 107 | + - String (Redis URL, redis://localhost:6379 ) |
| 108 | + * - `enable_offline_energy_generation` |
| 109 | + - To enable storing and periodic update of historical energy in csv files |
| 110 | + - false |
| 111 | + - true/false |
| 112 | + * - `offline_data_dir_path` |
| 113 | + - Path to the folder where historical energy data will be stored |
| 114 | + - None |
| 115 | + - String |
| 116 | + * - `offline_data_start_date` |
| 117 | + - The start date from which historical energy data must be downloaded and stored |
| 118 | + - None |
| 119 | + - String (`YYYY-mm-dd` format) |
52 | 120 |
|
53 |
| -.. image:: _static/modules.png |
54 |
| - :alt: modules |
55 |
| - :width: 400px |
56 |
| - :align: center |
| 121 | +**Which data is used to predict optimal computation start time ?** |
57 | 122 |
|
| 123 | +One of the main features of the `codegreen_core` package is the ability to calculate the optimal time for running a computation. |
| 124 | +This calculation depends on forecasts of hourly energy generation data from renewable and non-renewable sources or time series forecasts of the carbon intensity of future energy production. |
58 | 125 |
|
59 |
| -The package is divided into two main sub packages: `data`` and `tools`. (There is also an additional module, `utilities`, which provides helper methods that support other modules.) |
| 126 | +While this data is available for some countries, it is typically only provided for short durations (usually 24 hours or less), which limits the accuracy of optimal time predictions. |
| 127 | +To address this limitation, we have trained prediction models that generate time series forecasts for longer periods, allowing for more effective optimization. |
60 | 128 |
|
61 |
| -The `data` sub package contains methods for fetching energy production data. This package relies on external data sources to retrieve this information, which is then processed to make it usable by other components of the package. For more details and a complete API , see the data module documentation. |
| 129 | +This setting is controlled by the `default_energy_mode` option. **By default**, the package uses publicly available energy data. To use the trained prediction models (if available for a specific country), set `default_energy_mode` to `local_prediction`. |
62 | 130 |
|
63 |
| -The `tools` sub package provides a variety of tools, including: |
| 131 | +**How to enable caching of recent energy data?** |
64 | 132 |
|
65 |
| -- Carbon intensity calculator |
66 |
| -- Carbon emission calculator |
67 |
| -- Optimal time-shifting predictor |
68 |
| -- Optimal location-shifting predictor |
| 133 | +Certain tools, such as `predict_optimal_time`, rely on recent energy forecasts / predictions. Fetching the same data multiple times can be avoided by intelligently caching it and updating it at regular intervals. |
| 134 | +Energy data caching can be enabled by setting `enable_energy_caching` to `true`. |
69 | 135 |
|
70 |
| -For more information, refer to the `tools` module documentation. |
| 136 | +Additionally, this requires a connection to Redis, which is specified using the `energy_redis_path` setting. |
| 137 | +When caching is enabled, the package first attempts to connect to Redis before storing or retrieving data. |
71 | 138 |
|
| 139 | +Once enabled, two types of data values are stored in the cache for each available country: |
72 | 140 |
|
73 |
| -Example : Calculating optimal time for a computational task |
74 |
| -------------------------------------------------------------- |
75 |
| -Assuming all the above steps are done, you can now calculate the optimal starting time for a computations. |
| 141 | +1. **Hourly time series forecasts** for the upcoming hours. |
| 142 | +2. **Actual energy generation data** for the past 72 hours. |
76 | 143 |
|
77 |
| -.. code-block:: python |
78 |
| - |
79 |
| - from datetime import datetime,timedelta |
80 |
| - from codegreen_core.tools.loadshift_time import predict_now |
81 |
| -
|
82 |
| - country_code = "DK" |
83 |
| - est_runtime_hour = 10 |
84 |
| - est_runtime_min = 0 |
85 |
| - now = datetime.now() |
86 |
| - hard_finish_date = now + timedelta(days=1) |
87 |
| - criteria = "percent_renewable" |
88 |
| - per_renewable = 50 |
89 |
| -
|
90 |
| - time = predict_now(country_code, |
91 |
| - est_runtime_hour, |
92 |
| - est_runtime_min, |
93 |
| - hard_finish_date, |
94 |
| - criteria, |
95 |
| - per_renewable) |
96 |
| - # (1728640800.0, <Message.OPTIMAL_TIME: 'OPTIMAL_TIME'>, 76.9090909090909) |
97 |
| - |
| 144 | + |
| 145 | +**How to download and use historical energy generation data offline?** |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | +**How to re-train prediction models ?** |
| 150 | +TODO |
| 151 | + |
| 152 | + |
| 153 | +Setting up your own web server |
| 154 | +-------------------------------- |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +Deploying the web server using the docker image |
| 159 | +----------------------------------------------- |
0 commit comments