-
Notifications
You must be signed in to change notification settings - Fork 12
Feature/time series load update and sgen update #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
54cbf47
1ce4df2
6d83c3f
1f27132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,12 +46,19 @@ def __init__(self, system_frequency: float = 50.0, trafo_loading: str = "current | |||||||||||||||||||||||
| self.pgm_input_data: SingleDataset = {} | ||||||||||||||||||||||||
| self.pp_output_data: PandaPowerData = {} | ||||||||||||||||||||||||
| self.pgm_output_data: SingleDataset = {} | ||||||||||||||||||||||||
| self.pp_update_data: PandaPowerData = {} | ||||||||||||||||||||||||
| self.pgm_update_data: SingleDataset = {} | ||||||||||||||||||||||||
| self.pgm_nodes_lookup: pd.DataFrame = pd.DataFrame() | ||||||||||||||||||||||||
| self.idx: Dict[Tuple[str, Optional[str]], pd.Series] = {} | ||||||||||||||||||||||||
| self.idx_lookup: Dict[Tuple[str, Optional[str]], pd.Series] = {} | ||||||||||||||||||||||||
| self.next_idx = 0 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def _parse_data(self, data: PandaPowerData, data_type: str, extra_info: Optional[ExtraInfo] = None) -> Dataset: | ||||||||||||||||||||||||
| def _parse_data( | ||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||
| data: PandaPowerData, | ||||||||||||||||||||||||
| data_type: str, | ||||||||||||||||||||||||
| extra_info: Optional[ExtraInfo] = None, | ||||||||||||||||||||||||
| ) -> Dataset: | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| Set up for conversion from PandaPower to power-grid-model | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -65,18 +72,21 @@ def _parse_data(self, data: PandaPowerData, data_type: str, extra_info: Optional | |||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||
| Converted power-grid-model data | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Clear pgm data | ||||||||||||||||||||||||
| self.pgm_input_data = {} | ||||||||||||||||||||||||
| self.idx_lookup = {} | ||||||||||||||||||||||||
| self.next_idx = 0 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Set pandas data | ||||||||||||||||||||||||
| self.pp_input_data = data | ||||||||||||||||||||||||
| self.pgm_update_data = {} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Convert | ||||||||||||||||||||||||
| if data_type == "input": | ||||||||||||||||||||||||
| # Set pandas data | ||||||||||||||||||||||||
| self.pp_input_data = data | ||||||||||||||||||||||||
| self._create_input_data() | ||||||||||||||||||||||||
| elif data_type == "update": | ||||||||||||||||||||||||
| self.pp_update_data = data | ||||||||||||||||||||||||
| self._update_input_data() | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this function is called Alternatively, maybe it's a good moment to split the (minor) chunks of differences between |
||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||
| raise ValueError(f"Data type: '{data_type}' is not implemented") | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -115,7 +125,7 @@ def _serialize_data(self, data: Dataset, extra_info: Optional[ExtraInfo]) -> Pan | |||||||||||||||||||||||
| def pgm_output_dtype_checker(check_type: str) -> bool: | ||||||||||||||||||||||||
| return all( | ||||||||||||||||||||||||
| ( | ||||||||||||||||||||||||
| comp_array.dtype == power_grid_meta_data[check_type][component] | ||||||||||||||||||||||||
| comp_array.dtype == power_grid_meta_data[check_type][component]["dtype"] | ||||||||||||||||||||||||
| for component, comp_array in self.pgm_output_data.items() | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
|
@@ -247,7 +257,7 @@ def _extra_info_to_pgm_input_data(self, extra_info: ExtraInfo): # pylint: disab | |||||||||||||||||||||||
| nan = np.iinfo(dtype).min | ||||||||||||||||||||||||
| all_other_cols = ["i_n"] | ||||||||||||||||||||||||
| for component, data in self.pgm_output_data.items(): | ||||||||||||||||||||||||
| input_cols = power_grid_meta_data["input"][component].dtype.names | ||||||||||||||||||||||||
| input_cols = power_grid_meta_data["input"][component]["dtype"].names | ||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this a bug? or a deprecated feature of structured arrays? the original one feels more correct but i could be wrong |
||||||||||||||||||||||||
| node_cols = [col for col in input_cols if NODE_REF_RE.fullmatch(col)] | ||||||||||||||||||||||||
| other_cols = [col for col in input_cols if col in all_other_cols] | ||||||||||||||||||||||||
| if not node_cols + other_cols: | ||||||||||||||||||||||||
|
|
@@ -332,6 +342,10 @@ def _create_output_data_3ph(self): | |||||||||||||||||||||||
| self._pp_asym_gens_output_3ph() | ||||||||||||||||||||||||
| self._pp_asym_loads_output_3ph() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def _update_input_data(self): | ||||||||||||||||||||||||
| self._pp_update_loads() | ||||||||||||||||||||||||
| self._pp_update_sgens() | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| def _create_pgm_input_nodes(self): | ||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
| This function converts a Bus Dataframe of PandaPower to a power-grid-model Node input array. | ||||||||||||||||||||||||
|
|
@@ -2045,6 +2059,273 @@ def _pp_asym_gens_output_3ph(self): | |||||||||||||||||||||||
| assert "res_asymmetric_sgen_3ph" not in self.pp_output_data | ||||||||||||||||||||||||
| self.pp_output_data["res_asymmetric_sgen_3ph"] = pp_output_asym_gens_3ph | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # pylint: disable-msg=too-many-locals | ||||||||||||||||||||||||
| def _pp_update_loads(self): # pragma: no cover | ||||||||||||||||||||||||
| pp_upd_data = self.pp_update_data["controller"]["object"] | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| scaling = self._get_pp_attr("load", "scaling", 1.0) | ||||||||||||||||||||||||
| all_load_ids = self.pp_update_data["load"].index.values | ||||||||||||||||||||||||
| const_i_multiplier = self._get_pp_attr("load", "const_i_percent", 0) * scaling * (1e-2 * 1e6) | ||||||||||||||||||||||||
| const_z_multiplier = self._get_pp_attr("load", "const_z_percent", 0) * scaling * (1e-2 * 1e6) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| const_i_multiplier = self._get_pp_attr("load", "const_i_percent", 0) * scaling * (1e-2 * 1e6) | |
| const_z_multiplier = self._get_pp_attr("load", "const_z_percent", 0) * scaling * (1e-2 * 1e6) | |
| const_i_multiplier = self._get_pp_attr("load", "const_i_percent", 0) * scaling * 1e4 | |
| const_z_multiplier = self._get_pp_attr("load", "const_z_percent", 0) * scaling * 1e4 |
or split the coefficients, e.g. (but please clean up a bit by reordening):
| const_i_multiplier = self._get_pp_attr("load", "const_i_percent", 0) * scaling * (1e-2 * 1e6) | |
| const_z_multiplier = self._get_pp_attr("load", "const_z_percent", 0) * scaling * (1e-2 * 1e6) | |
| percent = 1e-2 | |
| unit_magnitude = 1e6 | |
| scaling *= unit_magnitude | |
| const_i_multiplier = self._get_pp_attr("load", "const_i_percent", 0) * percent * scaling | |
| const_z_multiplier = self._get_pp_attr("load", "const_z_percent", 0) * percent * scaling |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it need to be a set in the first place? why not start with a list? or, if it should be a set, there's probably a problem somewhere down the line 😄
For instance, i don't know if _get_timeseries_load_ids wants a list as input. If so, either start with a list or convert to list there.
If you really need the uniqueness feature of set, as well as use the list output in multiple places, then please update the comment instead
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: remove before merge (you can always re-add later)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: probably a good idea to split in separate functions if it complains about this
(note: i understand why it's still in there, so no hurry. i just add this comment for reference)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now, it always
returnsself.pgm_input_data. I think it should returnself.pgm_update_datawhen thedata_type == "update", right?