(WIP) feature: add pipe sizing to dhn analysis

This commit is contained in:
Majid Rezaei 2024-08-01 11:39:05 -04:00
parent ad2d0a86d5
commit b3ebabf6e6
3 changed files with 284 additions and 349 deletions

23
main.py
View File

@ -25,6 +25,7 @@ from scripts.pv_feasibility import pv_feasibility
import matplotlib.pyplot as plt
from scripts.district_heating_network.district_heating_network_creator import DistrictHeatingNetworkCreator
from scripts.district_heating_network.road_processor import road_processor
from scripts.district_heating_network.district_heating_factory import DistrictHeatingFactory
base_path = Path(__file__).parent
dir_manager = DirectoryManager(base_path)
@ -61,7 +62,7 @@ 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)
roads_file = road_processor(location[1], location[0], 0.001)
@ -69,5 +70,21 @@ 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)}")
DistrictHeatingFactory(
city,
network_graph,
60,
40,
0.8
).enrich()
DistrictHeatingFactory(
city,
network_graph,
60,
40,
0.8
).sizing()
for u, v, attributes in network_graph.edges(data=True):
print(f"Edge between {u} and {v} with attributes: {attributes}")

View File

@ -1,20 +1,26 @@
import networkx as nx
import logging
import CoolProp as CP
import math
class DistrictHeatingFactory:
"""
DistrictHeatingFactory class
"""
def __init__(self, city, graph):
def __init__(self, city, graph, supply_temperature, return_temperature, simultaneity_factor):
self._city = city
self._network_graph = graph
self._supply_temperature = supply_temperature
self._return_temperature = return_temperature
self.simultaneity_factor = simultaneity_factor
self.fluid = "Water"
def enrich(self):
"""
Enrich the network graph nodes with attributes from the city buildings.
Enrich the network graph nodes with the whole building object from the city buildings.
"""
for node in self._network_graph.nodes(data=True):
node_id, node_attrs = node
if node_attrs.get('type') == 'building':
@ -22,11 +28,52 @@ class DistrictHeatingFactory:
building_found = False
for building in self._city.buildings:
if building.name == building_name:
building_attrs = vars(building)
for attr, value in building_attrs.items():
if attr not in self._network_graph.nodes[node_id]:
self._network_graph.nodes[node_id][attr] = value
self._network_graph.nodes[node_id]['building_obj'] = building
building_found = True
break
if not building_found:
logging.error(msg=f"Building with name '{building_name}' not found in city.")
logging.error(msg=f"Building with name '{building_name}' not found in city.")
def sizing(self):
"""
Calculate the diameter of the pipes in the district heating network.
"""
for node in self._network_graph.nodes(data=True):
node_id, node_attrs = node
if node_attrs.get('type') == 'building':
heating_peak_load = node_attrs.get('heating_peak_load') # Adjusted key to match your data
print(heating_peak_load['year'][0])
if heating_peak_load:
# Calculate peak mass flow rate
peak_mass_flow_rate = heating_peak_load['year'][0] / CP.PropsSI('C',
'T',
(
self._supply_temperature +
self._return_temperature
) / 2,
'P',
101325,
self.fluid)
print(peak_mass_flow_rate)
# Calculate density of the fluid
density = CP.PropsSI('D', # 'D' for density
'T',
(
self._supply_temperature +
self._return_temperature
) / 2,
'P',
101325,
self.fluid)
# Set the design velocity (V)
velocity = 0.9 # m/s
# Calculate the diameter (D)
D = math.sqrt((4 * peak_mass_flow_rate) / (density * velocity * math.pi)) # m
print(D)
# Find the edge connected to the building node
for neighbor in self._network_graph.neighbors(node_id):
if not self._network_graph.nodes[neighbor].get('type') == 'building': # Ensure it's a pipe connection
self._network_graph.edges[node_id, neighbor]['diameter'] = D
logging.info(f"Diameter for edge ({node_id}, {neighbor}) set to {D} meters.")

View File

