Exemple #1
0
def getPs(h5pFile, pC, Nk):
    isOut = lfmpp.getOut(h5pFile)
    R, PhiMP0, LambdaF, Tmp = lfmpp.getSphLoss1st(h5pFile)
    ids, PhiBX = lastPhi(h5pFile)

    dPhi = PhiBX - PhiMP0

    Ind = (abs(dPhi) >= pC)
    Ntot = Ind.sum()
    ids = ids[Ind]
    print("Found %d values larger than %3.2f" % (Ntot, pC))
    IndR = np.random.choice(Ntot, Nk, replace=False)
    ids = ids[IndR]
    return ids
Exemple #2
0
def mpxK(fIn):
    #Get energies at last/first MPX
    isOut = lfmpp.getOut(fIn, mp=True)
    t, kevPT = lfmpp.getH5p(fIn, "kev")
    #Last MP crossings
    pid, Tmpx = lfmpp.getH5pFin(fIn, "tCr", Mask=isOut)
    #First MP crossings
    R, Phi, Lambda, Tmpx0 = lfmpp.getSphLoss1st(fIn)
    Np = isOut.sum()  #Number of out particles
    mpK = np.zeros(Np)
    mpK0 = np.zeros(Np)

    for n in range(Np):
        idn = np.int(pid[n] - 1)
        #Time slices of first/last MPX
        ts0 = np.argmin(Tmpx0[n] >= t)
        tsF = np.argmin(Tmpx[n] >= t)
        #print(n,idn,ts0,tsF)
        mpK[n] = kevPT[tsF, idn]
        mpK0[n] = kevPT[ts0, idn]
    return mpK0, mpK
Exemple #3
0
def getPBlk(h5pFile, pC, Np):
    #Get Np particles for each of 3 types
    #pI:(0,180), (-15,0),(-180,-15)
    #And have dPhi>=pC
    pIL = [0, -45, -180]
    pIH = [180, 0.0, -45]
    Nd = len(pIL)

    pIDs = np.zeros(Np * Nd, dtype=np.int)
    isOut = lfmpp.getOut(h5pFile)
    R, PhiMP0, LambdaF, Tmp = lfmpp.getSphLoss1st(h5pFile)
    ids, PhiBX = lastPhi(h5pFile)
    dPhi = PhiBX - PhiMP0

    print(PhiMP0.min(), PhiMP0.max())
    print(dPhi.min(), dPhi.max())
    for d in range(Nd):
        pcd = pC[d]
        if (pC[d] >= 0):
            IndPC = (dPhi >= pC[d])
        else:
            IndPC = (dPhi <= pC[d])

        IndPI = (PhiMP0 >= pIL[d]) & (PhiMP0 <= pIH[d])
        Ind = IndPC & IndPI
        subIDs = ids[Ind]
        subDP = dPhi[Ind]
        #Pick Np randomly
        Ntot = Ind.sum()
        print("Found %d values w/ dP >= %f, and pI between %f and %f" %
              (Ntot, pC[d], pIL[d], pIH[d]))
        IndR = np.random.choice(Ntot, Np, replace=False)
        rIDs = subIDs[IndR]
        i0 = d * Np
        i1 = i0 + Np
        pIDs[i0:i1] = rIDs
        print(rIDs)
        print(subDP[IndR])
    return pIDs
Exemple #4
0
def getTimes(fIn, doTail=False):
    isOut = lfmpp.getOut(fIn, mp=True, tl=doTail)
    t, mpF = lfmpp.getH5p(fIn, "mp")
    mp = mpF[:, isOut]

    #Last MP crossings
    pid, Tmpx = lfmpp.getH5pFin(fIn, "tCr", Mask=isOut)

    #First MP crossings
    R, Phi, Lambda, Tmpx0 = lfmpp.getSphLoss1st(fIn)

    #Time of loss from box, time slice index
    tsMP = np.argmax(mp, axis=0)
    #Convert to physical time
    Tbx = t[tsMP]
    if (doTail):
        #Remove particles that leave through tail but never cross MP
        DelT = Tbx - Tmpx
        Tbx = Tbx[DelT > 0]
        Tmpx = Tmpx[DelT > 0]
        pid = pid[DelT > 0]

    return Tmpx, Tmpx0, Tbx, pid
Exemple #5
0
msDp = []
pBX = []
mDp = []
LogScl = LogNorm(1, 500)

