implementen some new functions to PDFStatistics

This commit is contained in:
sebastianp 2016-07-13 15:26:36 +02:00
parent 8433767b22
commit 1ed83d786d

View File

@ -342,62 +342,53 @@ class PDFstatistics(object):
''' '''
To do: To do:
plots for std, quantiles, plots for std, quantiles,
calc: quantiles
encountering error when trying to get quantile... float.. utcdatetime error
''' '''
def __init__(self, directory): def __init__(self, directory):
self.directory = directory self.directory = directory
self.arraylen = 0
self.stations = {} self.stations = {}
self.p_std = {} self.p_std = {}
self.s_std = {} self.s_std = {}
self.theta015 = [] self.theta015 = []
self.theta1 = [] self.theta1 = []
self.theta2 = [] self.theta2 = []
self.dirlist = list() self.makefilelist()
self.evtdict = {} self.getData()
#self.makeDirlist() self.getStatistics()
#self.getData()
#self.getStatistics()
#self.showData() #self.showData()
def makeDirlist(self, fn_pattern='*'): def makefilelist(self, fn_pattern='*'):
self.dirlist = glob.glob1(self.directory, fn_pattern) self.evtlist = glob.glob1((os.path.join(self.directory)), '*.xml')
self.evtdict = {}
for rd in self.dirlist:
self.evtdict[rd] = glob.glob1((os.path.join(self.directory, rd)), '*.xml')
def getData(self): def getData(self):
arraylen = 0 for evt in self.evtlist:
for dir in self.dirlist: print evt
for evt in self.evtdict[dir]: self.stations[evt] = []
print evt self.p_std[evt] = []
self.stations[evt] = [] self.s_std[evt] = []
self.p_std[evt] = [] self.getPDFDict(self.directory, evt)
self.s_std[evt] = [] for station, pdfs in self.pdfdict.pdf_data.items():
self.getPDFDict(dir, evt) # print station, pdfs
for station, pdfs in self.pdfdict.pdf_data.items(): try:
# print station, pdfs p_std = pdfs['P'].standard_deviation()
try: self.theta015.append(pdfs['P'].qtile_dist_quot(0.015))
p_std = pdfs['P'].standard_deviation() self.theta1.append(pdfs['P'].qtile_dist_quot(0.1))
self.theta015.append(pdfs['P'].qtile_dist_quot(0.015)) self.theta2.append(pdfs['P'].qtile_dist_quot(0.2))
self.theta1.append(pdfs['P'].qtile_dist_quot(0.1)) except KeyError:
self.theta2.append(pdfs['P'].qtile_dist_quot(0.2)) p_std = np.nan
except KeyError: try:
p_std = np.nan s_std = pdfs['S'].standard_deviation()
try: self.theta015.append(pdfs['S'].qtile_dist_quot(0.015))
s_std = pdfs['S'].standard_deviation() self.theta1.append(pdfs['S'].qtile_dist_quot(0.1))
self.theta015.append(pdfs['S'].qtile_dist_quot(0.015)) self.theta2.append(pdfs['S'].qtile_dist_quot(0.2))
self.theta1.append(pdfs['S'].qtile_dist_quot(0.1)) except KeyError:
self.theta2.append(pdfs['S'].qtile_dist_quot(0.2)) s_std = np.nan
except KeyError: self.stations[evt].append(station)
s_std = np.nan self.p_std[evt].append(p_std)
self.stations[evt].append(station) self.s_std[evt].append(s_std)
self.p_std[evt].append(p_std) self.arraylen += 1
self.s_std[evt].append(s_std)
arraylen += 1
self.arraylen = arraylen
self.makeArray() self.makeArray()
@ -414,14 +405,23 @@ class PDFstatistics(object):
def showData(self): def histplot(self ,array , bins = 100, label=None):
#figure(p, s) = plt.pyplot.subplots(2) # baustelle
#p.hist(self.p_stdarray, Bins=100, range=[min(self.p_stdarray),max(self.p_stdarray)/256]) import matplotlib.pyplot as plt
#s.hist(self.s_stdarray, Bins=100, range=[min(self.s_stdarray),max(self.s_stdarray)/256])
#p.set_title('Histogramm der P-Wellen-Standartabweichung') plt.hist(self.axis, self.data())
#s.set_title('Histogramm der S-Wellen-Standartabweichung') plt.xlabel('x')
# plt.show() plt.ylabel('f(x)')
pass plt.autoscale(axis='x', tight=True)
if self:
title_str = 'Probability density function '
if label:
title_str += label
title_str.strip()
else:
title_str = 'Function not suitable as probability density function'
plt.title(title_str)
plt.show()
def getPDFDict(self, month, evt): def getPDFDict(self, month, evt):
@ -440,9 +440,6 @@ class PDFstatistics(object):
if __name__ == "__main__": if __name__ == "__main__":
rootdir = '/home/sebastianp/Data/Reassessment/Insheim/2012.10/' rootdir = '/home/sebastianp/Data/Reassessment/Insheim/2012.10/'
Insheim = PDFstatistics(rootdir) Insheim = PDFstatistics(rootdir)
Insheim.dirlist = [rootdir] Insheim.makefilelist()
Insheim.evtdict[rootdir] = ['e0002.294.12.xml']
Insheim.getData() Insheim.getData()
print Insheim.theta015
print Insheim.theta1
print Insheim.theta2