-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataProcessing.py
106 lines (95 loc) · 3.07 KB
/
dataProcessing.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
import json
import math
import basicFun
inputFileName = 'database.json'
def readJson():
'''
This file will read in the json data base and return a list of dictionary about the database
'''
outputDict = {}
inputJson = open(inputFileName)
data = json.load(inputJson)
# pprint(data)
inputJson.close()
return data
def transformCoordinate(data):
'''
This function will transform all the angles into pi unit
'''
for i in range(len(data)):
if data[i]['theta'] == None or data[i]['phi'] == None:
continue
data[i]['theta'] *= math.pi/180
data[i]['phi'] *= math.pi/180
data[i]['x_coor'] = basicFun.getXCoor(data[i]['theta'], data[i]['phi'])
data[i]['y_coor'] = basicFun.getYCoor(data[i]['theta'], data[i]['phi'])
data[i]['z_coor'] = basicFun.getZCoor(data[i]['theta'], data[i]['phi'])
return data
def chooseStarWithName(data):
'''
This function will select all the stars with names and proper coordinates
'''
starWithName = []
for index in range(len(data)):
if data[index]['name'] == '' or 'NOVA' in data[index]['name'] or data[index]['brightness'] == None:
continue
starWithName.append(data[index])
return starWithName
def selectBrightness(data, threshold, constellationName = None):
'''
This function will pick the stars with brightness larger than the threshold
and with the third argument as the constellation name
Without the third input, the function will not select star names
'''
selectedStars = []
for index in range(len(data)):
if constellationName == None:
if data[index]['brightness'] <= threshold:
selectedStars.append(data[index])
else:
if data[index]['brightness'] <= threshold and constellationName in data[index]['name']:
selectedStars.append(data[index])
return selectedStars
def selectNames(data, constellationName, threshold = None):
'''
This function has almost the same function as the previous one, but with different
argument input order. It will focus on the names of the stars.
'''
selectedStars = []
for index in range(len(data)):
if threshold == None:
if constellationName in data[index]['name']:
selectedStars.append(data[index])
else:
if constellationName in data[index]['name'] and data[index]['brightness'] <= threshold:
selectedStars.append(data[index])
return selectedStars
def getConstellationNames(data):
'''
This function will return all the constellation names
'''
constellationNames = {}
for index in range(len(data)):
constellationNames[data[index]['name'][-3:]] = 1
return constellationNames
def getTrueLabel(data):
'''
This function will give the true label for all the data
'''
trueLabel = []
constellationNames = getConstellationNames(data).keys()
for i in range(len(data)):
for j in range(len(constellationNames)):
if data[i]['name'][-3:] == constellationNames[j]:
trueLabel.append(j)
continue
return trueLabel
'''
database = readJson()
data = transformCorrdinate(database)
starWithName = chooseStarWithName(data)
selectedStars = selectBrightness(starWithName, 4.5)
selectedStars_2 = selectNames(starWithName, 'And')
print len(selectedStars)
print selectedStars_2
'''