Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added DataBase-Outputs/Base Shear Output/AB_20f2_X.pdf
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/AB_20f2_Y.pdf
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/AB_20f4_X.pdf
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/AB_20f4_Y.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/FB_20f2_X.pdf
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/FB_20f2_Y.pdf
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/FB_20f4_X.pdf
Binary file not shown.
Binary file added DataBase-Outputs/Base Shear Output/FB_20f4_Y.pdf
Binary file not shown.
Binary file removed DataBase-Outputs/Base Shear Output/None.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/AB_20f2_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/AB_20f2_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/AB_20f4_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/AB_20f4_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/DRM_20f2_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/DRM_20f2_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/DRM_20f4_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/DRM_20f4_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/FB_20f2_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/FB_20f2_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/FB_20f4_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Drift Output/FB_20f4_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/AB_20f2_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/AB_20f2_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/AB_20f4_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/AB_20f4_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/DRM_20f2_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/DRM_20f2_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/DRM_20f4_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/DRM_20f4_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/FB_20f2_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/FB_20f2_Y.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/FB_20f4_X.pdf
Binary file not shown.
Binary file modified DataBase-Outputs/Story Spectra Output/FB_20f4_Y.pdf
Binary file not shown.
271 changes: 271 additions & 0 deletions DataBase-Outputs/base_shear_df.csv

Large diffs are not rendered by default.

271 changes: 271 additions & 0 deletions DataBase-Outputs/drift_df.csv

Large diffs are not rendered by default.

271 changes: 271 additions & 0 deletions DataBase-Outputs/spectra_df.csv

Large diffs are not rendered by default.

70 changes: 50 additions & 20 deletions Python Scripts/PySeesTKO/pyseestko/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ def setup_direction(self, x_direction:bool=True):
self.direction = 'X' if x_direction else 'Y'
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'
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}'
self.drift_title = f'Drift per story plot | {self.id}'
self.spectrums_title = f'Story PSa plot | {self.id}'
self.drift_title = f'Drift per story Plot | {self.id}'
self.spectrums_title = f'Story PSa Plot | {self.id}'
self.base_shear_ss_title = f'Base Shear Plot | {self.id}'

def plotConfig(self, title:str, x = 19.2, y = 10.8):
Expand Down Expand Up @@ -314,15 +314,19 @@ def plotModelDrift(self, max_corner_x: list, max_center_x: list, max_corner_y: l
# Plot center drift
y = [i for i in range(1, self.stories+1)]
if self.x_direction:
candidate = np.array(max_center_x).max() + 0.0005 if self.station == 1 else 0
candidate = np.array(max_center_x).max() + 0.0005 if self.station == 1 else 0
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])
color = color_1 if self.grid and not line_color else 'red'
ax.plot(max_center_x, y, label='max_center_x', color=color, linewidth=0.5, markersize=5)
linewidth = 0.5 if self.grid and not line_color else 0.6
marker = 'v' if line_color else None
ax.plot(max_center_x, y, label='max_center_x', marker=marker, color=color, linewidth=0.5, markersize=2)
else:
candidate = np.array(max_center_y).max() + 0.0005 if self.station == 1 else 0
candidate = np.array(max_center_y).max() + 0.0005 if self.station == 1 else 0
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])
color = color_1 if self.grid and not line_color else 'blue'
ax.plot(max_center_y, y, label='max_center_y', color=color, linewidth=0.5, markersize=5)
linewidth = 0.5 if self.grid and not line_color else 0.6
marker = 'd' if line_color else None
ax.plot(max_center_y, y, label='max_center_y', marker=marker, color=color, linewidth=linewidth, markersize=2)

# Plot NCH433 limits
ax.axvline(x=0.002, color='black', linestyle='--', linewidth=0.55, alpha = 0.9, label='NCh433 Limit - 5.9.2 = 0.002')
Expand Down Expand Up @@ -361,7 +365,9 @@ def plotLocalStoriesSpectrums(self,
row = (self.station - 1) // 3
col = (self.station - 1) % 3
ax = axes[row, col]

# Set local title
ax.set_title(f'Station {self.station}')

# Setup axis
formatter = FuncFormatter(self.to_empty)
ax.set_xlabel('T (s)') if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter)
Expand Down Expand Up @@ -421,12 +427,15 @@ def plotMeanStoriesSpectrums(self,
row = (self.station - 1) // 3
col = (self.station - 1) % 3
ax = axes[row, col]


# Set local title
ax.set_title(f'Station {self.station}')

# Setup axis
formatter = FuncFormatter(self.to_empty)
ax.set_xlabel('T (s)') if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter)
ax.set_ylabel(f'Acceleration in {direction.upper()} (m/s/s)') if self.station in [4] else ax.set_ylabel('')

