@@ -0,0 +1,113 | |||
|
1 | import h5py | |
|
2 | import numpy | |
|
3 | import matplotlib.pyplot as plt | |
|
4 | import glob | |
|
5 | import os | |
|
6 | ||
|
7 | #---------------------- Functions --------------------- | |
|
8 | ||
|
9 | def findFiles(path): | |
|
10 | ||
|
11 | dirList = [] | |
|
12 | fileList = [] | |
|
13 | ||
|
14 | for thisPath in os.listdir(path): | |
|
15 | dirList.append(os.path.join(path,thisPath)) | |
|
16 | dirList.sort() | |
|
17 | ||
|
18 | for thisDirectory in dirList: | |
|
19 | files = glob.glob1(thisDirectory, "*.hdf5") | |
|
20 | files.sort() | |
|
21 | for thisFile in files: | |
|
22 | fileList.append(os.path.join(thisDirectory,thisFile)) | |
|
23 | ||
|
24 | return fileList | |
|
25 | ||
|
26 | def readFiles(fileList): | |
|
27 | ||
|
28 | meteors_array = numpy.zeros((1,4)) | |
|
29 | ||
|
30 | for thisFile in fileList: | |
|
31 | ||
|
32 | #Leer | |
|
33 | f1 = h5py.File(thisFile,'r') | |
|
34 | grp1 = f1['Data'] | |
|
35 | grp2 = grp1['data_output'] | |
|
36 | meteors1 = grp2['table0'][:] | |
|
37 | meteors_array = numpy.vstack((meteors_array,meteors1)) | |
|
38 | #cerrar | |
|
39 | f1.close() | |
|
40 | ||
|
41 | meteors_array = numpy.delete(meteors_array, 0, axis=0) | |
|
42 | meteors_list = [meteors_array[:,0],meteors_array[:,1],meteors_array[:,2],meteors_array[:,3]] | |
|
43 | return meteors_list | |
|
44 | ||
|
45 | def estimateMean(offset_list): | |
|
46 | ||
|
47 | mean_off = [] | |
|
48 | axisY_off = [] | |
|
49 | axisX_off = [] | |
|
50 | ||
|
51 | for thisOffset in offset_list: | |
|
52 | mean_aux = numpy.mean(thisOffset, axis = 0) | |
|
53 | mean_off.append(mean_aux) | |
|
54 | axisX_off.append(numpy.array([0,numpy.size(thisOffset)])) | |
|
55 | axisY_off.append(numpy.array([mean_aux,mean_aux])) | |
|
56 | ||
|
57 | return mean_off, axisY_off, axisX_off | |
|
58 | ||
|
59 | def plotPhases(offset0, axisY0, axisX0, title): | |
|
60 | f, axarr = plt.subplots(4, sharey=True) | |
|
61 | color = ['b','g','r','c'] | |
|
62 | # plt.grid() | |
|
63 | for i in range(len(offset0)): | |
|
64 | thisMeteor = offset0[i] | |
|
65 | thisY = axisY0[i] | |
|
66 | thisX = axisX0[i] | |
|
67 | thisColor = color[i] | |
|
68 | ||
|
69 | opt = thisColor + 'o' | |
|
70 | axarr[i].plot(thisMeteor,opt) | |
|
71 | axarr[i].plot(thisX, thisY, thisColor) | |
|
72 | axarr[i].set_ylabel('Offset ' + str(i)) | |
|
73 | ||
|
74 | plt.ylim((-180,180)) | |
|
75 | axarr[0].set_title(title + ' Offsets') | |
|
76 | axarr[3].set_xlabel('Number of estimations') | |
|
77 | ||
|
78 | return | |
|
79 | ||
|
80 | def filterOffsets(offsets0, stdvLimit): | |
|
81 | offsets1 = [] | |
|
82 | ||
|
83 | for thisOffset in offsets0: | |
|
84 | pstd = numpy.std(thisOffset)*stdvLimit | |
|
85 | pmean = numpy.mean(thisOffset) | |
|
86 | outlier1 = thisOffset > pmean - pstd | |
|
87 | outlier2 = thisOffset < pmean + pstd | |
|
88 | not_outlier = numpy.logical_and(outlier1,outlier2) | |
|
89 | thisOffset1 = thisOffset[not_outlier] | |
|
90 | offsets1.append(thisOffset1) | |
|
91 | ||
|
92 | return offsets1 | |
|
93 | ||
|
94 | #---------------------- Setup --------------------------- | |
|
95 | ||
|
96 | path = '/home/jespinoza/Pictures/JASMET30/201608/phase' | |
|
97 | stdvLimit = 0.5 | |
|
98 | ||
|
99 | #---------------------- Script --------------------------- | |
|
100 | ||
|
101 | fileList = findFiles(path) | |
|
102 | offsets0 = readFiles(fileList) | |
|
103 | mean0, axisY0, axisX0 = estimateMean(offsets0) | |
|
104 | plotPhases(offsets0, axisY0, axisX0, 'Original') | |
|
105 | ||
|
106 | offsets1 = filterOffsets(offsets0, stdvLimit) | |
|
107 | mean1, axisY1, axisX1 = estimateMean(offsets1) | |
|
108 | plotPhases(offsets1, axisY1, axisX1, 'Filtered') | |
|
109 | ||
|
110 | print "Original Offsets: %.2f, %.2f, %.2f, %.2f" % (mean0[0],mean0[1],mean0[2],mean0[3]) | |
|
111 | print "Filtered Offsets: %.2f, %.2f, %.2f, %.2f" % (mean1[0],mean1[1],mean1[2],mean1[3]) | |
|
112 | ||
|
113 | plt.show() |
General Comments 0
You need to be logged in to leave comments.
Login now