Skip to content

Commit

Permalink
updated model dev demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklise committed Jan 13, 2025
1 parent aed510e commit 62a18cd
Showing 1 changed file with 69 additions and 38 deletions.
107 changes: 69 additions & 38 deletions examples/demos/.virtual_documents/model_development_v2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ wntr.network.io.write_geojson(wn0, "../data/ky4", crs=crs)



# Option 1. Create a WaterNetworkModel from the GeoJSON files
geojson_files = {
"junctions": "../data/ky4_junctions.geojson",
"tanks": "../data/ky4_tanks.geojson",
Expand All @@ -51,31 +50,6 @@ geojson_files = {
wn = wntr.network.read_geojson(geojson_files)


# Option 2, Create a WaterNetworkModel from GeoDataFrames
junctions = gpd.read_file("../data/ky4_junctions.geojson", crs=crs)
tanks = gpd.read_file("../data/ky4_tanks.geojson", crs=crs)
reservoirs = gpd.read_file("../data/ky4_reservoirs.geojson", crs=crs)
pipes = gpd.read_file("../data/ky4_pipes.geojson", crs=crs)
pumps = gpd.read_file("../data/ky4_pumps.geojson", crs=crs)

junctions.set_index("name", inplace=True)
tanks.set_index("name", inplace=True)
reservoirs.set_index("name", inplace=True)
pipes.set_index("name", inplace=True)
pumps.set_index("name", inplace=True)

gis_data = wntr.gis.WaterNetworkGIS(
{
"junctions": junctions,
"tanks": tanks,
"reservoirs": reservoirs,
"pipes": pipes,
"pumps": pumps,
}
)
wn = wntr.network.from_gis(gis_data)





Expand Down Expand Up @@ -124,6 +98,11 @@ pressure = results.node["pressure"].loc[0, :]
wntr.graphics.plot_network(wn, node_attribute=pressure, node_size=30, title="Pressure")


wn0.describe()
wn1.describe()
# compare RMSE pressure at a specific time





Expand All @@ -134,14 +113,18 @@ wntr.graphics.plot_network(wn, node_attribute=pressure, node_size=30, title="Pre


diconnected_pipes = gpd.read_file("../data/ky4_disconnected_pipes.geojson", crs=crs)
diconnected_tanks = gpd.read_file("../data/ky4_tanks.geojson", crs=crs)
diconnected_reservoirs = gpd.read_file("../data/ky4_reservoirs.geojson", crs=crs)
diconnected_pumps = gpd.read_file("../data/ky4_pumps.geojson", crs=crs)
tanks = gpd.read_file("../data/ky4_tanks.geojson", crs=crs)
reservoirs = gpd.read_file("../data/ky4_reservoirs.geojson", crs=crs)
pumps = gpd.read_file("../data/ky4_pumps.geojson", crs=crs)

diconnected_pipes.set_index("index", inplace=True) # This needs to be updated to name
diconnected_tanks.set_index("name", inplace=True)
diconnected_reservoirs.set_index("name", inplace=True)
diconnected_pumps.set_index("name", inplace=True)
tanks.set_index("name", inplace=True)
reservoirs.set_index("name", inplace=True)
pumps.set_index("name", inplace=True)

# TODO remove start_node_name end_node_name and pumps -- not sure how we add these back in, but I don't think the names should exist here
del pumps['start_node_name']
del pumps['end_node_name']

# Define distance threshold used to refine data
distance_threshold = 100.0
Expand All @@ -151,7 +134,9 @@ distance_threshold = 100.0


pipes, junctions = wntr.gis.geospatial.connect_lines(diconnected_pipes, distance_threshold)
print(pipes.head())

# TODO, change to plotly or interactive so we can zoom in
fig, ax = plt.subplots()
diconnected_pipes.plot(color="b", linewidth=4, ax=ax)
pipes.plot(color="r", linewidth=2, ax=ax)
Expand All @@ -161,16 +146,57 @@ junctions.plot(color="k", ax=ax)



# TODO use sample_raster function
junctions["elevation"] = 100
print(junctions)
print(junctions.head())





snap_reservoirs = wntr.gis.snap(reservoirs, junctions, distance_threshold)
print(reservoirs.head())
print(snap_reservoirs)

snap_tanks = wntr.gis.snap(tanks, junctions, distance_threshold)
print(tanks.head())
print(snap_tanks)

# TODO, how do we add the pump? snap to the nearest pipe? why is the pump a point? does this work with the perfect data above?
snap_pumps = wntr.gis.snap(pumps, junctions, distance_threshold)
print(pumps.head())
print(snap_pumps)




reservoirs = wntr.gis.snap(diconnected_reservoirs, junctions, distance_threshold)
tanks = wntr.gis.snap(diconnected_tanks, junctions, distance_threshold)
pumps = wntr.gis.snap(diconnected_pumps, junctions, distance_threshold)

def add_connector(snap_attribute, pipes):
for name, row in snap_attribute.iterrows():
attributes = {'CV': 0,
'diameter': 0.3,
'status': 'Open',
'length': 1,
'minor_loss': 0,
'roughness': 150,
'geometry': row['geometry'],
'start_node_name': row['node'],
'end_node_name': name}
pipes.loc[name+'_connector'] = attributes
return pipes

add_connector(snap_reservoirs, pipes)
add_connector(snap_tanks, pipes)





# TODO
# For each pump
# Determine upstream direction using the graph
# Add upstream junction (junction_upstream)
# Add start_node_name and end_node_name to pump



Expand All @@ -186,15 +212,15 @@ snap_buildings = wntr.gis.snap(buildings, junctions, distance_threshold)
buildings["junction"] = None
buildings.loc[snap_buildings.index, "junction"] = snap_buildings.loc[:, "node"]

print(buildings.head())








# build the wn_gis object
# TODO, add back in tanks, reservoirs, and pumps
gis_data = wntr.gis.WaterNetworkGIS(
{
"junctions": junctions,
Expand Down Expand Up @@ -259,3 +285,8 @@ sim = wntr.sim.EpanetSimulator(wn)
results = sim.run_sim()
pressure = results.node["pressure"].loc[0, :]
wntr.graphics.plot_network(wn, node_attribute=pressure, node_size=30, title="Pressure")


wn0.describe()
wn2.describe()
# compare RMSE pressure at a specific time

0 comments on commit 62a18cd

Please sign in to comment.