Skip to content

Commit 58fab06

Browse files
committed
added basic tests on duplicates and technology_compositions
1 parent 4b01ca2 commit 58fab06

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mescal/esm.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,27 @@ def check_inputs(self) -> None:
183183
techno_compositions = self.technology_compositions
184184
tech_specifics = self.tech_specifics
185185

186+
dict_df_names = {
187+
'model': model,
188+
'mapping': mapping,
189+
'mapping_esm_flows_to_CPC_cat': mapping_esm_flows_to_CPC_cat,
190+
'unit_conversion': unit_conversion,
191+
'efficiency': efficiency,
192+
'lifetime': lifetime,
193+
'tech_specifics': tech_specifics,
194+
'technology_compositions': techno_compositions,
195+
}
196+
186197
try:
187198
self.technology_compositions.Components = self.technology_compositions.Components.apply(ast.literal_eval)
188199
except ValueError:
189200
pass
190201

202+
# Check for duplicates in all dataframes
203+
for df_name, df in dict_df_names.items():
204+
if df.duplicated().any():
205+
print(f"Warning: there are duplicates in the {df_name} dataframe. Please check your inputs.")
206+
191207
# Check if the technologies and resources in the model file are in the mapping file
192208
set_in_model_and_not_in_mapping = set()
193209
for tech_or_res in list(model.Name.unique()):
@@ -275,6 +291,18 @@ def check_inputs(self) -> None:
275291
f"(this will not be a problem in the workflow).\n")
276292
print(f"--> {sorted(set_in_tech_specifics_and_not_in_mapping)}\n")
277293

294+
# Check that sub-technologies in the technology_compositions file are in the mapping file
295+
set_sub_techs_not_in_mapping = set()
296+
for tech in list(techno_compositions.Name):
297+
sub_techs = [sub_tech for sub_tech in self.technology_compositions.Components
298+
if sub_tech not in list(mapping.Name)]
299+
if len(sub_techs) > 0:
300+
set_sub_techs_not_in_mapping.add(tech)
301+
if len(set_sub_techs_not_in_mapping) > 0:
302+
print(f"List of technologies that are in the technology_compositions file but not in the mapping file "
303+
f"(this will not be a problem in the workflow).\n")
304+
print(f"--> {sorted(set_sub_techs_not_in_mapping)}\n")
305+
278306
def create_esm_database(
279307
self,
280308
return_database: bool = False,

0 commit comments

Comments
 (0)