[task] PDFStatistics object is now far more flexible
This commit is contained in:
parent
b72e16aaed
commit
f4bdb38e16
@ -345,13 +345,6 @@ class PDFstatistics(object):
|
|||||||
'''
|
'''
|
||||||
def __init__(self, directory):
|
def __init__(self, directory):
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
#self.arraylen = 0
|
|
||||||
# self.stations = {}
|
|
||||||
# self.p_std = {}
|
|
||||||
#self.s_std = {}
|
|
||||||
# self.theta0 = []
|
|
||||||
# self.theta1 = []
|
|
||||||
# self.theta2 = []
|
|
||||||
|
|
||||||
|
|
||||||
def readTheta(self, arname, dir, fnpattern):
|
def readTheta(self, arname, dir, fnpattern):
|
||||||
@ -366,17 +359,11 @@ class PDFstatistics(object):
|
|||||||
fid.close()
|
fid.close()
|
||||||
|
|
||||||
|
|
||||||
def fromFileList(self):
|
|
||||||
self.makeFileList()
|
|
||||||
self.getData()
|
|
||||||
self.getStatistics()
|
|
||||||
|
|
||||||
|
|
||||||
def makeFileList(self, fn_pattern='*'):
|
def makeFileList(self, fn_pattern='*'):
|
||||||
self.evtlist = glob.glob1((os.path.join(self.directory)), '*.xml')
|
self.evtlist = glob.glob1((os.path.join(self.directory)), '*.xml')
|
||||||
|
|
||||||
def nextPDF(self):
|
|
||||||
|
|
||||||
|
def nextPDF(self):
|
||||||
for evt in self.evtlist:
|
for evt in self.evtlist:
|
||||||
self.getPDFDict(self.directory, evt)
|
self.getPDFDict(self.directory, evt)
|
||||||
for station, pdfs in self.pdfdict.pdf_data.items():
|
for station, pdfs in self.pdfdict.pdf_data.items():
|
||||||
@ -389,93 +376,75 @@ class PDFstatistics(object):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
yield np.nan
|
yield np.nan
|
||||||
|
|
||||||
|
|
||||||
def getQD(self,value):
|
def getQD(self,value):
|
||||||
pdfgen = self.nextPDF()
|
pdfgen = self.nextPDF()
|
||||||
QDlist = []
|
QDlist = []
|
||||||
for pdf in pdfgen:
|
for pdf in pdfgen:
|
||||||
if pdf == np.nan:
|
try:
|
||||||
continue
|
QD = pdf.quantile_distance(value)
|
||||||
QD = pdf.quantile_distance(value)
|
QDlist.append(QD)
|
||||||
QDlist.append(QD)
|
except AttributeError as e:
|
||||||
|
if e.message == "'float' object has no attribute 'quantile_distance'":
|
||||||
|
continue
|
||||||
return QDlist
|
return QDlist
|
||||||
|
|
||||||
|
|
||||||
|
def getQDQ(self,value):
|
||||||
|
pdfgen = self.nextPDF()
|
||||||
|
QDQlist = []
|
||||||
|
for pdf in pdfgen:
|
||||||
|
try:
|
||||||
|
QDQ = pdf.qtile_dist_quot(value)
|
||||||
|
QDQlist.append(QDQ)
|
||||||
|
except AttributeError as e:
|
||||||
|
if e.message == "'float' object has no attribute 'quantile_distance'":
|
||||||
|
continue
|
||||||
|
return QDQlist
|
||||||
|
|
||||||
def getData(self):
|
|
||||||
for evt in self.evtlist:
|
def getSTD(self):
|
||||||
print evt
|
pdfgen = self.nextPDF()
|
||||||
self.stations[evt] = []
|
self.p_std = []
|
||||||
self.p_std[evt] = []
|
self.s_std = []
|
||||||
self.s_std[evt] = []
|
for pdf in pdfgen:
|
||||||
self.getPDFDict(self.directory, evt)
|
try:
|
||||||
for station, pdfs in self.pdfdict.pdf_data.items():
|
self.p_std.append(pdf['P'].standard_deviation())
|
||||||
# print station, pdfs
|
except KeyError:
|
||||||
try:
|
pass
|
||||||
p_std = pdfs['P'].standard_deviation()
|
try:
|
||||||
self.theta0.append(pdfs['P'].qtile_dist_quot(0.015))
|
self.s_std.append(pdf['S'].standard_deviation())
|
||||||
self.theta1.append(pdfs['P'].qtile_dist_quot(0.1))
|
except KeyError:
|
||||||
self.theta2.append(pdfs['P'].qtile_dist_quot(0.2))
|
pass
|
||||||
except KeyError:
|
|
||||||
p_std = np.nan
|
|
||||||
try:
|
|
||||||
s_std = pdfs['S'].standard_deviation()
|
|
||||||
self.theta0.append(pdfs['S'].qtile_dist_quot(0.015))
|
|
||||||
self.theta1.append(pdfs['S'].qtile_dist_quot(0.1))
|
|
||||||
self.theta2.append(pdfs['S'].qtile_dist_quot(0.2))
|
|
||||||
except KeyError:
|
|
||||||
s_std = np.nan
|
|
||||||
self.stations[evt].append(station)
|
|
||||||
self.p_std[evt].append(p_std)
|
|
||||||
self.s_std[evt].append(s_std)
|
|
||||||
self.arraylen += 1
|
|
||||||
self.makeArray()
|
self.makeArray()
|
||||||
|
|
||||||
|
|
||||||
def makeArray(self):
|
def makeArray(self):
|
||||||
index = 0
|
self.p_stdarray = np.array(self.p_std)
|
||||||
self.p_stdarray = np.zeros(self.arraylen)
|
self.s_stdarray = np.array(self.s_std)
|
||||||
self.s_stdarray = np.zeros(self.arraylen)
|
|
||||||
for evt in self.p_std.keys():
|
|
||||||
for n in range(len(self.p_std[evt])):
|
|
||||||
self.p_stdarray[index] = self.p_std[evt][n]
|
|
||||||
self.s_stdarray[index] = self.s_std[evt][n]
|
|
||||||
index += 1
|
|
||||||
|
|
||||||
|
|
||||||
def histplot(self, num, label=None):
|
def getBinList(self,l_boundary,u_boundary,nbins = 100):
|
||||||
binlist = []
|
binlist = []
|
||||||
if num == 0:
|
for i in range(nbins):
|
||||||
bfactor = 0.001
|
binlist.append(l_boundary + i*(u_boundary-l_boundary)/nbins)
|
||||||
badd = 0
|
return binlist
|
||||||
elif num == 1:
|
|
||||||
bfactor = 0.003
|
|
||||||
badd = 0
|
|
||||||
else:
|
|
||||||
bfactor = 0.006
|
|
||||||
badd = 0.4
|
|
||||||
for i in range(100):
|
|
||||||
binlist.append(badd+bfactor*i)
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
plt.hist(self.getTheta(num),bins = binlist)
|
|
||||||
|
def histplot(self, array, binlist, xlab = 'Values',
|
||||||
|
ylab = 'Frequency', title = None, label=None):
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
plt.hist(array,bins = binlist)
|
||||||
plt.xlabel('Values')
|
plt.xlabel('Values')
|
||||||
plt.ylabel('Frequency')
|
plt.ylabel('Frequency')
|
||||||
title_str = 'Quantile distance quotient distribution'
|
if title:
|
||||||
if label:
|
title_str = 'Quantile distance quotient distribution'
|
||||||
title_str += ' (' + label + ')'
|
if label:
|
||||||
plt.title(title_str)
|
title_str += ' (' + label + ')'
|
||||||
|
plt.title(title_str)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
def getTheta(self,number):
|
|
||||||
if number == 0:
|
|
||||||
return self.theta0
|
|
||||||
elif number == 1:
|
|
||||||
return self.theta1
|
|
||||||
elif number == 2:
|
|
||||||
return self.theta2
|
|
||||||
|
|
||||||
|
|
||||||
def getPDFDict(self, month, evt):
|
def getPDFDict(self, month, evt):
|
||||||
self.pdfdict = PDFDictionary.from_quakeml(os.path.join(self.directory,month,evt))
|
self.pdfdict = PDFDictionary.from_quakeml(os.path.join(self.directory,month,evt))
|
||||||
|
|
||||||
@ -499,8 +468,11 @@ def main():
|
|||||||
root_dir ='/home/sebastianp/Codetesting/xmls/'
|
root_dir ='/home/sebastianp/Codetesting/xmls/'
|
||||||
Insheim = PDFstatistics(root_dir)
|
Insheim = PDFstatistics(root_dir)
|
||||||
Insheim.makeFileList()
|
Insheim.makeFileList()
|
||||||
qdlist = Insheim.getQD(0.3)
|
Insheim.getSTD()
|
||||||
|
Insheim.getStatistics()
|
||||||
|
qdlist = Insheim.getQDQ(0.3)
|
||||||
print qdlist
|
print qdlist
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
Loading…
Reference in New Issue
Block a user