-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresults_viz.py
178 lines (131 loc) · 4.91 KB
/
results_viz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import urllib.request
import urllib.error
import os
def download(df):
obj_paths = []
for i, row in df.iterrows():
print(i)
object_id = round(row['COADD_OBJECT_ID'])
dist = row['distCol']
candidate = f'{object_id}-{dist}.jpg'
ra = row['RA']
dec = row['DEC']
print(f'downloading ra={ra}, dec={dec}')
legacy_survey = f'https://www.legacysurvey.org/viewer/cutout.jpg?ra={ra}&dec={dec}&layer=ls-dr9&pixscale={ps}'
obj_paths.append((candidate, i))
print(legacy_survey)
try:
urllib.request.urlretrieve(legacy_survey, os.path.join(output_dir, candidate))
except urllib.error.HTTPError as e:
print(e)
continue
return obj_paths
lsbgs_path = 'LSBG_catalog_v2 (1).csv'
lsbgs = pd.read_csv(lsbgs_path)
lsbgs_ids = lsbgs['COADD_OBJECT_ID']
filepath = 'lsbgs-5.csv'
df = pd.read_csv(filepath, names=['COADD_OBJECT_ID', 'RA', 'DEC' ,'distCol'])
obj = round(df.iloc[0]['COADD_OBJECT_ID'])
merged = pd.merge(df, lsbgs, on='COADD_OBJECT_ID')
# plot histogram
plt.figure(figsize=(15,10), dpi=200)
sns.histplot(df.iloc[1:], x='distCol', color='blue', bins=70, label=f'Nearest neighbors to object ID={obj}')
sns.histplot(merged.iloc[1:], x='distCol', color='orange', bins=70, label='T21 LSBGs')
plt.title(f'Matched objects: {len(merged)}')
plt.xlabel('Distance from key')
plt.ylabel('Count')
plt.legend()
plt.show()
# fetch and plot neighbors
ps = 0.10
output_dir = 'neighbors\\'
print(obj)
tops = download(df.iloc[:6])
mids = download(df.iloc[int(len(df)/2):int(len(df)/2)+5])
fartest = download(df.iloc[-5:])
key = tops[0]
nearest = tops[1:]
fig = plt.figure(figsize=(15, 10))
ax_key= fig.add_subplot(3,6,7)
ax1= fig.add_subplot(3,6,2)
ax2= fig.add_subplot(3,6,3)
ax3= fig.add_subplot(3,6,4)
ax4= fig.add_subplot(3,6,5)
ax5= fig.add_subplot(3,6,6)
ax6= fig.add_subplot(3,6,8)
ax7= fig.add_subplot(3,6,9)
ax8= fig.add_subplot(3,6,10)
ax9= fig.add_subplot(3,6,11)
ax10= fig.add_subplot(3,6,12)
ax11= fig.add_subplot(3,6,14)
ax12= fig.add_subplot(3,6,15)
ax13= fig.add_subplot(3,6,16)
ax14= fig.add_subplot(3,6,17)
ax15= fig.add_subplot(3,6,18)
import matplotlib.image as mpimg
ax_nearest = [ax1, ax2, ax3, ax4, ax5]
ax_mid = [ax6, ax7, ax8, ax9, ax10]
ax_fartest = [ax11, ax12, ax13, ax14, ax15]
for ax, n in zip(ax_nearest, nearest):
img = mpimg.imread(os.path.join(output_dir, n[0]))
ax.grid(False)
ax.set_axis_off()
title = n[0].split('-')[1][:-4][:5]
ax.set_title(f'd = {title}; i = {n[1]}')
bbox = ax.get_tightbbox(fig.canvas.get_renderer())
x0, y0, width, height = bbox.transformed(fig.transFigure.inverted()).bounds
# slightly increase the very tight bounds:
xpad = 0.06 * width
ypad = 0.01 * height
if int(n[0].split('-')[0]) in lsbgs_ids.values:
color = 'green'
else:
color = 'red'
fig.add_artist(plt.Rectangle((x0-xpad, y0-ypad), width+2*xpad, height+2*ypad, edgecolor=color, linewidth=3, fill=False))
ax.imshow(img)
for ax, n in zip(ax_mid, mids):
img = mpimg.imread(os.path.join(output_dir, n[0]))
ax.grid(False)
ax.set_axis_off()
title = n[0].split('-')[1][:-4][:6]
ax.set_title(f'd = {title}; i = {n[1]}')
bbox = ax.get_tightbbox(fig.canvas.get_renderer())
x0, y0, width, height = bbox.transformed(fig.transFigure.inverted()).bounds
# slightly increase the very tight bounds:
xpad = 0.0 * width
ypad = 0.01 * height
if int(n[0].split('-')[0]) in lsbgs_ids.values:
color = 'green'
else:
color = 'red'
fig.add_artist(plt.Rectangle((x0-xpad, y0-ypad), width+2*xpad, height+2*ypad, edgecolor=color, linewidth=3, fill=False))
ax.imshow(img)
for ax, n in zip(ax_fartest, fartest):
img = mpimg.imread(os.path.join(output_dir, n[0]))
ax.grid(False)
ax.set_axis_off()
title = n[0].split('-')[1][:-4][:6]
ax.set_title(f'd = {title}; i = {n[1]+1}')
bbox = ax.get_tightbbox(fig.canvas.get_renderer())
x0, y0, width, height = bbox.transformed(fig.transFigure.inverted()).bounds
# slightly increase the very tight bounds:
xpad = 0.0 * width
ypad = 0.01 * height
if int(n[0].split('-')[0]) in lsbgs_ids.values:
color = 'green'
else:
color = 'red'
fig.add_artist(plt.Rectangle((x0-xpad, y0-ypad), width+2*xpad, height+2*ypad, edgecolor=color, linewidth=3, fill=False))
ax.imshow(img)
img = mpimg.imread(os.path.join(output_dir, key[0]))
ax_key.grid(False)
ax_key.set_axis_off()
#title = key.split('-')[1][:-4][:7]
#ax_key.set_title(f'Key')
ax_key.set_title(f'Key')
ax_key.imshow(img)
fig.suptitle(f'Neighbors of object ID={obj}', fontsize='xx-large')
plt.show()