# Make plot spectrum
T = np.linspace(0.003, 2, 1000)
spa_lst = []
Expand All @@ -445,14 +454,14 @@ def plotMeanStoriesSpectrums(self,
ax.plot(T, Spe, label=f'Story {story}', linestyle=line_style, color=color, linewidth=0.5)

handles, labels = axes[0, 0].get_legend_handles_labels()
fig.legend(handles[-5:], labels[-5:], loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure)
fig.legend(handles[-5:], labels[-5:], loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure, fontsize='small')

if save_fig:
self.plotSave(fig)


def plotShearBaseOverTime(self, time:np.ndarray, time_shear_fma:list[float], Qmax:float, dir_:str, axes: plt.Axes=None,
save_fig:bool=True, fig_size:tuple[float, float]=(19.2, 10.8), mean=False):
save_fig:bool=True, fig_size:tuple[float, float]=(19.2, 10.8), mean=False, leyend=False,
ylim_inf=-100, ylim_sup=100)->plt.Axes|NDArray[plt.Axes]:
# Input params
if dir_ not in ['x','X','y','Y']: raise ValueError(f'dir must be x, y! Current: {dir}')

Expand All @@ -468,18 +477,39 @@ def plotShearBaseOverTime(self, time:np.ndarray, time_shear_fma:list[float], Qma
row = (self.station - 1) // 3
col = (self.station - 1) % 3
ax = axes[row, col]

ax.axhline(y=Qmax, color='red', linestyle='--', linewidth=0.5, alpha = 0.9, label='NCh433 Qmax - 6.3.7.1') if not mean and self.iteration == 1 else None
ax.axhline(y=-Qmax, color='red', linestyle='--', linewidth=0.5, alpha = 0.9, label=None) if not mean and self.iteration == 1 else None

formatter = FuncFormatter(self.to_empty)
ax.set_xlabel('Time (s)') if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter)
ax.set_ylabel(f'Shear in {dir_.upper()} direction (kN)') if self.station in [4] else ax.set_ylabel('')

# Set local title
ax.set_title(f'Station {self.station}')

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

# Setup axis
formatter1 = FuncFormatter(self.to_empty)
formatter2 = FuncFormatter(self.to_equal)
ax.set_ylim(ylim_inf, ylim_sup) if self.station ==1 and self.iteration == 1 else ax.set_ylim(axes[0, 0].get_ylim())
ax.set_xlabel('Time (s)') if self.station in [8] else ax.xaxis.set_major_formatter(formatter1)
ax.set_ylabel(f'Shear in {dir_.upper()} direction (kN)') if self.station in [4] else ax.set_ylabel('')
ax.xaxis.set_major_formatter(formatter2) if self.station in [7,8,9] else ax.xaxis.set_major_formatter(formatter1)
ax.yaxis.set_major_formatter(formatter2) if self.station in [1,4,7] else ax.yaxis.set_major_formatter(formatter1)

# Update lim negative if candidate is less than the current limit
#candidate_neg = np.array(time_shear_fma).min() - 1000 if self.station == 1 else 0
#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])
#candidate_pos = np.array(time_shear_fma).max() + 1000 if self.station == 1 else 0
#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])

candidate_neg = np.array(time_shear_fma).min() - 1000 if self.station == 1 and mean else 0
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])
candidate_pos = np.array(time_shear_fma).max() + 1000 if self.station == 1 and mean else 0
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])

