Skip to content

Commit 9b7445d

Browse files
adjusted aggregated forks of superpipes. the last and first forks are also aggregated, if they are not already. added removed_con_prod_forks
1 parent 4855f3b commit 9b7445d

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

dhnx/gistools/geometry_operations.py

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from shapely import geometry
4040
from shapely import ops
4141

42+
4243
def create_forks(lines):
4344
"""
4445
Creates a forks(nodes) GeoDataFrame from a "line"-GeoDataFrame
@@ -515,8 +516,8 @@ def check_crs(gdf, crs=4647):
515516

516517
return gdf
517518

518-
def aggregation(forks, pipes, consumers, producers):
519519

520+
def aggregation(forks, pipes, consumers, producers):
520521
"""
521522
This function forms a new aggregated network consisting of super forks, super pipes and super produsers
522523
Super forks are forks with less or more than two connections to DL or are connected to GL.
@@ -550,7 +551,6 @@ def aggregation(forks, pipes, consumers, producers):
550551
network_aggregation
551552
"""
552553

553-
554554
# # # 1. identify super forks
555555
# DL and GL pipes copied from pipes
556556
DLpipes = pipes.loc[pipes['type'].isin(['DL'])]
@@ -594,8 +594,6 @@ def aggregation(forks, pipes, consumers, producers):
594594
i += 1
595595
# select the current super fork (i)...
596596
superfork_i_id_full = super_forks.loc[i]['id_full']
597-
# ... and add to the aggregated forks
598-
aggregated_forks.append(superfork_i_id_full)
599597

600598
# search for consumer which are connected with super fork i
601599
aggregated_consumer_super_fork_i = []
@@ -698,9 +696,17 @@ def aggregation(forks, pipes, consumers, producers):
698696

699697
merged_segment_i_a.at[0, 'to_node'] = last_fork_segment_i_a
700698

699+
# add last and first fork, if they are not aggregated yet
700+
if superfork_i_id_full not in aggregated_forks:
701+
aggregated_forks.append(superfork_i_id_full)
702+
aggregated_forks_segment_i_a.append(superfork_i_id_full)
703+
704+
if last_fork_segment_i_a not in aggregated_forks:
705+
aggregated_forks.append(last_fork_segment_i_a)
706+
aggregated_forks_segment_i_a.append(last_fork_segment_i_a)
701707

702-
# # add column 'aggregated_forks' # added also the last fork of a superpipe
703-
str_aggregated_forks_segment_i_a = ', '.join(aggregated_forks_segment_i_a) + ', ' + last_fork_segment_i_a
708+
# # add column 'aggregated_forks'
709+
str_aggregated_forks_segment_i_a = ', '.join(aggregated_forks_segment_i_a)
704710
merged_segment_i_a.at[0, 'aggregated_forks'] = str_aggregated_forks_segment_i_a
705711

706712
# # add column 'aggregated_pipes'
@@ -709,21 +715,23 @@ def aggregation(forks, pipes, consumers, producers):
709715

710716
# # add column 'aggregated_consumers'
711717
aggregated_consumer_segment_i_a = []
712-
aggregated_consumer_segment_i_a = HLpipes.loc[HLpipes['from_node'].isin(aggregated_forks_segment_i_a)][
718+
aggregated_consumer_segment_i_a = \
719+
HLpipes.loc[HLpipes['from_node'].isin(aggregated_forks_segment_i_a)][
713720
'to_node'].tolist()
714721
str_aggregated_consumer_segment_i_a = ', '.join(aggregated_consumer_segment_i_a)
715722
merged_segment_i_a.at[0, 'aggregated_consumer'] = str_aggregated_consumer_segment_i_a
716723

717724
# # add column 'aggregated_P_heat_max'
718725
aggregated_P_heat_max_segment_i_a = []
719726
aggregated_P_heat_max_segment_i_a = \
720-
consumers.loc[consumers['id_full'].isin(aggregated_consumer_segment_i_a)]['P_heat_max'].tolist()
727+
consumers.loc[consumers['id_full'].isin(aggregated_consumer_segment_i_a)]['P_heat_max'].tolist()
721728
sum_aggregated_P_heat_max_segment_i_a = sum(aggregated_P_heat_max_segment_i_a)
722729
merged_segment_i_a.at[0, 'P_heat_max'] = sum_aggregated_P_heat_max_segment_i_a
723730

724731
# # add column 'simultaneity factor'
725732
number_aggregated_consumer_segment_i_a = len(aggregated_consumer_segment_i_a)
726-
simultaneity_factor_segment_i_a = pow(1.05, -number_aggregated_consumer_segment_i_a) # Note: this is just a placeholder formula
733+
simultaneity_factor_segment_i_a = pow(1.05,
734+
-number_aggregated_consumer_segment_i_a) # Note: this is just a placeholder formula
727735
merged_segment_i_a.at[0, 'simultaneity factor'] = simultaneity_factor_segment_i_a
728736

729737
# add new pipe to super pipes
@@ -747,7 +755,6 @@ def aggregation(forks, pipes, consumers, producers):
747755
DLGLpipes['to_node'].isin([fork_next_segment_i_a])][
748756
'id'].tolist()
749757

750-
751758
if segment_i_a.at[b, 'id'] == list_of_connected_pipes_to_next_fork[0]:
752759
pipe_next_segment_i_a = DLGLpipes.loc[
753760
DLGLpipes['id'].isin([list_of_connected_pipes_to_next_fork[1]])]
@@ -782,7 +789,30 @@ def aggregation(forks, pipes, consumers, producers):
782789
# return
783790
return {
784791
'super_forks': super_forks,
785-
'super_consumers': consumers, # not yet defined
786-
'super_producers': producers, # not yet defined
792+
'super_consumers': consumers, # not yet defined
793+
'super_producers': producers, # not yet defined
787794
'super_pipes': super_pipes,
788795
}
796+
797+
798+
def remove_con_prod_forks(forks, consumers, producers):
799+
"""
800+
Parameters
801+
----------
802+
forks
803+
consumers
804+
producers
805+
Returns
806+
-------
807+
"""
808+
consumers["geometry_wkt"] = \
809+
consumers["geometry"].apply(lambda geom: geom.wkt)
810+
811+
producers["geometry_wkt"] = \
812+
producers["geometry"].apply(lambda geom: geom.wkt)
813+
814+
con_prod = list(producers["geometry_wkt"]) + list(consumers["geometry_wkt"])
815+
816+
forks_only = forks[forks.geometry_wkt.isin(con_prod) == False]
817+
818+
return forks_only

0 commit comments

Comments
 (0)