· 8 years ago · Aug 28, 2018, 07:22 PM
1# %%writefile compare_plots_for_txt_with_comment_head.py
2# Plot the files
3# Date: Jul 10, 2018
4import pandas as pd
5import matplotlib.pyplot as plt
6import numpy as np
7import os,sys,argparse
8import glob
9
10"""
11This program shows the plots of base_NaiveCentroid_x vs base_NaiveCentroid_y
12for the lsst,lsst90, lsst_mono, and lsst_mono90 src.csv data files.
13
14These input data files are created from Dmstack module OBS_FILE.
15(Acutally obs_file gives fits table we convert it to csv file.)
16
17
18Note:
19Numpy savetxt writes the header line with # comment.
20We can use pandas to read this data, but need to read
21the header columns separately.
22
23
24"""
25
26# read column names
27def commented_colnames(ifile):
28 """ Create column names list from first comment line of a datafile."""
29 colnames = []
30 with open(ifile) as fi:
31 for l in fi:
32 if l.strip().startswith('#'):
33 names = l.strip('#')
34 colnames = [i for i in names.split(',')]
35 break
36 return colnames
37
38
39def myplot(x,y,title):
40 plt.plot(x,y,'bo')
41 plt.xlabel('x')
42 plt.ylabel('y')
43 plt.title(title)
44 plt.show()
45
46def plot_fourfiles(x,x2,x3,x4,y,y2,y3,y4,t,t2,t3,t4):
47 plt.figure(figsize=(20,12))
48
49 plt.subplot(2,2,1) # row, col, number of image
50 plt.plot(x,y,'bo')
51 plt.xlabel('x')
52 plt.ylabel('y')
53 plt.title(t)
54
55 plt.subplot(2,2,2)
56 plt.plot(x2,y2,'ro')
57 plt.xlabel('x')
58 plt.ylabel('y')
59 plt.title(t2)
60
61 plt.subplot(2,2,3) # row, col, number of image
62 plt.plot(x3,y3,'go')
63 plt.xlabel('x')
64 plt.ylabel('y')
65 plt.title(t3)
66
67 plt.subplot(2,2,4)
68 plt.plot(x4,y4,'ko')
69 plt.xlabel('x')
70 plt.ylabel('y')
71 plt.title(t4)
72
73
74 plt.tight_layout()
75 plt.show()
76
77
78def main(title,txt_path):
79 #title = ' (nstar=100 starval=20 multiply=10k)'
80 #txt_path = 'dms_text_outputs/txt_z0.7_100_20_10000/txt_lsst_z0.7'
81 chro = 'lsst'
82 i = 0
83 not_common = 0
84 for f in glob.glob(txt_path + '/*.csv'):
85
86 # input text files for 0 and 90 degree
87 colnames = commented_colnames(f)
88 ifile = f
89 ifile2 = f.replace(chro,chro+'90')
90 ifile3 = f.replace(chro,chro+'_mono')
91 ifile4 = f.replace(chro,chro+'_mono90')
92
93 # plot only if xxx0deg and xxx90deg exists
94 if os.path.isfile(ifile) and os.path.isfile(ifile2) \
95 and os.path.isfile(ifile3) and os.path.isfile(ifile4) :
96
97 # lsst
98 df = pd.read_csv(ifile, sep=",", comment='#', header=None, names = colnames)
99 df2 = df.dropna()
100 x = df2['base_NaiveCentroid_x']
101 y = df2['base_NaiveCentroid_y']
102
103
104 # lsst90
105 df = pd.read_csv(ifile2, sep=",", comment='#', header=None, names = colnames)
106 df2 = df.dropna()
107 x2 = df2['base_NaiveCentroid_x']
108 y2 = df2['base_NaiveCentroid_y']
109
110
111 # lsst_mono
112 df = pd.read_csv(ifile3, sep=",", comment='#', header=None, names = colnames)
113 df2 = df.dropna()
114 x3 = df2['base_NaiveCentroid_x']
115 y3 = df2['base_NaiveCentroid_y']
116
117
118 # lsst_mono90
119 df = pd.read_csv(ifile2, sep=",", comment='#', header=None, names = colnames)
120 df2 = df.dropna()
121 x4 = df2['base_NaiveCentroid_x']
122 y4 = df2['base_NaiveCentroid_y']
123
124 # plot files
125 t = chro + '' + title+ ' file: ' + str(f[-7:-4])
126 t2 = chro + '90' + title+ ' file: ' + str(f[-7:-4])
127 t3 = chro + '_mono' + title+ ' file: ' + str(f[-7:-4])
128 t4 = chro + '_mono90' + title+ ' file: ' + str(f[-7:-4])
129
130
131 plot_fourfiles(x,x2,x3,x4,y,y2,y3,y4,t,t2,t3,t4)
132
133 # increment common files
134 i +=1
135
136 else:
137 not_common += 1
138
139 print('Number of files with both 0 and 90 deg: '+ str(i))
140 print('Number of files with NOT both 0 and 90 deg: '+ str(not_common))
141
142
143# Run the code
144title = ' (nstar=100 starval=100k)'
145txt_path = 'wcs_star_100_100000_jout_z0.7_0_19/lsst/dmstack_output/dm_out_lsst_z0.7/txt_lsst_z0.7'
146main(title,txt_path)