Skip to content

Pypsa e2e tests#114

Merged
tbittar merged 8 commits intomainfrom
pypsa_e2e_tests
Jul 15, 2025
Merged

Pypsa e2e tests#114
tbittar merged 8 commits intomainfrom
pypsa_e2e_tests

Conversation

@aoustry
Copy link
Collaborator

@aoustry aoustry commented Jul 15, 2025

Small refacto to clean PyPSA converter code regarding

  • Preprocessing of PyPSA object names

Preparing e2e tests with Antares

  • Delete scenario-dependency in pypsa_models
  • export timeseries also in .tsv

@aoustry aoustry requested a review from tbittar July 15, 2025 15:08
Comment on lines +178 to +190
if len(self.pypsa_network.buses) > 0:
self.pypsa_network.buses.index = self.pypsa_network.buses.index.str.replace(
" ", "_"
)
for _, val in self.pypsa_network.buses_t.items():
val.columns = val.columns.str.replace(" ", "_")
### Update the 'bus' columns for the different types of PyPSA components
for component_type in self.pypsa_components:
df = getattr(self.pypsa_network, component_type)
if len(df) > 0:
for col in ["bus", "bus0", "bus1"]:
if col in df.columns:
df[col] = df[col].str.replace(" ", "_")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factorize all this in a function self._rename_buses()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +211 to +222
if len(df) > 0:
### Rename PyPSA components, to make sure that the names are uniques (used as id in the Gems model)
prefix = component_type[:-1]
df.index = prefix + "_" + df.index.str.replace(" ", "_")
dictionnary = getattr(self.pypsa_network, component_type + "_t")
for _, val in dictionnary.items():
val.columns = prefix + "_" + val.columns.str.replace(" ", "_")
if extendable:
### Adding min and max capacities to non-extendable objects
for field in [capa_str + "_min", capa_str + "_max"]:
df.loc[df[capa_str + "_extendable"] == False, field] = df[capa_str]
df.loc[df[capa_str + "_extendable"] == False, "capital_cost"] = 0.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark, encapsulate in a renaming function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

logger.info("Converting PyPSA network to Gems format...")
input_system_from_pypsa_converter = convert_pypsa_network(
pypsa_network, systems_dir, series_dir
pypsa_network.copy(), systems_dir, series_dir, ".txt"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a copy here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pypsa_converter has side effects on the pypsa_network object (due to renaming and addition of "fictive" carrier). The PyPSA simulation - performed here to get the reference value gems should comply with - should be done with the original PyPSA object.


if __name__ == "__main__":
test_case_pypsaeur_operational()
test_case_gemspy()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use test fixtures ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used above, I delete this

@aoustry aoustry requested a review from tbittar July 15, 2025 16:13
@tbittar tbittar merged commit e1b2009 into main Jul 15, 2025
2 checks passed
@tbittar tbittar deleted the pypsa_e2e_tests branch July 15, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants