fix: replace id with name in node attributes

This commit is contained in:
Majid Rezaei 2024-07-31 17:38:17 -04:00
parent 34f3ed9a11
commit cf117e9896
3 changed files with 360 additions and 121 deletions

14
main.py
View File

@ -23,7 +23,8 @@ import hub.helpers.constants as cte
from hub.exports.exports_factory import ExportsFactory
from scripts.pv_feasibility import pv_feasibility
import matplotlib.pyplot as plt
import numpy as np
from scripts.district_heating_network.district_heating_network_creator import DistrictHeatingNetworkCreator
from scripts.district_heating_network.road_processor import road_processor
base_path = Path(__file__).parent
dir_manager = DirectoryManager(base_path)
@ -60,6 +61,13 @@ UsageFactory('nrcan', city).enrich()
WeatherFactory('epw', city).enrich()
# EnergyPlus workflow
energy_plus_workflow(city, energy_plus_output_path)
# energy_plus_workflow(city, energy_plus_output_path)
print('test')
roads_file = road_processor(location[1], location[0], 0.001)
dhn_creator = DistrictHeatingNetworkCreator(geojson_file_path, roads_file)
network_graph = dhn_creator.run()
for node_id, attrs in network_graph.nodes(data=True):
print(f"Node {node_id} has attributes: {dict(attrs)}")

View File

@ -1,16 +1,17 @@
import json
import matplotlib.pyplot as plt
from shapely.geometry import Polygon, Point, LineString
import networkx as nx
from typing import List, Tuple
from rtree import index
import math
import logging
import matplotlib.pyplot as plt
import networkx as nx
from shapely.geometry import Polygon, Point, LineString
from typing import List, Tuple
from rtree import index
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.getLogger('numexpr').setLevel(logging.ERROR)
def haversine(lon1, lat1, lon2, lat2):
"""
Calculate the great-circle distance between two points
@ -126,6 +127,7 @@ class DistrictHeatingNetworkCreator:
"""
Find the nearest point on each closest road for each centroid.
"""
def find_nearest_point_on_line(point: Point, line: LineString) -> Point:
return line.interpolate(line.project(point))
@ -151,6 +153,7 @@ class DistrictHeatingNetworkCreator:
"""
Break down roads into segments connecting nearest points.
"""
def break_down_roads(closest_roads: List[LineString], nearest_points_list: List[Point]) -> List[LineString]:
new_segments = []
for road in closest_roads:
@ -190,6 +193,7 @@ class DistrictHeatingNetworkCreator:
"""
Create a Minimum Spanning Tree (MST) from the graph.
"""
def find_paths_between_nearest_points(g: nx.Graph, nearest_points: List[Point]) -> List[Tuple]:
edges = []
for i, start_point in enumerate(nearest_points):
@ -282,7 +286,10 @@ class DistrictHeatingNetworkCreator:
for i, centroid in enumerate(self.centroids):
centroid_tuple = (centroid.x, centroid.y)
building_name = self.building_names[i]
self.final_mst.add_node(centroid_tuple, type='building', id=building_name)
# Add the centroid node with its attributes
self.final_mst.add_node(centroid_tuple, type='building', name=building_name)
nearest_point = None
min_distance = float('inf')
for node in self.final_mst.nodes():

File diff suppressed because one or more lines are too long