Update app.py
Browse files
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 |
-
#
|
211 |
-
|
212 |
|
213 |
-
#
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
|
219 |
-
#
|
220 |
-
|
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 |
-
|
229 |
-
#
|
230 |
-
|
231 |
|
232 |
-
|
233 |
|
234 |
-
|
235 |
|
236 |
-
|
237 |
-
|
238 |
|
239 |
-
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
|
246 |
-
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
|
|
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")
|