Plsek commited on
Commit
f615c2b
·
1 Parent(s): 1a8a2fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -33
app.py CHANGED
@@ -141,7 +141,7 @@ def decompose_cavity(pred, th2=0.7, amin=6):
141
 
142
  return image_decomposed
143
 
144
- @st.cache
145
  def load_file(fname):
146
  with fits.open(fname) as hdul:
147
  data = hdul[0].data
@@ -190,9 +190,6 @@ with col:
190
 
191
  if uploaded_file is not None:
192
  data, wcs = load_file(uploaded_file)
193
- # with fits.open(uploaded_file) as hdul:
194
- # data = hdul[0].data
195
- # wcs = WCS(hdul[0].header)
196
 
197
  # Make six columns for buttons
198
  _, col1, col2, col3, col4, col5, col6, _ = st.columns([bordersize,0.5,0.5,0.5,0.5,0.5,0.5,bordersize])
@@ -207,17 +204,17 @@ if uploaded_file is not None:
207
  scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden") #, on_change=change_scale)
208
  scale = int(scale.split("x")[0]) // 128
209
 
210
- # # Detect button
211
- # with col3: detect = st.button('Detect', key="detect")
212
 
213
- # # Threshold slider
214
- # with col4:
215
- # st.markdown("")
216
- # # st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
217
- # threshold = st.slider("Threshold", 0.0, 1.0, 0.0, 0.05, key="threshold") #, label_visibility="hidden")
218
 
219
- # # Decompose button
220
- # with col5: decompose = st.button('Decompose', key="decompose")
221
 
222
  # Make two columns for plots
223
  _, colA, colB, colC, _ = st.columns([bordersize,1,1,1,bordersize])
@@ -225,31 +222,31 @@ if uploaded_file is not None:
225
  image = np.log10(data+1)
226
  plot_image(image, scale)
227
 
228
- # if detect or threshold:
229
- # # if st.session_state.get("detect", True):
230
- # y_pred, wcs = cut_n_predict(data, wcs, scale)
231
 
232
- # y_pred_th = np.where(y_pred > threshold, y_pred, 0)
233
 
234
- # plot_prediction(y_pred_th)
235
 
236
- # if decompose or st.session_state.get("download", False):
237
- # image_decomposed = decompose_cavity(y_pred_th)
238
 
239
- # plot_decomposed(image_decomposed)
240
 
241
- # with col6:
242
- # st.markdown("<br style='margin:4px 0'>", unsafe_allow_html=True)
243
- # # st.markdown("""<style>[data-baseweb="select"] {margin-top: 16px;}</style>""", unsafe_allow_html=True)
244
- # fname = uploaded_file.name.strip(".fits")
245
 
246
- # # if st.session_state.get("download", False):
247
 
248
- # shutil.make_archive("predictions", 'zip', "predictions")
249
- # with open('predictions.zip', 'rb') as f:
250
- # res = f.read()
251
 
252
- # download = st.download_button(label="Download", data=res, key="download",
253
- # file_name=f'{fname}_{int(scale*128)}.zip',
254
- # # disabled=st.session_state.get("disabled", True),
255
- # mime="application/octet-stream")
 
141
 
142
  return image_decomposed
143
 
144
+ # @st.cache
145
  def load_file(fname):
146
  with fits.open(fname) as hdul:
147
  data = hdul[0].data
 
190
 
191
  if uploaded_file is not None:
192
  data, wcs = load_file(uploaded_file)
 
 
 
193
 
194
  # Make six columns for buttons
195
  _, col1, col2, col3, col4, col5, col6, _ = st.columns([bordersize,0.5,0.5,0.5,0.5,0.5,0.5,bordersize])
 
204
  scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden") #, on_change=change_scale)
205
  scale = int(scale.split("x")[0]) // 128
206
 
207
+ # Detect button
208
+ with col3: detect = st.button('Detect', key="detect")
209
 
210
+ # Threshold slider
211
+ with col4:
212
+ st.markdown("")
213
+ # st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
214
+ threshold = st.slider("Threshold", 0.0, 1.0, 0.0, 0.05, key="threshold") #, label_visibility="hidden")
215
 
216
+ # Decompose button
217
+ with col5: decompose = st.button('Decompose', key="decompose")
218
 
219
  # Make two columns for plots
220
  _, colA, colB, colC, _ = st.columns([bordersize,1,1,1,bordersize])
 
222
  image = np.log10(data+1)
223
  plot_image(image, scale)
224
 
225
+ if detect or threshold:
226
+ # if st.session_state.get("detect", True):
227
+ y_pred, wcs = cut_n_predict(data, wcs, scale)
228
 
229
+ y_pred_th = np.where(y_pred > threshold, y_pred, 0)
230
 
231
+ plot_prediction(y_pred_th)
232
 
233
+ if decompose or st.session_state.get("download", False):
234
+ image_decomposed = decompose_cavity(y_pred_th)
235
 
236
+ plot_decomposed(image_decomposed)
237
 
238
+ with col6:
239
+ st.markdown("<br style='margin:4px 0'>", unsafe_allow_html=True)
240
+ # st.markdown("""<style>[data-baseweb="select"] {margin-top: 16px;}</style>""", unsafe_allow_html=True)
241
+ fname = uploaded_file.name.strip(".fits")
242
 
243
+ # if st.session_state.get("download", False):
244
 
245
+ shutil.make_archive("predictions", 'zip', "predictions")
246
+ with open('predictions.zip', 'rb') as f:
247
+ res = f.read()
248
 
249
+ download = st.download_button(label="Download", data=res, key="download",
250
+ file_name=f'{fname}_{int(scale*128)}.zip',
251
+ # disabled=st.session_state.get("disabled", True),
252
+ mime="application/octet-stream")