コード例 #1
0
ファイル: vis.py プロジェクト: bdb112/pyfusion
def vis(dd, ax=None, size=1, show=False, inds = None, debug=False):
    """ return the indices in dd which are currently visible and greater
    in size than size (>=).  Use after visual.sp  
    size = 0 will return all points and sizes
    """

    from pyfusion.data.convenience import btw

    if inds is None:  raise Exception('inds must be set  (-1 for all) for now')

    if ax is None: 
        ax=pl.gca()

    x = ax.get_xlabel()
    xlim = ax.get_xlim()
    y = ax.get_ylabel()
    ylim = ax.get_ylim()

    if len(np.shape(inds)) == 0 and inds == -1:
        inds = np.arange(len(dd[x]))

    #  w = np.where(btw(dd[x],xlim) & btw(dd[y],ylim))[0]
    w = np.where(btw(dd[x][inds],xlim) & btw(dd[y][inds],ylim))[0]
    if len(w) == 0:
        raise LookupError('No points found')
    if show:
        pl.scatter(dd[x][w], dd[y][w],'+')

    if debug: 1/0
    return(w)
コード例 #2
0
def vis(dd, ax=None, size=1, show=False, inds=None, debug=False):
    """ return the indices in dd which are currently visible and greater
    in size than size (>=).  Use after visual.sp  
    size = 0 will return all points and sizes
    """

    from pyfusion.data.convenience import btw

    if inds is None: raise Exception('inds must be set  (-1 for all) for now')

    if ax is None:
        ax = pl.gca()

    x = ax.get_xlabel()
    xlim = ax.get_xlim()
    y = ax.get_ylabel()
    ylim = ax.get_ylim()

    if len(np.shape(inds)) == 0 and inds == -1:
        inds = np.arange(len(dd[x]))

    #  w = np.where(btw(dd[x],xlim) & btw(dd[y],ylim))[0]
    w = np.where(btw(dd[x][inds], xlim) & btw(dd[y][inds], ylim))[0]
    if len(w) == 0:
        raise LookupError('No points found')
    if show:
        pl.scatter(dd[x][w], dd[y][w], '+')

    if debug: 1 / 0
    return (w)
コード例 #3
0
ファイル: DP14_mode_plot.py プロジェクト: bdb112/pyfusion
cind = 0
colorset=('b,g,r,c,m,y,k,orange,purple,lightgreen,gray'.split(',')) # to be rotated

DA65MPH=DA('DA65MP2010HMPno612b5_M_N_fmax.npz',load=1)
DA65MPH.extract(locals())
pyfusion.config.set('Plots',"FT_Axis","[0.5,4,0,80000]")
"""
run -i pyfusion/examples/plot_specgram.py shot_number=65139 channel_number=1 NFFT=1024
pl.set_cmap(cm.gray_r)
pl.clim(-60,-0)
"""
sc_kw=dict(edgecolor='k',linewidth = 0.3)

for n in (-1,0,1):
    for m in (-2, -1,1,2):
        w =np.where((N==n) & (M==m) & (_binary_svs < 99) & btw(freq,frlow,frhigh))[0]
        if len(w) != 0:
            col = colorset[cind]
            pl.scatter(t_mid[w], freq[w], size_scale*amp[w], color=col, label='m,n=~{m},{n}'.format(m=m, n=n),**sc_kw)
            cind += 1
w=np.where((_binary_svs < 99) & btw(freq,frlow,frhigh)  & btw(MM, 0,130) & (NN== -4))[0]
col = colorset[cind] ; cind+=1
m = 1; n=0
pl.scatter(t_mid[w], freq[w], size_scale*amp[w], color=col, label='m,n=~{m},{n}'.format(m=m, n=n),**sc_kw)

DA65H=DA('DA65HMPno612b_M.npz',load=1)
DA65H.extract(locals())

w=np.where((_binary_svs < 99999) & btw(freq,frlow*0.8,frhigh*1.2)  & btw(MM, -60,-5))[0]
#col = colorset[cind] ; cind+=1
m = 1; n=0
コード例 #4
0
import numpy as np
from numpy import where, array
from pyfusion.data.DA_datamining import DA
from pyfusion.acquisition.read_text_pyfusion import read_text_pyfusion, plot_fs_DA, merge_ds
from pyfusion.visual.window_manager import rmw, cmw, omw, lmw, smw
from pyfusion.utils.utils import fix2pi_skips, modtwopi
from pyfusion.visual.sp import off, on, tog
from pyfusion.data.convenience import between, bw, btw, decimate, his, broaden


