You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit introduces a new configuration option, `custom_carbon_intensity_g_co2e_kwh`,
allowing you to specify a direct carbon intensity value (in gCO2e/kWh) for your
energy consumption.
When this value is provided (either via the `.codecarbon.config` file or the
`CODECARBON_CUSTOM_CARBON_INTENSITY_G_CO2E_KWH` environment variable),
it overrides all other methods of determining carbon intensity, including
cloud provider data, CO2 Signal API, and default geographical energy mixes.
Key changes include:
- Modifications to `codecarbon/core/config.py` to recognize the new
configuration parameter (though existing mechanisms were largely sufficient).
- Updates to `codecarbon/emissions_tracker.py` (specifically
`BaseEmissionsTracker`) to read, validate (must be a positive float),
and pass the custom intensity to the `Emissions` class.
- Updates to `codecarbon/core/emissions.py` to use this custom intensity
value in `get_cloud_emissions` and `get_private_infra_emissions` if provided,
bypassing other data lookups.
- Comprehensive unit tests added to:
- `tests/core/test_config.py` for configuration loading.
- `tests/test_tracker.py` for validation and initialization logic in
`BaseEmissionsTracker`.
- `tests/core/test_emissions.py` for the `Emissions` class calculation
logic using the custom value and fallback mechanisms.
This feature provides you with greater flexibility and accuracy in
reporting emissions, especially for on-premise setups with specific energy
mixes or when default data sources are not representative.
0 commit comments