Skip to content

Commit 04eccd1

Browse files
committed
results 8
1 parent e01371d commit 04eccd1

File tree

3 files changed

+162
-71
lines changed

3 files changed

+162
-71
lines changed

Python Scripts/PySeesTKO/pyseestko/plotting.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ def __init__(
226226
def setup_direction(self, x_direction:bool=True):
227227
self.x_direction = x_direction
228228
self.direction = 'X' if x_direction else 'Y'
229-
self.id = f'{self.sim_type} | {self.stories} stories - {self.nsubs} subs - {self.direction}dir' if self.grid else f'{self.sim_type} | {self.magnitude}Mw | Station {self.station} | {self.stories} stories - {self.nsubs} subs - {self.direction}dir'
229+
self.id = f'{self.sim_type} - {self.stories} stories - {self.nsubs} subs - {self.direction}dir' if self.grid else f'{self.sim_type} - {self.magnitude}Mw - Station {self.station} - {self.stories} stories - {self.nsubs} subs - {self.direction}dir'
230230
self.file_name = f'{self.sim_type}_20f{self.nsubs}_{self.direction}' if self.grid else f'{self.sim_type}_{self.magnitude}_{self.rup_type}{self.iteration}_s{self.station}_{self.direction}'
231-
self.drift_title = f'Drift per story Plot | {self.id}'
232-
self.spectrums_title = f'Story PSa Plot | {self.id}'
233-
self.base_shear_ss_title = f'Base Shear Plot | {self.id}'
231+
self.drift_title = f'Drift Plot - {self.id}'
232+
self.spectrums_title = f'Story PSa Plot - {self.id}'
233+
self.base_shear_ss_title = f'Base Shear Plot - {self.id}'
234234

235235
def plotConfig(self, title:str, x = 19.2, y = 10.8):
236236
"""
@@ -276,7 +276,10 @@ def to_empty(self, x, pos):
276276
return ''
277277
def to_equal(self, x, pos):
278278
return f'{x}'
279-
279+
def to_int(self, x, pos):
280+
return f'{int(x)}'
281+
def to_dot_mil(self, x, pos):
282+
return f'{(int(x/1000))}'
280283
def plotModelDrift(self, max_corner_x: list, max_center_x: list, max_corner_y: list, max_center_y:list, xlim_inf:float = 0.0, xlim_sup:float = 0.002,
281284
axes:plt.Axes|NDArray[plt.Axes]=None, save_fig:bool=True, legend:bool=True, fig_size: tuple[float, float]=(19.2, 10.8), line_color = None
282285
)->plt.Axes|NDArray[plt.Axes]:
@@ -319,23 +322,26 @@ def plotModelDrift(self, max_corner_x: list, max_center_x: list, max_corner_y: l
319322
color = color_1 if self.grid and not line_color else 'red'
320323
linewidth = 0.5 if self.grid and not line_color else 0.6
321324
marker = 'v' if line_color else None
322-
ax.plot(max_center_x, y, label='max_center_x', marker=marker, color=color, linewidth=0.5, markersize=2)
325+
label = 'Iter.Drift' if not line_color else 'Mean Iter.Drift'
326+
ax.plot(max_center_x, y, label=label, marker=marker, color=color, linewidth=0.5, markersize=2)
323327
else:
324328
candidate = np.array(max_center_y).max() + 0.0005 if self.station == 1 else 0
325329
ax.set_xlim(xlim_inf, candidate) if candidate > axes[0,0].get_xlim()[1] else ax.set_xlim(xlim_inf, axes[0,0].get_xlim()[1])
326330
color = color_1 if self.grid and not line_color else 'blue'
327331
linewidth = 0.5 if self.grid and not line_color else 0.6
328332
marker = 'd' if line_color else None
329-
ax.plot(max_center_y, y, label='max_center_y', marker=marker, color=color, linewidth=linewidth, markersize=2)
333+
label = 'Iter.Drift' if not line_color else 'Mean Iter.Drift'
334+
ax.plot(max_center_y, y, label=label, marker=marker, color=color, linewidth=linewidth, markersize=2)
330335

331336
# Plot NCH433 limits
332-
ax.axvline(x=0.002, color='black', linestyle='--', linewidth=0.55, alpha = 0.9, label='NCh433 Limit - 5.9.2 = 0.002')
337+
ax.axvline(x=0.002, color='black', linestyle='--', linewidth=0.55, alpha = 0.9, label='NCh433 Limit=0.002')
333338

334339
# Set legend and save fig if needed
335340
if legend:
336341
handles, labels = axes[0, 0].get_legend_handles_labels()
337-
fig.legend(handles, labels, loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure)
338-
342+
fig.legend([handles[-4], handles[-2], handles[-1]], [labels[-4], labels[-2], labels[-1]],
343+
loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure, fontsize='small')
344+
339345
if save_fig:
340346
fig.tight_layout()
341347
self.plotSave(fig)
@@ -397,7 +403,6 @@ def plotLocalStoriesSpectrums(self,
397403
# Compute df
398404
spa_df = pd.DataFrame({f'Story {story} {direction}': spa for story, spa in zip(stories_lst, spa_lst)}, index=T)
399405

400-
401406
if save_fig:
402407
self.plotSave(fig)
403408
return axes, spa_df
@@ -432,10 +437,12 @@ def plotMeanStoriesSpectrums(self,
432437
ax.set_title(f'Station {self.station}')
433438

434439
# Setup axis
435-
formatter = FuncFormatter(self.to_empty)
436-
ax.set_xlabel('T (s)') if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter)
440+
formatter1 = FuncFormatter(self.to_empty)
441+
formatter2 = FuncFormatter(self.to_int)
442+
ax.set_xlabel('T (s)') if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter1)
437443
ax.set_ylabel(f'Acceleration in {direction.upper()} (m/s/s)') if self.station in [4] else ax.set_ylabel('')
438-
444+
ax.yaxis.set_major_formatter(formatter2)
445+
439446
# Make plot spectrum
440447
T = np.linspace(0.003, 2, 1000)
441448
spa_lst = []
@@ -483,33 +490,30 @@ def plotShearBaseOverTime(self, time:np.ndarray, time_shear_fma:list[float], Qma
483490

484491
# Plot
485492
alpha = 0.1 if not mean else 1
486-
ax.plot(time, time_shear_fma, label='Shear Base Series', color='blue', linewidth=0.5, alpha=alpha)
487-
ax.axhline(y=Qmax, color='red', linestyle='--', linewidth=0.5, alpha = 0.9, label='NCh433 Qmax - 6.3.7.1')
493+
ax.plot(time, time_shear_fma, label='Shear Base', color='blue', linewidth=0.5, alpha=alpha)
494+
ax.axhline(y=Qmax, color='red', linestyle='--', linewidth=0.5, alpha = 0.9, label='NCh433 Qmax')
488495
ax.axhline(y=-Qmax, color='red', linestyle='--', linewidth=0.5, alpha = 0.9, label=None)
489496

490497
# Setup axis
491498
formatter1 = FuncFormatter(self.to_empty)
492499
formatter2 = FuncFormatter(self.to_equal)
500+
formatter3 = FuncFormatter(self.to_dot_mil)
493501
ax.set_ylim(ylim_inf, ylim_sup) if self.station ==1 and self.iteration == 1 else ax.set_ylim(axes[0, 0].get_ylim())
494502
ax.set_xlabel('Time (s)') if self.station in [8] else ax.xaxis.set_major_formatter(formatter1)
495-
ax.set_ylabel(f'Shear in {dir_.upper()} direction (kN)') if self.station in [4] else ax.set_ylabel('')
503+
ax.set_ylabel(f'Shear in {dir_.upper()} direction (Mega Newtons)') if self.station in [4] else ax.set_ylabel('')
496504
ax.xaxis.set_major_formatter(formatter2) if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter1)
497-
ax.yaxis.set_major_formatter(formatter2) if self.station in [1,4,7] else ax.yaxis.set_major_formatter(formatter1)
498-
499-
# Update lim negative if candidate is less than the current limit
500-
#candidate_neg = np.array(time_shear_fma).min() - 1000 if self.station == 1 else 0
501-
#ax.set_ylim(candidate_neg, axes[0,0].get_ylim()[1]) if candidate_neg < axes[0,0].get_ylim()[0] else ax.set_ylim(axes[0,0].get_ylim()[0], axes[0,0].get_ylim()[1])
502-
#candidate_pos = np.array(time_shear_fma).max() + 1000 if self.station == 1 else 0
503-
#ax.set_ylim(axes[0,0].get_ylim()[0], candidate_pos) if candidate_pos > axes[0,0].get_ylim()[1] else ax.set_ylim(axes[0,0].get_ylim()[0], axes[0,0].get_ylim()[1])
504-
505+
ax.yaxis.set_major_formatter(formatter3) if self.station in [1,4,7] else ax.yaxis.set_major_formatter(formatter1)
506+
505507
candidate_neg = np.array(time_shear_fma).min() - 1000 if self.station == 1 and mean else 0
506508
ax.set_ylim(candidate_neg, axes[0,0].get_ylim()[1]) if candidate_neg < axes[0,0].get_ylim()[0] else ax.set_ylim(axes[0,0].get_ylim()[0], axes[0,0].get_ylim()[1])
507509
candidate_pos = np.array(time_shear_fma).max() + 1000 if self.station == 1 and mean else 0
508510
ax.set_ylim(axes[0,0].get_ylim()[0], candidate_pos) if candidate_pos > axes[0,0].get_ylim()[1] else ax.set_ylim(axes[0,0].get_ylim()[0], axes[0,0].get_ylim()[1])
509511

510-
handles, labels = axes[0, 0].get_legend_handles_labels()
511512
if leyend:
512-
fig.legend(handles[-5:], labels[-5:], loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure)
513+
handles, labels = axes[0, 0].get_legend_handles_labels()
514+
fig.legend([handles[-3], handles[-2]], [labels[-3], labels[-2]],
515+
loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure, fontsize='small')
516+
513517
if save_fig:
514518
self.plotSave(fig)
515519
return axes

Python Scripts/PySeesTKO/pyseestko/queries.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,15 @@ def _plotMeanDriftColor(drifts_df_dict: Dict[str, pd.DataFrame], plotter: Plotti
325325
plotter.plotModelDrift([], mean_drifts_x, [], [],
326326
xlim_sup = xlim_sup,
327327
axes = drift_axes[0],
328-
legend = False,
328+
legend = True,
329329
save_fig = save_fig,
330330
fig_size = fig_size,
331331
line_color = 'red')
332332
plotter.setup_direction(x_direction=False)
333333
plotter.plotModelDrift([], [], [], mean_drifts_y,
334334
xlim_sup = xlim_sup,
335335
axes = drift_axes[1],
336-
legend = False,
336+
legend = True,
337337
save_fig = save_fig,
338338
fig_size = fig_size,
339339
line_color = 'blue')
@@ -360,7 +360,7 @@ def _plotMeanBaseShearColor(base_shear_df_dict: Dict[str, pd.DataFrame], plotter
360360
axes = base_shear_axes[0],
361361
save_fig = save_fig,
362362
fig_size = fig_size,
363-
leyend = False,
363+
leyend = True,
364364
mean = True)
365365
plotter.setup_direction(x_direction=False)
366366
plotter.plotShearBaseOverTime(
@@ -371,7 +371,7 @@ def _plotMeanBaseShearColor(base_shear_df_dict: Dict[str, pd.DataFrame], plotter
371371
axes = base_shear_axes[1],
372372
save_fig = save_fig,
373373
fig_size = fig_size,
374-
leyend = False,
374+
leyend = True,
375375
mean = True)
376376

377377
def getDriftDFs(drifts_df_lst:List[pd.DataFrame]):
@@ -798,10 +798,11 @@ def getAllResults(self,
798798
if save_b_shear is not None:
799799
# Init the query
800800
time_series, shear_x, shear_y, shear_z = self.base_shear()
801+
shear_x = list(np.array(shear_x) / 2.6)
802+
shear_y = list(np.array(shear_y) / 2.8)
801803

802804
# Init plot params
803805
nch = NCh433_2012(zone, soil_category, importance)
804-
Qmin = nch.computeMinBaseShear_c6_3_7_1(structure_weight)
805806
Qmax = nch.computeMaxBaseShear_c6_3_7_2(structure_weight)
806807

807808
# Plot the data

Python Scripts/query_data.py

Lines changed: 125 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pyseestko.utilities import getDriftResultsDF #type: ignore
88
from pyseestko.utilities import getSpectraResultsDF #type: ignore
99
from pyseestko.utilities import getSBaseResultsDF #type: ignore
10+
from pyseestko.utilities import assignZonesToStationsInDF #type: ignore
1011
# Temp imports
1112
import pandas as pd
1213
import winsound
@@ -58,8 +59,8 @@
5859
host = host,
5960
database = database,
6061
# Save params
61-
save_drift = True,
62-
save_spectra = True,
62+
save_drift = False,
63+
save_spectra = False,
6364
save_b_shear = True,
6465
save_results = save_csvs,
6566
# Plot params
@@ -75,45 +76,130 @@
7576
)
7677

7778
winsound.Beep(1000, 500)
78-
# --------------------------------------- LOAD DATA FOR ANOVA ----------------------------------------
79-
# Spectra results:
80-
max_spectra_lst_x = [(df.iloc[:,:5]).mean().max() for df in spectra_df_dict.values()]
81-
max_spectra_lst_y = [(df.iloc[:,5:]).mean().max() for df in spectra_df_dict.values()]
82-
83-
## Base shear results:
84-
#mean_base_shear_lst_x = [abs(df['Shear X'].mean()) for df in base_shear_df_dict.values()]
85-
#mean_base_shear_lst_y = [abs(df['Shear Y'].mean()) for df in base_shear_df_dict.values()]
8679

8780

8881
# %%
82+
# ----------------------------------------------------------------------------------------------------
83+
# --------------------------------------- LOAD DATA FOR ANOVA ----------------------------------------
84+
# ----------------------------------------------------------------------------------------------------
85+
# --------------------------------------- DRIFT ----------------------------------------
8986
# Compute Drift Results
90-
sim_type_lst = [key.split('_')[0] for key in drifts_df_dict.keys()]
91-
nsubs_lst = [key.split('_')[1] for key in drifts_df_dict.keys()]
92-
iteration_lst = [key.split('_')[4] for key in drifts_df_dict.keys()]
93-
station_lst = [key.split('_')[5] for key in drifts_df_dict.keys()]
94-
drift_df_max_x = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
95-
[df['Max x'].max() for df in drifts_df_dict.values()])
96-
drift_df_max_y = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
97-
[df['Max y'].max() for df in drifts_df_dict.values()])
98-
drift_df_mean_x = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
99-
[df['Max x'].mean() for df in drifts_df_dict.values()])
100-
drift_df_mean_y = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
101-
[df['Max y'].mean() for df in drifts_df_dict.values()])
102-
drift_tple = (drifts_df_dict, drift_df_max_x, drift_df_max_y, drift_df_mean_x, drift_df_mean_y)
103-
104-
# Compute Spectra Results
105-
sim_type_lst = [key.split('_')[0] for key in spectra_df_dict.keys()]
106-
nsubs_lst = [key.split('_')[1] for key in spectra_df_dict.keys()]
107-
iteration_lst = [key.split('_')[4] for key in spectra_df_dict.keys()]
108-
station_lst = [key.split('_')[5] for key in spectra_df_dict.keys()]
109-
spectra_df = getSpectraResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
110-
spectra_df_dict)
111-
112-
# Compute Base Shear Results
113-
sim_type_lst = [key.split('_')[0] for key in base_shear_df_dict.keys()]
114-
nsubs_lst = [key.split('_')[1] for key in base_shear_df_dict.keys()]
115-
iteration_lst = [key.split('_')[4] for key in base_shear_df_dict.keys()]
116-
station_lst = [key.split('_')[5] for key in base_shear_df_dict.keys()]
117-
base_shear_df = getSBaseResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
118-
base_shear_df_dict)
87+
if all(isinstance(value, pd.DataFrame) for value in drifts_df_dict.values()):
88+
sim_type_lst = [key.split('_')[0] for key in drifts_df_dict.keys()]
89+
nsubs_lst = [key.split('_')[1] for key in drifts_df_dict.keys()]
90+
iteration_lst = [key.split('_')[4] for key in drifts_df_dict.keys()]
91+
station_lst = [key.split('_')[5] for key in drifts_df_dict.keys()]
92+
93+
drift_df = pd.DataFrame({
94+
'Sim_Type' : sim_type_lst,
95+
'Nsubs' : nsubs_lst,
96+
'Iteration' : iteration_lst,
97+
'Station' : station_lst})
98+
99+
dfx = pd.DataFrame([df['CM x'] for df in drifts_df_dict.values()])
100+
dfy = pd.DataFrame([df['CM y'] for df in drifts_df_dict.values()])
101+
dfy = dfy.reset_index()
102+
dfx = dfx.reset_index()
103+
dfy = dfy.iloc[:,1:]
104+
dfx = dfx.iloc[:,1:]
105+
drift_df_x = pd.concat([drift_df, dfx], axis=1)
106+
drift_df_y = pd.concat([drift_df, dfy], axis=1)
107+
rename_dict = {
108+
1 : 's1',
109+
2 : 's2',
110+
3 : 's3',
111+
4 : 's4',
112+
5 : 's5',
113+
6 : 's6',
114+
7 : 's7',
115+
8 : 's8',
116+
9 : 's9',
117+
10 : 's10',
118+
11 : 's11',
119+
12 : 's12',
120+
13 : 's13',
121+
14 : 's14',
122+
15 : 's15',
123+
16 : 's16',
124+
17 : 's17',
125+
18 : 's18',
126+
19 : 's19',
127+
20 : 's20',
128+
}
129+
drift_df_x = drift_df_x.rename(columns=rename_dict).copy()[['Sim_Type', 'Nsubs', 'Iteration', 'Station', 's1','s5','s10','s15','s20']]
130+
drift_df_y = drift_df_y.rename(columns=rename_dict).copy()[['Sim_Type', 'Nsubs', 'Iteration', 'Station', 's1','s5','s10','s15','s20']]
131+
else:
132+
drift_df_x = pd.read_csv(project_path / 'drift_per_story_X_df.csv', index_col=0)
133+
drift_df_y = pd.read_csv(project_path / 'drift_per_story_Y_df.csv', index_col=0)
119134

135+
#%% Compute Spectra Results
136+
# --------------------------------------- SPECTRUM ----------------------------------------
137+
# We will have the acceleration at the period equal to mode 3 = 0.83s
138+
if all(isinstance(value, pd.DataFrame) for value in spectra_df_dict.values()):
139+
sim_type_lst = [key.split('_')[0] for key in spectra_df_dict.keys()]
140+
nsubs_lst = [key.split('_')[1] for key in spectra_df_dict.keys()]
141+
iteration_lst = [key.split('_')[4] for key in spectra_df_dict.keys()]
142+
station_lst = [key.split('_')[5] for key in spectra_df_dict.keys()]
143+
spectra_df = pd.DataFrame({
144+
'Sim_Type' : sim_type_lst,
145+
'Nsubs' : nsubs_lst,
146+
'Iteration' : iteration_lst,
147+
'Station' : station_lst,})
148+
spectra_df['Zone'] = spectra_df['Station'].apply(assignZonesToStationsInDF)
149+
columns_x = ['Story 1 x', 'Story 5 x', 'Story 10 x', 'Story 15 x', 'Story 20 x']
150+
columns_y = ['Story 1 y', 'Story 5 y', 'Story 10 y', 'Story 15 y', 'Story 20 y']
151+
152+
dfx = pd.DataFrame([df[columns_x].iloc[416] for df in spectra_df_dict.values()])
153+
dfy = pd.DataFrame([df[columns_y].iloc[416] for df in spectra_df_dict.values()])
154+
dfy = dfy.reset_index()
155+
dfx = dfx.reset_index()
156+
dfy = dfy.iloc[:,1:]
157+
dfx = dfx.iloc[:,1:]
158+
spectra_df_x = pd.concat([spectra_df, dfx], axis=1)
159+
spectra_df_y = pd.concat([spectra_df, dfy], axis=1)
160+
rename_dict = {
161+
'Story 1 x' : 's1',
162+
'Story 5 x' : 's5',
163+
'Story 10 x' : 's10',
164+
'Story 15 x' : 's15',
165+
'Story 20 x' : 's20',
166+
}
167+
spectra_df_x = spectra_df_x.rename(columns=rename_dict)
168+
rename_dict = {
169+
'Story 1 y' : 's1',
170+
'Story 5 y' : 's5',
171+
'Story 10 y' : 's10',
172+
'Story 15 y' : 's15',
173+
'Story 20 y' : 's20',
174+
}
175+
spectra_df_y = spectra_df_y.rename(columns=rename_dict)
176+
177+
else:
178+
spectra_df_x = pd.read_csv(project_path / 'spectra_per_story_X_df.csv', index_col=0)
179+
spectra_df_y = pd.read_csv(project_path / 'spectra_per_story_Y_df.csv', index_col=0)
180+
181+
#%% Compute Base Shear Results
182+
# --------------------------------------- BASE SHEAR ----------------------------------------
183+
if all(isinstance(value, pd.DataFrame) for value in base_shear_df_dict.values()):
184+
sim_type_lst = [key.split('_')[0] for key in base_shear_df_dict.keys()]
185+
nsubs_lst = [key.split('_')[1] for key in base_shear_df_dict.keys()]
186+
iteration_lst = [key.split('_')[4] for key in base_shear_df_dict.keys()]
187+
station_lst = [key.split('_')[5] for key in base_shear_df_dict.keys()]
188+
base_shear_df = pd.DataFrame({
189+
'Sim_Type' : sim_type_lst,
190+
'Nsubs' : nsubs_lst,
191+
'Iteration' : iteration_lst,
192+
'Station' : station_lst,})
193+
dfx = pd.DataFrame([df['Shear X'].abs().max() for df in base_shear_df_dict.values()], columns=['MaxShearX'])
194+
dfy = pd.DataFrame([df['Shear Y'].abs().max() for df in base_shear_df_dict.values()], columns=['MaxShearY'])
195+
dfy = dfy.reset_index()
196+
dfx = dfx.reset_index()
197+
dfy = dfy.iloc[:,1:]
198+
dfx = dfx.iloc[:,1:]
199+
base_shear_df_x = pd.concat([base_shear_df, dfx], axis=1)
200+
base_shear_df_y = pd.concat([base_shear_df, dfy], axis=1)
201+
else:
202+
base_shear_df_x = pd.read_csv(project_path / 'max_base_shear_X_df.csv', index_col=0)
203+
base_shear_df_y = pd.read_csv(project_path / 'max_base_shear_Y_df.csv', index_col=0)
204+
205+
# %%

0 commit comments

Comments
 (0)