Example #1
0
def LCFS_plot(da, diag, t0_utc, t_range, av=None, ax=None, xtoLCFS=1, nrm=None, labelpoints=False, col=None, Tesmooth=None):
    """ plot Te ne etc vs distance to LCFS, averaging over a time range.
    The average uses a Nanmean by default, so it does not de-emphasize 
    values with large uncertainties.
    Alternatively np.median can be used - but it treats nans as large => bias up
    """
    av = np.nanmean if av is None else av
    ax = plt.gca() if ax is None else ax
    chans = np.array(da['info']['channels'])
    dt = (t0_utc - da['info']['params']['i_diag_utc'][0])/1e9
    indrange = np.searchsorted(da['t_mid'], np.array(t_range) + dt)
    inds = range(*indrange)
    if len(inds) < 3:
        ll = len(inds)
        pyfusion.logging.warn('{msg} samples ({ll}) in the time range {t}'
                              .format(msg=['!No! ','too few'][ll>0], ll=ll, t=t_range))
    distLCFS = []
    td = []         # td is transverse signed distance from limiter vertical midplane 

    if diag in  ['ne18','Pdens','I0']:
        exclude.extend(['LP11','LP12','L57_LP09'])
    for (c, ch) in enumerate(chans):
        LPnum = int(ch[-2:])
        lim = 'lower' if 'L57' in ch else 'upper'
        X, Y, Z, dLCFS = lookupPosition(LPnum, lim)
        td.append(rot(X, Y,  2*np.pi*4/5.)[1])
        distLCFS.append(dLCFS)

    if diag in ['ne18', 'Te', 'I0', 'Vf', 'Vp']:
        if diag=='Vf' and 'Vp' in da.keys():
            diag = 'Vp'
        sig = av(da.masked[diag][inds], axis=0)
        if 'e'+diag in da:
            ebars = av(da['e'+diag][inds], axis=0)
        else:
            ebars = None
    else:
        sig, ebars = get_calculated(da, diag, inds, av=av, x=td, nrm=nrm, Tesmooth=Tesmooth)
        sig = av(sig[inds], axis=0)

        #print()
    # normalise before plots - intended for ne and I0 to allow for probe wear
    if nrm is not None:
        sig = sig/nrm
        if debug>0:
            print(nrm)

    signed_dLCFS = distLCFS * np.sign(td)
    for (c, ch) in enumerate(chans):
        if sum([st in ch for st in exclude]):
            sig[c] = np.nan
        if labelpoints>0 and (not np.isnan(sig[c])):
            if labelpoints>1 or sig[c]>1.3*np.median(sig):
                ax.text(signed_dLCFS[c], sig[c], ch)
    ax.errorbar([td, signed_dLCFS][xtoLCFS], sig, ebars, fmt='o', label=lim, color=col, lw=0.5)
    ax.set_ylabel(diag)
    #if diag == 'Te':
    ax.set_ylim(0, ax.get_ylim()[1])
    return(signed_dLCFS, td, sig, ebars)
Example #2
0
from lukas.PickledAssistant import lookupPosition

for lim in ['lower','upper']:
    print('\n ===== Limiter {l} ===== '.format(l=lim))
    print('Probe  X,       Y,      Z,     dLCFS')
    for LPnum in range(1,20+1):
        X,Y,Z,dLC = lookupPosition(LPnum, lim)
	print('LP{LPnum:02}: {xyz}: {dLC:6.2f}'
              .format(LPnum=LPnum, xyz=np.round([X,Y,Z], 2), dLC=dLC))