Exemplo n.º 1
0
def getEQXs(fIn):
	isOut = lfmpp.getOut(fIn)
	t,xeq = lfmpp.getH5p(fIn,"xeq",Mask=isOut)
	t,yeq = lfmpp.getH5p(fIn,"yeq",Mask=isOut)
	t,tCr = lfmpp.getH5p(fIn,"tCr",Mask=isOut)
	t,tEq = lfmpp.getH5p(fIn,"Teq",Mask=isOut)

	R = []
	P = []
	Np = xeq.shape[1]
	print("Working with %d particles"%(Np))
	for n in range(Np):
		#Accumulate EQXs for time after first crossing
		tCrn = tCr[:,n]
		tSlc1 = tCrn.argmax()
		teqn = tEq[tSlc1:,n]
		ts,Ind = np.unique(teqn,return_index=True)
		#Have unique EQXs
		Neq = len(Ind)
		if (Neq>0):
			x = xeq[tSlc1:,n]
			y = yeq[tSlc1:,n]
			x = x[Ind]
			y = y[Ind]
	
			r = np.sqrt(x**2.0 + y**2.0)
			phi = np.arctan2(y,x)
			for i in range(Neq):
				R.append(r[i])
				P.append(phi[i])
	return np.array(R),np.array(P)
Exemplo n.º 2
0
def getXKA(fIn):
    isOut = lfmpp.getOut(fIn, mp=True)

    #Get spherical coordinates of last MP Xing
    R, Phi, Lambda = lfmpp.getSphLoss(fIn)

    #Get time index of last MP crossing
    t, tEq = lfmpp.getH5p(fIn, "Teq", Mask=isOut)

    tsEq = np.argmax(tEq, axis=0)
    #Use these slices to find values at last X'ing
    t, Kt = lfmpp.getH5p(fIn, "kev", Mask=isOut)
    t, Vxt = lfmpp.getH5p(fIn, "vx", Mask=isOut)
    t, Vyt = lfmpp.getH5p(fIn, "vy", Mask=isOut)
    t, Vzt = lfmpp.getH5p(fIn, "vz", Mask=isOut)

    Np = Kt.shape[1]
    K = np.zeros(Np)
    A = np.zeros(Np)

    for i in range(Np):
        tsi = tsMP[i]
        vxi = Vxt[tsi, i]
        vyi = Vyt[tsi, i]
        vzi = Vzt[tsi, i]
        vmag = np.sqrt(vxi**2.0 + vyi**2.0 + vzi**2.0)

        K[i] = Kt[tsi, i]
        A[i] = np.arccos(vzi / vmag) * 180 / np.pi

    mlt = Phi
    return mlt, K, A
Exemplo n.º 3
0
def NumCross(fIn, onlyOut=True):

    isOut = lfmpp.getOut(fIn)
    t, tCrF = lfmpp.getH5p(fIn, "tCr")
    t, pids = lfmpp.getH5p(fIn, "id")
    pids = pids[-1, :]
    print("\tAll particles:\n")
    NumX_All = CountXs(tCrF, pids)
    print("\tOnly out:\n")
    NumX_Out = CountXs(tCrF[:, isOut], pids[isOut])
    print("\tOnly in:\n")
    NumX_In = CountXs(tCrF[:, np.logical_not(isOut)],
                      pids[np.logical_not(isOut)])
    print("\t# of In + MP-X = %d\n" % np.sum(NumX_In > 0))

    return NumX_All, NumX_Out, NumX_In
Exemplo n.º 4
0
def findMaxRad(fIn):

    isOut = lfmpp.getOut(fIn)
    t, ids = lfmpp.getH5p(fIn, "id", Mask=isOut)
    t, mp = lfmpp.getH5p(fIn, "mp", Mask=isOut)
    t, x = lfmpp.getH5p(fIn, "x", Mask=isOut)
    t, y = lfmpp.getH5p(fIn, "y", Mask=isOut)
    t, z = lfmpp.getH5p(fIn, "z", Mask=isOut)
    t, tCr = lfmpp.getH5p(fIn, "tCr", Mask=isOut)
    ids = ids[0, :]

    cylR = np.sqrt(x**2.0 + y**2.0)
    Np = len(ids)
    Rs = []
    print("\tFound %d particles\n" % (Np))
    print(Np)
    #Find slices for which particle is in sheath
    for n in range(Np):
        #Find last MP xing
        mpn = mp[:, n]
        tCrn = tCr[:, n]
        tSlc1 = tCrn.argmax()
        #Find box xing
        tSlc2 = np.argmax(mpn > 0)
        Rn = cylR[tSlc1:tSlc2, n]
        if (len(Rn) > 0):
            maxRn = Rn.max()
            Rs.append(maxRn)
    return Rs
