-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinteract_click.py
64 lines (50 loc) · 1.44 KB
/
interact_click.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
import time
import numpy as np
import matplotlib.pyplot as plt
from astropy.io import fits
def find_the_sources():
filename='data/j0947_i_7_sliced.fits'
data1=fits.open(filename)
image1=data1[0].data
def tellme(s):
data=fits.open(filename)
image=data[0].data
mean,std=np.mean(image),np.std(image)
print(s)
plt.imshow(image,origin='lower',cmap='gray_r',vmin=mean-std,vmax=mean+std)
plt.title(s, fontsize=16)
#plt.draw()
plt.clf()
tellme('In this interactive window, we select sources')
def input_source(val):
val=int(val)
print(val)
return val
vals=input('How many sources you want to select?')
nsources=input_source(vals)
plt.setp(plt.gca(), autoscale_on=True)
plt.waitforbuttonpress()
pts = []
while len(pts) < nsources:
tellme('Select 3 corners with mouse')
pts = np.asarray(plt.ginput(nsources, timeout=-1))
#print(pts[0],pts[1])
#raise SystemExit
plt.clf()
for i in range(len(pts)):
k=pts[i]
x=k[0]
y=k[1]
new_x=np.arange(x-40,x+40,1).astype(int)
new_y=np.arange(y-40,y+40,1).astype(int)
mod_image=image1[new_x[0]:new_x[78],new_y[0]:new_y[78]]
plt.plot(mod_image)
plt.show()
#
#plt.plot(new_x,new_y)
#
'''
tellme('All Done!')
plt.show()
plt.pause(1)
'''