dd=DA('W7X_MIR/DAMIRNOV_41_13_nocache_15_3m_2018fl.zip')
dd.info()
fig4, axs4=plt.subplots(4,1)
figfs, axf=plt.subplots(1,1)
plot_fs_DA(dd, ax=axf)
w6=where((btw(dd['freq'],4,8)) & (dd['amp']>0.0015) & (dd['t_mid']>3.2) &(dd['shot'] == 180904035))[0]
plot_fs_DA(dd, ax=axf, inds=w6,marker='s',ms=300,alpha=0.5)
axs4[0].plot(array([modtwopi(ph,offset=0) for ph in dd['phases'][w6]]).T,'c',lw=.5)
w6=where((btw(dd['freq'],4,8)) & (dd['amp']>0.015) & (dd['t_mid']>3.2) &(dd['shot'] == 180904035))[0]
axs4[0].plot(array([modtwopi(ph,offset=0) for ph in dd['phases'][w6]]).T,'b',lw=.5)
axs4[0].set_title('4-8kHz, after 3.2s')
w0=where((btw(dd['freq'],0,2)) & (dd['amp']>0.0015) & (dd['t_mid']>3.2) &(dd['shot'] == 180904035))[0]
plot_fs_DA(dd, ax=axf, inds=w0,marker='s',ms=300,alpha=0.5)
axs4[1].plot(array([modtwopi(ph,offset=0) for ph in dd['phases'][w0]]).T,'b',lw=.5)
axs4[1].set_title('0-2kHz, > 3.2s')
w6e=where((btw(dd['freq'],4,12)) & (dd['amp']>0.015) & (dd['t_mid']<3.2) &(dd['shot'] == 180904035))[0]
plot_fs_DA(dd, ax=axf, inds=w6e,marker='^',ms=300,alpha=0.5)
axs4[2].plot(array([modtwopi(ph,offset=0) for ph in dd['phases'][w6e]]).T,'c',lw=.5)
w6e=where((btw(dd['freq'],4,12)) & (dd['amp']>0.025) & (dd['t_mid']<3.2) &(dd['shot'] == 180904035))[0]
axs4[2].plot(array([modtwopi(ph,offset=0) for ph in dd['phases'][w6e]]).T,'b',lw=1)
axs4[2].set_title('4-12kHz, before 3.2s')
コード例 #5
0
def remove_baseline(input_data,
                    baseline=None,
                    delta_t=0.01,
                    chan=None,
                    copy=True):
    """ Remove a tilted baseline from a signal
    If baseline is None, then average over delta_t at either end
    If it is two times, then subtract the average between those (no tilt)
    If it is 4 times, then bl[0,1] and bl[2,3] are averaged - so 
    the correction is at two points (mid point of those intervals)

    baseline in the same units as the timebase
    baseline == None is NOT the same as for integrate
    
    """
    from pyfusion.data.convenience import whr, btw
    if copy:
        input_data = deepcopy(input_data)

    if (len(np.shape(input_data.signal)) == 2) and chan is None:
        for (s, sig) in enumerate(input_data.signal):
            input_data.signal[s][:] = remove_baseline(input_data,
                                                      chan=s,
                                                      baseline=baseline,
                                                      delta_t=delta_t).signal

    else:
        if chan is None:
            signal = input_data.signal
        else:
            signal = input_data.signal[chan]

        tb = input_data.timebase

        bl = np.array(baseline).flatten()
        if baseline is None or len(baseline) == 0:
            bl = [
                np.min(tb),
                np.min(tb) + delta_t,
                np.max(tb) - delta_t,
                np.max(tb)
            ]

        wst = np.where(btw(tb, bl[0:2]))[0]
        bl_st = np.average(signal[wst])
        time_st = np.average(tb[wst])

        if len(bl) == 4:
            wend = np.where(btw(tb, bl[2:4]))[0]
            bl_end = np.average(signal[wend])
            time_end = np.average(tb[wend])
            input_data.signal = signal - (bl_st * (time_end - tb) /
                                          (time_end - time_st) - bl_end *
                                          (time_st - tb) /
                                          (time_end - time_st))

        else:
            bl_end, time_end = None, None
            input_data.signal = signal - bl_st  # these are to avoid upsetting print

        if pyfusion.VERBOSE > 0:
            print('baseline removal start, end, indicies', bl_st, bl_end,
                  time_st, time_end)

    return (input_data)
