-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstarmed.py
More file actions
124 lines (115 loc) · 3.91 KB
/
starmed.py
File metadata and controls
124 lines (115 loc) · 3.91 KB
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
#This function takes lists of row and column indices where all star exist and divides them into sublists by star
#It also returns the number of stars by row and by column, the median pixel values for each star, and paired coordinates for each star
#By Teresa Symons 2016
def starmed(starrow,starcol,inset,mid,xlow,ylow):
#Import math
import numpy as np
#Divide all star location indices by star
rowloc = []
colloc = []
starr = []
starc = []
starr.append(starrow[0])
starc.append(starcol[0])
#Start adding star indices to a list
#If difference between previous and next index is greater than 1, assume new star begins and start new list of indices
for i in range(1,len(starrow)):
if starrow[i] == starrow[i-1] + 1:
starr.append(starrow[i])
elif starrow[i] == starrow[i-1] + 2:
starr.append(starrow[i])
else:
rowloc.append(starr)
starr = []
starr.append(starrow[i])
rowloc.append(starr)
for j in range(1,len(starcol)):
if starcol[j] == starcol[j-1] + 1:
starc.append(starcol[j])
elif starcol[j] == starcol[j-1] + 2:
starc.append(starcol[j])
else:
colloc.append(starc)
starc = []
starc.append(starcol[j])
colloc.append(starc)
#Calculate number of stars (sublists) found by both row and column
numstarr = len(rowloc)
numstarc = len(colloc)
#Find median pixel value of each star by row and column
#If a star as only one pixel, include that as median value
rowmed = []
colmed = []
for k in range(0,len(rowloc)):
if len(rowloc[k]) == 1:
rowmed.append(rowloc[k][0])
else:
rowmed.append(int(round(np.nanmedian(rowloc[k]))))
for k in range(0,len(colloc)):
if len(colloc[k]) == 1:
colmed.append(colloc[k][0])
else:
colmed.append(int(round(np.nanmedian(colloc[k]))))
#Check original data array for maximum column value associated with each star's row coordinate
#If column value appears within +/- one pixel in list of column coordinates, add coordinate pair to list of star coordinates
starpoints = []
for i in rowmed:
j = np.argmax(inset[i, :])
if j in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j+1 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j-1 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j+2 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j-2 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j+3 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j-3 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j+4 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j-4 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j+5 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
elif j-5 in colmed:
pt = []
pt.append(i)
pt.append(j)
starpoints.append(pt)
#Adjust coordinates for original image and python indexing
adjstarpoints = [[xlow+y+round(mid/2)+1,ylow+x+round(mid/2)+1] for [x,y] in starpoints]
return rowloc, colloc, numstarr, numstarc, rowmed, colmed, starpoints, adjstarpoints