for i in range(Ns):
    #xBin = np.linspace(-180,180,100)
    xBin = np.linspace(-60, 60, 100)
    yBin = np.linspace(0, 30, 30)

    fIn = dirStub + "/" + spcs[i] + "." + fileStub
    print("Reading %s" % (fIn))
    print("Species %s" % (Leg[i]))
    isOut = lfmpp.getOut(fIn)
    pid, NumX = lfmpp.countMPX(fIn, isOut)
    R, PhiMP0, LambdaF, Tmp = lfmpp.getSphLoss1st(fIn)
    R, PhiMP1, LambdaL = lfmpp.getSphLoss(fIn)
    PhiBX = lastPhi(fIn)

    pMP0.append(PhiMP0)
    pMP1.append(PhiMP1)
    mpDp.append(PhiMP1 - PhiMP0)
    pBX.append(PhiBX)
    msDp.append(PhiBX - PhiMP1)

    mDp.append(PhiBX - PhiMP0)
Nb = 40
N0 = -60
N1 = 120
bins = np.linspace(N0, N1, Nb)
doNorm = True
Exemple #6
0
        Lambdas = pickle.load(f)

else:
    print("No data file found, calculating")
    Phis = []
    Lambdas = []

    for i in range(Ns):

        fIn = RootDir + spcs[i] + "." + fileStub
        if (doTest):
            Phi = np.random.rand(Np) * P1
            Lambda = np.random.rand(Np) * L1
        else:
            if (doFirst):
                R, Phi, Lambda, Tl = lfmpp.getSphLoss1st(fIn)
            else:
                R, Phi, Lambda = lfmpp.getSphLoss(fIn)
        Phis.append(Phi)
        Lambdas.append(Lambda)

    print("Writing pickle")
    with open(mpDF, "wb") as f:
        pickle.dump(Phis, f)
        pickle.dump(Lambdas, f)

lfmv.ppInit()
fig = plt.figure(figsize=figSize)

wRat = np.ones(Ns + 1)
wRat[-1] = 0.05
Exemple #7
0
spcs = ["H","O","e"]
cMap="jet"

Nb = 50
Ns = len(spcs)
fig = plt.figure(1, figsize=(10, 10))
cMin = 1.0e-5
cMax = 1.0e-2

cNorm = LogNorm(vmin=cMin,vmax=cMax)

for i in range(Ns-1):
	fIn = dirStub + "/" + spcs[i] + "." + fileStub
	Rf,Pf,Lf = lfmpp.getSphLoss(fIn)
	Ri,Pi,Li,Tmp = lfmpp.getSphLoss1st(fIn)
	Np = 2*i+1
	plt.subplot(Ns-1,2,Np)
	#plt.hist2d(Pi,Li,[xbins,ybins],cmap=cMap,normed=True,norm=LogNorm())
	xe,ye,Hi = h2d(Pi,Li,Nb)
	plt.pcolormesh(xe,ye,Hi,norm=cNorm)
	cbar=plt.colorbar()
	plt.xlim( (-180,180) )
	plt.ylim( (-90,90) )
	plt.subplot(Ns,2,Np+1)
	#plt.hist2d(Pf,Lf,[xbins,ybins],cmap=cMap,normed=True,norm=LogNorm())
	xe,ye,Hf = h2d(Pf,Lf,Nb)
	plt.pcolormesh(xe,ye,Hf,norm=cNorm)
	cbar=plt.colorbar()
	plt.xlim( (-180,180) )
	plt.ylim( (-90,90) )
Exemple #8
0
aNumX = []
LogScl = LogNorm(1,500)
fig = plt.figure(1, figsize=(20,6))

for i in range(2):
	#xBin = np.linspace(-180,180,100)
	xBin = np.linspace(-60,60,100)
	yBin = np.linspace(0,30,30)

	fIn = dirStub + "/" + spcs[i] + "." + fileStub
	print("Reading %s"%(fIn))
	print("Species %s"%(Leg[i]))
	isOut = lfmpp.getOut(fIn)
	pid, NumX = lfmpp.countMPX(fIn,isOut)
	R, PhiF, Lambda, Tmp = lfmpp.getSphLoss1st(fIn)
	R,PhiL,Lambda = lfmpp.getSphLoss(fIn)
	DelPhi = PhiL-PhiF
	#IndF = (PhiF<=45) & (PhiF>=-45)
	#IndL = (PhiL<=0) & (PhiL>=-45)
	#Ind = IndF & IndL
	#DelPhi = PhiL[Ind]-PhiF[Ind]
	#NumX = NumX[Ind]
	t**S = "%s 100 keV"%Leg[i]
	plt.subplot(1,3,i+1)
	#plt.hist2d(Phi,NumX,[xBin,yBin],norm=LogScl)

	plt.hist2d(DelPhi,NumX,[xBin,yBin],norm=LogScl)
	#plt.hist2d(DelPhi,NumX,[xBin,yBin])
	plt.xlim( (-120,120) ); plt.xlabel("Delta-Phi")
	plt.ylim( (0,30) ); plt.ylabel("# of Crossings")