Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from tensorflow.keras.models import load_model
|
|
8 |
|
9 |
st.set_option('deprecation.showPyplotGlobalUse', False)
|
10 |
|
11 |
-
st.title("
|
12 |
|
13 |
model = load_model("CADET.hdf5")
|
14 |
|
@@ -25,23 +25,44 @@ def plot_image(image_array, pred):
|
|
25 |
st.pyplot()
|
26 |
|
27 |
def cut(data0, wcs0, scale=1):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
# Create file uploader widget
|
35 |
uploaded_file = st.file_uploader("Choose a FITS file", type=['fits'])
|
36 |
|
|
|
|
|
|
|
37 |
# If file is uploaded, read in the data and plot it
|
38 |
if uploaded_file is not None:
|
39 |
with fits.open(uploaded_file) as hdul:
|
40 |
data = hdul[0].data
|
41 |
wcs = WCS(hdul[0].header)
|
42 |
-
data, wcs = cut(data, wcs, scale=
|
43 |
|
44 |
image_data = np.log10(data+1)
|
45 |
pred = model.predict(image_data.reshape(1, 128, 128, 1)).reshape(128 ,128)
|
46 |
|
|
|
|
|
|
|
47 |
plot_image(image_data, pred)
|
|
|
8 |
|
9 |
st.set_option('deprecation.showPyplotGlobalUse', False)
|
10 |
|
11 |
+
st.title("Cavity Detection Tool")
|
12 |
|
13 |
model = load_model("CADET.hdf5")
|
14 |
|
|
|
25 |
st.pyplot()
|
26 |
|
27 |
def cut(data0, wcs0, scale=1):
|
28 |
+
shape = data0.shape[0]
|
29 |
+
x0 = shape / 2
|
30 |
+
size = 128 * scale
|
31 |
+
cutout = Cutout2D(data0, (x0, x0), (size, size), wcs=wcs0)
|
32 |
+
data, wcs = cutout.data, cutout.wcs
|
33 |
+
|
34 |
+
# REGRID DATA
|
35 |
+
factor = size // 128
|
36 |
+
data = data.reshape(128, factor, 128, factor).mean(-1).mean(1)
|
37 |
+
|
38 |
+
# REGIRD WCS
|
39 |
+
ra, dec = wcs.wcs_pix2world(np.array([[63, 63]]),0)[0]
|
40 |
+
wcs.wcs.cdelt[0] = wcs.wcs.cdelt[0] * factor
|
41 |
+
wcs.wcs.cdelt[1] = wcs.wcs.cdelt[1] * factor
|
42 |
+
wcs.wcs.crval[0] = ra
|
43 |
+
wcs.wcs.crval[1] = dec
|
44 |
+
wcs.wcs.crpix[0] = 64 / factor
|
45 |
+
wcs.wcs.crpix[1] = 64 / factor
|
46 |
+
|
47 |
+
return data, wcs
|
48 |
|
49 |
# Create file uploader widget
|
50 |
uploaded_file = st.file_uploader("Choose a FITS file", type=['fits'])
|
51 |
|
52 |
+
# Add a slider to change the scale
|
53 |
+
scale = st.slider("Scale", 1, 4, 1, 1)
|
54 |
+
|
55 |
# If file is uploaded, read in the data and plot it
|
56 |
if uploaded_file is not None:
|
57 |
with fits.open(uploaded_file) as hdul:
|
58 |
data = hdul[0].data
|
59 |
wcs = WCS(hdul[0].header)
|
60 |
+
data, wcs = cut(data, wcs, scale=scale)
|
61 |
|
62 |
image_data = np.log10(data+1)
|
63 |
pred = model.predict(image_data.reshape(1, 128, 128, 1)).reshape(128 ,128)
|
64 |
|
65 |
+
ccd = CCDData(pred, unit="adu", wcs=wcs)
|
66 |
+
ccd.write(f"predicted.fits", overwrite=True)
|
67 |
+
|
68 |
plot_image(image_data, pred)
|