MCPcopy Create free account
hub / github.com/mlco2/codecarbon / DataSource

Class DataSource

codecarbon/input.py:66–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

64
65
66class DataSource:
67 def __init__(self):
68 self.config = {
69 "geo_js_url": "https://get.geojs.io/v1/ip/geo.json",
70 "cloud_emissions_path": "data/cloud/impact.csv",
71 "usa_emissions_data_path": "data/private_infra/2016/usa_emissions.json",
72 "can_energy_mix_data_path": "data/private_infra/2023/canada_energy_mix.json", # noqa: E501
73 "global_energy_mix_data_path": "data/private_infra/global_energy_mix.json", # noqa: E501
74 "carbon_intensity_per_source_path": "data/private_infra/carbon_intensity_per_source.json",
75 "cpu_power_path": "data/hardware/cpu_power.csv",
76 }
77 self.module_name = "codecarbon"
78
79 @property
80 def geo_js_url(self):
81 return self.config["geo_js_url"]
82
83 @staticmethod
84 def get_ressource_path(package: str, filepath: str):
85 file_manager = ExitStack()
86 atexit.register(file_manager.close)
87 ref = importlib_resources_files(package).joinpath(filepath)
88 path = file_manager.enter_context(importlib_resources_as_file(ref))
89 return path
90
91 @property
92 def cloud_emissions_path(self):
93 """
94 Resource Extraction from a package
95 https://setuptools.readthedocs.io/en/latest/pkg_resources.html#resource-extraction
96 """
97 return self.get_ressource_path(
98 self.module_name, self.config["cloud_emissions_path"]
99 )
100
101 @property
102 def carbon_intensity_per_source_path(self):
103 """
104 Get the path from the package resources.
105 """
106 return self.get_ressource_path(
107 self.module_name, self.config["carbon_intensity_per_source_path"]
108 )
109
110 def country_emissions_data_path(self, country: str):
111 return self.get_ressource_path(
112 self.module_name, self.config[f"{country}_emissions_data_path"]
113 )
114
115 def country_energy_mix_data_path(self, country: str):
116 return self.get_ressource_path(
117 self.module_name, self.config[f"{country}_energy_mix_data_path"]
118 )
119
120 @property
121 def global_energy_mix_data_path(self):
122 return self.get_ressource_path(
123 self.module_name, self.config["global_energy_mix_data_path"]

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…