Skip to content

Commit 738d088

Browse files
authored
Merge pull request #232 from Baltic-RCC/dev
Dev to prod release
2 parents 58c8e3a + c97420a commit 738d088

File tree

9 files changed

+123
-145
lines changed

9 files changed

+123
-145
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "pypi"
66
[packages]
77
pandas = "2.2.2"
88
numpy = "2.0.0"
9-
pypowsybl = "1.8.1"
9+
pypowsybl = "1.9.0"
1010
aniso8601 = "*"
1111
lxml = "*"
1212
edx = "*"

Pipfile.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ FROM python:3.11 as emfos-model-retriever
66
RUN pip install --upgrade setuptools
77
RUN pip install --upgrade pip
88
RUN pip install uv
9-
#RUN pip install pipenv
9+
RUN pip install pipenv
1010

1111
# Install needed modules
1212
COPY Pipfile .
1313
COPY Pipfile.lock .
14-
COPY requirements.txt .
14+
#COPY requirements.txt .
1515
#RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
1616
#RUN pipenv install --system --deploy
17-
#RUN pipenv requirements > requirements.txt
17+
RUN pipenv requirements > requirements.txt
1818
RUN uv pip sync requirements.txt --system
1919
#RUN uv cache clean
2020

@@ -42,15 +42,15 @@ FROM python:3.11 as emfos-model-merger
4242
RUN pip install --upgrade setuptools
4343
RUN pip install --upgrade pip
4444
RUN pip install uv
45-
#RUN pip install pipenv
45+
RUN pip install pipenv
4646

4747
# Install needed modules
4848
COPY Pipfile .
4949
COPY Pipfile.lock .
50-
COPY requirements.txt .
50+
#COPY requirements.txt .
5151
#RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy
5252
#RUN pipenv install --system --deploy
53-
#RUN pipenv requirements > requirements.txt
53+
RUN pipenv requirements > requirements.txt
5454
RUN uv pip sync requirements.txt --system
5555
#RUN uv cache clean
5656

