Update app.py
Browse files
app.py
CHANGED
|
@@ -33,14 +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 |
-
with
|
| 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
|
| 44 |
|
| 45 |
# Cut input image and rebin it to 128x128 pixels
|
| 46 |
def cut(data0, wcs0, scale=1):
|
|
@@ -73,26 +73,33 @@ if uploaded_file is not None:
|
|
| 73 |
wcs = WCS(hdul[0].header)
|
| 74 |
|
| 75 |
# Make two columns
|
| 76 |
-
col1, col2 = st.columns(
|
| 77 |
col1.subheader("Input image")
|
| 78 |
-
|
| 79 |
|
| 80 |
# Add a slider to change the scale
|
| 81 |
with col1:
|
| 82 |
-
st.
|
| 83 |
-
|
| 84 |
-
|
| 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 |
-
|
| 92 |
-
|
| 93 |
-
with col2:
|
| 94 |
detect = st.button('Detect cavities')
|
|
|
|
|
|
|
|
|
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if detect:
|
| 97 |
data, wcs = cut(data, wcs, scale=scale)
|
| 98 |
|
|
@@ -110,11 +117,8 @@ if uploaded_file is not None:
|
|
| 110 |
|
| 111 |
plot_prediction(y_pred)
|
| 112 |
|
| 113 |
-
with col2:
|
| 114 |
-
download = st.button('Download')
|
| 115 |
-
|
| 116 |
if download:
|
| 117 |
-
ccd = CCDData(
|
| 118 |
ccd.write("predicted.fits", overwrite=True)
|
| 119 |
with open('predicted.fits', 'rb') as f:
|
| 120 |
data = f.read()
|
|
|
|
| 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 colA: 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 colB: st.pyplot()
|
| 44 |
|
| 45 |
# Cut input image and rebin it to 128x128 pixels
|
| 46 |
def cut(data0, wcs0, scale=1):
|
|
|
|
| 73 |
wcs = WCS(hdul[0].header)
|
| 74 |
|
| 75 |
# Make two columns
|
| 76 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 77 |
col1.subheader("Input image")
|
| 78 |
+
col3.subheader("CADET prediction")
|
| 79 |
|
| 80 |
# Add a slider to change the scale
|
| 81 |
with col1:
|
| 82 |
+
smooth = st.button("Smooth")
|
| 83 |
+
|
| 84 |
+
with col2:
|
| 85 |
+
st.markdown("""<style>[data-baseweb="select"] {margin-top: -52px;}</style>""", unsafe_allow_html=True)
|
| 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 |
+
with col3:
|
|
|
|
|
|
|
| 92 |
detect = st.button('Detect cavities')
|
| 93 |
+
|
| 94 |
+
with col4:
|
| 95 |
+
download = st.button('Download')
|
| 96 |
|
| 97 |
+
|
| 98 |
+
colA, colB = st.columns(2)
|
| 99 |
+
|
| 100 |
+
plot_image(np.log10(data+1), scale)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
if detect:
|
| 104 |
data, wcs = cut(data, wcs, scale=scale)
|
| 105 |
|
|
|
|
| 117 |
|
| 118 |
plot_prediction(y_pred)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
| 120 |
if download:
|
| 121 |
+
ccd = CCDData(y_pred, unit="adu", wcs=wcs)
|
| 122 |
ccd.write("predicted.fits", overwrite=True)
|
| 123 |
with open('predicted.fits', 'rb') as f:
|
| 124 |
data = f.read()
|