예제 #1
0
import get_lp
import get_ts
from scipy.signal import lfilter

# Grab ts_data.
ts_dict = get_ts.run_script(167196, 'core')

ts_psins = ts_dict['psins']['avg_psins']

# Grab lp data.
lp_dict = get_lp.get_dict_of_lps(167196)

for p in lp_dict.keys():
    min_idx = np.where(lp_dict[p]['time'] > 2500)[0][0]
    max_idx = np.where(lp_dict[p]['time'] > 5000)[0][0]
    avg_psin = lp_dict[p]['psin'][min_idx:max_idx].mean()
    lp_dict[p]['avg_psin'] = avg_psin

# probe 23 1.019 --> chord 8 1.022
# probe 25 1.028 --> chord 7 1.029
# probe 29 1.050 --> chord 5 1.056
# probe 31 1.063 --> chord 4 1.070
# probe 33 1.077 --> chord 4 1.070
# probe 35 1.092 --> chord 3 1.087

# Plot the time series of matching probes.
lp_min_idx = np.where(lp_dict['probe 25']['time'] > 2500)[0][0]
lp_max_idx = np.where(lp_dict['probe 25']['time'] > 5000)[0][0]
ts_min_idx = np.where(ts_dict['density']['X'] > 2500)[0][0]
ts_max_idx = np.where(ts_dict['density']['X'] > 5000)[0][0]
lp25_time = lp_dict['probe 25']['time'][lp_min_idx:lp_max_idx]
예제 #2
0
def runScript(aNumber=28,
              bNumber=10,
              cNumber=10,
              timeStart=2500,
              timeEnd=4500):
    # The TS data.
    #netcdf_files = getOMFITprofilesFiles()

    # Get the probe objects as a list.
    probes = Probe.get_multiple(aNumber=aNumber,
                                bNumber=bNumber,
                                cNumber=cNumber,
                                startTime=timeStart,
                                endTime=timeEnd)
    aProbe = probes[0]
    bProbe = probes[1]
    cProbe = probes[2]

    # The shots the probes were in for.
    shots = aProbe.r2d2DICT["shots"]

    # Load the TS data averaged over all the shots at each psin.
    ts_data = loadOMFITdata(shots)

    # Get the divertor LP data.
    lp_dict = {}
    for shot in shots:
        lp_dict[str(shot)] = lp.get_dict_of_lps(shot)

    lp_data = avgTeFromLPs(lp_dict, timeStart, timeEnd)

    # Get the psiN values for each probe.
    au_psiN = aProbe.atlasDICT["psiN_U"]
    ad_psiN = aProbe.atlasDICT["psiN_D"]

    # Estimate of time of shot.
    timeOfShot = 5000.0
    numberOfShots = 4

    # Rough estimate of the net flux as defined in "shawn_model".
    au_net = aProbe.r2d2DICT["w_areal_U"] / (timeOfShot * numberOfShots)
    ad_net = aProbe.r2d2DICT["w_areal_D"] / (timeOfShot * numberOfShots)

    fig, ax1 = plt.subplots()
    ax1.plot(lp_data[0], lp_data[1], 'r.', label="LP Data")
    ax1.plot(ts_data[0], ts_data[1], 'r-', label="TS Data")
    ax1.set_ylabel(r"$\mathrm{T_e}$ (eV)", color="r")
    ax1.set_xlim([1.0, 1.4])
    ax1.set_ylim([0, 50])
    ax1.tick_params("x", colors="r")

    ax2 = ax1.twinx()
    ax2.plot(au_psiN, au_net, 'b', label="AU Net")
    ax1.set_xlim([1.0, 1.4])
    ax2.set_xlabel(r"$\psi_{\mathrm{N}}$")
    ax2.set_ylabel(r"Flux $\mathrm{m^{-2}s^{-1}}$", color="b")
    ax2.tick_params("y", colors="b")

    #plt.plot(au_psiN, au_net, label="AU Net")
    #plt.plot(lp_data[0], lp_data[1], label="LP Data")
    #plt.plot(ts_data[0], ts_data[1], label="TS Data")
    plt.title("TS/LP Te Data with Net Flux")
    plt.legend()
    plt.show()

    return [lp_data, ts_data, au_psiN, au_net]