Exemplo n.º 5
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
Exemplo n.º 6
0
def getEQXs(fIn):
	isOut = lfmpp.getOut(fIn)
	t,xeq = lfmpp.getH5p(fIn,"xeq",Mask=isOut)
	t,yeq = lfmpp.getH5p(fIn,"yeq",Mask=isOut)
	t,tCr = lfmpp.getH5p(fIn,"tCr",Mask=isOut)
	t,tEq = lfmpp.getH5p(fIn,"Teq",Mask=isOut)
	t,Vx  = lfmpp.getH5p(fIn,"vx",Mask=isOut)
	t,Vy  = lfmpp.getH5p(fIn,"vy",Mask=isOut)
	t,Vz  = lfmpp.getH5p(fIn,"vz",Mask=isOut)

	Vmag = np.sqrt(Vx**2.0+Vy**2.0+Vz**2.0)

	A = []
	P = []
	Np = xeq.shape[1]
	print("Working with %d particles"%(Np))
	for n in range(Np):
		#Accumulate EQXs for time after first crossing
		tCrn = tCr[:,n]
		tSlc1 = tCrn.argmax()
		teqn = tEq[tSlc1:,n]
		ts,Ind = np.unique(teqn,return_index=True)
		#Have unique EQXs
		Neq = len(Ind)
		if (Neq>0):
			x = xeq[tSlc1:,n]
			y = yeq[tSlc1:,n]
			x = x[Ind]
			y = y[Ind]
			vm = Vmag[tSlc1:,n]
			vm = vm[Ind]
			vzn = Vz[tSlc1:,n]
			vzn = vzn[Ind]


			als = np.arccos(vzn/vm)*180.0/np.pi
			r = np.sqrt(x**2.0 + y**2.0)
			phi = np.arctan2(y,x)
			for i in range(Neq):
				A.append(als[i])
				P.append(phi[i])
	return np.array(A),np.array(P)
Exemplo n.º 7
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
Exemplo n.º 8
0
import argparse
import numpy as np
import os
import lfmViz as lfmv
import lfmPostproc as lfmpp
import matplotlib as mpl
import matplotlib.pyplot as plt

dirStub = "/Users/soratka1/Work/magnetoloss/synth"
fileStub = "100keV.h5part"

spcs = ["H", "O", "e"]
Leg = ["H", "O", "e"]

Ns = len(spcs)
#fig = plt.figure(1, figsize=(10, 10))

Np = 100000.0
for i in range(Ns):
    fIn = dirStub + "/" + spcs[i] + "." + fileStub
    t, mpTp = lfmpp.getH5p(fIn, "mp")
    mpT = mpTp.sum(axis=1)
    print(mpT.shape)
    plt.plot(t, mpT / Np)