コード例 #6
0
from pyfusion.data.convenience import between, bw, btw, decimate, his, broaden
# paste NOt %PASTE
#_PYFUSION_TEST_@@SCRIPT

run -i pyfusion/examples/gen_fs_bands.py  dev_name='W7X' diag_name=W7X_MIRNOV_41_BEST_LOOP shot_range="[[20180912,s] for s in range(43,44)]" max_bands=1 info=0 min_svs=2 max_H=0.999 min_p=0 exception=() outfile='W7X_MIR/preproc/201809/PMIRNOV_41_BEST_LOOP_10_3m_20180912043' fmax=10e3  seg_dt=3e-3 min_svs=2
#  clean up not usually needed
run -i pyfusion/examples/clean_up_pyfusion_text_mp.py MP=0 fileglob="'W7X_MIR/preproc/201809/P*'"
run -i pyfusion/examples/merge_text_pyfusion.py file_list="np.sort(glob('W7X_MIR/preproc/201809/PMIRNOV_41_BEST_LOOP_10_3m_20180912043'))"
run  pyfusion/examples/plot_specgram.py diag_name='W7X_MIR_4136' shot_number=[20180912,43]  NFFT=2048*4
plot_fs_DA(dd);pl.ylim(0,30)
from pyfusion.data.DA_datamining import DA, report_mem, append_to_DA_file
DA43MIRNOV_13_BEST_LOOP=DA(dd)
DA43MIRNOV_13_BEST_LOOP.save('/tmp/DAMIRNOV_41_13_BEST_LOOP_10_3ms_20180912043.npz")

dd = DA("DAMIRNOV_41_13_BEST_LOOP_10_3ms_20180912043.npz")
w=where((btw(dd['freq'],2,4)) & (dd['amp']>0.012) )[0]
plt.plot(dd['phases'][w].T)
# prettier plots
plt.rcParams['font.size']=20
phs=array([modtwopi(ph,offset=-1) for ph in dd['phases']])
w3=where((btw(dd['freq'],2,4)) & (dd['amp']>0.012) )[0]
plt.plot(phs[w3].T)
plt.figure()
w6=where((btw(dd['freq'],5,7)) & (dd['amp']>0.015) )[0];len(w6)
plt.plot(phs[w6].T)
title('6kHz mode')
ylabel('phase dif n, n-1')
xlabel('probe pairs (n,n-1)')


w=where((btw(dd['freq'],2,4)) & (dd['amp']>0.05) )[0]
コード例 #7
0
    kh_req  # these lines are just to keep the lint checker quiet
except:
    kh_req = None
    kappa_v = None
    shot = None
    indx = None

noverlap = 20 - 1
lrun = 20

scans = [[
    [shot[ind] for ind in inds],
    unique(kh_req[inds]),
    unique(kappa_v[inds]), inds
] for inds in [indx[ind:ind + lrun] for ind in indx[::lrun // (noverlap + 1)]]
         if ((btw(len(unique(kappa_v[inds])), 2, 5)) and (
             btw(len(unique(kh_req[inds])), 2, 10)))]

sorti = argsort([len(scan[2]) for scan in scans])  # sort by number of kv's
sorti = argsort([scan[0][0] for scan in scans])  # sort by number of kv's

header = str('ind   numkh range        numkv range        shots    from   to')
print(header)
for ind, scan in zip(sorti, array(scans)[sorti]):
    print('{ind:3}: {nkh:3} {khr}  {nkv:4}  {kvr} {ns:6}    {mins:6}-{maxs:6}'.
          format(ind=ind,
                 nkh=len(scan[1]),
                 nkv=len(scan[2]),
                 ns=len(scan[0]),
                 mins=min(scan[0]),
                 maxs=max(scan[0]),