-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_test_result.py
More file actions
executable file
·123 lines (120 loc) · 4.27 KB
/
Copy pathplot_test_result.py
File metadata and controls
executable file
·123 lines (120 loc) · 4.27 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
#!/usr/bin/python3
'''
Abstract:
This is a program to show the basic result of AI testing.
Usage:
plot_test_result.py [main_name of test set]
Editor:
Jacob975
##################################
# Python3 #
# This code is made in python3 #
##################################
20190306
####################################
update log
20190306 version alpha 1:
1. The code works.
'''
import numpy as np
import time
from sys import argv
import os
from matplotlib import pyplot as plt
#--------------------------------------------
# main code
if __name__ == "__main__":
VERBOSE = 0
# measure times
start_time = time.time()
#----------------------------------------
# Initialize variables and constants
data = None
tracer = None
cls_pred = None
cls_true = None
#----------------------------------------
# Load argv
if len(argv) != 2:
print ("Error!\nUsage: plot_test_result.py [main_name for test set]")
exit()
main_name = argv[1]
#----------------------------------------
# Load data
print("Loading ...")
labels_pred = np.loadtxt("{0}_label_pred.txt".format(main_name))
cls_pred = np.argmax(labels_pred, axis = 1)
cls_true = np.loadtxt("{0}_cls_true.txt".format(main_name), dtype = int)
data = np.loadtxt("{0}_sed.txt".format(main_name))
Q = np.loadtxt("{0}_Q.txt".format(main_name), dtype = str)
coord = np.loadtxt("{0}_coord.txt".format(main_name))
template = np.loadtxt("{0}_template.txt".format(main_name))
Sp = np.loadtxt("{0}_Sp.txt".format(main_name), dtype = str)
Av = np.loadtxt("{0}_Av.txt".format(main_name), dtype = str)
print("done")
#----------------------------------------
# ploting
print ("ploting ... ")
source_type = ['star', 'galaxy', 'YSOc']
wavelength = [ 1.235,
1.662,
2.159,
3.550,
4.493,
5.731,
7.872,
24.00]
for i, source in enumerate(data):
fig, ax = plt.subplots(figsize = (8,6))
#ax.set_aspect(0.4)
ax.set_title("Actual: {0}, Predicted: {1}\nRA: {2:.4f}, DEC: {3:.4f}".format(
source_type[cls_true[i]],
source_type[cls_pred[i]],
coord[i,0],
coord[i,1]))
textstr1 = "Quality label: {0}\nprobability: ({1:.3f}, {2:.3f}, {3:.3f})".format(
" ".join(Q[i]),
labels_pred[i,0],
labels_pred[i,1],
labels_pred[i,2])
textstr2 = "{0} with Av={1}$\pm${2}".format(
Sp[i],
Av[i,0],
Av[i,1])
props2 = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
props1 = dict(boxstyle='round', facecolor='cyan', alpha=0.5)
y = source[:8]
yerr = source[8:]
ax.errorbar(x = wavelength, y = y, yerr = yerr, label = "SED")
ax.plot(wavelength, template[i], 'k--', label = "best fit template")
ax.grid(True)
ax.set_xlabel("wavelength($\mu$m)")
ax.set_ylabel("flux(m$J_{y}$)")
ax.set_yscale("log")
ax.set_xscale('log')
ax.text(0.87, 0.1,
textstr1,
transform=ax.transAxes,
fontsize = 14,
verticalalignment='bottom',
horizontalalignment = 'right',
bbox=props1)
ax.text(0.87, 0.03,
textstr2,
transform=ax.transAxes,
fontsize = 14,
verticalalignment='bottom',
horizontalalignment = 'right',
bbox=props2)
ax.set_xticks(wavelength, minor = False)
ax.set_xticklabels(wavelength)
ax.legend(loc =1)
fig.savefig("Source_{0:.4f}_{1:.4f}.png".format(
coord[i,0],
coord[i,1]))
if i%20 == 0:
plt.close()
#----------------------------------------
# measuring time
elapsed_time = time.time() - start_time
print ("Exiting Main Program, spending ", elapsed_time, "seconds.")