plt.legend(Leg, loc='lower right')
plt.xlabel('Time [s]')
plt.ylabel('Cumulative Loss Fraction')
plt.show()
Exemplo n.º 9
0
def findCrossings(fIn, PhiC=30.0, DelPhi=5):

    isOut = lfmpp.getOut(fIn)
    t, ids = lfmpp.getH5p(fIn, "id", Mask=isOut)
    t, mp = lfmpp.getH5p(fIn, "mp", Mask=isOut)
    t, x = lfmpp.getH5p(fIn, "x", Mask=isOut)
    t, y = lfmpp.getH5p(fIn, "y", Mask=isOut)
    t, z = lfmpp.getH5p(fIn, "z", Mask=isOut)
    t, vx = lfmpp.getH5p(fIn, "vx", Mask=isOut)
    t, vy = lfmpp.getH5p(fIn, "vy", Mask=isOut)
    t, vz = lfmpp.getH5p(fIn, "vz", Mask=isOut)
    t, tCr = lfmpp.getH5p(fIn, "tCr", Mask=isOut)
    ids = ids[0, :]

    phi = np.arctan2(y, x) * 180 / np.pi
    if (np.abs(PhiC) > 5):
        #Fix for flop
        phi[phi < 0] = phi[phi < 0] + 360
    Np = len(ids)
    #print("\tFound %d particles\n"%(Np))
    Vx = []
    Vy = []
    Vz = []
    sM = []
    zM = []

    for n in range(Np):

        #Find last MP xing
        mpn = mp[:, n]
        tCrn = tCr[:, n]
        tSlc1 = tCrn.argmax()
        #Find box xing
        tSlc2 = np.argmax(mpn > 0)
        pn = phi[tSlc1:tSlc2, n]

        #print(pn.shape)
        #Identify sign changes and bound for within +/- 5 degrees
        #Otherwise funny business @ p=0/360
        dp = pn - PhiC
        dpsgn = np.sign(dp)
        dpFlp = ((np.roll(dpsgn, 1) - dpsgn) != 0).astype(int)
        dpFlp = (dpFlp > 0)
        dpAbs = np.abs(dp) <= DelPhi
        isPCr = dpFlp & dpAbs
        #print(len(pn),tCr.sum())
        Nx = isPCr.sum()
        if (Nx > 0):
            vxn = vx[tSlc1:tSlc2, n]
            vyn = vy[tSlc1:tSlc2, n]
            vzn = vz[tSlc1:tSlc2, n]
            xn = x[tSlc1:tSlc2, n]
            yn = y[tSlc1:tSlc2, n]
            zn = z[tSlc1:tSlc2, n]

            vxx = vxn[isPCr]
            vyx = vyn[isPCr]
            vzx = vzn[isPCr]
            xx = xn[isPCr]
            yx = yn[isPCr]
            zx = zn[isPCr]

            for i in range(Nx):
                Vx.append(vxx[i])
                Vy.append(vyx[i])
                Vz.append(vzx[i])
                sM.append(np.sqrt(xx[i]**2.0 + yx[i]**2.0))
                zM.append(zx[i])
            #print(n,isPCr)
    Vx = np.array(Vx)
    Vy = np.array(Vy)
    Vz = np.array(Vz)
    sM = np.array(sM)
    zM = np.array(zM)
    print("\tPhi = %5.2f, NumP = %d\n" % (PhiC, len(Vx)))
    return sM, zM, Vx, Vy, Vz
Exemplo n.º 10
0
K = [10, 50, 100]
Spc = ["p", "Hepp", "O"]
sLab = ["H+", "He++", "O+"]

for k in range(len(K)):
    for s in range(len(Spc)):
        Files.append("%s_sInj.K%02d.0001.h5part" % (Spc[s], K[k]))
        fOuts.append("%s%02d.mk.png" % (Spc[s], K[k]))
        T**S.append("%s %02d keV" % (sLab[s], K[k]))

Nf = len(Files)
for n in range(Nf):
    fIn = RootDir + Files[n]
    fOut = fOuts[n]

    t, K = lfmpp.getH5p(fIn, "kev")
    t, Mu = lfmpp.getH5p(fIn, "Mu")

    dK = K[2:-2, :] - K[0:-4, :]
    dlK = dK / (dt * K[1:-3, :])

    dMu = Mu[2:-2, :] - Mu[0:-4, :]
    dlMu = dMu / (dt * Mu[1:-3, :])

    muf = Mu[1:-3, :].flatten()
    dm = dlMu.flatten()
    dk = dlK.flatten()

    #Restrict to good values
    Ind = (muf > 1.0e-8) & (~np.isnan(muf))
    dm = dm[Ind]
Exemplo n.º 11
0
subVTI = True

dirStub = "/Users/soratka1/Work/magnetoloss/synth"
fileStub = "100keV.h5part"

spcs = ["H", "O"]
Leg = ["Hydrogen", "Oxygen"]
fOut = "OxyDelP.h5part"
K = 5
i = 1  #Oxygen

fIn = dirStub + "/" + spcs[i] + "." + fileStub
print("Reading %s" % (fIn))
print("Species %s" % (Leg[i]))
t, ids = lfmpp.getH5p(fIn, "id")

