Skip to content

Commit e7e6f2c

Browse files
HinetziedactedSaboniAmine
authored andcommitted
Add caching for Nordic country energy mix data
- Load and cache Nordic country energy mix data in _load_static_data() - Add get_nordic_country_energy_mix_data() method to retrieve cached data - This addresses the caching performance request in PR #1039
1 parent b77f3a6 commit e7e6f2c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

codecarbon/input.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def _load_static_data() -> None:
5454
_CACHE["cpu_power"] = pd.read_csv(path)
5555

5656

57+
# Nordic country energy mix - used for emissions calculations
58+
path = _get_resource_path("data/private_infra/nordic_country_energy_mix.json")
59+
with open(path) as f:
60+
_CACHE["nordic_country_energy_mix"] = json.load(f)
61+
5762
# Load static data at module import
5863
_load_static_data()
5964

@@ -182,6 +187,13 @@ def get_cpu_power_data(self) -> pd.DataFrame:
182187
"""
183188
return _CACHE["cpu_power"]
184189

190+
def get_nordic_country_energy_mix_data(self) -> Dict:
191+
"""
192+
Returns Nordic Country Energy Mix Data.
193+
Data is cached on first access per country.
194+
"""
195+
return _CACHE["nordic_country_energy_mix"]
196+
185197

186198
class DataSourceException(Exception):
187199
pass

0 commit comments

Comments
 (0)