Merge branch 'develop' of ariadne.geophysik.ruhr-uni-bochum.de:/data/git/pylot into develop

This commit is contained in:
Marcel Paffrath 2016-08-10 14:24:40 +02:00
commit c72ed1e169

View File

@ -345,7 +345,8 @@ class PDFstatistics(object):
''' '''
def __init__(self, directory): def __init__(self, directory):
self.directory = directory self.directory = directory
self.evtlist = list()
self.return_phase = None
def readTheta(self, arname, dir, fnpattern): def readTheta(self, arname, dir, fnpattern):
exec('self.' + arname +' = []') exec('self.' + arname +' = []')
@ -358,70 +359,67 @@ class PDFstatistics(object):
exec('self.' + arname + ' += list') exec('self.' + arname + ' += list')
fid.close() fid.close()
def makeFileList(self, fn_pattern='*.xml'):
evtlist = list()
evtlist = glob.glob1((os.path.join(self.directory)), fn_pattern)
if not evtlist:
for root, _, files in os.walk(self.directory):
for file in files:
if file.endswith(fn_pattern[1:]):
evtlist.append(os.path.join(root, file))
self.evtlist = evtlist
def makeFileList(self, fn_pattern='*'): def __iter__(self):
self.evtlist = glob.glob1((os.path.join(self.directory)), '*.xml') assert isinstance(self.return_phase, str), 'phase has to be set before being able to iterate over items...'
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():
try: try:
yield pdfs['P'] yield pdfs[self.return_phase]
except KeyError: except KeyError:
yield np.nan continue
try:
yield pdfs['S']
except KeyError:
yield np.nan
def set_return_phase(self, type):
if type.upper() not in 'PS':
raise ValueError("phase type must be either 'P' or 'S'!")
else:
self.return_phase = type.upper()
def getQD(self,value): def getQD(self,value):
pdfgen = self.nextPDF()
QDlist = [] QDlist = []
for pdf in pdfgen: for pdf in self:
try:
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): def getQDQ(self,value):
pdfgen = self.nextPDF()
QDQlist = [] QDQlist = []
for pdf in pdfgen: for pdf in self:
try:
QDQ = pdf.qtile_dist_quot(value) QDQ = pdf.qtile_dist_quot(value)
QDQlist.append(QDQ) QDQlist.append(QDQ)
except AttributeError as e:
if e.message == "'float' object has no attribute 'quantile_distance'":
continue
return QDQlist return QDQlist
def getSTD(self): def getSTD(self):
pdfgen = self.nextPDF() std = []
self.p_std = [] for pdf in self:
self.s_std = []
for pdf in pdfgen:
try: try:
self.p_std.append(pdf['P'].standard_deviation()) std.append(pdf.standard_deviation())
except KeyError: except KeyError:
pass continue
try: std = np.array(std)
self.s_std.append(pdf['S'].standard_deviation()) self.set_stdarray(std)
except KeyError:
pass
self.makeArray()
def makeArray(self): def set_stdarray(self, array):
self.p_stdarray = np.array(self.p_std) if self.return_phase == 'P':
self.s_stdarray = np.array(self.s_std) self.p_stdarray = array
elif self.return_phase == 'S':
self.s_stdarray = array
else:
raise ValueError('phase type not set properly...\n'
'Actual phase type: {0}'.format(self.return_phase))
def getBinList(self,l_boundary,u_boundary,nbins = 100): def getBinList(self,l_boundary,u_boundary,nbins = 100):
@ -432,7 +430,8 @@ class PDFstatistics(object):
def histplot(self, array, binlist, xlab = 'Values', def histplot(self, array, binlist, xlab = 'Values',
ylab = 'Frequency', title = None, label=None): ylab = 'Frequency', title = None, label=None,
fnout = None):
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
plt.hist(array,bins = binlist) plt.hist(array,bins = binlist)
plt.xlabel('Values') plt.xlabel('Values')
@ -442,6 +441,9 @@ class PDFstatistics(object):
if label: if label:
title_str += ' (' + label + ')' title_str += ' (' + label + ')'
plt.title(title_str) plt.title(title_str)
if fnout:
plt.savefig(fnout+'histplot.png')
else:
plt.show() plt.show()
@ -468,9 +470,10 @@ 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()
Insheim.set_return_phase('p')
Insheim.getSTD() Insheim.getSTD()
Insheim.getStatistics()
qdlist = Insheim.getQDQ(0.3) qdlist = Insheim.getQDQ(0.3)
binlist = Insheim.getBinList(0.,3.)
print qdlist print qdlist