def plot_vecs(t1, t2): gp3.splot( Data(magvecs[(vecstime > t1) * (vecstime < t1 + 64. / 86400.)], with_="vectors lt 3")) te = t1 + 64. / 86400. while te < t2: print te gp3.splot( Data(magvecs[(vecstime > t1) * (vecstime < te)], with_="vectors lt 3")) print sqrt( (magvecs[(vecstime > te - 64. / 86440) * (vecstime < te)][:, 0] + magvecs[(vecstime > te - 64. / 86440) * (vecstime < te)][:, 3])**2 + (magvecs[(vecstime > te - 64. / 86440) * (vecstime < te)][:, 1] + magvecs[(vecstime > te - 64. / 86440) * (vecstime < te)][:, 4])**2 + (magvecs[(vecstime > te - 64. / 86440) * (vecstime < te)][:, 2] + magvecs[(vecstime > te - 64. / 86440) * (vecstime < te)][:, 5])**2), hedata.vel[ (hedata.time > te - 64. / 86440.) * (hedata.time < te + 656. / 86400.)], sqrt( swdata.velx[(swdata.time > te - 64. / 86440.) * (swdata.time < te)]**2 + (swdata.vely[(swdata.time > te - 64. / 86440.) * (swdata.time < te)] + 30.)**2 + swdata.velz[(swdata.time > te - 64. / 86440.) * (swdata.time < te)]**2) te += 64. / 86400. raw_input()
def buildplotmarks(self, panel): for mark in self.plotmarks: tmpmark = [] if (mark.style == "vline"): tmppos = mark.pos tmppos[0][1] = self.panel[panel].yrange[0] * 1.01 tmppos[0][3] = (self.panel[panel].yrange[1] - self.panel[panel].yrange[0]) * 0.99 tmpmark = Data(tmppos) if (mark.style == "hline"): tmppos = mark.pos tmppos[0][0] = self.xrange[0] * 1.01 tmppos[0][2] = (self.xrange[1] - self.xrange[0]) * 0.99 tmpmark = Data(tmppos) if (mark.style == "box"): if mark.pos[0][2] == 1e-20: ymin = self.panel[panel].yrange[0] else: ymin = mark.pos[0][2] if mark.pos[0][3] == 1e20: ymax = self.panel[panel].yrange[1] else: ymax = mark.pos[0][3] tmppos = [[mark.pos[0][0], ymin, ymax], [mark.pos[0][1], ymin, ymax]] #tmppos=[[mark.pos[0][0],self.panel[panel].yrange[1],self.panel[panel].yrange[0]],[mark.pos[0][2],self.panel[panel].yrange[1],self.panel[panel].yrange[0]]] tmpmark = Data(tmppos) if (mark.style == "function"): tmpmark = mark.function if (tmpmark != []): mark.addplot(tmpmark)
def getcircle(r): tmpcirc = [] for y in range(int(-r), int(r)): tmpcirc.append([circle(y, r), y]) ptmpcirc = Data(tmpcirc) ptmpcirc.set_option_colonsep("with", "l lt -0") return ptmpcirc
def getarc(x0, y0, ang0, ang1, r, lt): tmparc = [] for ang in range(int(min(ang0, ang1)), int(max(ang0, ang1) + 1)): radang = pi / 180. * float(ang) tmparc.append([x0 + r * cos(radang), y0 + r * sin(radang)]) ptmparc = Data(tmparc) ptmparc.set_option_colonsep("with", "l ls %i" % (lt)) radang = pi / 180. * (ang0 + ang1) / 2. labelpos = [x0 + r * 2. / 3. * cos(radang), y0 + r * 2. / 3. * sin(radang)] return ptmparc, labelpos
def plotstep(step, gp=gp): cut1 = [[210, 0.1], [210, 1.], [210, 1e2], [210, 1.e3], [210, 1.e4], [210, 1.e5], [210, 1.e6], [210, 1.e7], [210, 1.e8]] cut2 = [[408, 0.1], [408, 1.], [408, 1e2], [408, 1.e3], [408, 1.e4], [408, 1.e5], [408, 1.e6], [408, 1.e7], [408, 1.e8]] gp("set style data lines") gp("set log y") gp("set title '%i'" % (step)) #gp.plot(Data(tof2mq(step),dcr[step])) gp.plot(Data(dcr[step]), Data(cut1, with_="l lt 0"), Data(cut2, with_="l lt 0"))
def plot_vdf(t1, t2): meanvalf = mean(valf[(valf[:, 0] > t1) * (valf[:, 0] < t2) * (valf[:, 1] > 0.)][:, 1]) meanvsw = mean(swdata.vel[(swdata.time > t1) * (swdata.time < t2) * (swdata.vel > 0.)]) gpvdf.plot( Data(d3hdata[(d3hdata[:, 0] > t1) * (d3hdata[:, 0] < t2)][:, 1], d3hdata[(d3hdata[:, 0] > t1) * (d3hdata[:, 0] < t2)][:, 2], with_="l lt 1 lw 3", title="H^{1+}"), Data(d3hedata[(d3hedata[:, 0] > t1) * (d3hedata[:, 0] < t2)][:, 1], d3hedata[(d3hedata[:, 0] > t1) * (d3hedata[:, 0] < t2)][:, 2], with_="l lt 3 lw 3", title="He^{2+}"), Data(d3odata[(d3odata[:, 0] > t1) * (d3odata[:, 0] < t2)][:, 1], d3odata[(d3odata[:, 0] > t1) * (d3odata[:, 0] < t2)][:, 2], with_="l lt 4 lw 3", title="O^{6+}"), Data([[meanvsw, 0.], [meanvsw, 1.]], with_="l lt -1 lw 2"), Data([[meanvsw + meanvalf, 0.], [meanvsw + meanvalf, 1.]], with_="l lt 0 lw 2"), Data([[meanvsw + 2. * meanvalf, 0.], [meanvsw + 2. * meanvalf, 1.]], with_="l lt 0 lw 2"), Data([[meanvsw - meanvalf, 0.], [meanvsw - meanvalf, 1.]], with_="l lt 0 lw 2"), Data([[meanvsw - 2. * meanvalf, 0.], [meanvsw - 2. * meanvalf, 1.]], with_="l lt 0 lw 2"))
def main(): filename = '../tmp/config.txt' c = ConfigReader() c.parse(filename) cluster = c.readCluster() maxPerf = getMaxPerformance(cluster.availableServers) outline = readOutlineFile('../tmp/outline.txt') trace = generateTrace(outline, maxPerf, 20) if Gnuplot is not None: data = Data(trace, with_='l') g = Gnuplot() g('set ytics 0, 100') g('set xtics 0, 20') g('set grid') g.plot(data) raw_input() file = open('../tmp/trace_gen.txt','w') for value in trace: file.write('%f\n' % value) file.close()
def plot_step(self, step): if self.valf[step] > 0.: self.gp("unset label") self.gp("set label 'v_{sw}=%f' at -1.5,0.95" % (self.swedata.vel[step])) self.gp("set label 'C_{A}=%f' at -1.5,0.90" % (self.valf[step])) self.gp("set label '{/Symbol= Q}=%f' at -1.5,0.85" % (self.theta[step] / pi * 180.)) self.gp("set label '{/Symbol= dQ}=%f' at -1.5,0.8" % (self.mag.sigTHETA[step] / pi * 180.)) self.gp("set title '%.4i DoY %f'" % (self.year, self.hedata.time[step])) if amax(self.hedata.countspec[step, :, 1]) > 0.: self.gp.plot( Data((self.hedata.countspec[step, :, 0] - self.swedata.vel[step]) / self.valf[step], self.hedata.countspec[step, :, 1] / amax(self.hedata.countspec[step, :, 1]), with_="lp lt 3 lw 3", title="He^{2+}")) if amax(self.odata.countspec[step, :, 1]) > 0.: self.gp.replot( Data((self.odata.countspec[step, :, 0] - self.swedata.vel[step]) / self.valf[step], self.odata.countspec[step, :, 1] / amax(self.odata.countspec[step, :, 1]), with_="lp lt 4 lw 3", title="O^{6+}")) il = where(self.hdata.time == self.hedata.time[step])[0] if il.shape[0] > 0 and amax(self.hdata.tcrspec[il[0], :] + self.hdata.dcrspec[il[0], :]) > 0.: self.gp.replot( Data((self.hdata.velspec - self.swedata.vel[step]) / self.valf[step], (self.hdata.tcrspec[il[0], :] + self.hdata.dcrspec[il[0], :]) / amax(self.hdata.tcrspec[il[0], :] + self.hdata.dcrspec[il[0], :]), with_="lp lt 1 lw 3", title="H^{1+}")) self.gp.hardcopy("vdistperp_%.4i_%.3i.%.6i.ps" % (self.year, int(self.hedata.time[step]), int((self.hedata.time[step] % 1) * 1e6)), color=True) self.gp.sync()
def plotstepmq(step, gp=gp): #cut1=[[210,0.1],[210,1.],[210,1e2],[210,1.e3],[210,1.e4],[210,1.e5],[210,1.e6],[210,1.e7],[210,1.e8]] #cut2=[[408,0.1],[408,1.],[408,1e2],[408,1.e3],[408,1.e4],[408,1.e5],[408,1.e6],[408,1.e7],[408,1.e8]] gp("set style data lines") gp("set log y") gp("set title '%i'" % (step)) gp.plot(Data(tof2mq(step), dcr[step]))
def plot(self): self.gp = Gnuplot() #self.gp("set autoscale") self.gp("set size square") self.gp("set xrange[0.01:.1]") self.gp("set yrange[100.:1000.]") self.gp("set format xy '10^%T'") self.gp("set xlabel '{/Symbol w} [Hz]'") self.gp("set ylabel 'Wave Power [arb.]'") self.gp("set logscale xy") self.pParr = Data(self.Parr) self.pParr.set_option_colonsep("with", "lp") self.gp.plot(self.pParr) #self.gp.replot(Data(self.dParr2)) #self.gp.replot(Data(self.dParr2)) self.gp("a=%f" % (self.power)) self.gp("k=%f" % (self.index)) self.gp("f(x)=a*x**-k") self.gp("f2(x)=(a*.7)*x**-(k+.1)") self.gp("f3(x)=(a*1e-5)*x**-(k+4.)") #self.gp.replot("f(x) with l lt 3","f2(x) with l lt 4","f3(x) with l lt 5") self.gp("set term postscript color 18 lw 2 eps") self.gp.hardcopy("Pcascall.ps", color="true", fontsize=18) self.gp2 = Gnuplot() self.gp2("set logscale xy") self.gp2("set title 'theocasc dE'") #gp2("set yrange[1:1.1]") first = 1 for j in range(self.dim): if (first == 1): self.gp2.plot(self.pdParr[j]) first = 0 else: self.gp2.replot(self.pdParr[j]) self.gp3 = Gnuplot() self.gp3("set logscale xy") self.gp3("set title 'theocasc dV'") first = 1 for j in range(self.dim): if (first == 1): self.gp3.plot(self.pdVarr[j]) first = 0 else: self.gp3.replot(self.pdVarr[j])
def geterror(self): gp=Gnuplot() # gp("set yrange[0:1e20]") gp("a=%f" %(self.counts)) print len(self.histogram[0]) gp("b=5.") gp("c=200.") gp("f(x)=c/(sqrt(2.*pi)*b)*exp(-((x-a)**2/(2.*b**2)))") self.gphist=Data(self.histogram[0]) self.gphist.set_option_colonsep("with","boxes") if (len(self.histogram[0])>3): gp("fit f(x) '"+self.gphist.filename+"' using 1:2 via a,b") gp("fit f(x) '"+self.gphist.filename+"' using 1:2 via b") else: gp("b=0.1") # gp.plot(self.gphist,"f(x)") # gp("pause 3") self.error=gp.eval("b")/self.counts print self.error
def plot_hist(self,arg,xvals,xlabel=None,ylabel=None,save=False,title=None,reset=False): print self.get_hist(arg,xvals)[0],self.get_hist(arg,xvals)[1] if reset: self.gphist.reset() if ylabel: self.gphist("set ylabel '%s'"%(ylabel)) if xlabel: self.gphist("set xlabel '%s'"%(xlabel)) if not title: title=arg self.gphist.replot(Data(self.get_hist(arg,xvals)[0],self.get_hist(arg,xvals)[1],with_="histeps lw 3",title=title)) if ylabel or xlabel: self.gphist("unset xlabel")
def add_2ddata(self, data, linewidth=2, color='red'): """ Here you can add additional 2 dimensional data to the color contour plot INPUT: data (must be of dimension of angular_bins, values must be in range of radial_bins) linewidth of the data color of the data """ from numpy import append datax, datay = self.__polar_to_cart__( append(data, data[0]), append(self.angular_bins, self.angular_bins[0])) dataobj = Data(datax, datay, with_="lines lw %s lc rgb '%s'" % (linewidth, color)) self.data2d.append(dataobj)
def __create_gpdata__(self): """ This routine create a Gnuplot data object from the given data, angular bins and radial bins """ self.__det_cbtics__() if self.log: max_counts = log10(max(self.data[nonzero(self.data)])) min_counts = log10(min(self.data[nonzero(self.data)])) else: max_counts = max(self.data) min_counts = min(self.data[nonzero(self.data)]) self.gparray = [] for rindex, radius in enumerate(self.radial_bins): for aindex, angle in enumerate(self.angular_bins): counts = self.data[aindex, rindex] if counts > 0: if self.log: counts = log10(counts) rgb_color = long(1020. * (counts - min_counts) / (max_counts - min_counts)) r, g, b = self.__det_rgb__(rgb_color) r_s = radius - (self.radial_bins[1] - self.radial_bins[0]) / 2. r_e = radius + (self.radial_bins[1] - self.radial_bins[0]) / 2. a_s = angle - (self.angular_bins[1] - self.angular_bins[0]) / 2. a_e = angle + (self.angular_bins[1] - self.angular_bins[0]) / 2. a_s = angle a_e = angle + (self.angular_bins[1] - self.angular_bins[0]) bin_koord = [] x1, y1 = self.__polar_to_cart__(r_s, a_s) x2, y2 = self.__polar_to_cart__(r_e, a_s) x3, y3 = self.__polar_to_cart__(r_e, a_e) x4, y4 = self.__polar_to_cart__(r_s, a_e) bin_koord.append([x1, y1]) bin_koord.append([x2, y2]) bin_koord.append([x3, y3]) bin_koord.append([x4, y4]) bin_koord.append([x1, y1]) dataobj = Data( bin_koord, with_='filledcurves lc rgb "#%02X%02X%02X"' % (r, g, b)) self.gparray.append(dataobj)
def select(self): """ Start interactive polygonal area selection. Please make sure that the lines do NOT cross. """ gp=self.gp # fix ranges so that the plot does not move while drawing the polygon xr=gp.getXrange() yr=gp.getYrange() gp.setXrange(xr) gp.setYrange(yr) poly=[] while True: p=gp.getxy() if gp.eval("MOUSE_KEY")==3: break poly.append(p) if len(poly)>1: gp._remove_last_from_queue() d=Data(poly) d.set_option(with="lines") gp.replot(d)
def __create_gpdata__(self): """ This routine create a Gnuplot data object from the given data, angular bins and radial bins """ """ if self.log: max_counts=log10(max(self.data[nonzero(self.data)])) min_counts=log10(min(self.data[nonzero(self.data)])) else: max_counts=max(self.data) min_counts=min(self.data[nonzero(self.data)]) """ self.gparray = [] for data_i, data in enumerate(self.data): data -= min(data) if self.log: data = log10(data + 0.01) if self.plotmode == 'T': data_processed = data / max(data) + 0.5 + data_i * 0. elif self.plotmode == 'S': data_processed = data / max(data) + 0.5 + data_i * 1. datax, datay = self.__polar_to_cart__(data_processed, self.angular_bins) dataobj = Data(datax, datay, with_="lines lw 2") self.gparray.append(dataobj)
weights=corrarr2[:, 1]) histvswmag, vswbins = histogram(corrarr2[:, 0], linspace(200, 1000, 41), weights=corrarr2[:, 2]) histvswcorrfac, vswbins = histogram(corrarr2[:, 0], linspace(200, 1000, 41), weights=corrarr2[:, 3]) normvswcounts, x = histogram(corrarr2[:, 0], linspace(200, 1000, 41)) histvswcounts /= normvswcounts histvswmag /= normvswcounts histvswcorrfac /= normvswcounts vswbins = vswbins[:-1] gp6 = Gnuplot() gp6.plot( Data(vswbins[histvswcounts > 0.], histvswcounts[histvswcounts > 0.], with_="steps lt 1"), Data(vswbins[histvswmag > 0.], histvswmag[histvswmag > 0.], with_="steps lt 3"), Data(vswbins[histvswcorrfac > 0.], histvswcorrfac[histvswcorrfac > 0.], with_="steps lt 4"), Data(vswbins[histvswcorrfac > 0.], histvswcorrfac[histvswcorrfac > 0.] * histvswmag[histvswcorrfac > 0.], with_="steps lt 5")) gp5 = Gnuplot() #gp5.plot(Data(vswbins[histvswcorrfac>0.],histvswcounts[histvswcorrfac>0.]/histvswcorrfac[histvswcorrfac>0.]*histvswmag[histvswcorrfac>0.],with_="steps lt 3")) gp5.plot( Data(vswbins[histvswcorrfac > 0.], histvswcounts[histvswcorrfac > 0.] /
ion_list=["He2+","O6+","O7+","C4+","C5+","C6+","N7+","Fe11+"] swepamv=[] swepamt=[] swepamd=[] swepamr=[] swepamin=open("Swepamd279-289y200516min.dat") for s in swepamin: k=s.split() swepamv.append([float(k[0]),float(k[4])]) swepamt.append([float(k[0]),float(k[2])]) swepamd.append([float(k[0]),float(k[1])]) swepamr.append([float(k[0]),float(k[3])]) plotswepamv=Data(swepamv) plotswepamt=Data(swepamt) plotswepamd=Data(swepamd) plotswepamr=Data(swepamr) plotswepamv.set_option_colonsep("title", "'SWEPAM H1+'") plotswepamt.set_option_colonsep("title", "'SWEPAM H1+'") plotswepamd.set_option_colonsep("title", "'SWEPAM H1+'") plotswepamr.set_option_colonsep("title", "'SWEPAM He2+/H1+'") pathl=open("pathlist2.in") data=[] print "readinding data" for s in pathl: p=s.split() liste=open(p[0]+"list.in") s2=liste.readline()
elem=elem+1 k=s.split() if (float(k[8])>0. and float(k[8])<14.): meancharge[elem].append([float(time),float(k[8])]) elemfile.close() listin.close() """ generate gnuplot data """ #erzeugt plotdaten plotdens=[] for ion in range(len(ionnames)): if (len(iondens[ion])>1): tmpplotdens=Data(iondens[ion]) else: tmpplotdens=Data([[0.,0.]]) tmpplotdens.set_option_colonsep("using", "1:2 ") tmpplotdens.set_option_colonsep("title", "'%s density*10^7'" %(ionnames[ion])) tmpplotdens.set_option_colonsep("with", "points") plotdens.append(tmpplotdens) plotmaxdens=[] for ion in range(len(ionnames)): if (len(ionmaxdens[ion])>1): tmpplotmaxdens=Data(ionmaxdens[ion]) else: tmpplotmaxdens=Data([[0.,0.]]) tmpplotmaxdens.set_option_colonsep("using", "1:2 ") tmpplotmaxdens.set_option_colonsep("title", "'%s density*10^7'" %(ionnames[ion])) tmpplotmaxdens.set_option_colonsep("with", "points")
def mrqcof(self, deriv, plot): from numpy import array, zeros from Gnuplot import Data dim = len(self.yvals[0]) dyda = zeros([self.ma, dim]) tmpdv = [] tmpvth = [] self.chisq = 0. for j in range(self.ma): for k in range(self.ma): self.covar[j][k] = 0. self.da[j] = 0. for i in range(self.ndata): ymod = self.func(self.xvals[i], self.paratry, dyda, deriv, self.ia) if (plot == 1): tmpdv.append([i * 0.2, ymod[0]]) tmpvth.append([i * 0.2, ymod[1]]) sig2i = [] for j in range(dim): if (self.sigvals[i][j] != 0.): sig2i.append(1. / (self.sigvals[i][j]**2)) else: sig2i.append(1.) dy = [] for j in range(dim): dy.append(self.yvals[i][j] - ymod[j]) if (deriv == 1): j = 0 for l in range(self.ma): if (self.ia[l]): wt = [] for n in range(dim): wt.append(dyda[l][n] * sig2i[n]) k = 0 for m in range(l + 1): if (self.ia[m]): for n in range(dim): self.covar[j][k] += wt[n] * dyda[m][n] k += 1 for n in range(dim): self.da[j] += dy[n] * wt[n] j += 1 for n in range(dim): self.chisq += dy[n] * dy[n] * sig2i[n] for j in range(1, self.mfit): for k in range(j): self.covar[k][j] = self.covar[j][k] if (plot == 1): tmpdv.append([1.6, 0.0]) tmpdvplot = Data(tmpdv) # tmpdvplot.set_option_colonsep("title","'chisq=%.2f,bp=%.2f,pb=%.2f,vpara=%.2f,vperp=%.2f'"%(self.chisq,self.paratry[0],self.paratry[1],self.paratry[2],self.paratry[3])) tmpdvplot.set_option_colonsep("title", "'Model'") tmpdvplot.set_option_colonsep("with", "steps lt 3 lw 3") tmpvth.append([1.6, 0.0]) tmpvthplot = Data(tmpvth) tmpvthplot.set_option_colonsep("title", "'Model'") tmpvthplot.set_option_colonsep("with", "steps lt 3 lw 3") self.pthdv.append(tmpdvplot) self.pthvth.append(tmpvthplot) del dyda return
alphanfft = [] for i in range(N): alphanfft.append(alphan[i][1]) psdnraw = fft(alphanfft) psdnges = [] for i in range(len(psdnraw) / 2 + 1): psdnges.append([ (float(i) / (float(N) * timeres)), 2. * abs(psdnraw[i].imag) / N + 2. * abs(psdnraw[i].real) / N ]) if (bin == 0): psdngessum = psdnges if (bin != 0): for i in range(len(psdngessum)): psdngessum[i][1] += psdnges[i][1] plotpsdngessum = Data(psdngessum) plotpsdngessum.set_option_colonsep("with", "lines") gp = Gnuplot() gp("set title '%f , gap = %i'" % (doy, gap)) gp("set logscale x") gp("set logscale y") gp("set yrange[1e-5:0.1]") gp("set xrange[0.001:1.]") gp.plot(plotpsdngessum) gp.hardcopy("%f_%is_%i_%i.ps" % (doy, int(timeres), N, binning), color=True, fontsize=18) del gp
data4[i][1] = float(i)**3 data5[i][1] = float(i)**3 panels = 4 mp = multiplot(panels) mp.addplotmark("vline") mp.addplotmark("vline") #mp.addplotmark("box") #mp.addplotmark("box") mp.plotmarks[0].setvlinepos(10.) mp.plotmarks[1].setvlinepos(15.) mp.plotmarks[1].setpanel([0, 2]) #mp.plotmarks[2].setpanel([-1]) #mp.plotmarks[2].setboxrange(0.,10.) #mp.plotmarks[3].setpanel([-1]) #mp.plotmarks[3].setboxrange(15.,40.) for panel in range(panels): mp.panel[panel].setylabel("Test") if (panel == 1): mp.panel[panel].setyrange(.1, 1e14) #mp.panel[panel].setgrid(1) else: mp.panel[panel].setyrange(0., 600.) if (panel == 1 or panel == 2): mp.panel[panel].setlogscale(1) mp.panel[panel].adddata(Data(data1)) mp.panel[panel].adddata(Data(data2)) mp.plot()
def hist_data(self): from math import acos, cos, sqrt, pi from libacepy.ancil import histogram, sig_histogram from Gnuplot import Data from numpy import array from scipy import zeros self.sumspec = zeros([15, 2], float) self.sumspecprotons = zeros([15, 2], float) for i in range(15): self.sumspec[i][0] = -0.9 + i * 0.2 self.sumspecprotons[i][0] = -0.9 + i * 0.2 dvarr = [] swicsdvarr = [] swicsvarr = [] vtharr = [] valfarr = [] barr = [] axarr = [] azarr = [] varr = [] for i in range(len(self.iondata.time)): # calculate mag angle if (self.syncmag.phi[i][1] >= 0. and self.syncmag.theta[i][1] != 0.): tmpmag = acos( abs( cos(self.syncmag.phi[i][1]) * cos(self.syncmag.theta[i][1]))) else: tmpmag = 0. # calculate alfvenspeed if (self.syncswepam.dens[i][1] > 0.): valf = 21.8 * self.syncmag.magb[i][1] / sqrt( self.syncswepam.dens[i][1]) else: valf = 0. if (self.iondata.vel[i] > 100. and self.iondata.vel[i] < 1000. and self.syncswepam.vel[i][1] > 600. and valf > 0. and tmpmag > 0. and tmpmag < 1.6 and self.syncmag.phi[i][1] * self.syncmag.dpp[i][1] < pi / 180. * 11.5 and self.syncmag.theta[i][1] * self.syncmag.dtt[i][1] < pi / 180. * 11.5 and self.iondata.crvth[i] > 10.): tmpasp = self.calc_newasp(self.syncmag.phi[i][1], self.syncmag.theta[i][1], self.syncatt.phi[i], self.syncatt.theta[i]) dvarr.append([ tmpmag, (self.iondata.crvel[i] - self.syncswepam.vel[i][1]) / valf ]) vtharr.append([tmpmag, self.iondata.crvth[i]]) valfarr.append([tmpmag, valf]) barr.append([tmpmag, tmpmag]) axarr.append([tmpmag, tmpasp[0]]) azarr.append([tmpmag, tmpasp[1]]) varr.append([tmpmag, self.syncswepam.vel[i][1]]) swicsdvarr.append([ tmpmag, (self.iondata.crvel[i] - self.swicsprotons.crvel[i]) / valf ]) swicsvarr.append([tmpmag, self.swicsprotons.crvel[i]]) if (self.iondata.vel[i] > 100. and self.iondata.vel[i] < 1000. and self.syncswepam.vel[i][1] > 600. and valf > 0. and tmpmag > 0. and tmpmag < 0.2 and self.syncmag.phi[i][1] * self.syncmag.dpp[i][1] < pi / 180. * 11.5 and self.syncmag.theta[i][1] * self.syncmag.dtt[i][1] < pi / 180. * 11.5 and self.iondata.crvth[i] > 10.): for j in range(len(self.iondata.countspec[i])): vtemp = (self.iondata.countspec[i][j][0] - self.syncswepam.vel[i][1]) / valf #vtemp=(self.iondata.countspec[i][j][0]-self.iondata.vel[i])/valf vtempprotons = (self.swicsprotons.countspec[i][j][0] - self.syncswepam.vel[i][1]) / valf if (j == 0): deltav = 2 * ( self.iondata.countspec[i][j][0] - self.iondata.countspec[i][j + 1][0]) / valf deltavp = 2 * ( self.swicsprotons.countspec[i][j][0] - self.swicsprotons.countspec[i][j + 1][0]) / valf elif (j == len(self.iondata.countspec[i]) - 1): deltav = 2 * (self.iondata.countspec[i][j - 1][0] - self.iondata.countspec[i][j][0]) / valf deltavp = 2 * ( self.swicsprotons.countspec[i][j - 1][0] - self.swicsprotons.countspec[i][j][0]) / valf else: deltav = (self.iondata.countspec[i][j - 1][0] - self.iondata.countspec[i][j + 1][0]) / valf deltavp = ( self.swicsprotons.countspec[i][j - 1][0] - self.swicsprotons.countspec[i][j + 1][0]) / valf rrange = vtemp + deltav / 2. lrange = vtemp - deltav / 2. rrangep = vtempprotons + deltavp / 2. lrangep = vtempprotons - deltavp / 2. if (lrange < self.sumspec[14][0] and rrange > self.sumspec[0][0]): for k in range(15): if (rrange <= self.sumspec[k][0] + 0.1 and lrange >= self.sumspec[k][0] - 0.1): self.sumspec[k][1] += self.iondata.countspec[ i][j][1] elif (rrange >= self.sumspec[k][0] + 0.1 and lrange <= self.sumspec[k][0] + 0.1): fac = (self.sumspec[k][0] + 0.1 - lrange) / (rrange - lrange) self.sumspec[k][ 1] += self.iondata.countspec[i][j][1] * fac elif (rrange >= self.sumspec[k][0] - 0.1 and lrange <= self.sumspec[k][0] - 0.1): fac = (rrange - (self.sumspec[k][0] - 0.1)) / (rrange - lrange) self.sumspec[k][ 1] += self.iondata.countspec[i][j][1] * fac if (lrangep < self.sumspec[14][0] and rrangep > self.sumspec[0][0]): for k in range(15): if (rrangep <= self.sumspec[k][0] + 0.1 and lrangep >= self.sumspec[k][0] - 0.1): self.sumspecprotons[k][ 1] += self.swicsprotons.countspec[i][j][1] elif (rrangep >= self.sumspec[k][0] + 0.1 and lrangep <= self.sumspec[k][0] + 0.1): fac = (self.sumspec[k][0] + 0.1 - lrangep) / (rrangep - lrangep) self.sumspecprotons[k][ 1] += self.swicsprotons.countspec[i][j][ 1] * fac elif (rrangep >= self.sumspec[k][0] - 0.1 and lrangep <= self.sumspec[k][0] - 0.1): fac = (rrangep - (self.sumspec[k][0] - 0.1)) / (rrangep - lrangep) self.sumspecprotons[k][ 1] += self.swicsprotons.countspec[i][j][ 1] * fac nrsumspec = 0 for val in self.sumspec: nrsumspec += val[1] for val in self.sumspec: val[1] = val[1] / nrsumspec nrsumspecprotons = 0 for val in self.sumspecprotons: nrsumspecprotons += val[1] for val in self.sumspecprotons: val[1] = val[1] / nrsumspecprotons valfhist = histogram(valfarr, 0., self.histstep, self.nrhist, 3) bhist = histogram(barr, 0., self.histstep, self.nrhist, 3) axhist = histogram(axarr, 0., self.histstep, self.nrhist, 3) azhist = histogram(azarr, 0., self.histstep, self.nrhist, 3) if (self.swepamorswics == 0): vhist = histogram(varr, 0., self.histstep, self.nrhist, 3) dvhist = histogram(dvarr, 0., self.histstep, self.nrhist, 4) else: vhist = histogram(swicsvarr, 0., self.histstep, self.nrhist, 3) dvhist = histogram(swicsdvarr, 0., self.histstep, self.nrhist, 4) sigdvhist = sig_histogram(dvarr, dvhist, 4) vthhist = histogram(vtharr, 0., self.histstep, self.nrhist, 4) sigvthhist = sig_histogram(vtharr, vthhist, 4) self.dverr = [] for i in range(len(dvhist)): if (sigdvhist[i][2] > 0.): self.dverr.append([ dvhist[i][0], dvhist[i][1], sigdvhist[i][1] / sqrt(sigdvhist[i][2]) ]) else: self.dverr.append([dvhist[i][0], dvhist[i][1], 0.]) self.vtherr = [] for i in range(len(dvhist)): if (sigvthhist[i][2] > 0.): self.vtherr.append([ vthhist[i][0], vthhist[i][1], sigvthhist[i][1] / sqrt(sigvthhist[i][2]) ]) else: self.vtherr.append([vthhist[i][0], vthhist[i][1], 0.]) self.pdvhist = (Data(self.dverr)) self.pdvhist.set_option_colonsep("title", "'Observations'") #self.pdvhist.set_option_colonsep("title","'Beobachtung'") self.pdvhist.set_option_colonsep("with", "yerrorbars lt 1 lw 3") self.pdvhist.set_option_colonsep("using", "1:2:3") self.pvthhist = (Data(self.vtherr)) self.pvthhist.set_option_colonsep("title", "'Observations'") #self.pvthhist.set_option_colonsep("title","'Beobachtung'") self.pvthhist.set_option_colonsep("with", "yerrorbars lt 1 lw 3") self.pvthhist.set_option_colonsep("using", "1:2:3") # build array of x values for fitting xvals = [] for i in range(len(vhist)): xvals.append([ vhist[i][1], valfhist[i][1], bhist[i][1], 0., axhist[i][1], azhist[i][1], 0.1, self.iondata.countspec[0], self.iondata.name, self.iondata.mass, self.iondata.charge, self.effpath ]) self.xvals = xvals # build array of y and sig values for fitting yvals = [] sigvals = [] for i in range(len(vhist)): yvals.append([self.dverr[i][1], self.vtherr[i][1]]) sigvals.append([self.dverr[i][2], self.vtherr[i][2]]) self.yvals = array(yvals) self.sigvals = array(sigvals)
def main(): traceFilename = '../../tmp/wc98_1.txt' configFilename = '../../tmp/dynGamma.txt' cReader = ConfigReader() cReader.parse(configFilename) cluster = cReader.readCluster() predictor = cReader.readPredictor() lb = cReader.readLoadBalancer(cluster) cluster.loadBalancer = lb config = cluster._availableServers[:] bestConfig = config[:] predConfig = config[:] reactiveConfig = config[:] bestConfigurator = cReader.readConfigurator(cluster, DummyFilter()) bestConfigurator.setEfficientServerList(cluster._availableServers) bestConfigurator.gamma = 1.0 #do not change!! predConfigurator = cReader.readConfigurator(cluster, predictor) predConfigurator.setEfficientServerList(cluster._availableServers) predConfigurator._gamma = 1.0 reactiveConfigurator = cReader.readConfigurator(cluster, DummyFilter()) reactiveConfigurator.setEfficientServerList(cluster._availableServers) #reactiveConfigurator._gamma = 0.55 step = predConfigurator.windowSize #reads the trace file data = file2data(1, traceFilename)[0] scale(data, cluster.availableServers) predCounter, reactiveCounter, bestCounter = 0, 0, 0 #configuration counter pred_upCounter, pred_downCounter = 0, 0 best_upCounter, best_downCounter = 0, 0 reactive_upCounter, reactive_downCounter = 0, 0 bestPerf = getMaxPerformance(bestConfig) reactivePerf = getMaxPerformance(bestConfig) predPerf = getMaxPerformance(bestConfig) avgs = [] reactivePerfs = [] predPerfs = [] bestPerfs = [] gammas = [] for i in range(len(data) / step): avgData = 0.0 for j in range(step): avgData += data[i * step + j] avgData /= step avgs.append(avgData) reactivePerfs.append(reactivePerf) predPerfs.append(predPerf) optimumConfig = None ''' Will use the efficient list to create the optimumConfig ''' optimumConfig = [bestConfigurator._efficientServerList[0]] k = 1 while getMaxPerformance(optimumConfig) < avgData: optimumConfig.append(bestConfigurator._efficientServerList[k]) k += 1 ''' Calculates the appropriate configuration, 'knowing' that avgData is true ''' if i > 0: #calculates false alarms tmp = bestConfigurator.getConfiguration(avgData, bestConfig, bestConfigurator._gamma) if tmp != bestConfig: bestCounter += 1 bestConfig = tmp bestPerf = getMaxPerformance(bestConfig) bestPerfs.append(bestPerf) ''' Compares the chosen configuration with a least powerful one ''' if avgData > bestPerf: best_downCounter += 1 elif getMaxPerformance(bestConfig) > getMaxPerformance( optimumConfig): best_upCounter += 1 if avgData > reactivePerf: reactive_downCounter += 1 elif getMaxPerformance(reactiveConfig) > getMaxPerformance( optimumConfig): reactive_upCounter += 1 if avgData > predPerf: pred_downCounter += 1 elif getMaxPerformance(predConfig) > getMaxPerformance( optimumConfig): pred_upCounter += 1 elif len(bestConfig) < len(predConfig): pred_upCounter += 1 prediction = predictor.apply(avgData) #actuation = prediction actuation = max(prediction, avgData) tmp = predConfigurator.getConfiguration(actuation, predConfig, predConfigurator._gamma) if set(tmp) != set(predConfig): predCounter += 1 predConfig = tmp predPerf = getMaxPerformance(predConfig) if reactiveConfigurator.dynGamma: idealConfig = bestConfigurator.getConfiguration( avgData, reactiveConfig, reactiveConfigurator.MAX_GAMMA) idealPerf = round(getMaxPerformance(idealConfig), 5) currPerf = round(getMaxPerformance(reactiveConfig), 5) reactiveConfigurator._gamma = reactiveConfigurator.adjustGamma( currPerf - idealPerf) gammas.append(reactiveConfigurator._gamma) tmp = reactiveConfigurator.getConfiguration( avgData, reactiveConfig, reactiveConfigurator._gamma) if set(tmp) != set(reactiveConfig): reactiveCounter += 1 reactiveConfig = tmp reactivePerf = getMaxPerformance(reactiveConfig) print 'Best - False alarms: up = %d, down = %d' % (best_upCounter, best_downCounter) print 'Predictive - False alarms: up = %d, down = %d' % (pred_upCounter, pred_downCounter) print 'Reactive - False alarms: up = %d, down = %d' % ( reactive_upCounter, reactive_downCounter) print 'Best Configs = %d, Predictive Configs = %d, Reactive Configs = %d' %\ (bestCounter, predCounter, reactiveCounter) g = Gnuplot(debug=0) g('reset') #g('set size 0.65,0.65') g('set encoding iso_8859_1') g('set terminal postscript eps enhanced monochrome') g('set output "carlos2.ps"') g('set key top left') g('set xlabel "Tempo (s)"') g('set xrange [0:%d]' % (len(data) / step)) spacing = 15 tics = ','.join([ '"%d" %d' % (x * step * spacing, x * spacing) for x in range(1, len(data) / (step * spacing) + 1) ]) g('set xtics (%s)' % tics) g('set ylabel "Requisições"'.encode('iso_8859_1')) g('set grid') #plot incoming requests avg with_plot = 'steps' #plot configurations pi1 = Data(avgs, with_=with_plot, title='Carga') pi2 = Data(reactivePerfs, with_=with_plot, title='Reativo') pi_gamma = Data(gammas, with_=with_plot, title='Gamma') #pi3 = Data(predPerfs, with_=with_plot,title='Preditivo') #pi4 = Data(bestPerfs, with_=with_plot,title='Perfect') #g.plot(pi1,pi2) #g.plot(pi_gamma) #raw_input() print 'Done'
phi = 0 else: phi = pi - atan(mdata.magby[i][1] / mdata.magbx[i][1]) # Ende: Winkel ausrechnen # Jedes binres-te Element neue bin anlegen und letzte normieren if (i % binres == 0): if (i > 0): mbin[len(mbin) - 1][1] /= binres mbin.append([mdata.time[i], phi]) else: mbin[len(mbin) - 1][1] += phi if (i % binres != 0): mbin[len(mbin) - 1][1] /= (i % binres) plotdata = Data(mbin) plotdata.set_option_colonsep("title", "'{/Symbol F}_B'") mp.panel[mpi].adddata(plotdata) mp.panel[mpi].adddata( Data([[timeframe[0], pi / 2 + parkerwinkel], [timeframe[1], pi / 2 + parkerwinkel]])) mp.panel[mpi].adddata( Data([[timeframe[0], parkerwinkel], [timeframe[1], parkerwinkel]])) mp.panel[mpi].adddata( Data([[timeframe[0], pi + parkerwinkel], [timeframe[1], pi + parkerwinkel]])) mp.panel[mpi].setyrange(-2, 6) mp.panel[mpi].setlogscale(0) mp.panel[mpi].setylabel("B-Winkel") mpi += 1 del plotdata
if ((sdata[ion][time][step][7] >= 1.5 * sdata[ion][time][maxflux][7]) and (sdata[ion][time][step][7] <= 1.69 * sdata[ion][time][maxflux][7])): tmpsumme += sdata[ion][time][step][12] if (sdata[ion][time][maxflux][12]): tailbulk = tmpsumme / sdata[ion][time][maxflux][12] else: tailbulk = 0. else: tailbulk = 0. tailbulkdisttmp.append([(279. + time * 5. * 0.00833), tailbulk]) tailbulkdist.append(tailbulkdisttmp) gptailbulkdist = [] for ion in range(len(sdata)): tmpgptailbulk = Data(tailbulkdist[ion]) tmpgptailbulk.set_option_colonsep("using", "1:2") tmpgptailbulk.set_option_colonsep("title", "'%s'" % (ion_list[ion])) gptailbulkdist.append(tmpgptailbulk) gp = Gnuplot() gp("set autoscale") gp("set yrange[0.00001:1.]") gp("set logscale y") gp("set xlabel 'DoY'") gp("set ylabel 'tail/bulk ratio' ") for ion in range(len(sdata)): if (first): gp.plot(gptailbulkdist[ion]) first = 0
def plot_period(t1, t2, off=1, power=5. / 3.): gp("set xrange[%f:%f]" % (t1, t2)) gp2("set xrange[%f:%f]" % (t1, t2)) #gp.splot(d3hdata[(d3hdata[:,0]>t1)*(d3hdata[:,0]<t2)],d3hedata[(d3hedata[:,0]>t1)*(d3hedata[:,0]<t2)],d3odata[(d3odata[:,0]>t1)*(d3odata[:,0]<t2)],d3fedata[(d3fedata[:,0]>t1)*(d3fedata[:,0]<t2)],d3hedata[(d3hedata[:,0]>t1)*(d3hedata[:,0]<t2)*(d3hedata[:,2]==1.)],d3odata[(d3odata[:,0]>t1)*(d3odata[:,0]<t2)*(d3odata[:,2]==1.)],d3fedata[(d3fedata[:,0]>t1)*(d3fedata[:,0]<t2)*(d3fedata[:,2]==1.)],d3hdata[(d3hdata[:,0]>t1)*(d3hdata[:,0]<t2)*(d3hdata[:,2]==1.)],d3swdata[d3swdata[:,1]>0.]) #gp.splot(d3hdata[(d3hdata[:,0]>t1)*(d3hdata[:,0]<t2)],d3hedata[(d3hedata[:,0]>t1)*(d3hedata[:,0]<t2)],d3hedata[(d3hedata[:,0]>t1)*(d3hedata[:,0]<t2)],d3hev) #gp.splot(d3hev,d3ov,d3fev,d3swdata[d3swdata[:,1]>0.]) #gp.plot(Data(d3hv[:,0],d3hv[:,1],with_="lp lt -1"),Data(d3hv2[:,0],d3hv2[:,1],with_="lp lt 0"),Data(d3hev[:,0],d3hev[:,1],with_="lp lt 1"),Data(d3ov[:,0],d3ov[:,1],with_="lp lt 3"),Data(d3fev[:,0],d3fev[:,1],with_="lp lt 4"),Data(d3swdata[d3swdata[:,1]>0.][:,0],d3swdata[d3swdata[:,1]>0.][:,1],with_="lp lt 5"))#,Data(d3swdens[d3swdens[:,1]>0.][:,0],d3swdens[d3swdens[:,1]>0.][:,1],with_="lp lt 6",axes="x1y2")) #gp2.plot(Data(magdat.time,theta,with_="l lt 1"),"pi/2. w l lt -1",Data(d3swdata[:,0],((d3swdata[:,1]-550.)/20.)-1.),Data(vswvalf[:,0],vswvalf[:,1],with_="l lt 4",axes="x1y2"),Data(d3swdata[:,0],d3swdata[:,1],with_="l lt 5",axes="x1y2")) gp2.plot(Data(magdat.time, theta, with_="l lt 1"), "pi/2. w l lt -1", Data(valf[:, 0], valf[:, 1], with_="l lt 3", axes="x1y2")) #gp2.hardcopy("magdata.eps",eps=True,color=True) gpfft("f(x)=%f*x**-(%f)" % (off, power)) psdy = fftPlot(magdat.magby[(magdat.time > t1) * (magdat.time < t2)]) psdz = fftPlot(magdat.magbz[(magdat.time > t1) * (magdat.time < t2)]) psdx = fftPlot(magdat.magbx[(magdat.time > t1) * (magdat.time < t2)]) meanvalf = mean(valf[(valf[:, 0] > t1) * (valf[:, 0] < t2) * (valf[:, 1] > 0.)][:, 1]) meanvsw = mean(swdata.vel[(swdata.time > t1) * (swdata.time < t2) * (swdata.vel > 0.)]) gp.splot( d3hdata[(d3hdata[:, 0] > t1) * (d3hdata[:, 0] < t2)], d3hedata[(d3hedata[:, 0] > t1) * (d3hedata[:, 0] < t2)], d3odata[(d3odata[:, 0] > t1) * (d3odata[:, 0] < t2)], d3fedata[(d3fedata[:, 0] > t1) * (d3fedata[:, 0] < t2)], d3sidata[(d3sidata[:, 0] > t1) * (d3sidata[:, 0] < t2)], d3cdata[(d3cdata[:, 0] > t1) * (d3cdata[:, 0] < t2)], d3hv, d3hev, d3ov, d3fev, d3swdata[d3swdata[:, 1] > 0.], Data([[(t1 + t2) / 2., meanvsw, 0.], [(t1 + t2) / 2., meanvsw, 1.]], with_="l lt -1"), Data([[(t1 + t2) / 2., meanvsw + meanvalf, 0.], [(t1 + t2) / 2., meanvsw + meanvalf, 1.]], with_="l lt 0"), Data([[(t1 + t2) / 2., meanvsw + 2 * meanvalf, 0.], [(t1 + t2) / 2., meanvsw + 2 * meanvalf, 1.]], with_="l lt 0"), Data([[(t1 + t2) / 2., meanvsw - 1 * meanvalf, 0.], [(t1 + t2) / 2., meanvsw - 1 * meanvalf, 1.]], with_="l lt 0"), Data([[(t1 + t2) / 2., meanvsw - 2 * meanvalf, 0.], [(t1 + t2) / 2., meanvsw - 2 * meanvalf, 1.]], with_="l lt 0")) #gp.hardcopy("tsspecs.eps",eps=True,color=True) gfe = mean( magdat.magb[(magdat.time > t1) * (magdat.time < t2)]) * 28. * (1 + meanvsw / meanvalf) gfp = mean(magdat.magb[ (magdat.time > t1) * (magdat.time < t2)]) * 0.01525 * abs(1 - meanvsw / meanvalf) gfhe = gfp * 0.5 gfo = gfp * 6. / 16. gfhep = gfhe / 0.5 gfhem = gfhe / 1.5 gfop = gfo / 0.5 gfom = gfo / 1.5 gffe = gfp * 12. / 56. gfsi = gfp * 9. / 28. gfpu = gfp * 0.25 #gfp=0.5-(gfp-0.5) #print "wp =",gfp,"whe =",gfhe,"wo =",gfo,"wsi =",gfsi,"wfe =",gffe,"wpu =",gfpu print "whe =", gfhe, "whe =", gfhem, "whep =", gfhep print "vsw =", meanvsw, "valf =", meanvalf psdy = array(psdy) #psdy[:,1]=(psdy[:,1]/(off*psdy[:,0]**-power)) psdz = array(psdz) psdx = array(psdx) #psdz[:,0]/=abs(1-meanvsw/meanvalf) #psdy[:,0]/=abs(1-meanvsw/meanvalf) #psdx[:,0]/=abs(1-meanvsw/meanvalf) fmax = meanvalf / 2 / meanvsw print "fmax = ", fmax #psdz[:,1]=(psdz[:,1]/(off*psdz[:,0]**-power)) bw = 5 psdyb = zeros([len(psdy) / bw, 2]) for i in range(len(psdy) / bw): psdyb[i, 0] = mean(psdy[i * bw:i * bw + bw, 0]) psdyb[i, 1] = mean(psdy[i * bw:i * bw + bw, 1]) psdzb = zeros([len(psdz) / bw, 2]) for i in range(len(psdz) / bw): psdzb[i, 0] = mean(psdz[i * bw:i * bw + bw, 0]) psdzb[i, 1] = mean(psdz[i * bw:i * bw + bw, 1]) psdxb = zeros([len(psdx) / bw, 2]) for i in range(len(psdx) / bw): psdxb[i, 0] = mean(psdx[i * bw:i * bw + bw, 0]) psdxb[i, 1] = mean(psdx[i * bw:i * bw + bw, 1]) #gpfft.plot(Data(psdxb,with_="l lt 5",title="'Bx'"),Data(psdyb,with_="l lt 1",title="'By'"),Data(psdzb,with_="l lt 3",title="'Bz'"),"f(x) with l lt 4 title 'x^-(5/3)'",Data([[gfp,1.],[gfp,1e4]],with_="l lt -1",title="'gfp'"),Data([[gfhe,1.],[gfhe,1e4]],with_="l lt 0",title="'gfhe'"),Data([[gfo,1.],[gfo,1e4]],with_="l lt 1",title="'gfo'"),Data([[gffe,1.],[gffe,1e4]],with_="l lt 3",title="'gffe'"))#,Data([[gfe,1.],[gfe,1e4]],with_="l lt 6",title="'gfe'")) gpfft.plot( Data(psdxb, with_="l lt 5", title="'Bx'"), Data(psdyb, with_="l lt 1", title="'By'"), Data(psdzb, with_="l lt 3", title="'Bz'"), "f(x) with l lt 4 title 'x^-(5/3)'", Data([[gfhe, 1.], [gfhe, 1e4]], with_="l lt -1", title="'gfhe'"), Data([[gfhem, 1.], [gfhem, 1e4]], with_="l lt 0", title="'gfhem'"), Data([[gfhep, 1.], [gfhep, 1e4]], with_="l lt 0", title="'gfhep'"), Data([[gfop, 1.], [gfop, 1e4]], with_="l lt 3", title="'gfop'"), Data([[gfom, 1.], [gfom, 1e4]], with_="l lt 3", title="'gfom'"), Data([[gfo, 1.], [gfo, 1e4]], with_="l lt 1", title="'gfo'"), Data([[gfp, 1.], [gfp, 1e4]], with_="l lt 4", title="'gfp'"))
class error: "Class error : contains errordata\n\t name = array[steps][ions] ..." def __init__(self,filename): self.filename=filename self.name=[] self.ionname="" self.step=0 self.counts=0. self.frac=0. self.error=0. self.fiterg=[] self.normerg=[] self.histogram=[] # self.gp=Gnuplot() """ method : reads in maximum-likelihood-fitresults to generated data. the name of the file is in self.filename """ def readerrordata(self): dim=200 infile=open(self.filename) tmpfitergion1=[] tmpfitergion2=[] tmpnormergion1=[] tmpnormergion2=[] for step in range(dim): s=infile.readline() k=s.split() numions=int(k[5]) numions=2 s=infile.readline() for ion in range(numions): s=infile.readline() k=s.split() if (step==0): self.name.append(k[0]) if (ion==0): tmpfitergion1.append(float(k[10])) tmpnormergion1.append(float(k[11])) if (ion==1): tmpfitergion2.append(float(k[10])) tmpnormergion2.append(float(k[11])) self.fiterg.append(tmpfitergion1) self.fiterg.append(tmpfitergion2) self.normerg.append(tmpnormergion1) self.normerg.append(tmpnormergion2) print "load : ",self.filename """ method : calculates error from already loaded maximum-likelihodd-fitresults (via readerrordata) gethistogram first makes a histogram out of the m-l-fitresults. afterwards getfitpara determines the parameters for the final fitting to the histogram. in the end the fit to the histogram is performed. """ def calcerror(self): gethistogram(self) self.getfitpara() self.geterror() """ method : """ def geterror(self): gp=Gnuplot() # gp("set yrange[0:1e20]") gp("a=%f" %(self.counts)) print len(self.histogram[0]) gp("b=5.") gp("c=200.") gp("f(x)=c/(sqrt(2.*pi)*b)*exp(-((x-a)**2/(2.*b**2)))") self.gphist=Data(self.histogram[0]) self.gphist.set_option_colonsep("with","boxes") if (len(self.histogram[0])>3): gp("fit f(x) '"+self.gphist.filename+"' using 1:2 via a,b") gp("fit f(x) '"+self.gphist.filename+"' using 1:2 via b") else: gp("b=0.1") # gp.plot(self.gphist,"f(x)") # gp("pause 3") self.error=gp.eval("b")/self.counts print self.error """ method : """ def getfitpara(self): positions=[] for i in range(len(self.filename)): if (self.filename[i:i+1]=="_"): positions.append(i) print positions self.ionname=self.filename[positions[2]+1:positions[3]] self.step=int(self.filename[positions[3]+5:positions[4]]) self.counts=float(self.filename[positions[4]+1:positions[5]]) self.frac=float(self.filename[positions[5]+1:positions[6]]) print self.ionname print self.step print self.counts print self.frac print self.name
sumhist[i][2] += spec[i][2] sumhist[i][3] = step / 2. deg = pi / 180. #corrarr=[1.,sin(.2*deg),sin(5.*deg),sin(90.*deg),0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.] #for i in range(int(dim/step)): # sumhist[i][1]=sumhist[i][1]*corrarr[i] # Plotobjekte werden erzeugt fitspec = [] for val in epaspec[fi]: if (val[0] > fg): fitspec.append(val) pfitspec = Data(fitspec) pfitspec.set_option_colonsep("title", "'%s'" % (fedata[i].name)) pfitspec.set_option_colonsep("with", "xyerrorbars") pfitspec.set_option_colonsep("using", "1:2:5:3") i = 0 while (epaspec[fi][i][0] > fg): i += 1 i = i - 1 print "i = ", i normval = [] xval = [] for j in range(i): if (epaspec[fi][i - j] != 0.): normval.append(epaspec[fi][i - j][1]) xval.append(epaspec[fi][i - j][0])
tmpsemdat = semtot[semtot[:, 1] == years[i]] if (years[i] != 2008): semdat[sum(doys[0:i]):sum(doys[0:i]) + doys[i], 1] = tmpsemdat[:, 15] else: semdat[sum(doys[0:i]):sum(doys[0:i]) + doys[i] - 2, 1] = tmpsemdat[:, 15] semdat2 = zeros([len(years) * 365 + 1, 2]) semdat2[:, 0] = arange(len(years) * 365. + 1.) for i in range(len(years)): tmpsemdat = semtot[semtot[:, 1] == years[i]] if (years[i] != 2008): semdat2[sum(doys[0:i]):sum(doys[0:i]) + doys[i], 1] = tmpsemdat[:, 14] else: semdat2[sum(doys[0:i]):sum(doys[0:i]) + doys[i] - 2, 1] = tmpsemdat[:, 14] semdat[:, 1] /= 1e8 semdat[:, 1] *= 1.5 gp2 = Gnuplot() gp2("set style data histeps") gp2("set yrange[0:2000]") gp2("set xlabel 'Date'") gp2("set ylabel 'He^{1+} 1.5<w<2.0 / scaled UV-flux'") gp2("set xtics ('2006' 1,'' 31+1 1,'' 31+28+1 1,'' 31+28+31+1 1,'' 31+28+31+30+1 1,'' 31+28+31+30+31+1 1,'' 31+28+31+30+31+30+1 1,'' 31+28+31+30+31+30+31+1 1,'' 31+28+31+30+31+30+31+31+1 1,'' 31+28+31+30+31+30+31+31+30+1 1,'' 31+28+31+30+31+30+31+31+30+31+1 1,'' 31+28+31+30+31+30+31+31+30+31+30+1 1,'2007' 365+1,'' 365+31+1 1,'' 365+31+28+1 1,'' 365+31+28+31+1 1,'' 365+31+28+31+30+1 1,'' 365+31+28+31+30+31+1 1,'' 365+31+28+31+30+31+30+1 1,'' 365+31+28+31+30+31+30+31+1 1,'' 365+31+28+31+30+31+30+31+31+1 1,'' 365+31+28+31+30+31+30+31+31+30+1 1,'' 365+31+28+31+30+31+30+31+31+30+31+1 1,'' 365+31+28+31+30+31+30+31+31+30+31+30+1 1,'2008' 2*365+1,'' 2*365+31+1 1,'' 2*365+31+29+1 1,'' 2*365+31+29+31+1 1,'' 2*365+31+29+31+30+1 1,'' 2*365+31+29+31+30+31+1 1,'' 2*365+31+29+31+30+31+30+1 1,'' 2*365+31+29+31+30+31+30+31+1 1,'' 2*365+31+29+31+30+31+30+31+31+1 1,'' 2*365+31+29+31+30+31+30+31+31+30+1 1,'' 2*365+31+29+31+30+31+30+31+31+30+31+1 1,'' 2*365+31+29+31+30+31+30+31+31+30+31+30+1 1,'2009' 3*365+2,'' 3*365+31+2 1,'' 3*365+31+28+2 1,'' 3*365+31+28+31+2 1,'' 3*365+31+28+31+30+2 1,'' 3*365+31+28+31+30+31+2 1,'' 3*365+31+28+31+30+31+30+2 1,'' 3*365+31+28+31+30+31+30+31+2 1,'' 3*365+31+28+31+30+31+30+31+31+2 1,'' 3*365+31+28+31+30+31+30+31+31+30+2 1,'' 3*365+31+28+31+30+31+30+31+31+30+31+2 1,'' 3*365+31+28+31+30+31+30+31+31+30+31+30+3 1,'2010' 4*365+2,'' 4*365+31+2 1,'' 4*365+31+28+2 1,'' 4*365+31+28+31+2 1,'' 4*365+31+28+31+30+2 1,'' 4*365+31+28+31+30+31+2 1,'' 4*365+31+28+31+30+31+30+2 1,'' 4*365+31+28+31+30+31+30+31+2 1,'' 4*365+31+28+31+30+31+30+31+31+2 1,'' 4*365+31+28+31+30+31+30+31+31+30+2 1,'' 4*365+31+28+31+30+31+30+31+31+30+31+2 1,'' 4*365+31+28+31+30+31+30+31+31+30+31+30+3 1)" ) gp2.plot(Data(hetsdata, title='He^{1+} [cts/day]', with_='histeps lt 1'), Data(herunav, title='He@_{RM}^{1+} (+-13 Days)', with_='l lt 3 lw 3'), Data(semdat, title="SEM UV", with_="l lt 4")) gp2.hardcopy("He1+_soho.ps", color=True)