def get_nesep(shot, tmin=2500, tmax=4000, tstep=250):
    ts_dict = ts.run_script(shot, 'core', tmin=tmin, tmax=tmax, tstep=tstep)

    # Plot the data to make sure its not grabbing during an ELM.
    all_psins = ts_dict['psins']['all_psins']
    all_nes   = ts_dict['psins']['all_nes']
    all_tes   = ts_dict['psins']['all_Tes']
    plt.style.use('seaborn')
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    ax1.plot(all_psins, all_tes, '.')
    ax1.set_xlabel('Psin')
    ax1.set_ylabel('Te (eV)')
    ax1.set_title(str(shot))

    # Plot the avg values over it.
    ax1.plot(ts_dict['psins']['avg_psins'], ts_dict['psins']['avg_Tes'])
    plt.show()

    # Assuming it's a good fit, get the first point inside and outside sep.
    inside = np.min(np.where(ts_dict['psins']['avg_psins']<1.0))
    outside = inside - 1

    # Get avg ne between the two as ne_sep.
    ne_sep = np.mean([ts_dict['psins']['avg_nes'][inside], ts_dict['psins']['avg_nes'][outside]])
    Te_sep = np.mean([ts_dict['psins']['avg_Tes'][inside], ts_dict['psins']['avg_Tes'][outside]])

    print('ne sep = {:.4e}'.format(ne_sep))
    print('Te sep = {:.4e}'.format(Te_sep))

    return Te_sep
Exemple #2
0
def heat_flux(shot, start_time=2000, end_time=4500):
    ts_dict = ts.run_script(shot, 'divertor', tmin=start_time, tmax=end_time)
    time = ts_dict['temp']['X']
    temp_0 = ts_dict['temp']['Y'][0]  # Right above DiMES.
    temp_7 = ts_dict['temp']['Y'][
        -1]  # Topmost chord near separatrix (167196, 167536).

    # Get the data in the time range.
    low = np.where(time > start_time)[0].min()
    high = np.where(time < end_time)[0].max()
    time = time[low:high]
    temp_0 = temp_0[low:high]
    temp_7 = temp_7[low:high]
    avg_temp_0 = np.mean(temp_0)
    avg_temp_7 = np.mean(temp_7)
    print("Chord 0: {:.2f}\nChord 7: {:.2f}".format(avg_temp_0, avg_temp_7))

    dens_0 = ts_dict['density']['Y'][0]  # Right above DiMES.
    dens_7 = ts_dict['density']['Y'][
        -1]  # Topmost chord near separatrix (167196, 167536).

    dens_0 = dens_0[low:high]
    dens_7 = dens_7[low:high]
    avg_dens_0 = np.mean(dens_0)
    avg_dens_7 = np.mean(dens_7)
    print("Chord 0: {:.2f}\nChord 7: {:.2f}".format(avg_dens_0, avg_dens_7))

    # Plot temp and density at each chord location.
    fig = plt.figure()
    ax1 = fig.add_subplot(211)  # Chord 7
    ax1.plot(ts_dict['temp']['X'], ts_dict['temp']['Y'][-1], 'r.')
    ax1.set_xlim([0, 6000])
    ax1.set_ylim([0, 500])
    ax1.set_ylabel('Te (eV)')
    ax2 = fig.add_subplot(212)  # Chord 0
    ax2.plot(ts_dict['temp']['X'], ts_dict['temp']['Y'][0], 'r.')
    ax2.set_xlim([0, 6000])
    ax2.set_ylim([0, 50])
    ax2.set_ylabel('Te (eV)')
    ax2.set_xlabel('Time (ms)')
    fig.tight_layout()
    fig.show()

    fig = plt.figure()
    ax1 = fig.add_subplot(211)  # Chord 7
    ax1.plot(ts_dict['density']['X'], ts_dict['density']['Y'][-1], 'r.')
    ax1.set_xlim([0, 6000])
    #ax1.set_ylim([0,500])
    ax1.set_ylabel('ne (m-3)')
    ax2 = fig.add_subplot(212)  # Chord 0
    ax2.plot(ts_dict['density']['X'], ts_dict['density']['Y'][0], 'r.')
    ax2.set_xlim([0, 6000])
    #ax2.set_ylim([0,50])
    ax2.set_ylabel('ne (m-3)')
    ax2.set_xlabel('Time (ms)')
    fig.tight_layout()
    fig.show()

    return ts_dict
