Skip to content

Commit

Permalink
TEMPORARY: updates to notebook to generate experimental test files
Browse files Browse the repository at this point in the history
  • Loading branch information
vtnate committed Feb 9, 2024
1 parent d69a902 commit 7207374
Showing 1 changed file with 55 additions and 41 deletions.
96 changes: 55 additions & 41 deletions topology/final.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"import json\n",
"from pathlib import Path\n",
"\n",
"from thermalnetwork.ground_heat_exchanger import GHE\n"
"from thermalnetwork.ground_heat_exchanger import GHE"
]
},
{
Expand All @@ -22,7 +22,7 @@
"source": [
"geojson_path = Path.cwd().parent / \"demos\" / \"sdk_output_skeleton_1_ghe\" / \"network.geojson\"\n",
"with open(geojson_path) as f:\n",
" geojson_data = json.load(f)\n"
" geojson_data = json.load(f)"
]
},
{
Expand All @@ -34,7 +34,7 @@
"source": [
"geojson_path = Path.cwd().parent / \"demos\" / \"sdk_output_skeleton_2_ghe_sequential\" / \"network.geojson\"\n",
"with open(geojson_path) as f:\n",
" geojson_data2 = json.load(f)\n"
" geojson_data2 = json.load(f)"
]
},
{
Expand All @@ -46,7 +46,41 @@
"source": [
"geojson_path = Path.cwd().parent / \"demos\" / \"sdk_output_skeleton_2_ghe_staggered\" / \"network.geojson\"\n",
"with open(geojson_path) as f:\n",
" geojson_data2_staggered = json.load(f)\n"
" geojson_data2_staggered = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d74d43a5",
"metadata": {},
"outputs": [],
"source": [
"# code for line 404 of network.py to generate ghe_data.json\n",
"\n",
"# ground_loads = np.array(network_load_per_area) * ghe_area\n",
"# # tolist() because writing json requires a python list, not a numpy array\n",
"# self.network[i].json_data[\"loads\"][\"ground_loads\"] = ground_loads.tolist()\n",
"\n",
"# sum_of_ground_loads = sum(self.network[i].json_data[\"loads\"][\"ground_loads\"])\n",
"# print(\"json data\")\n",
"# print(self.network[i].json_data)\n",
"\n",
"# print(\"ghe_input:\")\n",
"# print(sum_of_ground_loads)\n",
"# with open(\"ghe_data.json\", \"w\", encoding=\"utf-8\") as f:\n",
"# json.dump(self.network[i].json_data, f, ensure_ascii=False, indent=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55b42b44",
"metadata": {},
"outputs": [],
"source": [
"# CLI command to use with the above code to generate ghe_data.json:\n",
"# thermalnetwork -y demos/sdk_output_skeleton_2_ghe_sequential/run/baseline_scenario/ghe_dir/sys_params.json -s demos/sdk_output_skeleton_2_ghe_sequential/run/baseline_scenario -f demos/sdk_output_skeleton_2_ghe_sequential/network.geojson -o cli_test # noqa: E501"
]
},
{
Expand Down Expand Up @@ -211,29 +245,6 @@
"ghe.ghe_size(total_ground_loads, Path.cwd())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d74d43a5",
"metadata": {},
"outputs": [],
"source": [
"# code for line 404 of network.py to generate ghe_data.json\n",
"\n",
"ground_loads = np.array(network_load_per_area) * ghe_area # noqa: F821\n",
"# tolist() because writing json requires a python list, not a numpy array\n",
"self.network[i].json_data[\"loads\"][\"ground_loads\"] = ground_loads.tolist() # noqa: F821\n",
"\n",
"# sum_of_ground_loads = sum(self.network[i].json_data[\"loads\"][\"ground_loads\"])\n",
" # print(\"json data\")\n",
" # print(self.network[i].json_data)\n",
"\n",
" # print(\"ghe_input:\")\n",
" # print(sum_of_ground_loads)\n",
" # with open(\"ghe_data.json\", \"w\", encoding=\"utf-8\") as f:\n",
" # json.dump(self.network[i].json_data, f, ensure_ascii=False, indent=4)"
]
},
{
"cell_type": "raw",
"id": "c0c5b980-e6d5-4d53-868e-2a8894bc2bc0",
Expand All @@ -260,21 +271,21 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"#THIS IS GOOD\n",
"# THIS IS GOOD\n",
"def find_startloop_feature_id(features):\n",
" for feature in features:\n",
" if feature[\"properties\"].get(\"is_ghe_start_loop\") == \"true\":\n",
" start_feature_id = feature[\"properties\"].get(\"buildingId\") or feature[\"properties\"].get(\"DSId\")\n",
" return start_feature_id\n",
" return None\n",
"\n",
"\n",
"def get_connected_features(geojson_data):\n",
" features = geojson_data[\"features\"]\n",
" connectors = [feature for feature in features if feature[\"properties\"][\"type\"] == \"ThermalConnector\"]\n",
" connected_features = []\n",
"\n",
" #get the id of the building or ds from the thermaljunction that has startloop: true\n",
" # get the id of the building or ds from the thermaljunction that has startloop: true\n",
" startloop_feature_id = find_startloop_feature_id(features)\n",
"\n",
" # Start with the first connector\n",
Expand All @@ -300,19 +311,22 @@
" for feature in features:\n",
" feature_id = feature[\"properties\"][\"id\"]\n",
" if feature_id in connected_features and feature[\"properties\"][\"type\"] in [\"Building\", \"District System\"]:\n",
" connected_objects.append({\n",
" \"id\": feature_id,\n",
" \"type\": feature[\"properties\"][\"type\"],\n",
" \"name\": feature[\"properties\"].get(\"name\", \"\"),\n",
" \"start_loop\": \"true\" if feature_id == startloop_feature_id else None\n",
" })\n",
" connected_objects.append(\n",
" {\n",
" \"id\": feature_id,\n",
" \"type\": feature[\"properties\"][\"type\"],\n",
" \"name\": feature[\"properties\"].get(\"name\", \"\"),\n",
" \"start_loop\": \"true\" if feature_id == startloop_feature_id else None,\n",
" }\n",
" )\n",
"\n",
" return connected_objects\n",
"\n",
"\n",
"def reorder_connected_features(features):\n",
" while features[0].get(\"start_loop\") != \"true\":\n",
" features.append(features.pop(0))\n",
" return features\n"
" return features"
]
},
{
Expand All @@ -322,7 +336,7 @@
"metadata": {},
"outputs": [],
"source": [
"connected_features = get_connected_features(geojson_data2)\n"
"connected_features = get_connected_features(geojson_data2)"
]
},
{
Expand All @@ -346,7 +360,7 @@
"source": [
"connected_features = get_connected_features(geojson_data2)\n",
"for feature in connected_features:\n",
" print(feature)\n"
" print(feature)"
]
},
{
Expand All @@ -356,7 +370,7 @@
"metadata": {},
"outputs": [],
"source": [
"reordered_features = reorder_connected_features(connected_features)\n"
"reordered_features = reorder_connected_features(connected_features)"
]
},
{
Expand Down Expand Up @@ -387,7 +401,7 @@
}
],
"source": [
"reordered_features\n"
"reordered_features"
]
},
{
Expand Down

0 comments on commit 7207374

Please sign in to comment.