Update app.py
Browse files
app.py
CHANGED
|
@@ -134,6 +134,18 @@ def decompose_cavity(pred, th2=0.7, amin=10):
|
|
| 134 |
|
| 135 |
return image_decomposed
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
# Use wide layout and create columns
|
| 138 |
st.set_page_config(page_title="Cavity Detection Tool", layout="wide")
|
| 139 |
bordersize = 0.6
|
|
@@ -149,29 +161,29 @@ with col:
|
|
| 149 |
st.markdown("Input images should be centred at the centre of the galaxy and point sources should be filled with surrounding background ([dmfilth](https://cxc.cfa.harvard.edu/ciao/ahelp/dmfilth.html)).")
|
| 150 |
st.markdown("If you use this tool for your research, please cite [Plšek et al. 2023](https://arxiv.org/abs/2304.05457)")
|
| 151 |
|
| 152 |
-
_, col_1, col_2, col_3, _ = st.columns([bordersize, 2.0, 0.5, 0.5, bordersize])
|
| 153 |
|
| 154 |
-
with
|
| 155 |
-
# Create file uploader widget
|
| 156 |
uploaded_file = st.file_uploader("Choose a FITS file", type=['fits'])
|
| 157 |
|
| 158 |
-
with col_2:
|
| 159 |
-
|
| 160 |
-
|
| 161 |
|
| 162 |
-
with col_3:
|
| 163 |
-
|
| 164 |
-
|
| 165 |
|
| 166 |
-
# if NGC4649:
|
| 167 |
-
#
|
|
|
|
|
|
|
| 168 |
|
| 169 |
# If file is uploaded, read in the data and plot it
|
| 170 |
if uploaded_file is not None:
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
# Make six columns for buttons
|
| 176 |
_, col1, col2, col3, col4, col5, col6, _ = st.columns([bordersize,0.5,0.5,0.5,0.5,0.5,0.5,bordersize])
|
| 177 |
col1.subheader("Input image")
|
|
@@ -182,7 +194,7 @@ if uploaded_file is not None:
|
|
| 182 |
with col1:
|
| 183 |
st.markdown("""<style>[data-baseweb="select"] {margin-top: -46px;}</style>""", unsafe_allow_html=True)
|
| 184 |
max_scale = int(data.shape[0] // 128)
|
| 185 |
-
scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden")
|
| 186 |
scale = int(scale.split("x")[0]) // 128
|
| 187 |
|
| 188 |
# Detect button
|
|
@@ -192,7 +204,7 @@ if uploaded_file is not None:
|
|
| 192 |
with col4:
|
| 193 |
st.markdown("")
|
| 194 |
# st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
|
| 195 |
-
threshold = st.slider("Threshold", 0.0, 1.0, 0.0, 0.05) #, label_visibility="hidden")
|
| 196 |
|
| 197 |
# Decompose button
|
| 198 |
with col5: decompose = st.button('Decompose', key="decompose")
|
|
@@ -203,8 +215,8 @@ if uploaded_file is not None:
|
|
| 203 |
image = np.log10(data+1)
|
| 204 |
plot_image(image, scale)
|
| 205 |
|
| 206 |
-
|
| 207 |
-
if st.session_state.get("detect", True)
|
| 208 |
y_pred, wcs = cut_n_predict(data, wcs, scale)
|
| 209 |
|
| 210 |
y_pred_th = np.where(y_pred > threshold, y_pred, 0)
|
|
|
|
| 134 |
|
| 135 |
return image_decomposed
|
| 136 |
|
| 137 |
+
@st.cache
|
| 138 |
+
def load_file(fname):
|
| 139 |
+
with fits.open(fname) as hdul:
|
| 140 |
+
data = hdul[0].data
|
| 141 |
+
wcs = WCS(hdul[0].header)
|
| 142 |
+
return data, wcs
|
| 143 |
+
|
| 144 |
+
def change_scale():
|
| 145 |
+
del st.session_state["threshold"]
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
| 149 |
# Use wide layout and create columns
|
| 150 |
st.set_page_config(page_title="Cavity Detection Tool", layout="wide")
|
| 151 |
bordersize = 0.6
|
|
|
|
| 161 |
st.markdown("Input images should be centred at the centre of the galaxy and point sources should be filled with surrounding background ([dmfilth](https://cxc.cfa.harvard.edu/ciao/ahelp/dmfilth.html)).")
|
| 162 |
st.markdown("If you use this tool for your research, please cite [Plšek et al. 2023](https://arxiv.org/abs/2304.05457)")
|
| 163 |
|
| 164 |
+
# _, col_1, col_2, col_3, _ = st.columns([bordersize, 2.0, 0.5, 0.5, bordersize])
|
| 165 |
|
| 166 |
+
# with col:
|
|
|
|
| 167 |
uploaded_file = st.file_uploader("Choose a FITS file", type=['fits'])
|
| 168 |
|
| 169 |
+
# with col_2:
|
| 170 |
+
# st.markdown("### Examples")
|
| 171 |
+
# NGC4649 = st.button("NGC4649")
|
| 172 |
|
| 173 |
+
# with col_3:
|
| 174 |
+
# st.markdown("""<style>[data-baseweb="select"] {margin-top: 26px;}</style>""", unsafe_allow_html=True)
|
| 175 |
+
# NGC5813 = st.button("NGC5813")
|
| 176 |
|
| 177 |
+
# if NGC4649:
|
| 178 |
+
# uploaded_file = "NGC4649_example.fits"
|
| 179 |
+
# elif NGC5813:
|
| 180 |
+
# uploaded_file = "NGC5813_example.fits"
|
| 181 |
|
| 182 |
# If file is uploaded, read in the data and plot it
|
| 183 |
if uploaded_file is not None:
|
| 184 |
+
data, wcs = load_file(uploaded_file)
|
| 185 |
+
|
| 186 |
+
if "data" in locals():
|
|
|
|
| 187 |
# Make six columns for buttons
|
| 188 |
_, col1, col2, col3, col4, col5, col6, _ = st.columns([bordersize,0.5,0.5,0.5,0.5,0.5,0.5,bordersize])
|
| 189 |
col1.subheader("Input image")
|
|
|
|
| 194 |
with col1:
|
| 195 |
st.markdown("""<style>[data-baseweb="select"] {margin-top: -46px;}</style>""", unsafe_allow_html=True)
|
| 196 |
max_scale = int(data.shape[0] // 128)
|
| 197 |
+
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)
|
| 198 |
scale = int(scale.split("x")[0]) // 128
|
| 199 |
|
| 200 |
# Detect button
|
|
|
|
| 204 |
with col4:
|
| 205 |
st.markdown("")
|
| 206 |
# st.markdown("""<style>[data-baseweb="select"] {margin-top: -36px;}</style>""", unsafe_allow_html=True)
|
| 207 |
+
threshold = st.slider("Threshold", 0.0, 1.0, 0.0, 0.05, key="threshold") #, label_visibility="hidden")
|
| 208 |
|
| 209 |
# Decompose button
|
| 210 |
with col5: decompose = st.button('Decompose', key="decompose")
|
|
|
|
| 215 |
image = np.log10(data+1)
|
| 216 |
plot_image(image, scale)
|
| 217 |
|
| 218 |
+
if detect or threshold:
|
| 219 |
+
# if st.session_state.get("detect", True):
|
| 220 |
y_pred, wcs = cut_n_predict(data, wcs, scale)
|
| 221 |
|
| 222 |
y_pred_th = np.where(y_pred > threshold, y_pred, 0)
|