def __init__(self, x, y): self.xFile = [] self.yFile = '{}'.format(y[0]) self.length = 0 self.volume = 0 self.peak = [] self.filterSignal = [] i = 0 while i < len(x): self.xFile.append('{}'.format(x[i])) i += 1 self.title = '{}'.format(namespace.title) self.output = '{}'.format(namespace.output) self.dataoutput = '{}'.format(namespace.dataoutput) self.dataStressFile = '{}'.format(namespace.dataStressFile) self.dataDir = '{}'.format(namespace.dataDir) self.distanceDump = '{}'.format(namespace.distanceDump) self.distanceStat = '{}'.format(namespace.distanceStat) self.xlabel = '{}'.format(namespace.xlabel) self.ylabel = '{}'.format(namespace.ylabel) self.l1 = '{}'.format(namespace.l1) self.l2 = '{}'.format(namespace.l2) self.l3 = '{}'.format(namespace.l3) self.time = np.array(getColumn(self.yFile, 0)).astype(float) * 0.001 self.sxx = np.array(getColumn(self.yFile, 1)).astype(float) self.syy = np.array(getColumn(self.yFile, 2)).astype(float) self.szz = np.array(getColumn(self.yFile, 3)).astype(float) if namespace.toforce: self.sxx *= np.pi / 100 self.syy *= np.pi / 100 self.szz *= np.pi / 100 self.computeDist() self.sxx /= self.volume self.syy /= self.volume self.szz /= self.volume if namespace.sumfilter: self.filterSignal = noiseFilter(self.syy, 5, 75) if namespace.plotpeaks: self.peakDetect(self.filterSignal, 12000, 40, 150, 5950) if namespace.writedata: self.writeToFile() if namespace.stdout and namespace.plotpeaks: self.stdOut() if namespace.dataStressFile: self.writeStressFile() self.computeDistAnalizeAtoms()
def plotChainStress(): """ atomStress() ploting graphix chain stress """ pFile = "%s/stress/null.stress.profile" % tempT pxx = np.array(getColumn(pFile, 1)).astype(float) pyy = np.array(getColumn(pFile, 2)).astype(float) pzz = np.array(getColumn(pFile, 3)).astype(float) xFile0 = "%s/stress/atom2.coordinate" % tempT xFile1 = "%s/stress/atom3.coordinate" % tempT xFile2 = "%s/stress/atom4.coordinate" % tempT xFile3 = "%s/stress/atom5.coordinate" % tempT xFile4 = "%s/stress/atom6.coordinate" % tempT xFile5 = "%s/stress/atom7.coordinate" % tempT xFile6 = "%s/stress/atom8.coordinate" % tempT xFile7 = "%s/stress/atom9.coordinate" % tempT xFile8 = "%s/stress/atom10.coordinate" % tempT xFile9 = "%s/stress/atom11.coordinate" % tempT l = (computeDist(xFile0, xFile1) + computeDist(xFile1, xFile2) + computeDist(xFile2, xFile3) + computeDist(xFile3, xFile4) + computeDist(xFile4, xFile5) + computeDist(xFile5, xFile6) + computeDist(xFile6, xFile7) + computeDist(xFile7, xFile8) + computeDist(xFile8, xFile9)) v = (l + 1.34) * np.pi if namespace.stresstime: time = np.array(getColumn(pFile, 0)).astype(float) * 0.001 p1 = pxx / v p2 = pyy / v p3 = pzz / v if namespace.toforce: p1 = np.pi * p1 / 100 p2 = np.pi * p2 / 100 p3 = np.pi * p3 / 100 plt.plot(time, p1, 'b', label=r'$\sigma_x$') plt.plot(time, p2, 'r', label=r'$\sigma_y$') plt.plot(time, p3, 'g', label=r'$\sigma_z$') if namespace.sumfilter: sumfsignal = noiseFilterPlot(time, p2) if namespace.plotpeaks: peak = plotPeaks(time, sumfsignal, 800, 20, 200, 5900)
def computeDist(xfile0, xfile1): xx0 = np.array(getColumn(xfile0, 1)).astype(float) xx1 = np.array(getColumn(xfile1, 1)).astype(float) xy0 = np.array(getColumn(xfile0, 2)).astype(float) xy1 = np.array(getColumn(xfile1, 2)).astype(float) xz0 = np.array(getColumn(xfile0, 3)).astype(float) xz1 = np.array(getColumn(xfile1, 3)).astype(float) dist = np.sqrt((xx0 - xx1) ** 2 + (xy0 - xy1) ** 2 + (xz0 - xz1) ** 2) return dist
'b', 'r', 'g', 'c', 'm' ] f_txt = ['data/4,2.dat', 'data/77.dat', 'data/300.dat', 'data/600.dat', 'data/1000.dat', 'data/1500.dat' ] force = [np.array(getColumn(f_txt[0], 1)).astype(float), np.array(getColumn(f_txt[1], 1)).astype(float), np.array(getColumn(f_txt[2], 1)).astype(float), np.array(getColumn(f_txt[3], 1)).astype(float), np.array(getColumn(f_txt[4], 1)).astype(float), np.array(getColumn(f_txt[5], 1)).astype(float), ] time = [np.array(getColumn(f_txt[0], 2)).astype(float), np.array(getColumn(f_txt[1], 2)).astype(float), np.array(getColumn(f_txt[2], 2)).astype(float), np.array(getColumn(f_txt[3], 2)).astype(float), np.array(getColumn(f_txt[4], 2)).astype(float), np.array(getColumn(f_txt[5], 2)).astype(float), ]
l1 = "{}".format(namespace.l1) l2 = "{}".format(namespace.l2) l3 = "{}".format(namespace.l3) yfile0 = "{}".format(namespace.yfile[0]) yfile1 = "{}".format(namespace.yfile[1]) yfile2 = "{}".format(namespace.yfile[2]) yfile3 = "{}".format(namespace.yfile[3]) yfile4 = "{}".format(namespace.yfile[4]) yfile5 = "{}".format(namespace.yfile[5]) yfile6 = "{}".format(namespace.yfile[6]) yfile7 = "{}".format(namespace.yfile[7]) yfile8 = "{}".format(namespace.yfile[8]) yfile9 = "{}".format(namespace.yfile[9]) yx0 = np.array(getColumn(yfile0, 1)).astype(float) yx1 = np.array(getColumn(yfile1, 1)).astype(float) yx2 = np.array(getColumn(yfile2, 1)).astype(float) yx3 = np.array(getColumn(yfile3, 1)).astype(float) yx4 = np.array(getColumn(yfile4, 1)).astype(float) yx5 = np.array(getColumn(yfile5, 1)).astype(float) yx6 = np.array(getColumn(yfile6, 1)).astype(float) yx7 = np.array(getColumn(yfile7, 1)).astype(float) yx8 = np.array(getColumn(yfile8, 1)).astype(float) yx9 = np.array(getColumn(yfile9, 1)).astype(float) yy0 = np.array(getColumn(yfile0, 2)).astype(float) yy1 = np.array(getColumn(yfile1, 2)).astype(float) yy2 = np.array(getColumn(yfile2, 2)).astype(float) yy3 = np.array(getColumn(yfile3, 2)).astype(float) yy4 = np.array(getColumn(yfile4, 2)).astype(float)
def read(self, distance_stat_file, file_type): """ Read from statistic file data :param distance_stat_file: standart "chain.dat" or "bound.dat" statistic file :param file_type: "chain" or "bound" file :return: self """ if file_type == 'chain': self.critLen = np.array(getColumn(distance_stat_file, 0)).astype(float) self.initLen = np.array(getColumn(distance_stat_file, 1)).astype(float) self.deltaLen = np.array(getColumn(distance_stat_file, 2)).astype(float) self.normalStrain = np.array(getColumn(distance_stat_file, 3)).astype(float) self.trueStrain = np.array(getColumn(distance_stat_file, 4)).astype(float) self.tau = np.array(getColumn(distance_stat_file, 5)).astype(float) self.stress = np.array(getColumn(distance_stat_file, 6)).astype(float) elif file_type == 'bound': number = np.array(getColumn(distance_stat_file, 0)).astype(float) self.number = int(number[0]) self.critLen = np.array(getColumn(distance_stat_file, 1)).astype(float) self.initLen = np.array(getColumn(distance_stat_file, 2)).astype(float) self.deltaLen = np.array(getColumn(distance_stat_file, 3)).astype(float) self.normalStrain = np.array(getColumn(distance_stat_file, 4)).astype(float) self.trueStrain = np.array(getColumn(distance_stat_file, 5)).astype(float) self.tau = np.array(getColumn(distance_stat_file, 6)).astype(float) self.stress = np.array(getColumn(distance_stat_file, 7)).astype(float) return self
# 'data/1000.dat', # 'data/1500.dat' # ] # for data 15.12.2015 dataDir='data/15_12_15' f_txt = ['%s/stress_4.2.dat'%(dataDir), '%s/stress_300.dat'%(dataDir), '%s/stress_600.dat'%(dataDir), '%s/stress_1000.dat'%(dataDir), ] force = [np.array(getColumn(f_txt[0], 1)).astype(float), np.array(getColumn(f_txt[1], 1)).astype(float), np.array(getColumn(f_txt[2], 1)).astype(float), np.array(getColumn(f_txt[3], 1)).astype(float), # np.array(getColumn(f_txt[4], 1)).astype(float), # np.array(getColumn(f_txt[5], 1)).astype(float), ] time = [np.array(getColumn(f_txt[0], 2)).astype(float), np.array(getColumn(f_txt[1], 2)).astype(float), np.array(getColumn(f_txt[2], 2)).astype(float), np.array(getColumn(f_txt[3], 2)).astype(float), #np.array(getColumn(f_txt[4], 2)).astype(float), #np.array(getColumn(f_txt[5], 2)).astype(float), ]
namespace = parser.parse_args(sys.argv[1:]) title = '{}'.format(namespace.title) output = '{}'.format(namespace.output) dataoutput = '{}'.format(namespace.dataoutput) xlabel = '{}'.format(namespace.xlabel) ylabel = '{}'.format(namespace.ylabel) l1 = '{}'.format(namespace.l1) l2 = '{}'.format(namespace.l2) l3 = '{}'.format(namespace.l3) pfile = '{}'.format(namespace.yfile[0]) pxx = np.array(getColumn(pfile, 1)).astype(float) pyy = np.array(getColumn(pfile, 2)).astype(float) pzz = np.array(getColumn(pfile, 3)).astype(float) c1 = [50, 20, 25, 10] c2 = [400, 100, 200, 70] if namespace.group: data = plotChainStress() if namespace.atom: data = plotAtomStress() if namespace.writedata: odata = np.matrix(data) header = '%s is data output\n%s file\ntimeMax tmaximum timeMin minimum\n (100*ps) (GPa or nN) (100*ps) (GPa or nN)' % (
l5 = '{}'.format(namespace.l5) l6 = '{}'.format(namespace.l6) l7 = '{}'.format(namespace.l7) l8 = '{}'.format(namespace.l8) l9 = '{}'.format(namespace.l9) l10 = '{}'.format(namespace.l10) plt.figure() plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.grid(True) if number == 1: x = getColumn(filename,0) y = getColumn(filename,1) p1 = plt.plot(x, y, 'r', label=l1) if number == 2: x = getColumn(filename,0) y1 = getColumn(filename,1) y2 = getColumn(filename,2) p1 = plt.plot(x, y1, 'b', label=l1) p2 = plt.plot(x, y2, 'r', label=l2) if number == 3: x = getColumn(filename,0) y1 = getColumn(filename,1) y2 = getColumn(filename,2)
if __name__ == '__main__': parser = createParser() namespace = parser.parse_args(sys.argv[1:]) number = namespace.number filename = '{}'.format(namespace.file) title = '{}'.format(namespace.title) xlabel = '{}'.format(namespace.xlabel) ylabel = '{}'.format(namespace.ylabel) output = '{}'.format(namespace.output) plt.figure() plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.grid(True) x = getColumn(filename,0) y = getColumn(filename,1) p1 = plt.plot(x, y, 'r') if namespace.sumfilter: noiseFilterPlot(x,y) if namespace.fft: fourierFilter(x,y) if namespace.plotlegend: plt.legend() plt.savefig(output, dpi=150)
title = '{}'.format(namespace.title) output = '{}'.format(namespace.output) xlabel = '{}'.format(namespace.xlabel) ylabel1 = '{}'.format(namespace.ylabel1) ylabel2 = '{}'.format(namespace.ylabel2) ylabel3 = '{}'.format(namespace.ylabel3) l1 = '{}'.format(namespace.l1) l2 = '{}'.format(namespace.l2) l3 = '{}'.format(namespace.l3) if number == 1: x = getColumn(filename,0) y1 = getColumn(filename,1) plt.figure() p1 =plt.subplot(1, 1, 1) subplots_adjust(hspace=0.1) p1.plot(x, y1, 'b', label=l1) plt.xlabel(xlabel) plt.ylabel(ylabel1) plt.title(title) plt.grid(True) plt.legend() if number == 2: x = getColumn(filename,0)
import numpy as np import matplotlib.mlab as mlab import matplotlib.pyplot as plt from column import getColumn import scipy.stats as stats from scipy.optimize import curve_fit def weib(x,n,a): return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a) num_bins = 20 num_weib = 200 file = "null.stress.profile" x = np.array(getColumn(file, 2)).astype(float) plt.figure(figsize=(10,5)) ax1=plt.subplot(121) n, bins, patches = ax1.hist(x, num_bins, facecolor='green', normed=True, alpha=0.5) idBinds = max(enumerate(n),key=lambda j: j[1])[0] mu = bins[idBinds+1] sigma = 23. scale = n.max()/weib(bins, mu, sigma).max() linsp = np.linspace(bins[0], bins[num_bins], num_weib)
def plotChainStress(): """ atomStress() ploting graphix chain stress """ xfile0 = '{}'.format(namespace.xfile[0]) xfile1 = '{}'.format(namespace.xfile[1]) xfile2 = '{}'.format(namespace.xfile[2]) xfile3 = '{}'.format(namespace.xfile[3]) xfile4 = '{}'.format(namespace.xfile[4]) xfile5 = '{}'.format(namespace.xfile[5]) xfile6 = '{}'.format(namespace.xfile[6]) xfile7 = '{}'.format(namespace.xfile[7]) xfile8 = '{}'.format(namespace.xfile[8]) xfile9 = '{}'.format(namespace.xfile[9]) l = (computeDist(xfile0, xfile1) + computeDist(xfile1, xfile2) + computeDist(xfile2, xfile3) + computeDist(xfile3, xfile4) + computeDist( xfile4, xfile5) + computeDist(xfile5, xfile6) + computeDist(xfile6, xfile7) + computeDist(xfile7, xfile8) + computeDist( xfile8, xfile9)) epsilon = (l - l[0]) / l[0] v = (l + 1.34) * np.pi if namespace.stressdia: time = np.array(getColumn(pfile, 0)).astype(float) * 0.001 p1 = pxx / v p2 = pyy / v p3 = pzz / v if namespace.toforce: p1 = np.pi * p1 / 100 p2 = np.pi * p2 / 100 p3 = np.pi * p3 / 100 plt.figure(title) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.grid(True) from operator import itemgetter list1 = epsilon list2 = p2 x, y = [list(x) for x in zip(*sorted(zip(list1, list2), key=itemgetter(0)))] # plt.plot(l, p1, 'b', label=l1) plt.plot(x, y, 'rx', label=l2) # plt.plot(l, p3, 'g', label=l3) if namespace.sumfilter: sumfsignal = noiseFilterPlot(time, p2) if namespace.plotpeaks: peak = plotPeaks(time, sumfsignal, 800, 20, 200, 5900) if namespace.windowfit: plotPolinom2Window(l, p1, c1[0], c1[1], c1[2], c1[3], 'k--') plotPolinom2Window(l, p2, c2[0], c2[1], c2[2], c2[3], 'k-') if namespace.stresstime: time = np.array(getColumn(pfile, 0)).astype(float) * 0.001 p1 = pxx / v p2 = pyy / v p3 = pzz / v if namespace.toforce: p1 = np.pi * p1 / 100 p2 = np.pi * p2 / 100 p3 = np.pi * p3 / 100 plt.figure(title) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.grid(True) plt.plot(time, p1, 'b', label=l1) plt.plot(time, p2, 'r', label=l2) plt.plot(time, p3, 'g', label=l3) if namespace.sumfilter: sumfsignal = noiseFilterPlot(time, p2) if namespace.plotpeaks: peak = plotPeaks(time, sumfsignal, 800, 20, 200, 5900) if namespace.windowfit: plotPolinom2Window(time, p1, c1[0], c1[1], c1[2], c1[3], 'k--') plotPolinom2Window(time, p2, c2[0], c2[1], c2[2], c2[3], 'k-') if namespace.plotpeaks: return peak
def plotAtomStress(): """ TODO atomStress() ploting graphix single atom stress """ if namespace.true: xfile0 = '{}'.format(namespace.xfile[0]) xfile1 = '{}'.format(namespace.xfile[1]) xfile2 = '{}'.format(namespace.xfile[2]) l1 = computeDist(xfile0, xfile1) l2 = computeDist(xfile1, xfile2) v = (0.5 * l1 + 0.5 * l2) * np.pi time = np.array(getColumn(pfile, 0)).astype(float) * 0.001 p1 = pxx / v p2 = pyy / v p3 = pzz / v if namespace.toforce: p1 = np.pi * p1 / 100 p2 = np.pi * p2 / 100 p3 = np.pi * p3 / 100 plt.figure(title) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.grid(True) plt.plot(time, p1, 'b') plt.plot(time, p2, 'r') plt.plot(time, p3, 'g') if namespace.sumfilter: sumfsignal = noiseFilterPlot(time, p2) if namespace.plotpeaks: peak = plotPeaks(time, sumfsignal, 800, 20, 200, 5900) if namespace.windowfit: plotPolinom2Window(time, p1, c1[0], c1[1], c1[2], c1[3], 'k--') plotPolinom2Window(time, p2, c2[0], c2[1], c2[2], c2[3], 'k-') if namespace.conditional: v = 1.34 * np.pi time = np.array(getColumn(pfile, 0)).astype(float) * 0.001 p1 = pxx / v p2 = pyy / v p3 = pzz / v if namespace.toforce: p1 = np.pi * p1 / 100 p2 = np.pi * p2 / 100 p3 = np.pi * p3 / 100 plt.figure(title) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.grid(True) plt.plot(time, p1, 'b') plt.plot(time, p2, 'r') plt.plot(time, p3, 'g') if namespace.sumfilter: sumfsignal = noiseFilterPlot(time, p2) if namespace.plotpeaks: peak = plotPeaks(time, sumfsignal, 800, 20, 200, 5900) if namespace.windowfit: plotPolinom2Window(time, p1, c1[0], c1[1], c1[2], c1[3], 'k--') plotPolinom2Window(time, p2, c2[0], c2[1], c2[2], c2[3], 'k-') if namespace.plotpeaks: return peak
parser = createParser() namespace = parser.parse_args(sys.argv[1:]) title = '{}'.format(namespace.title) output = '{}'.format(namespace.output) xlabel = '{}'.format(namespace.xlabel) ylabel = '{}'.format(namespace.ylabel) label = '{}'.format(namespace.label) if namespace.dist: stepf = '{}'.format(namespace.file[0]) step = np.array(getColumn(stepf,0)).astype(float) xfile0 = '{}'.format(namespace.file[0]) xfile1 = '{}'.format(namespace.file[1]) lenght = computeDist(xfile0,xfile1) plt.figure(title) if namespace.apr: p = np.polyfit(step,lenght,1) if namespace.dif: vel=p[0]/0.001*0.1 plt.plot(step, lenght, 'g', label=vel) else: plt.plot(step, lenght, 'g')
# number plot namespace num = argparse.Namespace() num.fit = 200 num.dism = 1.0 num.dism_plot = '1' num.xmax = 2400**num.dism num.ymax = 12 # read file data = argparse.Namespace() #data.file = "dat/hist.dat" data.file = "dat/dispersion" #data.s_05 = np.array(getColumn(data.file, 0)).astype(float) #data.s_50 = np.array(getColumn(data.file, 1)).astype(float) data.s_95 = np.array(getColumn(data.file, 2)).astype(float) data.temp = np.array(getColumn(data.file, 0)).astype(float)**num.dism data.linespace = np.linspace(0, num.xmax, num.fit) #data.fit_s_05 = np.polyval(np.polyfit(data.temp,data.s_05,3), data.linespace) data.fit_s_95 = np.polyval(np.polyfit(data.temp,data.s_95, 3), data.linespace) #data.err_upper = data.s_95 - data.s_50 #data.err_lower = data.s_50 - data.s_05 #data.asymmetric_error = [data.err_lower, data.err_upper] # building graphix plt.figure() if num.dism != 1: plt.xlabel(r'Temperatute, $T^{%s}$ ($K^{%s}$)'%(num.dism_plot,num.dism_plot), fontsize=16) elif num.dism == 1: plt.xlabel(r'Temperatute, $T$ ($K$)', fontsize=17) plt.tick_params(axis='both', which='major', labelsize=15)
#exponweib.pdf = lambda x, k, l, a: a*k/l #exponweib.cdf = lambda x, k, l, a: #exponweib.fit = lambda x, y: curve_fit(exponweib.cdf, x, y, p0 = [10., 250.]) # number plot namespace num = argparse.Namespace() num.bins = 20 num.histbins = 50 num.weib = 200 num.alpha = 0.8 # read file data = argparse.Namespace() data.numfile = '1000' data.file = "dat/stress_%s.dat" % (data.numfile) data.x = np.array(getColumn(data.file, 2)).astype(float) data.t = np.array(getColumn(data.file, 1)).astype(float) # create histogram hist, bin_edges = np.histogram(data.x, num.histbins, density=True) # Calculate histogram data.x_hist = bin_edges[1:] # Take the upper edges of the bins data.y_hist = hist.cumsum()/hist.cumsum().max() # Normalise the cumulative sum t_hist, t_bin_edges = np.histogram(data.t, num.histbins, density=True) # Calculate histogram data.t_x_hist = t_bin_edges[1:] # Take the upper edges of the bins data.t_y_hist = t_hist.cumsum()/t_hist.cumsum().max() # Normalise the cumulative sum # distribution namespace coeff = argparse.Namespace() coeff.popt, coeff.pcov = weib.fit(data.x_hist, data.y_hist) coeff.shape = coeff.popt[0] # Scipy's shape parameter corresponds to log(geo. std. dev.)
if __name__ == '__main__': parser = createParser() namespace = parser.parse_args(sys.argv[1:]) file = '{}'.format(namespace.file) title = '{}'.format(namespace.title) output = '{}'.format(namespace.output) xlabel = '{}'.format(namespace.xlabel) ylabel1 = '{}'.format(namespace.ylabel1) ylabel2 = '{}'.format(namespace.ylabel2) ylabel3 = '{}'.format(namespace.ylabel3) #l1 = '{}'.format(namespace.l1) #l2 = '{}'.format(namespace.l2) #l3 = '{}'.format(namespace.l3) xx = np.array(getColumn(file,0)).astype(float) yx = np.array(getColumn(file,1)).astype(float) yy = np.array(getColumn(file,2)).astype(float) yz = np.array(getColumn(file,3)).astype(float) if namespace.abs: y = np.sqrt(yx**2+yy**2+yx**2) plt.figure() plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel1) plt.vlines(xx, [0], y*1.604, 'b') plt.grid(True) #leg = plt.legend()