Merged
Conversation
tbittar
requested changes
Jul 15, 2025
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(" ", "_") |
Collaborator
There was a problem hiding this comment.
Factorize all this in a function self._rename_buses()
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 |
Collaborator
There was a problem hiding this comment.
Same remark, encapsulate in a renaming function
| 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" |
Collaborator
There was a problem hiding this comment.
Why do you need a copy here ?
Collaborator
Author
There was a problem hiding this comment.
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() |
Collaborator
There was a problem hiding this comment.
Why not use test fixtures ?
Collaborator
Author
There was a problem hiding this comment.
Used above, I delete this
tbittar
approved these changes
Jul 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Small refacto to clean PyPSA converter code regarding
Preparing e2e tests with Antares