Skip to content

Commit 85f27b1

Browse files
authored
Update BNewmark_app.py
1 parent 9418c1a commit 85f27b1

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

fun_BNewmark/Simple_App/BNewmark_app.py

+30-20
Original file line numberDiff line numberDiff line change
@@ -113,29 +113,39 @@
113113

114114

115115
################################################ Selection of Record #################################################
116+
# Selection of Record
116117
at2_files = glob.glob('*.AT2')
117118

118-
119-
col1, col2 = st.columns([1,2])
120-
with col1:
121-
st.markdown('**Seismic Records in the Directory**')
122-
srd = pd.DataFrame(at2_files)
123-
st.write(srd)
124-
125-
with col2:
126-
st.markdown('**Select a Record form the list**')
127-
row_numbers = list(range(len(srd)))
128-
aux = st.selectbox('**Record #**:', row_numbers)
129-
st.metric(label='Record Selected', value= at2_files[aux])
119+
if len(at2_files) > 0:
120+
col1, col2 = st.columns([1, 2])
121+
with col1:
122+
st.markdown('**Seismic Records in the Directory**')
123+
srd = pd.DataFrame(at2_files, columns=["Record Files"])
124+
st.write(srd)
130125

131-
with open(at2_files[aux], 'r') as f:
132-
contents = f.read()
133-
lines = contents.splitlines()
134-
data = []
135-
for line in lines:
136-
time, accel = line.split()
137-
data.append((float(time), float(accel)))
138-
Seismic = pd.DataFrame(data, columns=["Time [s]", "Acceleration [g]"])
126+
with col2:
127+
st.markdown('**Select a Record form the list**')
128+
row_numbers = list(range(len(srd)))
129+
aux = st.selectbox('**Record #**:', row_numbers)
130+
131+
if aux is not None:
132+
st.metric(label='Record Selected', value=at2_files[aux])
133+
with open(at2_files[aux], 'r') as f:
134+
contents = f.read()
135+
lines = contents.splitlines()
136+
data = []
137+
for line in lines:
138+
time, accel = line.split()
139+
data.append((float(time), float(accel)))
140+
Seismic = pd.DataFrame(data, columns=["Time [s]", "Acceleration [g]"])
141+
142+
# Further processing of the selected record
143+
TG = np.vstack([item[0] for item in data]) # Extracting the first column of data (time) as a NumPy array
144+
SG = np.vstack([item[1] for item in data]) # Extracting the second column of data (Acceleration) as a NumPy array
145+
146+
# Other parts of your code for plotting and displaying results remain the same
147+
else:
148+
st.warning("No seismic records found in the directory.")
139149

140150

141151
################################################ Convertion of Selected Record #################################################

0 commit comments

Comments
 (0)