-
Notifications
You must be signed in to change notification settings - Fork 0
/
correlation.py
130 lines (105 loc) · 4.01 KB
/
correlation.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
__author__ = 'cheng109'
import star_list
import sys
import numpy as np
import matplotlib.pyplot as plt
import astrometric_error as astro_error
def update_grid(starListDict, spacing):
firstStarList = starListDict.values()[0]
temp_RA = firstStarList[0].sex_RA
temp_DEC = firstStarList[0].sex_DEC
for key, starList in starListDict.items():
for i in range(len(starList)):
starList[i].RA_grid=int(np.round((starList[i].sex_RA-temp_RA)/spacing))
starList[i].DEC_grid=int(np.round((starList[i].sex_DEC-temp_DEC)/spacing))
#plt.plot(starList[i].RA_grid, starList[i].DEC_grid, '*b')
#plt.axis('equal')
#plt.show()
def mergeAllStarList(starListDict):
mergedDict_RA = {}
mergedDict_DEC = {}
for key, starList in starListDict.items():
for star in starList:
if star.RA_grid not in mergedDict_RA:
mergedDict_RA[star.RA_grid]=[]
if star.DEC_grid not in mergedDict_DEC:
mergedDict_DEC[star.DEC_grid]=[]
mergedDict_RA[star.RA_grid].append(star)
mergedDict_DEC[star.DEC_grid].append(star)
mergedDict = {}
mergedDict['ra']=mergedDict_RA
mergedDict['dec']=mergedDict_DEC
return mergedDict
def createDistanceList(mergedDict, direction='ra'):
cov = []
unit = []
X = 4
indexDict=mergedDict[direction]
if direction=='ra':
for RA_grid, starList in indexDict.items():
if np.remainder(RA_grid, X)==0:
for i in range(len(starList)-1):
for j in range(i+1, len(starList)):
A = starList[i]
B = starList[j]
cov.append(A.e1*B.e1 + A.e2*B.e2)
unit.append(int(abs(B.DEC_grid - A.DEC_grid)))
if direction=='dec':
for DEC_grid, starList in indexDict.items():
if np.remainder(DEC_grid, X)==0:
for i in range(len(starList)-1):
for j in range(i+1, len(starList)):
A = starList[i]
B = starList[j]
cov.append(A.e1*B.e1 + A.e2*B.e2)
unit.append(int(abs(B.RA_grid - A.RA_grid)))
x=list(set(unit))
mean = [0]*len(x)
d = [[] for i in range(len(x))]
for i in range(len(unit)):
d[unit[i]-1].append(cov[i])
for j in range(len(d)):
mean[j] = np.mean(d[j])
return x, mean
def plotCorrelation(x, cov):
plt.plot(x,cov, '*-')
plt.xlabel(r"$\theta$ (arcmin)")
plt.ylabel("Correlation")
plt.show()
def writeToFile(x, cov, outFileName):
f=open(outFileName, 'w')
for i in range(len(x)):
f.write(str(x[i])+"\t"+str(cov[i])+"\n")
f.close()
def writeOutAllStars(starListDict, outFileName):
f=open(outFileName, 'w')
for key, value in starListDict.items():
for star in value:
f.write(str(star.sex_RA) + "\t"
+str(star.sex_DEC) + "\t"
#+str(star.psfSize) + "\t"
#+str(star.e1) + "\t"
#+str(star.e2) +"\t"
+str(star.sex_ellipticity) + "\t"
#+str(star.moffat_smallest_fwhm) + "\t"
#+str(star.sex_FWHM) + "\t"
#+str(star.moffat_largest_fwhm) +"\t"
+ "\n")
f.close()
if __name__=="__main__":
spacing = 0.003 # unit degree
winX=10
winY=10
xlim = [20,4000-20]
ylim = [20,4000-20]
starListDict = star_list.generateStarListDictionary(sys.argv[1:], (winX, winY), (xlim, ylim), sex=False, Moffat=False, dir="data/defect_OFF_atm_ON/") #with ending '/'
#writeOutAllStars(starListDict, "star_info.txt")
update_grid(starListDict, spacing)
print "updating grids done ! "
mergedDict = mergeAllStarList(starListDict)
print "merging dictionary done !"
x,mean = createDistanceList(mergedDict, direction='dec')
x[:]=[a*spacing*60.0 for a in x] # convert the unit to be arcmin.
plotCorrelation(x, mean)
writeToFile(x, mean, "outputFile.txt")
print "completely done ! "