isOut = lfmpp.getOut(fIn)
pid, NumX = lfmpp.countMPX(fIn, isOut)
R, PhiF, LambdaF, Tmp = lfmpp.getSphLoss1st(fIn)
R, PhiL, LambdaL = lfmpp.getSphLoss(fIn)
DelPhi = PhiL - PhiF

isOut[isOut] = (DelPhi) > 60
Mask = isOut

id0 = ids[0, Mask]
Np = Mask.sum()

print(Np)
print(K)
Exemplo n.º 12
0
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec

fld = "/Users/soratka1/Work/magnetoloss/eqSlc/eqSlc.0250.vti"
IDs = [1335, 301, 95834, 12593, 63464, 75685]
fIn = "/Users/soratka1/Work/magnetoloss/synth/O.100keV.h5part"

Bz = lfmv.getVTI_SlcSclr(fld, fldStr='dBz')
xm = np.linspace(-15.0, 13, 560)
ym = np.linspace(-20.0, 20, 801)
xx, yy = np.meshgrid(xm, ym)
Ni = len(IDs)
#fig = plt.figure(1, figsize=(15,10))
gs = gridspec.GridSpec(Ni, 1)

t, x = lfmpp.getH5p(fIn, "x")
t, y = lfmpp.getH5p(fIn, "y")
t, z = lfmpp.getH5p(fIn, "z")
t, pids = lfmpp.getH5p(fIn, "id")
t, Om = lfmpp.getH5p(fIn, "Om")
t, Op = lfmpp.getH5p(fIn, "Op")

Omp = (Om + Op)
for n in range(len(IDs)):
    pid = IDs[n]
    npid = (pids == pid).argmax()
    xp = x[:, npid]
    yp = y[:, npid]
    zp = z[:, npid]
    cp = Omp[:, npid]
    #ax = plt.subplot(gs[n,0])
Exemplo n.º 13
0
	P0 = -135; P1 = -80
else:
	fIn = '/Users/soratka1/Work/magnetoloss/synth/e.100keV.h5part'
	fIn = '/Users/soratka1/Work/magnetoloss/debug/e.100keV.h5part'
	#Find particles whose last Teq is in range
	T0 = 2250
	T1 = 2300
	P0 = 80; P1 = 135




fOut = "khiSub.h5part"
Out = lfmpp.getOut(fIn)

t,x   = lfmpp.getH5p(fIn,"x")
t,y   = lfmpp.getH5p(fIn,"y")
t,z   = lfmpp.getH5p(fIn,"z")

t,Teq = lfmpp.getH5pFin(fIn,"Teq")
t,ids = lfmpp.getH5p(fIn,"id")
id0   = ids[0,:]

R,Phi,Lambda = lfmpp.getSphLoss(fIn)

Out[Out] = (Phi>=P0) & (Phi<=P1)
Mask = (Teq>=T0) & (Teq<=T1) & Out

Np = Mask.sum()
t,xeq = lfmpp.getH5p(fIn,"xeq")
t,yeq = lfmpp.getH5p(fIn,"yeq")
Exemplo n.º 14
0
Tail = "_csInj.K0.0001.h5part"
Stubs = ["p", "Hep", "Hepp", "O"]
Labs = ["H+", "He+", "He++", "O+"]
Plts = ["b", "g", "r", "c"]
t**S = "Single Injection (1 eV)"

figName = "cs_Kt.png"
figQ = 300
pC = [1, 10, 50, 99]

Ns = len(Stubs)
Np = len(pC)
for n in range(Ns):
    fIn = Root + Stubs[n] + Tail

    t, Kev = lfmpp.getH5p(fIn, "kev")
    K = Kev
    Kb = K.mean(axis=1)  #Average(t)
    dK = K.std(axis=1)  #Std
    T = t - t.min()
    for i in range(Np):
        pLab = "_"
        if (i == 0):
            pLab = "%s, %s Percentiles" % (Labs[n], str(pC))
        Kc = np.percentile(K, pC[i], axis=1)
        plt.semilogy(T, Kc, Plts[n], label=pLab)

    #plt.errorbar(t,Kb,dK,label=Labs[n],errorevery=10)
    #plt.plot(t,Kc,label=Labs[n])
    print("Spc = %s" % (Labs[n]))
    print("\tMax = %f" % (K.max()))