Skip to content

Commit 806eb73

Browse files
HinetziedactedSaboniAmine
authored andcommitted
Refactor emissions.py to use cached Nordic energy mix data
- Replace direct JSON file loading with cached data retrieval - Use self._data_source.get_nordic_country_energy_mix_data() method - Improves performance by eliminating repeated file I/O operations - Part of implementation for PR #1039 reviewer feedback
1 parent e7e6f2c commit 806eb73

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

codecarbon/core/emissions.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,8 @@ def get_private_infra_emissions(self, energy: Energy, geo: GeoMetadata) -> float
183183
nordic_regions = ["SE1", "SE2", "SE3", "SE4", "NO1", "NO2", "NO3", "NO4", "NO5", "FI"]
184184
if geo.region is not None and geo.region.upper() in nordic_regions:
185185
try:
186-
import json
187-
from pathlib import Path
188-
nordic_file = Path(__file__).parent.parent / "data" / "private_infra" / "nordic_emissions.json"
189-
with open(nordic_file, 'r') as f:
190-
nordic_data = json.load(f)
186+
# Get Nordic energy mix data from cache
187+
nordic_data = self._data_source.get_nordic_country_energy_mix_data() nordic_data = json.load(f)
191188
region_data = nordic_data["data"].get(geo.region.upper())
192189
if region_data:
193190
emission_factor_g = region_data["emission_factor"] # gCO2eq/kWh

0 commit comments

Comments
 (0)