예제 #3
0
import get_lp as lp
import shawn_model as model
import compareLPtoTS_psiN as comp
import HModeTest as test

import numpy as np
import matplotlib.pyplot as plt
import EFIT.load_gfile_d3d as loadg
from scipy import interpolate
import MDSplus as mds

lp_dict = lp.get_dict_of_lps(167192)
plunge_dict = comp.runScript()

# Average between 1900 and 2000 for the divertor LPs since this is when the
# plunging LP was in for.
psin_list = []
te_list = []
for lp_name in lp_dict.keys():
    print "Averaging " + lp_name + "..."
    lp = lp_dict[lp_name]
    times = lp["time"]
    temp = lp["temp"]
    psin = lp["psin"]

    # Find what index 1900 and 2000 is at.
    time1 = 1900
    while (True):
        try:
            index1, = np.where(times == time1)[0]
            break
예제 #4
0
import get_lp
from gadata import gadata
import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
import numpy as np
from scipy.signal import savgol_filter

# Grab the LP data and pedestal density.
d = get_lp.get_dict_of_lps(167247)
neped = gadata('prmtan_neped', 167247)


def interp_func(x, y):

    # Strip zeros.
    keep_idx = x != 0
    x = x[keep_idx]
    y = y[keep_idx]
    return interp1d(x, y)


# Interpolation functions so we can use the same time ranges.
f11 = interp_func(d['probe 11']['time'], d['probe 11']['jsat'])
f13 = interp_func(d['probe 13']['time'], d['probe 13']['jsat'])
f15 = interp_func(d['probe 15']['time'], d['probe 15']['jsat'])
f17 = interp_func(d['probe 17']['time'], d['probe 17']['jsat'])
f19 = interp_func(d['probe 19']['time'], d['probe 19']['jsat'])
f21 = interp_func(d['probe 21']['time'], d['probe 21']['jsat'])
fneped = interp_func(neped.xdata, neped.zdata)

# A common time range.
예제 #5
0
import get_lp            as lp
import numpy             as np
import matplotlib.pyplot as plt
from scipy.optimize      import curve_fit


shot   = 167196
m_deut = 2.01 * 931.49 * 10**6 / ((3*10**8)**2.0)
if True:
    lp_dict = lp.get_dict_of_lps(shot)

# Get estimated flux at floor ring using the probes there: 15, 17, 19, 21.
avg_flux_floor_vals = np.array([])
avg_flux_floor_stds = np.array([])
for p in [15, 17, 19, 21]:
    try:
        # Load lp data.
        mylp = lp_dict['probe ' + str(p)]

        # Get indices of time range 2000-4000.
        idx  = np.where(np.logical_and(mylp['time']>=2000, mylp['time']<=4000))

        # Get the density and temp data.
        mydens = np.array(mylp['dens'])[idx]
        mytemp = np.array(mylp['temp'])[idx]

        # Calculate sound speed and then flux.
        mycs   = np.sqrt(2 * mytemp / m_deut)
        myflux = 0.5 * mydens * mycs

        # Calculate average flux at the floor ring.
