[task] read statistics from file

This commit is contained in:
sebastianp 2016-07-29 12:01:34 +02:00
parent 10fbfe5554
commit 2a798a554b

View File

@ -349,19 +349,33 @@ class PDFstatistics(object):
self.stations = {} self.stations = {}
self.p_std = {} self.p_std = {}
self.s_std = {} self.s_std = {}
self.theta015 = [] self.theta0 = []
self.theta1 = [] self.theta1 = []
self.theta2 = [] self.theta2 = []
self.makefilelist()
def readTheta(self, arname, dir, fnpattern):
exec('self.' + arname +' = []')
filelist = glob.glob1(dir, fnpattern)
for file in filelist:
fid = open(os.path.join(dir,file), 'r')
list = []
for line in fid.readlines():
list.append(eval(line))
exec('self.' + arname + ' += list')
fid.close()
def fromFileList(self):
self.makeFileList()
self.getData() self.getData()
self.getStatistics() self.getStatistics()
#self.showData()
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 getData(self): def getData(self):
for evt in self.evtlist: for evt in self.evtlist:
print evt print evt
@ -373,14 +387,14 @@ class PDFstatistics(object):
# print station, pdfs # print station, pdfs
try: try:
p_std = pdfs['P'].standard_deviation() p_std = pdfs['P'].standard_deviation()
self.theta015.append(pdfs['P'].qtile_dist_quot(0.015)) self.theta0.append(pdfs['P'].qtile_dist_quot(0.015))
self.theta1.append(pdfs['P'].qtile_dist_quot(0.1)) self.theta1.append(pdfs['P'].qtile_dist_quot(0.1))
self.theta2.append(pdfs['P'].qtile_dist_quot(0.2)) self.theta2.append(pdfs['P'].qtile_dist_quot(0.2))
except KeyError: except KeyError:
p_std = np.nan p_std = np.nan
try: try:
s_std = pdfs['S'].standard_deviation() s_std = pdfs['S'].standard_deviation()
self.theta015.append(pdfs['S'].qtile_dist_quot(0.015)) self.theta0.append(pdfs['S'].qtile_dist_quot(0.015))
self.theta1.append(pdfs['S'].qtile_dist_quot(0.1)) self.theta1.append(pdfs['S'].qtile_dist_quot(0.1))
self.theta2.append(pdfs['S'].qtile_dist_quot(0.2)) self.theta2.append(pdfs['S'].qtile_dist_quot(0.2))
except KeyError: except KeyError:
@ -403,29 +417,24 @@ class PDFstatistics(object):
index += 1 index += 1
def histplot(self, num, label=None):
def histplot(self, array, label=None):
# baustelle
binlist = [] binlist = []
if array[-1] == '5': if num == 0:
bfactor = 0.001 bfactor = 0.001
badd = 0 badd = 0
elif array[-1] == '1': elif num == 1:
bfactor = 0.003 bfactor = 0.003
badd = 0 badd = 0
else: else:
bfactor = 0.006 bfactor = 0.006
badd = 0.4 badd = 0.4
for i in range(100): for i in range(100):
binlist.append(badd+bfactor*i) binlist.append(badd+bfactor*i)
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
plt.hist(eval('self.'+array),bins = binlist) plt.hist(self.getTheta(num),bins = binlist)
plt.xlabel('Values') plt.xlabel('Values')
plt.ylabel('Frequency') plt.ylabel('Frequency')
#plt.autoscale(axis='x', tight=True)
title_str = 'Quantile distance quotient distribution' title_str = 'Quantile distance quotient distribution'
if label: if label:
title_str += ' (' + label + ')' title_str += ' (' + label + ')'
@ -435,14 +444,13 @@ class PDFstatistics(object):
def getTheta(self,number): def getTheta(self,number):
if number == 0: if number == 0:
return self.theta015 return self.theta0
elif number == 1: elif number == 1:
return self.theta1 return self.theta1
elif number == 2: elif number == 2:
return self.theta2 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))
@ -456,9 +464,12 @@ class PDFstatistics(object):
self.s_median = np.median(self.s_stdarray) self.s_median = np.median(self.s_stdarray)
if __name__ == "__main__": def writeThetaToFile(self,array,out_dir,filename = None):
rootdir = '/home/sebastianp/Data/Reassessment/Insheim/2012.10/' fid = open(os.path.join(out_dir,filename), 'w')
Insheim = PDFstatistics(rootdir) for val in array:
Insheim.makefilelist() fid.write(str(val)+'\n')
Insheim.getData() fid.close()
#if __name__ == "__main__":