@ -6,8 +6,8 @@
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2024-07-31T21:38:47.230085Z",
"start_time": "2024-07-31T21:38:47.206748Z"
"end_time": "2024-08-02T12:57:37.696565Z",
"start_time": "2024-08-02T12:57:36.171119Z"
}
},
"source": [
@ -39,13 +39,13 @@
"import numpy as np"
],
"outputs": [],
"execution_count": 110
"execution_count": 1
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:38:47.861524Z",
"start_time": "2024-07-31T21:38:47.843529Z"
"end_time": "2024-08-02T12:57:39.137773Z",
"start_time": "2024-08-02T12:57:39.125428Z"
}
},
"cell_type": "code",
@ -68,13 +68,13 @@
],
"id": "7d895f0e4ec2b851",
"outputs": [],
"execution_count": 111
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:39:02.661096Z",
"start_time": "2024-07-31T21:38:48.727802Z"
"end_time": "2024-08-02T12:57:55.109576Z",
"start_time": "2024-08-02T12:57:40.139063Z"
}
},
"cell_type": "code",
@ -90,18 +90,18 @@
"WindowsPath('C:/Users/ab_reza/Majid/Concordia/Repositories/energy_system_modelling_workflow/input_files/output_buildings.geojson')"
]
},
"execution_count": 112,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 112
"execution_count": 3
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:39:02.992446Z",
"start_time": "2024-07-31T21:39:02.663422Z"
"end_time": "2024-08-02T12:57:56.302754Z",
"start_time": "2024-08-02T12:57:55.998185Z"
}
},
"cell_type": "code",
@ -115,26 +115,26 @@
],
"id": "c03ae7cae09d4b21",
"outputs": [],
"execution_count": 113
"execution_count": 4
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:39:03.340164Z",
"start_time": "2024-07-31T21:39:02.993466Z"
"end_time": "2024-08-02T12:57:57.451734Z",
"start_time": "2024-08-02T12:57:57.072693Z"
}
},
"cell_type": "code",
"source": "ConstructionFactory('nrcan', city).enrich()",
"id": "c7d73638802e40d9",
"outputs": [],
"execution_count": 114
"execution_count": 5
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:39:04.079698Z",
"start_time": "2024-07-31T21:39:03.342163Z"
"end_time": "2024-08-02T12:57:59.217403Z",
"start_time": "2024-08-02T12:57:58.188682Z"
}
},
"cell_type": "code",
@ -150,26 +150,26 @@
]
}
],
"execution_count": 115
"execution_count": 6
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:39:04.648022Z",
"start_time": "2024-07-31T21:39:04.081700Z"
"end_time": "2024-08-02T12:58:03.733492Z",
"start_time": "2024-08-02T12:58:03.184816Z"
}
},
"cell_type": "code",
"source": "WeatherFactory('epw', city).enrich()",
"id": "f66c01cb42c33b64",
"outputs": [],
"execution_count": 116
"execution_count": 7
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:40:39.688386Z",
"start_time": "2024-07-31T21:39:04.650024Z"
"end_time": "2024-08-02T12:59:40.634144Z",
"start_time": "2024-08-02T12:58:05.175534Z"
}
},
"cell_type": "code",
@ -183,18 +183,18 @@
"exporting:\n",
" idf exported...\n",
"\r\n",
"C:/EnergyPlusV23-2-0\\energyplus.exe --weather C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\hub\\data\\weather\\epw\\CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw --output-directory C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\out_files\\energy_plus_outputs --idd C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\hub\\exports\\building_energy\\idf_files\\Energy+.idd --expandobjects --readvars --output-prefix Laval_ C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\out_files\\energy_plus_outputs\\Laval_602570.idf\r\n",
"C:/EnergyPlusV23-2-0\\energyplus.exe --weather C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\hub\\data\\weather\\epw\\CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw --output-directory C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\out_files\\energy_plus_outputs --idd C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\hub\\exports\\building_energy\\idf_files\\Energy+.idd --expandobjects --readvars --output-prefix Laval_ C:\\Users\\ab_reza\\Majid\\Concordia\\Repositories\\energy_system_modelling_workflow\\out_files\\energy_plus_outputs\\Laval_6bc439.idf\r\n",
"\n"
]
}
],
"execution_count": 117
"execution_count": 8
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:53:14.440222Z",
"start_time": "2024-07-31T21:53:10.290860Z"
"end_time": "2024-08-02T13:07:12.099372Z",
"start_time": "2024-08-02T13:07:07.642747Z"
}
},
"cell_type": "code",
@ -211,194 +211,42 @@
"network_graph = dhn_creator.run()"
],
"id": "8403846b0831b51d",
"outputs": [
{
"ename": "AttributeError",
"evalue": "'Graph' object has no attribute 'building_names'",
"output_type": "error",
"traceback": [
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[1;31mAttributeError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[1;32mIn[121], line 11\u001B[0m\n\u001B[0;32m 8\u001B[0m dhn_creator \u001B[38;5;241m=\u001B[39m DistrictHeatingNetworkCreator(geojson_file_path, roads_file)\n\u001B[0;32m 10\u001B[0m network_graph \u001B[38;5;241m=\u001B[39m dhn_creator\u001B[38;5;241m.\u001B[39mrun()\n\u001B[1;32m---> 11\u001B[0m \u001B[43mnetwork_graph\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mbuilding_names\u001B[49m\n",
"\u001B[1;31mAttributeError\u001B[0m: 'Graph' object has no attribute 'building_names'"
]
}
],
"execution_count": 121
"outputs": [],
"execution_count": 9
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:43:05.521839Z",
"start_time": "2024-07-31T21:43:05.503748Z"
}
},
"metadata": {},
"cell_type": "code",
"source": [
"for node_id, attrs in network_graph.nodes(data=True):\n",
" print(f\"Node {node_id} has attributes: {list(attrs.keys())}\")"
],
"id": "9c4c32ed4a5b5434",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Node (-73.70263014634182, 45.52966550204674) has attributes: []\n",
"Node (-73.70252245592799, 45.52959782722166) has attributes: []\n",
"Node (-73.70277983402246, 45.52975956880018) has attributes: []\n",
"Node (-73.70292834674622, 45.52985289718704) has attributes: []\n",
"Node (-73.70299601156968, 45.52989541912497) has attributes: []\n",
"Node (-73.70304798829301, 45.52992808234479) has attributes: []\n",
"Node (-73.70315317772048, 45.52999418549968) has attributes: []\n",
"Node (-73.70322951375971, 45.530042156604246) has attributes: []\n",
"Node (-73.70334527410391, 45.53011490273612) has attributes: []\n",
"Node (-73.70388612860485, 45.530454786598085) has attributes: []\n",
"Node (-73.70321670301797, 45.53098320823811) has attributes: []\n",
"Node (-73.70309371940914, 45.53090572804479) has attributes: []\n",
"Node (-73.70336752508702, 45.53107818505422) has attributes: []\n",
"Node (-73.70300302780161, 45.53115122842582) has attributes: []\n",
"Node (-73.70298632291501, 45.53083806779961) has attributes: []\n",
"Node (-73.70284664272657, 45.53075006869057) has attributes: []\n",
"Node (-73.70282694240179, 45.530737657402696) has attributes: []\n",
"Node (-73.70268296446567, 45.530646950694454) has attributes: []\n",
"Node (-73.70262035905371, 45.53060750902034) has attributes: []\n",
"Node (-73.70250974072788, 45.53053781900757) has attributes: []\n",
"Node (-73.70248122664219, 45.530519855013075) has attributes: []\n",
"Node (-73.70237692791034, 45.53045414637121) has attributes: []\n",
"Node (-73.70241425825014, 45.52952983362164) has attributes: []\n",
"Node (-73.70258909924681, 45.53147671471601) has attributes: []\n",
"Node (-73.70246956317335, 45.531401341489406) has attributes: []\n",
"Node (-73.70281850395438, 45.53162108764596) has attributes: []\n",
"Node (-73.70235595692806, 45.53165968576366) has attributes: []\n",
"Node (-73.70235908646175, 45.53133168062488) has attributes: []\n",
"Node (-73.70226538550632, 45.5312725976791) has attributes: []\n",
"Node (-73.7022262934011, 45.531247948232114) has attributes: []\n",
"Node (-73.70218216283965, 45.53122012179686) has attributes: []\n",
"Node (-73.7020876584622, 45.53116053225497) has attributes: []\n",
"Node (-73.70208089954498, 45.53115627043355) has attributes: []\n",
"Node (-73.70195718026818, 45.531078259496624) has attributes: []\n",
"Node (-73.7019336727694, 45.53106343689135) has attributes: []\n",
"Node (-73.70183972286668, 45.53100419697237) has attributes: []\n",
"Node (-73.70182154258106, 45.53099273343045) has attributes: []\n",
"Node (-73.70170504466955, 45.530919275910655) has attributes: []\n",
"Node (-73.70169068527439, 45.5309102216234) has attributes: []\n",
"Node (-73.70191018896638, 45.53200952628766) has attributes: []\n",
"Node (-73.70343390828414, 45.5311199883841) has attributes: []\n",
"Node (-73.70308928370066, 45.53179149942939) has attributes: []\n",
"Node (-73.70154615235963, 45.53081908668964) has attributes: []\n",
"Node (-73.70149535566978, 45.53078705694076) has attributes: []\n",
"Node (-73.70139243548935, 45.530722160831516) has attributes: []\n",
"Node (-73.70235555653572, 45.5304406823149) has attributes: []\n",
"Node (-73.70223631048641, 45.530365556799865) has attributes: []\n",
"Node (-73.70218808966641, 45.53033517747947) has attributes: []\n",
"Node (-73.7020516180255, 45.53024919976893) has attributes: []\n",
"Node (-73.70202483520858, 45.530232326481084) has attributes: []\n",
"Node (-73.70189576536478, 45.53015101193401) has attributes: []\n",
"Node (-73.70188535693748, 45.53014445458083) has attributes: []\n",
"Node (-73.70176137113975, 45.53006634300427) has attributes: []\n",
"Node (-73.70171679336974, 45.53003825882077) has attributes: []\n",
"Node (-73.70161674578377, 45.52997522841877) has attributes: []\n",
"Node (-73.70157021391765, 45.52994591314646) has attributes: []\n",
"Node (-73.70145508528618, 45.52987338162208) has attributes: []\n",
"Node (-73.7015262783945, 45.53176766055835) has attributes: []\n",
"Node (-73.70142255824699, 45.531702316306436) has attributes: []\n",
"Node (-73.70132694890151, 45.53164208190352) has attributes: []\n",
"Node (-73.70249378379357, 45.529882494691094) has attributes: ['type', 'id']\n",
"Node (-73.70236957992, 45.530697070843594) has attributes: ['type', 'id']\n",
"Node (-73.7023772579133, 45.52982887967387) has attributes: ['type', 'id']\n",
"Node (-73.70310348189996, 45.530242710105696) has attributes: ['type', 'id']\n",
"Node (-73.70219141578475, 45.5309810002753) has attributes: ['type', 'id']\n",
"Node (-73.7015878987858, 45.53110506016847) has attributes: ['type', 'id']\n",
"Node (-73.70197756808213, 45.531335127032875) has attributes: ['type', 'id']\n",
"Node (-73.70171824652937, 45.53119684899265) has attributes: ['type', 'id']\n",
"Node (-73.70181225980849, 45.53125598840158) has attributes: ['type', 'id']\n",
"Node (-73.70212216033907, 45.53141309516707) has attributes: ['type', 'id']\n",
"Node (-73.70224797036111, 45.531522088920134) has attributes: ['type', 'id']\n",
"Node (-73.70319066728962, 45.53075184355254) has attributes: ['type', 'id']\n",
"Node (-73.70309318391786, 45.53066844829803) has attributes: ['type', 'id']\n",
"Node (-73.70326346262547, 45.53124343502157) has attributes: ['type', 'id']\n",
"Node (-73.70289161913149, 45.53100954740511) has attributes: ['type', 'id']\n",
"Node (-73.7031243168426, 45.52969124795911) has attributes: ['type', 'id']\n",
"Node (-73.70332165936908, 45.531298238343524) has attributes: ['type', 'id']\n",
"Node (-73.70291683392738, 45.531464843960194) has attributes: ['type', 'id']\n",
"Node (-73.70257423757026, 45.53123533603945) has attributes: ['type', 'id']\n",
"Node (-73.70246354979903, 45.53116600989907) has attributes: ['type', 'id']\n",
"Node (-73.70137270924536, 45.53098156462814) has attributes: ['type', 'id']\n",
"Node (-73.70228611728258, 45.52973374332967) has attributes: ['type', 'id']\n",
"Node (-73.70192277090158, 45.530832193189546) has attributes: ['type', 'id']\n",
"Node (-73.70247403248253, 45.530300013163604) has attributes: ['type', 'id']\n",
"Node (-73.70233258364674, 45.53021274328478) has attributes: ['type', 'id']\n",
"Node (-73.70150159992788, 45.530157998392504) has attributes: ['type', 'id']\n",
"Node (-73.70178207574742, 45.53033147043354) has attributes: ['type', 'id']\n",
"Node (-73.70279118480165, 45.53007116190442) has attributes: ['type', 'id']\n",
"Node (-73.70290386342012, 45.53015742711493) has attributes: ['type', 'id']\n",
"Node (-73.70199360008198, 45.529972641218336) has attributes: ['type', 'id']\n",
"Node (-73.7032815855412, 45.52978985115031) has attributes: ['type', 'id']\n",
"Node (-73.70166271484868, 45.53063422765041) has attributes: ['type', 'id']\n",
"Node (-73.7015006171488, 45.530550593136034) has attributes: ['type', 'id']\n",
"Node (-73.70265213028476, 45.529962782747816) has attributes: ['type', 'id']\n",
"Node (-73.7029326957311, 45.53056979610127) has attributes: ['type', 'id']\n",
"Node (-73.70166661687237, 45.5297928936099) has attributes: ['type', 'id']\n",
"Node (-73.70193452736822, 45.53043505670828) has attributes: ['type', 'id']\n",
"Node (-73.70320906423977, 45.53033165241546) has attributes: ['type', 'id']\n",
"Node (-73.70242433058544, 45.531020523149344) has attributes: ['type', 'id']\n",
"Node (-73.70229173916934, 45.53104634226288) has attributes: ['type', 'id']\n",
"Node (-73.70164581777142, 45.53024975981883) has attributes: ['type', 'id']\n",
"Node (-73.70181323564402, 45.52988517687263) has attributes: ['type', 'id']\n",
"Node (-73.70207977647193, 45.53050710203167) has attributes: ['type', 'id']\n",
"Node (-73.70180201572698, 45.53073366018695) has attributes: ['type', 'id']\n",
"Node (-73.70260551746348, 45.53038579346295) has attributes: ['type', 'id']\n",
"Node (-73.7015368490746, 45.531520903846236) has attributes: ['type', 'id']\n",
"Node (-73.70277909755795, 45.530494359508104) has attributes: ['type', 'id']\n",
"Node (-73.7016306503588, 45.531601992190964) has attributes: ['type', 'id']\n",
"Node (-73.703188128229, 45.531634438129004) has attributes: ['type', 'id']\n",
"Node (-73.70225201894137, 45.5306050266003) has attributes: ['type', 'id']\n",
"Node (-73.70250211711432, 45.53079519337939) has attributes: ['type', 'id']\n",
"Node (-73.70143287673753, 45.53147394391961) has attributes: ['type', 'id']\n",
"Node (-73.7015564456529, 45.52971249323039) has attributes: ['type', 'id']\n",
"Node (-73.70213321668199, 45.530060293550356) has attributes: ['type', 'id']\n",
"Node (-73.70205098392802, 45.53092949418992) has attributes: ['type', 'id']\n",
"Node (-73.70273955351598, 45.53092005042424) has attributes: ['type', 'id']\n"
]
}
],
"execution_count": 119
"outputs": [],
"execution_count": null,
"source": "",
"id": "fb74382fc70b6933"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:29:21.717811Z",
"start_time": "2024-07-31T21:29:21.697811Z"
}
},
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "9898d47485af4e62"
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": [
"from scripts.district_heating_network.district_heating_factory import DistrictHeatingFactory\n",
"\n",
"DistrictHeatingFactory(city=city, graph=network_graph)"
"DistrictHeatingFactory(city=city, graph=network_graph).enrich()"
],
"id": "25e14bd5433e3d95",
"outputs": [
{
"ename": "TypeError",
"evalue": "__init__() got an unexpected keyword argument 'graph'",
"output_type": "error",
"traceback": [
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[1;31mTypeError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[1;32mIn[94], line 3\u001B[0m\n\u001B[0;32m 1\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mscripts\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mdistrict_heating_network\u001B[39;00m\u001B[38;5;21;01m.\u001B[39;00m\u001B[38;5;21;01mdistrict_heating_factory\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m DistrictHeatingFactory\n\u001B[1;32m----> 3\u001B[0m \u001B[43mDistrictHeatingFactory\u001B[49m\u001B[43m(\u001B[49m\u001B[43mcity\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mcity\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mgraph\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43mnetwork_graph\u001B[49m\u001B[43m)\u001B[49m\n",
"\u001B[1;31mTypeError\u001B[0m: __init__() got an unexpected keyword argument 'graph'"
]
}
],
"execution_count": 94
"id": "1230e418a231389d"
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T21:18:46.818842Z",
"start_time": "2024-07-31T21:18:46.799573Z"
"end_time": "2024-08-02T13:08:04.652085Z",
"start_time": "2024-08-02T13:08:04.639087Z"
}
},
"cell_type": "code",
@ -472,175 +320,198 @@
"Node (-73.7015262783945, 45.53176766055835) has attributes: []\n",
"Node (-73.70142255824699, 45.531702316306436) has attributes: []\n",
"Node (-73.70132694890151, 45.53164208190352) has attributes: []\n",
"Node (-73.70249378379357, 45.529882494691094) has attributes: ['type', 'id']\n",
"Node (-73.70236957992, 45.530697070843594) has attributes: ['type', 'id']\n",
"Node (-73.7023772579133, 45.52982887967387) has attributes: ['type', 'id']\n",
"Node (-73.70310348189996, 45.530242710105696) has attributes: ['type', 'id']\n",
"Node (-73.70219141578475, 45.5309810002753) has attributes: ['type', 'id']\n",
"Node (-73.7015878987858, 45.53110506016847) has attributes: ['type', 'id']\n",
"Node (-73.70197756808213, 45.531335127032875) has attributes: ['type', 'id']\n",
"Node (-73.70171824652937, 45.53119684899265) has attributes: ['type', 'id']\n",
"Node (-73.70181225980849, 45.53125598840158) has attributes: ['type', 'id']\n",
"Node (-73.70212216033907, 45.53141309516707) has attributes: ['type', 'id']\n",
"Node (-73.70224797036111, 45.531522088920134) has attributes: ['type', 'id']\n",
"Node (-73.70319066728962, 45.53075184355254) has attributes: ['type', 'id']\n",
"Node (-73.70309318391786, 45.53066844829803) has attributes: ['type', 'id']\n",
"Node (-73.70326346262547, 45.53124343502157) has attributes: ['type', 'id']\n",
"Node (-73.70289161913149, 45.53100954740511) has attributes: ['type', 'id']\n",
"Node (-73.7031243168426, 45.52969124795911) has attributes: ['type', 'id']\n",
"Node (-73.70332165936908, 45.531298238343524) has attributes: ['type', 'id']\n",
"Node (-73.70291683392738, 45.531464843960194) has attributes: ['type', 'id']\n",
"Node (-73.70257423757026, 45.53123533603945) has attributes: ['type', 'id']\n",
"Node (-73.70246354979903, 45.53116600989907) has attributes: ['type', 'id']\n",
"Node (-73.70137270924536, 45.53098156462814) has attributes: ['type', 'id']\n",
"Node (-73.70228611728258, 45.52973374332967) has attributes: ['type', 'id']\n",
"Node (-73.70192277090158, 45.530832193189546) has attributes: ['type', 'id']\n",
"Node (-73.70247403248253, 45.530300013163604) has attributes: ['type', 'id']\n",
"Node (-73.70233258364674, 45.53021274328478) has attributes: ['type', 'id']\n",
"Node (-73.70150159992788, 45.530157998392504) has attributes: ['type', 'id']\n",
"Node (-73.70178207574742, 45.53033147043354) has attributes: ['type', 'id']\n",
"Node (-73.70279118480165, 45.53007116190442) has attributes: ['type', 'id']\n",
"Node (-73.70290386342012, 45.53015742711493) has attributes: ['type', 'id']\n",
"Node (-73.70199360008198, 45.529972641218336) has attributes: ['type', 'id']\n",
"Node (-73.7032815855412, 45.52978985115031) has attributes: ['type', 'id']\n",
"Node (-73.70166271484868, 45.53063422765041) has attributes: ['type', 'id']\n",
"Node (-73.7015006171488, 45.530550593136034) has attributes: ['type', 'id']\n",
"Node (-73.70265213028476, 45.529962782747816) has attributes: ['type', 'id']\n",
"Node (-73.7029326957311, 45.53056979610127) has attributes: ['type', 'id']\n",
"Node (-73.70166661687237, 45.5297928936099) has attributes: ['type', 'id']\n",
"Node (-73.70193452736822, 45.53043505670828) has attributes: ['type', 'id']\n",
"Node (-73.70320906423977, 45.53033165241546) has attributes: ['type', 'id']\n",
"Node (-73.70242433058544, 45.531020523149344) has attributes: ['type', 'id']\n",
"Node (-73.70229173916934, 45.53104634226288) has attributes: ['type', 'id']\n",
"Node (-73.70164581777142, 45.53024975981883) has attributes: ['type', 'id']\n",
"Node (-73.70181323564402, 45.52988517687263) has attributes: ['type', 'id']\n",
"Node (-73.70207977647193, 45.53050710203167) has attributes: ['type', 'id']\n",
"Node (-73.70180201572698, 45.53073366018695) has attributes: ['type', 'id']\n",
"Node (-73.70260551746348, 45.53038579346295) has attributes: ['type', 'id']\n",
"Node (-73.7015368490746, 45.531520903846236) has attributes: ['type', 'id']\n",
"Node (-73.70277909755795, 45.530494359508104) has attributes: ['type', 'id']\n",
"Node (-73.7016306503588, 45.531601992190964) has attributes: ['type', 'id']\n",
"Node (-73.703188128229, 45.531634438129004) has attributes: ['type', 'id']\n",
"Node (-73.70225201894137, 45.5306050266003) has attributes: ['type', 'id']\n",
"Node (-73.70250211711432, 45.53079519337939) has attributes: ['type', 'id']\n",
"Node (-73.70143287673753, 45.53147394391961) has attributes: ['type', 'id']\n",
"Node (-73.7015564456529, 45.52971249323039) has attributes: ['type', 'id']\n",
"Node (-73.70213321668199, 45.530060293550356) has attributes: ['type', 'id']\n",
"Node (-73.70205098392802, 45.53092949418992) has attributes: ['type', 'id']\n",
"Node (-73.70273955351598, 45.53092005042424) has attributes: ['type', 'id']\n"
"Node (-73.70249378379357, 45.529882494691094) has attributes: ['type', 'name']\n",
"Node (-73.70236957992, 45.530697070843594) has attributes: ['type', 'name']\n",
"Node (-73.7023772579133, 45.52982887967387) has attributes: ['type', 'name']\n",
"Node (-73.70310348189996, 45.530242710105696) has attributes: ['type', 'name']\n",
"Node (-73.70219141578475, 45.5309810002753) has attributes: ['type', 'name']\n",
"Node (-73.7015878987858, 45.53110506016847) has attributes: ['type', 'name']\n",
"Node (-73.70197756808213, 45.531335127032875) has attributes: ['type', 'name']\n",
"Node (-73.70171824652937, 45.53119684899265) has attributes: ['type', 'name']\n",
"Node (-73.70181225980849, 45.53125598840158) has attributes: ['type', 'name']\n",
"Node (-73.70212216033907, 45.53141309516707) has attributes: ['type', 'name']\n",
"Node (-73.70224797036111, 45.531522088920134) has attributes: ['type', 'name']\n",
"Node (-73.70319066728962, 45.53075184355254) has attributes: ['type', 'name']\n",
"Node (-73.70309318391786, 45.53066844829803) has attributes: ['type', 'name']\n",
"Node (-73.70326346262547, 45.53124343502157) has attributes: ['type', 'name']\n",
"Node (-73.70289161913149, 45.53100954740511) has attributes: ['type', 'name']\n",
"Node (-73.7031243168426, 45.52969124795911) has attributes: ['type', 'name']\n",
"Node (-73.70332165936908, 45.531298238343524) has attributes: ['type', 'name']\n",
"Node (-73.70291683392738, 45.531464843960194) has attributes: ['type', 'name']\n",
"Node (-73.70257423757026, 45.53123533603945) has attributes: ['type', 'name']\n",
"Node (-73.70246354979903, 45.53116600989907) has attributes: ['type', 'name']\n",
"Node (-73.70137270924536, 45.53098156462814) has attributes: ['type', 'name']\n",
"Node (-73.70228611728258, 45.52973374332967) has attributes: ['type', 'name']\n",
"Node (-73.70192277090158, 45.530832193189546) has attributes: ['type', 'name']\n",
"Node (-73.70247403248253, 45.530300013163604) has attributes: ['type', 'name']\n",
"Node (-73.70233258364674, 45.53021274328478) has attributes: ['type', 'name']\n",
"Node (-73.70150159992788, 45.530157998392504) has attributes: ['type', 'name']\n",
"Node (-73.70178207574742, 45.53033147043354) has attributes: ['type', 'name']\n",
"Node (-73.70279118480165, 45.53007116190442) has attributes: ['type', 'name']\n",
"Node (-73.70290386342012, 45.53015742711493) has attributes: ['type', 'name']\n",
"Node (-73.70199360008198, 45.529972641218336) has attributes: ['type', 'name']\n",
"Node (-73.7032815855412, 45.52978985115031) has attributes: ['type', 'name']\n",
"Node (-73.70166271484868, 45.53063422765041) has attributes: ['type', 'name']\n",
"Node (-73.7015006171488, 45.530550593136034) has attributes: ['type', 'name']\n",
"Node (-73.70265213028476, 45.529962782747816) has attributes: ['type', 'name']\n",
"Node (-73.7029326957311, 45.53056979610127) has attributes: ['type', 'name']\n",
"Node (-73.70166661687237, 45.5297928936099) has attributes: ['type', 'name']\n",
"Node (-73.70193452736822, 45.53043505670828) has attributes: ['type', 'name']\n",
"Node (-73.70320906423977, 45.53033165241546) has attributes: ['type', 'name']\n",
"Node (-73.70242433058544, 45.531020523149344) has attributes: ['type', 'name']\n",
"Node (-73.70229173916934, 45.53104634226288) has attributes: ['type', 'name']\n",
"Node (-73.70164581777142, 45.53024975981883) has attributes: ['type', 'name']\n",
"Node (-73.70181323564402, 45.52988517687263) has attributes: ['type', 'name']\n",
"Node (-73.70207977647193, 45.53050710203167) has attributes: ['type', 'name']\n",
"Node (-73.70180201572698, 45.53073366018695) has attributes: ['type', 'name']\n",
"Node (-73.70260551746348, 45.53038579346295) has attributes: ['type', 'name']\n",
"Node (-73.7015368490746, 45.531520903846236) has attributes: ['type', 'name']\n",
"Node (-73.70277909755795, 45.530494359508104) has attributes: ['type', 'name']\n",
"Node (-73.7016306503588, 45.531601992190964) has attributes: ['type', 'name']\n",
"Node (-73.703188128229, 45.531634438129004) has attributes: ['type', 'name']\n",
"Node (-73.70225201894137, 45.5306050266003) has attributes: ['type', 'name']\n",
"Node (-73.70250211711432, 45.53079519337939) has attributes: ['type', 'name']\n",
"Node (-73.70143287673753, 45.53147394391961) has attributes: ['type', 'name']\n",
"Node (-73.7015564456529, 45.52971249323039) has attributes: ['type', 'name']\n",
"Node (-73.70213321668199, 45.530060293550356) has attributes: ['type', 'name']\n",
"Node (-73.70205098392802, 45.53092949418992) has attributes: ['type', 'name']\n",
"Node (-73.70273955351598, 45.53092005042424) has attributes: ['type', 'name']\n"
]
}
],
"execution_count": 80
"execution_count": 13
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T20:23:57.446448Z",
"start_time": "2024-07-31T20:23:57.431469Z"
"end_time": "2024-08-01T13:46:14.045488Z",
"start_time": "2024-08-01T13:46:14.025941Z"
}
},
"cell_type": "code",
"source": [
"for building in city.buildings:\n",
" print(building.name)"
"for node in network_graph.nodes(data=True):\n",
" node_id, node_attrs = node\n",
" if node_attrs.get('name') == '65418':\n",
" building_demand = node_attrs.get('_heating_demand')\n",
" print(building_demand[\"hour\"][1])"
],
"id": "5b96a042e349e0eb",
"id": "f7c0742941b4f2d1",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"65418\n",
"70816\n",
"73478\n",
"82649\n",
"84906\n",
"87241\n",
"87719\n",
"88675\n",
"88747\n",
"89061\n",
"89062\n",
"89251\n",
"91214\n",
"92337\n",
"92399\n",
"92520\n",
"92979\n",
"93149\n",
"95265\n",
"95266\n",
"95465\n",
"95704\n",
"96241\n",
"96579\n",
"96580\n",
"96930\n",
"96931\n",
"96996\n",
"96997\n",
"97648\n",
"98087\n",
"98666\n",
"98667\n",
"102035\n",
"103043\n",
"103740\n",
"103795\n",
"107302\n",
"108296\n",
"108297\n",
"109211\n",
"109305\n",
"109773\n",
"110561\n",
"110873\n",
"113368\n",
"116927\n",
"118062\n",
"118250\n",
"119143\n",
"120435\n",
"124177\n",
"125538\n",
"128322\n",
"129429\n",
"130498\n"
"10687074.91690603\n"
]
}
],
"execution_count": 75
"execution_count": 24
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-07-31T19:35:10.949715Z",
"start_time": "2024-07-31T19:35:09.846007Z"
"end_time": "2024-08-01T14:02:29.592771Z",
"start_time": "2024-08-01T14:02:29.549689Z"
}
},
"cell_type": "code",
"source": "",
"id": "2bb88967eb45bcec",
"source": [
"import CoolProp.CoolProp as CP\n",
"\n",
"# Define the fluid\n",
"fluid = 'Water'\n",
"\n",
"# Define the state properties\n",
"temperature = 300 # Temperature in Kelvin\n",
"pressure = 101325 # Pressure in Pascals (1 atm)\n",
"\n",
"# Calculate specific heat capacity at constant pressure (Cp)\n",
"cp = CP.PropsSI('C', 'T', temperature, 'P', pressure, fluid)\n",
"\n",
"print(f\"The specific heat capacity of water at {temperature} K and {pressure} Pa is {cp} J/kg.K\")"
],
"id": "954e9fbbfe3dbe87",
"outputs": [
{
"name": "stderr",
"name": "stdout",
"output_type": "stream",
"text": [
"IOPub data rate exceeded.\n",
"The Jupyter server will temporarily stop sending output\n",
"to the client in order to avoid crashing it.\n",
"To change this limit, set the config variable\n",
"`--ServerApp.iopub_data_rate_limit`.\n",
"\n",
"Current values:\n",
"ServerApp.iopub_data_rate_limit=1000000.0 (bytes/sec)\n",
"ServerApp.rate_limit_window=3.0 (secs)\n",
"\n"
"The specific heat capacity of water at 300 K and 101325 Pa is 4180.6357765560715 J/kg.K\n"
]
}
],
"execution_count": 52
"execution_count": 25
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-02T12:47:52.738098Z",
"start_time": "2024-08-02T12:47:52.701565Z"
}
},
"cell_type": "code",
"source": [
"import math\n",
"import logging\n",
"supply_temperature = 60\n",
"return_temperature = 40\n",
"\n",
"for node in network_graph.nodes(data=True):\n",
" node_id, node_attrs = node\n",
" if node_attrs.get('type') == 'building':\n",
" heating_peak_load = node_attrs.get('heating_peak_load') # Adjusted key to match your data\n",
" print(heating_peak_load['year'][0])\n",
" # if heating_peak_load:\n",
" # # Calculate peak mass flow rate\n",
" # peak_mass_flow_rate = heating_peak_load['year'][0] / CP.PropsSI('C',\n",
" # 'T',\n",
" # (\n",
" # supply_temperature +\n",
" # return_temperature\n",
" # ) / 2,\n",
" # 'P',\n",
" # 101325,\n",
" # fluid)\n",
" # print(peak_mass_flow_rate)\n",
" # # Calculate density of the fluid\n",
" # density = CP.PropsSI('D', # 'D' for density\n",
" # 'T',\n",
" # (\n",
" # supply_temperature +\n",
" # return_temperature\n",
" # ) / 2,\n",
" # 'P',\n",
" # 101325,\n",
" # fluid)\n",
" # \n",
" # # Set the design velocity (V)\n",
" # velocity = 0.9 # m/s\n",
" # \n",
" # # Calculate the diameter (D)\n",
" # D = math.sqrt((4 * peak_mass_flow_rate) / (density * velocity * math.pi)) # m\n",
" # print(D)\n",
" # # Find the edge connected to the building node\n",
" # for neighbor in network_graph.neighbors(node_id):\n",
" # if not network_graph.nodes[neighbor].get('type') == 'building': # Ensure it's a pipe connection\n",
" # network_graph.edges[node_id, neighbor]['diameter'] = D\n",
" # logging.info(f\"Diameter for edge ({node_id}, {neighbor}) set to {D} meters.\")\n"
],
"id": "84557dd2ba1070e0",
"outputs": [
{
"ename": "TypeError",
"evalue": "'NoneType' object is not subscriptable",
"output_type": "error",
"traceback": [
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[1;31mTypeError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[1;32mIn[28], line 10\u001B[0m\n\u001B[0;32m 8\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m node_attrs\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mtype\u001B[39m\u001B[38;5;124m'\u001B[39m) \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mbuilding\u001B[39m\u001B[38;5;124m'\u001B[39m:\n\u001B[0;32m 9\u001B[0m heating_peak_load \u001B[38;5;241m=\u001B[39m node_attrs\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mheating_peak_load\u001B[39m\u001B[38;5;124m'\u001B[39m) \u001B[38;5;66;03m# Adjusted key to match your data\u001B[39;00m\n\u001B[1;32m---> 10\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[43mheating_peak_load\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43myear\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m]\u001B[49m[\u001B[38;5;241m0\u001B[39m])\n",
"\u001B[1;31mTypeError\u001B[0m: 'NoneType' object is not subscriptable"
]
}
],
"execution_count": 28
},
{
"metadata": {},
@ -648,7 +519,7 @@
"outputs": [],
"execution_count": null,
"source": "",
"id": "f7c0742941b4f2d1"
"id": "11ebedbf06ddfe38"
}
],
"metadata": {