예제 #6
0
def use_lp(shot, tmin, tmax, p_exclude=None, V_adjust=False):
    """
    Calculate the PF stuff using LP data (i.e. near the source). Typically
    less data points available and the integrity suffers. Especially when
    the SP is on the floor.

    p_exclude: Exclude these first (last) probes in plots using a positive
               (negative) value for an index.
    """

    # Get the LP data.
    lps = lp.get_dict_of_lps(shot)

    # Get the LP data into plottable arrays.
    Rs = np.array([])
    Tes = np.array([])
    nes = np.array([])
    Vs = np.array([])
    for lp_num in lps.keys():
        #print('lp: {}'.format(lp_num))

        # Don't want the upper divertor or anything.
        if lps[lp_num]['pnum'] < 39:
            tmp_R = lps[lp_num]['rprobe']
            Rs = np.append(Rs, tmp_R)

            # Average between times.
            lptimes = lps[lp_num]['time']
            idx_start = int(
                np.where(
                    np.abs(lptimes - tmin) == np.abs(lptimes -
                                                     tmin).min())[0][0])
            idx_end = int(
                np.where(
                    np.abs(lptimes - tmax) == np.abs(lptimes -
                                                     tmax).min())[0][0])
            tmp_te = lps[lp_num]['temp'][idx_start:idx_end].mean()
            tmp_ne = lps[lp_num]['dens'][idx_start:idx_end].mean()
            tmp_V = lps[lp_num]['pot'][idx_start:idx_end].mean()
            Tes = np.append(Tes, tmp_te)
            nes = np.append(nes, tmp_ne)
            Vs = np.append(Vs, tmp_V)

    # Remove unwanted LPs.
    if p_exclude:
        Rs = np.delete(Rs, p_exclude)
        Tes = np.delete(Tes, p_exclude)
        nes = np.delete(nes, p_exclude)
        Vs = np.delete(Vs, p_exclude)

    # Pressure as just nkT.
    ps = nes * Tes * 10**(-18)

    # Do an exponential fit.
    def exp_fit(x, a, b):
        return a * np.exp(-b * x)

    if V_adjust:
        Vs = Vs + np.abs(Vs.min()) + 0.01

    popt_V, pcov_V = curve_fit(exp_fit, Rs, Vs, maxfev=10000)
    popt_p, pcov_p = curve_fit(exp_fit, Rs, ps, maxfev=10000)
    popt_ne, pcov_ne = curve_fit(exp_fit, Rs, nes * 10**(-18), maxfev=10000)
    popt_te, pcov_te = curve_fit(exp_fit, Rs, Tes, maxfev=10000)

    # Get the average SP location.
    conn = MDSplus.Connection('localhost')
    ga_obj = gadata('rvsout', shot, connection=conn)
    ga_idx = np.logical_and(ga_obj.xdata > tmin, ga_obj.xdata < tmax)
    avg_rvsout = ga_obj.zdata[ga_idx].mean()

    # Average magnetic field.
    bt_obj = gadata('bt', shot, connection=conn)
    bt_idx = np.logical_and(bt_obj.xdata > tmin, bt_obj.xdata < tmax)
    avg_bt = bt_obj.zdata[bt_idx].mean()

    # Get derivative values at SP (assuming exponential so easy).
    sp_E = popt_V[1] * exp_fit(avg_rvsout, *popt_V)
    sp_pgrad = popt_p[1] * exp_fit(avg_rvsout, *popt_p)
    sp_ne = exp_fit(avg_rvsout, *popt_ne)
    sp_te = exp_fit(avg_rvsout, *popt_te)

    # Print out info.
    print('Strike Point R:      {:.2f}'.format(avg_rvsout))
    print('Strike Point E:      {:.2e}'.format(sp_E))
    print('Strike Point grad p: {:.2e}'.format(sp_pgrad * 10**(24)))
    print('Strike Point ne:     {:.2e}'.format(sp_ne * 10**(24)))
    print('Strike Point Te:     {:.2f}'.format(sp_te))
    print('Average Bt:          {:.2f}'.format(avg_bt))

    fit_Rs = np.linspace(Rs.min(), Rs.max(), 100)
    fit_Vs = exp_fit(fit_Rs, *popt_V)
    fit_ps = exp_fit(fit_Rs, *popt_p)
    fit_nes = exp_fit(fit_Rs, *popt_ne)

    fig = pp.pplot(Rs, Vs)
    fig = pp.pplot(fit_Rs, fit_Vs, fig=fig, fmt='--', ylabel='V')

    fig = pp.pplot(Rs, ps * 10**(24))
    fig = pp.pplot(fit_Rs, fit_ps * 10**(24), fig=fig, fmt='--', ylabel='pe')

    fig = pp.pplot(Rs, nes * 10**(6))
    fig = pp.pplot(fit_Rs, fit_nes * 10**(24), fig=fig, fmt='--', ylabel='ne')