emf/common/integrations/elastic.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def send_to_elastic_bulk(index: str,
121121
data=(ndjson.dumps(json_message_list[batch:batch + batch_size])+"\n").encode(),
122122
timeout=None,
123123
headers={"Content-Type": "application/x-ndjson"})
124+
if json.loads(response.content).get('errors'):
125+
logger.error(f"Send to elasticsearch responded with errors: {response.text}")
124126
if debug:
125127
logger.debug(f"ELK response: {response.content}")
126128
response_list.append(response.ok)
@@ -219,15 +221,12 @@ def __init__(self,
219221
self.session.auth = auth
220222

221223
def handle(self, byte_string, properties):
222-
223-
Elastic.send_to_elastic_bulk(index=self.index,
224-
json_message_list=json.loads(byte_string),
225-
id_from_metadata=self.id_from_metadata,
226-
id_metadata_list=self.id_metadata_list,
227-
server=self.server,
228-
debug=self.debug)
229-
230-
# TODO add support for properties argument
224+
response = Elastic.send_to_elastic_bulk(index=self.index,
225+
json_message_list=json.loads(byte_string),
226+
id_from_metadata=self.id_from_metadata,
227+
id_metadata_list=self.id_metadata_list,
228+
server=self.server,
229+
debug=self.debug)
231230

232231

233232
if __name__ == '__main__':

emf/loadflow_tool/helper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ def get_slack_generators(network: pypowsybl.network):
234234
return slack_generators
235235

236236

237-
def get_connected_components_data(network: pypowsybl.network, bus_count_threshold: int | None = None,
238-
country_name: str = 'country'):
237+
def get_connected_components_data(network: pypowsybl.network,
238+
bus_count_threshold: int | None = None,
239+
country_col_name: str = 'country'):
239240
buses = get_network_elements(network, pypowsybl.network.ElementType.BUS)
240-
data = buses.groupby('connected_component').agg(countries=(country_name, lambda x: list(x.unique())),
241+
data = buses.groupby('connected_component').agg(countries=(country_col_name, lambda x: list(x.unique())),
241242
bus_count=('name', 'size'))
242243
if bus_count_threshold:
243244
data = data[data.bus_count > bus_count_threshold]

emf/loadflow_tool/loadflow_settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@
119119
}
120120

121121
__CGM_RELAXED_2_PROVIDER = {
122-
'loadPowerFactorConstant': 'False', # cim:PowerFlowSettings.loadVoltageDependency "false" ; TODO - check this
122+
# 'loadPowerFactorConstant': 'False', # cim:PowerFlowSettings.loadVoltageDependency "false" ; TODO - check this
123+
'loadPowerFactorConstant': 'True',
123124
'maxOuterLoopIterations': '30', # eumd:PowerFlowSettings.maxIterationNumber "30"
124125
'lowImpedanceThreshold': '1.0E-5', # cim:PowerFlowSettings.impedanceThreshold "1e-05" ;
125126
'newtonRaphsonStoppingCriteriaType': 'PER_EQUATION_TYPE_CRITERIA',
@@ -214,7 +215,8 @@
214215
read_slack_bus=True,
215216
write_slack_bus=False,
216217
distributed_slack=True, # cim:PowerFlowSettings.slackDistributionKind cim:SlackDistributionKind.generationDistributionActivePowerAndVoltageNodesOnly ;
217-
balance_type=pypowsybl._pypowsybl.BalanceType.PROPORTIONAL_TO_GENERATION_REMAINING_MARGIN, #cim:PowerFlowSettings.slackDistributionKind cim:SlackDistributionKind.generationDistributionActivePowerAndVoltageNodesOnly ;
218+
# balance_type=pypowsybl._pypowsybl.BalanceType.PROPORTIONAL_TO_GENERATION_REMAINING_MARGIN, #cim:PowerFlowSettings.slackDistributionKind cim:SlackDistributionKind.generationDistributionActivePowerAndVoltageNodesOnly ;
219+
balance_type=pypowsybl._pypowsybl.BalanceType.PROPORTIONAL_TO_CONFORM_LOAD,
218220
dc_use_transformer_ratio=None,
219221
countries_to_balance=None,
220222
connected_component_mode=pypowsybl._pypowsybl.ConnectedComponentMode.ALL,

emf/loadflow_tool/model_merger/model_merger.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,28 @@ def handle(self, task_object: dict, **kwargs):
248248
.groupby('id').agg(curve_p_min=('p', 'min'), curve_p_max=('p', 'max'))).reset_index()
249249
curve_generators = generators.merge(curve_limits, on='id')
250250
# low end can be zero
251-
curve_generators = curve_generators[(curve_generators['target_p'] > curve_generators['curve_p_max'])]
251+
curve_generators = curve_generators[(curve_generators['target_p'] > curve_generators['curve_p_max']) |
252+
((curve_generators['target_p'] > 0) &
253+
(curve_generators['target_p'] < curve_generators['curve_p_min']))]
252254
if not curve_generators.empty:
253255
logger.warning(f"Found {len(curve_generators.index)} generators for "
254-
f"which p > max(reactive capacity curve(p))")
255-
# Solution 1: set max_p from curve max, it should contain p on target_p
256-
# curve_generators['max_p'] = curve_generators['curve_p_max']
257-
# network_pre_instance.update_generators(curve_generators[['id', 'max_p']].set_index('id'))
256+
f"which p > max(reactive capacity curve(p)) or p < min(reactive capacity curve(p))")
257+
# in order this to work curve_p_min <= p_min <= target_p <= p_max <= curve_p_max
258+
# Solution 1: set max_p from curve max, it should contain p on target-p
259+
upper_limit_violated = curve_generators[
260+
(curve_generators['max_p'] > curve_generators['curve_p_max'])]
261+
if not upper_limit_violated.empty:
262+
logger.warning(f"Updating max p from curve for {len(upper_limit_violated.index)} generators")
263+
upper_limit_violated['max_p'] = upper_limit_violated['curve_p_max']
264+
network_pre_instance.update_generators(upper_limit_violated[['id', 'max_p']].set_index('id'))
265+
266+
lower_limit_violated = curve_generators[
267+
(curve_generators['min_p'] < curve_generators['curve_p_min'])]
268+
if not lower_limit_violated.empty:
269+
logger.warning(f"Updating min p from curve for {len(lower_limit_violated.index)} generators")
270+
lower_limit_violated['min_p'] = lower_limit_violated['curve_p_min']
271+
network_pre_instance.update_generators(lower_limit_violated[['id', 'min_p']].set_index('id'))
272+
258273
# Solution 2: discard generator from participating
259274
extensions = network_pre_instance.get_extensions('activePowerControl')
260275
remove_curve_generators = extensions.merge(curve_generators[['id']],

emf/loadflow_tool/model_merger/temporary_fixes.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
fix_sv_tapsteps, remove_duplicate_sv_voltages,
99
remove_small_islands,check_and_fix_dependencies,
1010
disconnect_equipment_if_flow_sum_not_zero,
11-
export_to_cgmes_zip, set_brell_lines_to_zero_in_models,
12-
configure_paired_boundarypoint_injections_by_nodes,
13-
set_brell_lines_to_zero_in_models_new)
11+
export_to_cgmes_zip,
12+
configure_paired_boundarypoint_injections_by_nodes)
1413

1514

1615
logger = logging.getLogger(__name__)
@@ -19,17 +18,7 @@
1918
def run_pre_merge_processing(input_models, merging_area):
2019

2120
# TODO warning logs for temp fix functions
22-
23-
# SET BRELL LINE VALUES
24-
if merging_area == 'BA':
25-
input_models = set_brell_lines_to_zero_in_models(input_models)
26-
2721
assembled_data = load_opdm_data(input_models)
28-
29-
# TODO try to optimize it better
30-
# if merging_area == 'BA':
31-
# assembled_data = set_brell_lines_to_zero_in_models_new(assembled_data)
32-
3322
assembled_data = triplets.cgmes_tools.update_FullModel_from_filename(assembled_data)
3423
assembled_data = configure_paired_boundarypoint_injections_by_nodes(assembled_data)
3524
escape_upper_xml = assembled_data[assembled_data['VALUE'].astype(str).str.contains('.XML')]

0 commit comments

Comments
 (0)