handles, labels = axes[0, 0].get_legend_handles_labels()
fig.legend(handles[-5:], labels[-5:], loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure)
if leyend:
fig.legend(handles[-5:], labels[-5:], loc='upper right', bbox_to_anchor=(1, 1), bbox_transform=fig.transFigure)
if save_fig:
self.plotSave(fig)
return axes
Expand Down
61 changes: 33 additions & 28 deletions Python Scripts/PySeesTKO/pyseestko/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pyseestko.utilities import initialize_ssh_tunnel #type: ignore
from pyseestko.utilities import checkMainQueryInput #type: ignore
from pyseestko.utilities import save_df_to_csv_paths #type: ignore
from pyseestko.utilities import getDriftResultsDF #type: ignore
from pathlib import Path
from typing import List, Dict, Tuple
from tqdm import tqdm
Expand Down Expand Up @@ -56,8 +55,7 @@ def executeMainQuery(
windows : bool = True,
project_path: Path = git_path/ 'DataBase-Outputs',
verbose : bool = True,
) -> Tuple[Tuple[dict, pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame],
Dict[str, List[pd.DataFrame]], Dict[str, pd.DataFrame]]:
) -> Tuple[Dict[str, pd.DataFrame], Dict[str, pd.DataFrame], Dict[str, pd.DataFrame]]:
"""
This function will execute the main query to get the results from the database
The logic is the following:
Expand Down Expand Up @@ -132,26 +130,11 @@ def executeMainQuery(
# -------------------------------------- RETURN THE RESULTS --------------------------------------
drift_tple = (None, None, None, None, None)
spectra_tple = (None, None)
base_shear_tple = None
base_shear_tple = (None, None)

# Compute Drift Results
if save_drift:
sim_type_lst = [key.split('_')[0] for key in drifts_df_dict.keys()]
nsubs_lst = [key.split('_')[1] for key in drifts_df_dict.keys()]
iteration_lst = [key.split('_')[4] for key in drifts_df_dict.keys()]
station_lst = [key.split('_')[5] for key in drifts_df_dict.keys()]

drift_df_max_x = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
[df['Max x'].max() for df in drifts_df_dict.values()])
drift_df_max_y = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
[df['Max y'].max() for df in drifts_df_dict.values()])
drift_df_mean_x = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
[df['Max x'].mean() for df in drifts_df_dict.values()])
drift_df_mean_y = getDriftResultsDF(sim_type_lst, nsubs_lst, iteration_lst, station_lst,
[df['Max y'].mean() for df in drifts_df_dict.values()])
drift_tple = (drifts_df_dict, drift_df_max_x, drift_df_max_y, drift_df_mean_x, drift_df_mean_y)


return drift_tple, spectra_df_dict, base_shear_df_dict
return drift_tple, spectra_tple, base_shear_tple

def queryMetricsInSinglePlots(
# Params
Expand Down Expand Up @@ -267,7 +250,7 @@ def queryMetricsInGridPlots(
# Optional params
windows : bool = True,
verbose : bool = True,
)-> Tuple[Dict[str, pd.DataFrame], Dict[str, List[pd.DataFrame]], Dict[str, pd.DataFrame]]:
)-> Tuple[Dict[str, pd.DataFrame], Dict[str, pd.DataFrame], Dict[str, pd.DataFrame]]:
"""
This function will execute the main query to get the results from the database in grid plots
The grid is going to be a 3x3 grid with the drifts, spectra and base shear.
Expand All @@ -282,11 +265,12 @@ def queryMetricsInGridPlots(
save_drift = project_path / 'Drift Output' if save_drift else None
save_spectra = project_path / 'Story Spectra Output' if save_spectra else None
save_b_shear = project_path / 'Base Shear Output' if save_b_shear else None

nch = NCh433_2012('Las Condes', 'B', 2)
# Iterate over the subs, then over the sim_type and then over the stations so we can get all the results
for sim_type in sim_types:
for nsubs in nsubs_lst:
structure_weight = 22241.3 if nsubs == 4 else 18032.3
Qmax = nch.computeMaxBaseShear_c6_3_7_2(structure_weight)

# Drift params
drift_axes = [np.full((3, 3), None), np.full((3, 3), None)]
Expand Down Expand Up @@ -333,7 +317,8 @@ def queryMetricsInGridPlots(
# Plot mean spectra
_plotMeanSpectraColor(spectra_df_dict, plotter, spectra_axes, save_fig, fig_size) if save_spectra else None

_plotMeanBaseShearColor(base_shear_df_dict, plotter, base_shear_axes, save_fig, fig_size) if save_b_shear else None
# Plot mean base shear
_plotMeanBaseShearColor(base_shear_df_dict, plotter, base_shear_axes, save_fig, fig_size, Qmax) if save_b_shear else None

# Update tqdm
pbar.update(1)
Expand Down Expand Up @@ -370,13 +355,31 @@ def _plotMeanSpectraColor(spectra_df_dict: Dict[str, pd.DataFrame], plotter: Plo
plotter.setup_direction(x_direction=False)
plotter.plotMeanStoriesSpectrums(mean_spectras_y, 'y', [1,5,10,15,20], save_fig, spectra_axes[1], fig_size)

def _plotMeanBaseShearColor(base_shear_df_dict: Dict[str, pd.DataFrame], plotter: Plotting, spectra_axes:plt.Axes, save_fig:bool, fig_size:bool):
def _plotMeanBaseShearColor(base_shear_df_dict: Dict[str, pd.DataFrame], plotter: Plotting, base_shear_axes:plt.Axes, save_fig:bool, fig_size:bool, Qmax:float):
mean_base_shear_x = pd.concat([df['Shear X'] for df in list(base_shear_df_dict.values())[-5:]], axis=1).mean(axis=1)
mean_base_shear_y = pd.concat([df['Shear Y'] for df in list(base_shear_df_dict.values())[-5:]], axis=1).mean(axis=1)
plotter.setup_direction(x_direction=True)
plotter.plotShearBaseOverTime(mean_base_shear_x.index, mean_base_shear_x.values, 0, 'x', spectra_axes[0], save_fig, fig_size, mean=True)
plotter.plotShearBaseOverTime(
time = mean_base_shear_x.index,
time_shear_fma = mean_base_shear_x.values,
Qmax = Qmax,
dir_ = 'x',
axes = base_shear_axes[0],
save_fig = save_fig,
fig_size = fig_size,
leyend = False,
mean = True)
plotter.setup_direction(x_direction=False)
plotter.plotShearBaseOverTime(mean_base_shear_y.index, mean_base_shear_y.values, 0, 'y', spectra_axes[1], save_fig, fig_size, mean=True)
plotter.plotShearBaseOverTime(
time = mean_base_shear_y.index,
time_shear_fma = mean_base_shear_y.values,
Qmax = Qmax,
dir_ = 'y',
axes = base_shear_axes[1],
save_fig = save_fig,
fig_size = fig_size,
leyend = False,
mean = True)

def getDriftDFs(drifts_df_lst:List[pd.DataFrame]):
"""
Expand Down Expand Up @@ -474,7 +477,7 @@ def getReplicaCummStatisticDriftDFs(drifts_df_lst:List[pd.DataFrame], statistic:

return df1, df2, drift_df

def getSpectraDfs(spectra_df_lst:List[pd.DataFrame]):
def DEPgetSpectraDfs(spectra_df_lst:List[pd.DataFrame]):
"""
This function will get the mean spectra dataframes of the x and y directions}
and return the spectra dataframe of the x direction, the spectra dataframe of the y direction
Expand Down Expand Up @@ -810,6 +813,7 @@ def getAllResults(self,

# Plot the data
self.plotter.save_path = Path(save_b_shear)
self.plotter.setup_direction(x_direction=True)
shear_axes_x = self.plotter.plotShearBaseOverTime(
time = time_series,
time_shear_fma = shear_x,
Expand All @@ -820,6 +824,7 @@ def getAllResults(self,
fig_size = fig_size,
mean = False
)
self.plotter.setup_direction(x_direction=False)
shear_axes_y = self.plotter.plotShearBaseOverTime(
time = time_series,
time_shear_fma = shear_y,
Expand Down
40 changes: 40 additions & 0 deletions Python Scripts/PySeesTKO/pyseestko/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,46 @@ def getDriftResultsDF(
drift_df['Zone'] = drift_df['Station'].apply(assignZonesToStationsInDF)
return drift_df

def getSpectraResultsDF(
sim_type_lst : List[str],
nsubs_lst : List[str],
iteration_lst : List[str],
station_lst : List[str],
spectra_df_dict: Dict[str, pd.DataFrame],
):
max_spectra_lst_x = [(df.iloc[:,:5]).mean().max() for df in spectra_df_dict.values()]
max_spectra_lst_y = [(df.iloc[:,5:]).mean().max() for df in spectra_df_dict.values()]
spectra_df = pd.DataFrame({
'Sim_Type' : sim_type_lst,
'Nsubs' : nsubs_lst,
'Iteration' : iteration_lst,
'Station' : station_lst,
'Max_Spectra_X': max_spectra_lst_x,
'Max_Spectra_Y': max_spectra_lst_y
})
spectra_df['Zone'] = spectra_df['Station'].apply(assignZonesToStationsInDF)
return spectra_df

def getSBaseResultsDF(
sim_type_lst : List[str],
nsubs_lst : List[str],
iteration_lst : List[str],
station_lst : List[str],
base_shear_df_dict: Dict[str, pd.DataFrame]
):
mean_base_shear_lst_x = [abs(df['Shear X'].mean()) for df in base_shear_df_dict.values()]
mean_base_shear_lst_y = [abs(df['Shear Y'].mean()) for df in base_shear_df_dict.values()]
base_shear_df = pd.DataFrame({
'Sim_Type' : sim_type_lst,
'Nsubs' : nsubs_lst,
'Iteration' : iteration_lst,
'Station' : station_lst,
'BShear_X' : mean_base_shear_lst_x,
'BShear_Y' : mean_base_shear_lst_y
})
base_shear_df['Zone'] = base_shear_df['Station'].apply(assignZonesToStationsInDF)
return base_shear_df


# ==================================================================================
# =============================== UTILITY FUNCTIONS ================================
Expand Down
Loading