def fit_ne(shot, lowlim=None, uplim=None, tmin=2000, tmax=4000):
    ts_dict = ts.run_script(shot, 'core', tmin=tmin, tmax=tmax)

    x_ts = ts_dict['psins']['avg_omps'] * 100
    y_te = ts_dict['psins']['avg_Tes']
    y_ne = ts_dict['psins']['avg_nes'] * 10e-18

    x_ts_err = ts_dict['psins']['avg_omps_err'] * 100
    y_te_err = ts_dict['psins']['avg_Tes_err']
    y_ne_err = ts_dict['psins']['avg_nes_err'] * 10e-18

    x_ts = x_ts[np.where(x_ts > 0)[0]][lowlim:uplim]
    y_te = y_te[np.where(x_ts > 0)[0]]
    y_ne = y_ne[np.where(x_ts > 0)[0]]

    x_ts_err = x_ts_err[np.where(x_ts > 0)[0]]
    y_te_err = y_te_err[np.where(x_ts > 0)[0]]
    y_ne_err = y_ne_err[np.where(x_ts > 0)[0]]

    def exp_fit(x, a, b):
        return a * np.exp(-x * b)

    popt_te, pcov_te = curve_fit(exp_fit, x_ts, y_te)
    popt_ne, pcov_ne = curve_fit(exp_fit, x_ts, y_ne)
    x_fit = np.linspace(0, 14, 100)
    y_fit_te = exp_fit(x_fit, *popt_te)
    y_fit_ne = exp_fit(x_fit, *popt_ne)

    print("ne fall off length:       {:.3f}".format(1 / popt_ne[1]))
    errs = np.sqrt(np.diag(pcov_ne))
    print("ne fall off length error: {:.4f}".format(
        (errs[1] / popt_ne[1]) * (1 / popt_ne[1])))
    print("Te fall off length:       {:.3f}".format(1 / popt_te[1]))
    errs = np.sqrt(np.diag(pcov_te))
    print("Te fall off length error: {:.4f}".format(
        (errs[1] / popt_te[1]) * (1 / popt_te[1])))

    font = {'fontsize': 24, 'weight': 'bold'}
    plt.style.use('seaborn')
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    ax1.errorbar(x_ts, y_ne, y_ne_err, 0.5, 'k.', ms=20, capsize=5, capthick=1)
    ax1.plot(x_fit, y_fit_ne, 'k--', lw=3)
    ax1.set_xlabel('R-Rsep omp (cm)', font)
    ax1.set_ylabel(r'$\mathrm{\mathbf{Density\ (1e18\ m^{-3}}}$)', font)
    ax1.tick_params(labelsize=22)
    fig.tight_layout()
    plt.show()
Exemple #4
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]
import get_ts as ts
from scipy.interpolate import Rbf
from scipy.signal import savgol_filter
import numpy as np
import matplotlib.pyplot as plt

shot = 167279
tmin = 2500
tmax = 4000

# Get core TS data (i.e. the dat at the top of the device).
core = ts.run_script(shot, 'core', tmin=2500, tmax=4500, tstep=300)

# Get the divertor TS data (i.e. close to the target).
div = ts.run_script(shot, 'divertor', tmin=2500, tmax=4500, tstep=300)

# Get average psin of divertor TS closest to target.
div_psin = div['psins']['avg_psins'][0]

# Get the raw TS data for the divertor TS.
div_raw_time = div['temp']['X']
div_raw_temp = div['temp']['Y'][0]

# Filter out the spikes from ELMs by just removing data above a threshold.
thresh = 40
div_noelm_time = div_raw_time[np.where(div_raw_temp < thresh)]
div_noelm_temp = div_raw_temp[np.where(div_raw_temp < thresh)]

