Plsek commited on
Commit
8111624
·
1 Parent(s): 47ec853

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -7,6 +7,7 @@ import os
7
  import shutil
8
  import numpy as np
9
  import matplotlib.pyplot as plt
 
10
  from matplotlib.patches import Rectangle
11
 
12
  # Astropy
@@ -44,11 +45,9 @@ with col:
44
  # Define function to plot the uploaded image
45
  def plot_image(image, scale):
46
  plt.figure(figsize=(4, 4))
47
-
48
  x0 = image.shape[0] // 2 - scale * 128 / 2
49
  plt.imshow(image, origin="lower")
50
  plt.gca().add_patch(Rectangle((x0, x0), scale*128, scale*128, linewidth=1, edgecolor='w', facecolor='none'))
51
-
52
  plt.axis('off')
53
  with colA: st.pyplot()
54
 
@@ -62,7 +61,14 @@ def plot_prediction(pred):
62
  # Define function to plot the decomposed prediction
63
  def plot_decomposed(decomposed):
64
  plt.figure(figsize=(4, 4))
65
- plt.imshow(decomposed, origin="lower")
 
 
 
 
 
 
 
66
  plt.axis('off')
67
  with colC: st.pyplot()
68
 
@@ -121,7 +127,6 @@ if uploaded_file is not None:
121
  with fits.open(uploaded_file) as hdul:
122
  data = hdul[0].data
123
  wcs = WCS(hdul[0].header)
124
- y_pred = np.zeros((128,128))
125
 
126
  # Make four columns for buttons
127
  _, col1, col2, col3, col4, col5, col6, _ = st.columns([bordersize,0.5,0.5,0.5,0.5,0.5,0.5,bordersize])
@@ -134,7 +139,6 @@ if uploaded_file is not None:
134
  max_scale = int(data.shape[0] // 128)
135
  scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden")
136
  scale = int(scale.split("x")[0]) // 128
137
- # np.save("pred.npy", y_pred)
138
 
139
  with col3:
140
  detect = st.button('Detect')
 
7
  import shutil
8
  import numpy as np
9
  import matplotlib.pyplot as plt
10
+ from matplotlib.colors import LogNorm
11
  from matplotlib.patches import Rectangle
12
 
13
  # Astropy
 
45
  # Define function to plot the uploaded image
46
  def plot_image(image, scale):
47
  plt.figure(figsize=(4, 4))
 
48
  x0 = image.shape[0] // 2 - scale * 128 / 2
49
  plt.imshow(image, origin="lower")
50
  plt.gca().add_patch(Rectangle((x0, x0), scale*128, scale*128, linewidth=1, edgecolor='w', facecolor='none'))
 
51
  plt.axis('off')
52
  with colA: st.pyplot()
53
 
 
61
  # Define function to plot the decomposed prediction
62
  def plot_decomposed(decomposed):
63
  plt.figure(figsize=(4, 4))
64
+ plt.imshow(decomposed, origin="lower", norm=LogNorm())
65
+
66
+ N = np.max(decomposed)
67
+ for i in range(N):
68
+ new = np.where(decomposed == i+1, 1, 0)
69
+ x0, y0 = center_of_mass(new)
70
+ plt.text(y0, x0, f"{i+1}", fontsize=15, color="white")
71
+
72
  plt.axis('off')
73
  with colC: st.pyplot()
74
 
 
127
  with fits.open(uploaded_file) as hdul:
128
  data = hdul[0].data
129
  wcs = WCS(hdul[0].header)
 
130
 
131
  # Make four columns for buttons
132
  _, col1, col2, col3, col4, col5, col6, _ = st.columns([bordersize,0.5,0.5,0.5,0.5,0.5,0.5,bordersize])
 
139
  max_scale = int(data.shape[0] // 128)
140
  scale = st.selectbox('Scale:',[f"{(i+1)*128}x{(i+1)*128}" for i in range(max_scale)], label_visibility="hidden")
141
  scale = int(scale.split("x")[0]) // 128
 
142
 
143
  with col3:
144
  detect = st.button('Detect')