-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplot_inputs_outputs.py
More file actions
110 lines (91 loc) · 4.14 KB
/
plot_inputs_outputs.py
File metadata and controls
110 lines (91 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import numpy as np
from mdof.utilities.testing import intensity_bounds, truncate_by_bounds
from pathlib import Path
import plotly.graph_objects as go
import utilities_visualization
# Analysis configuration
WINDOWED_PLOT = True
STRUCTURE = "bridge" # "frame", "bridge"
ELASTIC = True
MULTISUPPORT = False
VERBOSE = 1
# Main output directory
BASE_DIR = Path("Modeling")
MODEL_OUT_DIR = BASE_DIR / STRUCTURE / ("elastic" if ELASTIC else "inelastic")
FIELD_OUT_DIR = BASE_DIR / STRUCTURE / "field"
Q_MAP = {
"acceleration": {"name": "Acceleration", "units": "in/s²"},
"displacement": {"name": "Displacement", "units": "in"},
}
if __name__ == "__main__":
if STRUCTURE == "frame":
if not MULTISUPPORT:
input_labels = ['Channel 0 (X)', 'Channel 2 (Y)']
output_nodes = [5, 5, 10, 10, 15, 15]
output_dofs = [1, 2, 1, 2, 1, 2]
elif STRUCTURE == "bridge":
if not MULTISUPPORT:
input_labels = ['Channel 1 (-X)', 'Channel 3 (Y)']
output_nodes = [9, 3, 10]
output_dofs = [2, 2, 2]
dof_map = {1: "X", 2: "Y", 3: "Z", 4: "RX", 5: "RY", 6: "RZ"}
output_labels = [f"Node{n}{dof_map[d]}" for n,d in zip(output_nodes,output_dofs)]
outputs = {"model": {}, "field": {}}
quantities = ["displacement", "acceleration"]
# Event ids are file names from saved field ground acceleration.
event_files = sorted((FIELD_OUT_DIR / "acceleration" / "ground").glob("*.csv"))
event_ids = [event.stem for event in event_files]
for event_id in event_ids:
if VERBOSE:
print(f"Plotting Event {event_id}")
try:
inputs = np.atleast_2d(np.loadtxt(
FIELD_OUT_DIR / "acceleration" / "ground" / f"{event_id}.csv",
))
for source in outputs.keys():
for q in quantities:
outputs[source][q] = np.loadtxt(
(MODEL_OUT_DIR if source == "model" else FIELD_OUT_DIR) / q / "structure" / f"{event_id}.csv",
)
except FileNotFoundError:
if VERBOSE:
print(f"No data for event {event_id}; skipping")
continue
dt = np.loadtxt(FIELD_OUT_DIR / "dt" / "ground" / f"{event_id}.csv")
t_in = np.arange(inputs.shape[1]) * dt
t_out = np.arange(outputs["model"]["displacement"].shape[1]) * dt
if WINDOWED_PLOT:
bounds = intensity_bounds(outputs["model"]["displacement"][0], lb=0.001, ub=0.999)
inputs = truncate_by_bounds(inputs, bounds)
t_in = t_in[bounds[0]:bounds[1]]
for source in outputs.keys():
for q in quantities:
outputs[source][q] = truncate_by_bounds(outputs[source][q], bounds)
t_out = t_out[bounds[0]:bounds[1]]
# --------- input ---------
fig = go.Figure()
for ch in range(inputs.shape[0]):
fig.add_scatter(x=t_in, y=inputs[ch], mode="lines", name=input_labels[ch])
fig.update_layout(title=f"Event {event_id} Inputs",
xaxis_title="Time (s)",
yaxis_title="Input Acceleration (in/s²)",
width=800,height=300)
fig.write_html(
FIELD_OUT_DIR / "acceleration" / "ground" / f"{event_id}.html",
include_plotlyjs="cdn"
)
# --------- output ---------
source_dirs = {"model": MODEL_OUT_DIR, "field": FIELD_OUT_DIR}
for source, source_dir in source_dirs.items():
for q in quantities:
fig = go.Figure()
for ch in range(outputs[source][q].shape[0]):
fig.add_scatter(x=t_out, y=outputs[source][q][ch], mode="lines", name=output_labels[ch])
fig.update_layout(title=f"Event {event_id} Outputs",
xaxis_title="Time (s)",
yaxis_title=f"Output {Q_MAP[q]['name']} ({Q_MAP[q]['units']})",
width=800,height=300)
fig.write_html(
source_dir / q / "structure" / f"{event_id}.html",
include_plotlyjs="cdn"
)