# Filter the data using a savgol filter.
div_filt_temp = savgol_filter(div_noelm_temp, 51, 3)
167463 : None, None
167481 : None, -5, [2000, 5000]
167530 : 5, None, [2000, 4500]
167531 : 3, None
167534 : None, None
167536 : None, -4
167618 :


"""
lowlim = None  # Furthest points out to ignore. Must be positive.
uplim = None  # Closest points to ignore. Must be negative.
r_tip = 6.84  # Tip coordinate as distance from sep at omp.

if True:
    ts_dict = ts.run_script(167537, 'core', tmin=3700, tmax=5400)

x_ts = ts_dict['psins']['avg_omps'] * 100
y_te = ts_dict['psins']['avg_Tes']
y_ne = ts_dict['psins']['avg_nes'] * 1e-18

x_ts_err = ts_dict['psins']['avg_omps_err'] * 100
y_te_err = ts_dict['psins']['avg_Tes_err']
y_ne_err = ts_dict['psins']['avg_nes_err'] * 1e-18

x_ts = x_ts[np.where(x_ts > 0)[0]][lowlim:uplim]
y_te = y_te[np.where(x_ts > 0)[0]]
y_ne = y_ne[np.where(x_ts > 0)[0]]

x_ts_err = x_ts_err[np.where(x_ts > 0)[0]]
y_te_err = y_te_err[np.where(x_ts > 0)[0]]
import sys
sys.path.append("/home/shawn/DIII-D/ORNL-Fusion/Collector-Probes")
import get_ts as ts
import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import savgol_filter
from scipy.interpolate import interp1d

ts192 = ts.run_script(167192, "core", tmin=1900, tmax=3000, tstep=150)
ts193 = ts.run_script(167193, "core", tmin=1900, tmax=3000, tstep=150)
ts194 = ts.run_script(167194, "core", tmin=1900, tmax=3000, tstep=150)
ts195 = ts.run_script(167195, "core", tmin=1900, tmax=3000, tstep=150)

all_psin = np.array([])
all_Te = np.array([])
all_Te_err = np.array([])
for ts_dict in [ts192, ts193, ts194, ts195]:
    psin = ts_dict["psins"]["avg_psins"][:-1]
    all_psin = np.append(all_psin, psin)
    Te = ts_dict["psins"]["avg_Tes"][:-1]
    Te_err = ts_dict["psins"]["avg_Tes_err"][:-1]
    all_Te = np.append(all_Te, Te)
    all_Te_err = np.append(all_Te_err, Te_err)
    shot = ts_dict["shot"]
    #plt.plot(psin, Te, label=str(shot))

# Sort all_psin and all_Te.
idx = np.argsort(all_psin)
all_psin = all_psin[idx]
all_Te = all_Te[idx]
all_Te_err = all_Te_err[idx]
Exemple #8
0
    # Only R's on the right half.
    Rs_trunc = Rs > R_axis

    # Interpolation functions of psin(R, Z) and R(psin, Z).
    f_psin = scinter.Rbf(Rs[Rs_trunc], Zs[Rs_trunc], gfile['psiRZn'][Rs_trunc])

    # No we have the function we want, psin(R, Z). Let's get those psins.
    lp_psins = np.array([f_psin(r, -0.18) for r in lp_r])

    # Plot it just to check it looks good.
    #plt.plot(lp_psins, lp_te)
    #plt.show()

    # Great looks good. Let's get the TS data now.
    ts_dict = ts.run_script(167192, "core", tmin=2930, tmax=2990, tstep=20)
    ts_psins = ts_dict["psins"]["avg_psins"]
    ts_te = ts_dict["psins"]["avg_Tes"]

    def exp_fit(x, a, b, c):
        return a * np.exp(-b * (x - 1.0)) + c

    last_sol_index = np.argmax(ts_psins < 1.0)
    popt, pcov = curve_fit(exp_fit,
                           ts_psins[:last_sol_index],
                           ts_te[:last_sol_index],
                           maxfev=5000)
    fit_to_ts = exp_fit(np.arange(0.9, 1.5, 0.01), *popt)

    # And now let's plot them together.
    plt.rcParams.update({'font.size': 22})