-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
198 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
from .generate import generate | ||
from .generate import add_tracer, generate | ||
from .parse import parse | ||
from .plot import plot | ||
from .plot import plot_fraction, plot_spatial | ||
from .util import run_delwaq | ||
|
||
__all__ = ["generate", "parse", "run_delwaq", "plot"] | ||
__all__ = [ | ||
"generate", | ||
"parse", | ||
"run_delwaq", | ||
"plot", | ||
"add_tracer", | ||
"plot_fraction", | ||
"plot_spatial", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
def plot(): | ||
pass | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.axes_grid1 import make_axes_locatable | ||
|
||
|
||
def plot_fraction( | ||
model, | ||
node_id, | ||
tracers=["Basin", "LevelBoundary", "FlowBoundary", "UserDemand", "Initial"], | ||
): | ||
table = model.basin.concentration_external.df | ||
table = table[table["node_id"] == node_id] | ||
table = table[table["substance"].isin(tracers)] | ||
|
||
groups = table.groupby("substance") | ||
stack = {k: v["concentration"].to_numpy() for (k, v) in groups} | ||
|
||
fig, ax = plt.subplots() | ||
ax.stackplot( | ||
groups.get_group(tracers[0])["time"], | ||
stack.values(), | ||
labels=stack.keys(), | ||
) | ||
ax.legend() | ||
ax.set_title(f"Fraction plot for node {node_id}") | ||
ax.set_xlabel("Time") | ||
ax.set_ylabel("Fraction") | ||
|
||
plt.show(fig) | ||
|
||
|
||
def plot_spatial(model, tracer="Basin"): | ||
table = model.basin.concentration_external.df | ||
table = table[table["substance"] == tracer] | ||
table = table[table["time"] == table["time"].max()] | ||
table.set_index("node_id", inplace=True) | ||
|
||
nodes = model.node_table().df | ||
nodes = nodes[nodes.index.isin(table.index)] | ||
|
||
fig, ax = plt.subplots() | ||
s = ax.scatter( | ||
nodes.geometry.x, | ||
nodes.geometry.y, | ||
c=table["concentration"][nodes.index], | ||
clim=(0, 1), | ||
) | ||
ax.legend() | ||
ax.set_title(f"Scatter plot for {tracer} tracer at {table["time"].iloc[0]}") | ||
|
||
divider = make_axes_locatable(ax) | ||
cax = divider.append_axes("right", size="5%", pad=0.05) | ||
|
||
fig.colorbar(s, cax=cax, orientation="vertical") | ||
ax.set_xlabel("x") | ||
ax.set_ylabel("y") | ||
|
||
plt.show(fig) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters