Update app.py
Browse files
app.py
CHANGED
|
@@ -33,15 +33,14 @@ def plot_image(image_array, scale):
|
|
| 33 |
plt.gca().add_patch(Rectangle((x0, x0), scale*128, scale*128, linewidth=1, edgecolor='w', facecolor='none'))
|
| 34 |
|
| 35 |
plt.axis('off')
|
| 36 |
-
st.pyplot()
|
| 37 |
|
| 38 |
# Define function to plot the prediction
|
| 39 |
def plot_prediction(pred):
|
| 40 |
plt.figure(figsize=(4, 4))
|
| 41 |
plt.imshow(pred, origin="lower")
|
| 42 |
plt.axis('off')
|
| 43 |
-
|
| 44 |
-
st.pyplot()
|
| 45 |
|
| 46 |
# Cut input image and rebin it to 128x128 pixels
|
| 47 |
def cut(data0, wcs0, scale=1):
|
|
@@ -77,54 +76,46 @@ if uploaded_file is not None:
|
|
| 77 |
col1, col2 = st.columns(2)
|
| 78 |
col1.subheader("Input image")
|
| 79 |
col2.subheader("CADET prediction")
|
| 80 |
-
|
| 81 |
-
with col1:
|
| 82 |
-
col1_1, col1_2 = st.columns(2)
|
| 83 |
-
|
| 84 |
-
with col1_2:
|
| 85 |
-
st.Button("Smooth")
|
| 86 |
|
| 87 |
-
with col1_1:
|
| 88 |
-
st.markdown(
|
| 89 |
-
"""<style>[data-baseweb="select"] {margin-top: -50px;}</style>""",
|
| 90 |
-
unsafe_allow_html=True
|
| 91 |
-
)
|
| 92 |
-
|
| 93 |
-
max_scale = int(data.shape[0] // 128)
|
| 94 |
-
# scale = st.slider("Scale", 1, max_scale, 1, 1)
|
| 95 |
-
scale = int(st.selectbox('Scale:',[i+1 for i in range(max_scale)], label_visibility="hidden"))
|
| 96 |
-
|
| 97 |
# Add a slider to change the scale
|
| 98 |
with col1:
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
with col2:
|
| 102 |
-
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
data, wcs = cut(data, wcs, scale=scale)
|
| 107 |
-
|
| 108 |
-
image = np.log10(data+1)
|
| 109 |
-
|
| 110 |
-
y_pred = 0
|
| 111 |
-
for j in [0,1,2,3]:
|
| 112 |
-
rotated = np.rot90(image, j)
|
| 113 |
-
pred = model.predict(rotated.reshape(1, 128, 128, 1)).reshape(128 ,128)
|
| 114 |
-
pred = np.rot90(pred, -j)
|
| 115 |
-
y_pred += pred / 4
|
| 116 |
-
|
| 117 |
-
# Thresholding
|
| 118 |
-
y_pred = np.where(y_pred > 0.4, y_pred, 0)
|
| 119 |
|
| 120 |
-
|
| 121 |
-
plot_prediction(y_pred)
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
plt.gca().add_patch(Rectangle((x0, x0), scale*128, scale*128, linewidth=1, edgecolor='w', facecolor='none'))
|
| 34 |
|
| 35 |
plt.axis('off')
|
| 36 |
+
with col1: st.pyplot()
|
| 37 |
|
| 38 |
# Define function to plot the prediction
|
| 39 |
def plot_prediction(pred):
|
| 40 |
plt.figure(figsize=(4, 4))
|
| 41 |
plt.imshow(pred, origin="lower")
|
| 42 |
plt.axis('off')
|
| 43 |
+
with col2: st.pyplot()
|
|
|
|
| 44 |
|
| 45 |
# Cut input image and rebin it to 128x128 pixels
|
| 46 |
def cut(data0, wcs0, scale=1):
|
|
|
|
| 76 |
col1, col2 = st.columns(2)
|
| 77 |
col1.subheader("Input image")
|
| 78 |
col2.subheader("CADET prediction")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
# Add a slider to change the scale
|
| 81 |
with col1:
|
| 82 |
+
st.markdown(
|
| 83 |
+
"""<style>[data-baseweb="select"] {margin-top: -50px;}</style>""",
|
| 84 |
+
unsafe_allow_html=True
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
max_scale = int(data.shape[0] // 128)
|
| 88 |
+
# scale = st.slider("Scale", 1, max_scale, 1, 1)
|
| 89 |
+
scale = int(st.selectbox('Scale:',[i+1 for i in range(max_scale)], label_visibility="hidden"))
|
| 90 |
+
|
| 91 |
+
plot_image(np.log10(data+1), scale)
|
| 92 |
|
| 93 |
with col2:
|
| 94 |
+
detect = st.button('Detect cavities'):
|
| 95 |
|
| 96 |
+
if detect:
|
| 97 |
+
data, wcs = cut(data, wcs, scale=scale)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
+
image = np.log10(data+1)
|
|
|
|
| 100 |
|
| 101 |
+
y_pred = 0
|
| 102 |
+
for j in [0,1,2,3]:
|
| 103 |
+
rotated = np.rot90(image, j)
|
| 104 |
+
pred = model.predict(rotated.reshape(1, 128, 128, 1)).reshape(128 ,128)
|
| 105 |
+
pred = np.rot90(pred, -j)
|
| 106 |
+
y_pred += pred / 4
|
| 107 |
+
|
| 108 |
+
# Thresholding
|
| 109 |
+
y_pred = np.where(y_pred > 0.4, y_pred, 0)
|
| 110 |
+
|
| 111 |
+
plot_prediction(y_pred)
|
| 112 |
+
|
| 113 |
+
# with col2:
|
| 114 |
+
# download = st.button('Download FITS File')
|
| 115 |
+
|
| 116 |
+
# if download:
|
| 117 |
+
# ccd = CCDData(pred, unit="adu", wcs=wcs)
|
| 118 |
+
# ccd.write(f"predicted.fits", overwrite=True)
|
| 119 |
+
# with open('predicted.fits', 'rb') as f:
|
| 120 |
+
# data = f.read()
|
| 121 |
+
# st.download_button(label="Download", data=data, file_name="predicted.fits", mime="application/octet-stream")
|