def getwspec(ion, he): from libacepy.ancil import histogram wspec = [] for i in range(len(he.vel)): if (he.time[i] == ion.time[i]): if he.vel[i] > 0. and he.vel[i] < 2000.: for val in ion.countspec[i]: if val[1] > 0.: wspec.append([val[0] / he.vel[i], val[1]]) whist = histogram(wspec, 0., 0.1, 30, 2) return whist
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)
densarr.append([tmpmag,iondata.dens[i][0]]) meanvalf.append([tmpmag,valf]) meanbx.append([tmpmag,syncmag.phi[i][1]]) meanbz.append([tmpmag,syncmag.theta[i][1]]) meanb.append([tmpmag,tmpmag]) #meanax.append([tmpmag,syncatt.phi[i]]) #meanaz.append([tmpmag,syncatt.theta[i]]) meanax.append([tmpmag,tmpasp[0]]) meanaz.append([tmpmag,tmpasp[1]]) meanv.append([tmpmag,syncswepam.vel[i][1]]) #meanv.append([tmpmag,protondata.crvel[i]]) nrhist=4 histstep=1.6/float(nrhist) # end building arrays valfhist=histogram(meanvalf,0.,histstep,nrhist,3) sigvalfhist=sig_histogram(meanvalf,valfhist,3) bxhist=histogram(meanbx,0.,histstep,nrhist,3) bzhist=histogram(meanbz,0.,histstep,nrhist,3) bhist=histogram(meanb,0.,histstep,nrhist,3) axhist=histogram(meanax,0.,histstep,nrhist,3) azhist=histogram(meanaz,0.,histstep,nrhist,3) vhist=histogram(meanv,0.,histstep,nrhist,3) dvhist=histogram(dvarr,0.,histstep,nrhist,4) #dvhist.append([1.6,0.,0]) sigdvhist=sig_histogram(dvarr,dvhist,4) dverr=[] for i in range(len(dvhist)): dverr.append([dvhist[i][0],dvhist[i][1],sigdvhist[i][1]/sqrt(sigdvhist[i][2]+1.)]) pdvhist.append(Data(dverr)) pdvhist[len(pdvhist)-1].set_option_colonsep("title","'Observations'")
pdvhist[-1].set_option_colonsep("using","1:2:3") """ print len(dvarr), len(dvarr2), len(vtharr), len(vtharr2) if (len(dvarr) == 0): dvarr.append([0.0, 0.0]) if (len(dvarr2) == 0): dvarr2.append([0.0, 0.0]) if (len(vtharr) == 0): vtharr.append([0.0, 0.0]) if (len(vtharr2) == 0): vtharr2.append([0.0, 0.0]) if linetype != 1: linetype += 1 else: linetype += 2 dvhist = histogram(dvarr, 0., binw, binnr, 3) pdvhist.append(Data(dvhist)) pdvhist[-1].set_option_colonsep("title", "'%s Earth-pointing'" % (ion)) pdvhist[-1].set_option_colonsep("with", "steps lt %i lw 2" % (linetype)) pdvhist[-1].set_option_colonsep("using", "1:2") nrdvhist = dvhist for val in nrdvhist: val[0] += (nrdvhist[1][0] - nrdvhist[0][0]) / 2. pnrdvhist.append(Data(nrdvhist)) pnrdvhist[-1].set_option_colonsep("title", "''") pnrdvhist[-1].set_option_colonsep("axes", "x1y2") pnrdvhist[-1].set_option_colonsep("with", "p lt %i lw 2" % (linetype)) pnrdvhist[-1].set_option_colonsep("using", "1:3") if linetype != 1: linetype += 1
from libacepy.ancil import histogram, sig_histogram from Gnuplot import Gnuplot, Data path = "/data/wimmer/ace/1hdata/2001/" timeframe = [[85., 105.]] elem = "Fe" fedata = swicselemdata(elem, timeframe, path) fedata.load() cleanmeanch = [] for val in fedata.meanch: if (val[1] > 7. and val[1] < 26.): cleanmeanch.append(val) onedaym = histogram(cleanmeanch, 85, 1, 20, 4) onedaym2 = sig_histogram(cleanmeanch, onedaym, 4) onedaym3 = [] for i in range(len(onedaym)): onedaym3.append([onedaym[i][0], onedaym[i][1], onedaym2[i][1]]) #for i in range(16): # nrsum=0 # onedaymean=0. # for j in range(24): # if (fedata.meanch[i*24+j][1]>0. and fedata.meanch[i*24+j][1]<20.): # nrsum+=1 # onedaymean+=fedata.meanch[i*24+j][1] # if (nrsum>0): # onedaym.append([90.5+float(i),onedaymean/nrsum]) ponedaym = Data(onedaym3)