-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_compare_histograms.py
More file actions
executable file
·87 lines (84 loc) · 3.68 KB
/
Copy pathplot_compare_histograms.py
File metadata and controls
executable file
·87 lines (84 loc) · 3.68 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
#!/usr/bin/python3
'''
Abstract:
This is a program to plot the relation between two dataset with the same band.
Currently, we focus on twomass and ukidss
Usage:
plot_compared_histograms.py [twomass] [ukidss]
Editor:
Jacob975
##################################
# Python3 #
# This code is made in python3 #
##################################
20180611
####################################
update log
20180611 version alpha 1
1. the code works
'''
import time
import numpy as np
from sys import argv
import matplotlib.pyplot as plt
from IPython.core.pylabtools import figsize
#--------------------------------------------
# main code
if __name__ == "__main__":
VERBOSE = 0
# measure times
start_time = time.time()
#-----------------------------------
# check argv is right
if len(argv) != 3:
print ("Error!\nUsage: plot_compared_histograms.py [two mass] [ukidss]")
print ("Example: plot_compared_histograms.py star_sed_j.txt ukidss_j_star.txt")
exit()
# read argv
name_twomass = argv[1]
name_ukidss = argv[2]
#-----------------------------------
# load data
twomass = np.loadtxt(name_twomass, dtype = np.float64)
ukidss = np.loadtxt(name_ukidss, dtype = np.float64)
# wipe out non-sense data
twomass_too_high = np.where(twomass > 1E308)
twomass[twomass_too_high] = 0.0
twomass_too_low = np.where(twomass <= -999)
twomass[twomass_too_low] = 0.0
ukidss_too_high = np.where(ukidss > 1E308)
ukidss[ukidss_too_high] = 0.0
ukidss_too_low = np.where(ukidss <= -999)
ukidss[ukidss_too_low] = 0.0
# print 10 data point as examples
try:
for i in range(1110, 1120):
print ("2mass: {0}; ukidss:{1}".format(twomass[i], ukidss[i]))
except:
pass
#-----------------------------------
# plot the intensities in 2mass versus difference of intensities in 2mass and ukidss.
no_loss_for_ukidss = np.where((ukidss[:,0] != 0) & (ukidss[:,0] < 50) )
no_loss_for_twomass = np.where((twomass[:,0] != 0) & (twomass[:, 0] < 50))
figsize(12.5, 5)
result_plt = plt.figure("Histograms of {0} and {1}".format(name_twomass[:-4], name_ukidss[:-4]))
plt.title("{0} and {1}".format(name_twomass[:-4], name_ukidss[:-4]))
plt.ylabel('# of sources')
plt.xlabel('$log_{10}(mjy)$')
plt.hist(np.log10(twomass[no_loss_for_twomass[0], 0]), 50, range = (-3, 2), histtype = "bar", color = "r", alpha=0.50, label = "{0}".format(name_twomass[:-4]))
plt.hist(np.log10(ukidss[no_loss_for_ukidss[0], 0]), 50, range = (-3, 2), histtype = "bar", color = "g", alpha=0.50, label = "{0}".format(name_ukidss[:-4]))
plt.legend()
result_plt.savefig("hist_{0}_and_{1}.png".format(name_twomass[:-4], name_ukidss[:-4]))
# plot the same figure but normalized
normed_result_plt = plt.figure("Normalized histograms of {0} and {1}".format(name_twomass[:-4], name_ukidss[:-4]))
plt.title("{0} and {1}".format(name_twomass[:-4], name_ukidss[:-4]))
plt.ylabel('normalized # of sources')
plt.xlabel('$log_{10}(mjy)$')
plt.hist(np.log10(twomass[no_loss_for_twomass[0], 0]), 50, range = (-3, 2), normed = True, histtype = "bar", color = "r", alpha=0.50, label = "{0}".format(name_twomass[:-4]))
plt.hist(np.log10(ukidss[no_loss_for_ukidss[0], 0]), 50, range = (-3, 2), normed = True, histtype = "bar", color = "g", alpha=0.50, label = "{0}".format(name_ukidss[:-4]))
plt.legend()
normed_result_plt.savefig("hist_{0}_and_{1}_n.png".format(name_twomass[:-4], name_ukidss[:-4]))
#-----------------------------------
# measuring time
elapsed_time = time.time() - start_time
print ("Exiting Main Program, spending ", elapsed_time, "seconds.")