Esempio n. 1
0
def do_plot(ffx, ffy, figx, figy):
    fnet = ffy + figy
    fig = pp.pplot(ffx, ffy, fmt='-', label='FF', color=4, alpha=0.7)
    fig = pp.pplot(ffx,
                   figy,
                   fmt='-',
                   label='FiG',
                   color=6,
                   fig=fig,
                   alpha=0.7)
    fig = pp.pplot(figx,
                   fnet,
                   fmt='-',
                   label='Fnet',
                   fig=fig,
                   xlabel='s (m)',
                   ylabel='Force (N)',
                   logy=False,
                   linthreshy=1e-20,
                   color=20,
                   weight='bold',
                   yrange=[-0.4e-17, 0.4e-17])

    # Want grid lines.
    #yticks = np.array([1e-16, 1e-17, 1e-18, 1e-19, 1e-20])
    #fig.axes[0].set_yticks(np.append(yticks, -yticks), minor=True)
    #fig.axes[0].grid(True, which='minor')
    fig.axes[0].grid(True, which='major')
    fig.tight_layout()
    fig.show()
def plot_centerline():
    # Do centerline plots.
    fig = pp.pplot(itf_x, itf_y, fmt='-', label='ITF')
    fig = pp.pplot(otf_x,
                   otf_y,
                   fmt='-',
                   fig=fig,
                   color=8,
                   label='OTF',
                   xlabel='Distance along probe (m)',
                   ylabel='Deposition (arbitrary units)')
def run(shot, tag, units, mult=1):
    conn = mds.Connection('localhost')
    ga_obj = gadata(tag, shot, connection=conn)
    time = ga_obj.xdata
    value = ga_obj.zdata * mult

    fig = pp.pplot(time,
                   value,
                   fmt='-',
                   xlabel='Time (ms)',
                   ylabel=tag.upper() + ' (' + units + ')',
                   xrange=[0, 6000])
    minmax = input(
        'Enter time min/max for analysis range (separated by commas): ').split(
            ',')

    min_idx = np.where(time > float(minmax[0]))[0][0]
    max_idx = np.where(time > float(minmax[1]))[0][0]

    avg_value = np.mean(value[min_idx:max_idx])

    # Convert from kW to MW.
    print('Average {}: {:.3f} {}'.format(tag.upper(), avg_value, units))

    return ga_obj
Esempio n. 4
0
def itf_otf_plot():
    lambda_ne = np.array([
        4.605, 4.544, 3.410, 5.623, 3.058, 2.164, 1.722, 2.612, 2.401, 2.027,
        1.453
    ])
    lambda_ne_err = np.array([
        0.4552, 0.5542, 0.7938, 1.2043, 0.4252, 0.3956, 0.2197, 0.7343, 0.4476,
        0.2407, 0.251
    ])
    itf_otf = np.array([
        3.323809525, 2.302325577, 1.733333322, 2.91666666, 0.749999985,
        1.850000003, 0.86734694, 0.800000011, 0.727272725, 1.375000004,
        0.345238096
    ])
    itf_otf_err = np.array([
        0.393703608, 0.462717516, 0.445963232, 0.6249957, 0.406947537,
        0.589904423, 0.138455898, 0.372362303, 0.222509805, 0.420682602,
        0.083429511
    ])

    fig = pp.pplot(x=lambda_ne,
                   xerr=lambda_ne_err,
                   y=itf_otf,
                   yerr=itf_otf_err,
                   ms=11,
                   xlabel='Plasma Density Falloff, ' + r'$\bf{\lambda}$' +
                   ' (cm)',
                   ylabel='ITF/OTF Max W Content',
                   weight='bold')
def plot_avg_pol():
    x = pol_locs
    y = np.mean(dep_arr, axis=1) / np.max(np.mean(dep_arr, axis=1))
    fig = pp.pplot(x,
                   y,
                   xlabel='Z Location (m)',
                   ylabel='Normalized Counts',
                   xrange=[-0.003, 0.003])
Esempio n. 6
0
def lmode_probe_plot():
    filename = '/mnt/c/Users/Shawn/Google Drive/July Backup/d3dscripts/Data/LModeProbes.xlsx'
    df = pd.read_excel(filename, sheet_name='A2', usecols=range(0,
                                                                14)).dropna()

    xd = df['rminrsep_D']
    xd_err = df['rminrsep_err_D']
    yd = df['w_areal_D']
    yd_err = df['w_areal_err_D']
    xu = df['rminrsep_U']
    xu_err = df['rminrsep_err_U']
    yu = df['w_areal_U']
    yu_err = df['w_areal_err_U']

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

    poptd, pcovd = curve_fit(exp_fit, xd[:-3], yd[:-3])
    x_fitd = np.linspace(7, 15, 100)
    y_fitd = exp_fit(x_fitd, *poptd)
    poptu, pcovu = curve_fit(exp_fit, xu[:-3], yu[:-3])
    x_fitu = np.linspace(7, 15, 100)
    y_fitu = exp_fit(x_fitu, *poptu)

    fig = pp.pplot(x_fitd, y_fitd, fmt='--', lw=3)
    fig = pp.pplot(x_fitu, y_fitu, fmt='--', color=8, lw=3, fig=fig)
    fig = pp.pplot(xd, yd, yerr=yd_err, ms=12, label='ITF', fig=fig)
    fig = pp.pplot(
        xu,
        yu,
        yerr=yu_err,
        ms=12,
        color=8,
        label='OTF',
        fig=fig,
        yrange=[0, 0.6],
        xlabel=r'$\mathrm{\bf{R-R_{sep}\ (cm)}}$',
        ylabel=r'$\mathrm{\bf{W\ Areal\ Density\ (10^{18}\ cm^{-2})}}$')
Esempio n. 7
0
def flat_top(shot):

    # Load densv2 tag data.
    conn = mds.Connection('localhost')
    ga_obj = gadata('densv2', shot, connection=conn)
    time = ga_obj.xdata
    dens = ga_obj.zdata

    # Plot and ask for the flat top range.
    fig = pp.pplot(time, dens, fmt='-',  xlabel='Time (ms)', ylabel=r'$\mathrm{\bar{n_e}\ (m^{-3})}$')
    minmax = input('Enter time min/max for analysis range (separated by commas): ').split(',')

    # Return requested time range for use in TS function (min, max).
    return int(minmax[0]), int(minmax[1])
def lambdas():
    def exp_fit(x, a, b):
        return a * np.exp(-x * b)

    itf_popt, itf_pcov = curve_fit(exp_fit, itf_x, itf_y)
    otf_popt, otf_pcov = curve_fit(exp_fit, otf_x, otf_y)
    itf_x_fit = np.linspace(itf_x.min(), itf_x.max(), 100)
    otf_x_fit = np.linspace(otf_x.min(), otf_x.max(), 100)
    itf_y_fit = exp_fit(itf_x_fit, *itf_popt)
    otf_y_fit = exp_fit(otf_x_fit, *otf_popt)

    print('ITF Lambda = {:.4f}'.format(1 / itf_popt[1]))
    print('OTF Lambda = {:.4f}'.format(1 / otf_popt[1]))

    fig = None
    fig = pp.pplot(itf_x_fit,
                   itf_y_fit,
                   '--',
                   label='ITF Fit',
                   color=6,
                   fig=fig)
    fig = pp.pplot(otf_x_fit,
                   otf_y_fit,
                   '--',
                   label='OTF Fit',
                   color=8,
                   fig=fig)
    fig = pp.pplot(itf_x, itf_y, '.', label='ITF', fig=fig)
    fig = pp.pplot(otf_x,
                   otf_y,
                   '.',
                   label='OTF',
                   color=8,
                   fig=fig,
                   xlabel='Distance along probe (m)',
                   ylabel='Deposition Counts')
Esempio n. 9
0
def use_ts(shot, tmin, tmax):
    """
    Calculate the PF stuff using the core TS system.
    """

    # Load in the TS data.
    ts = ThomsonClass(shot, 'core')
    ts.load_ts()
    ts.map_to_efit(np.linspace(tmin, tmax, 10))

    # Pressure as just nkT.
    Rs = ts.avg_omp['RminRsep_omp']

    # Get the part only outside the separatrix.
    outside = np.where(Rs > 0.0)[0]
    Rs = Rs[outside]
    nes = ts.avg_omp['ne_omp'][outside] * 10**(-18)
    Tes = ts.avg_omp['Te_omp'][outside]
    ps = nes * Tes

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

    popt_p, pcov_p = curve_fit(exp_fit, Rs, ps, maxfev=10000)
    popt_ne, pcov_ne = curve_fit(exp_fit, Rs, nes, maxfev=10000)
    popt_te, pcov_te = curve_fit(exp_fit, Rs, Tes, maxfev=10000)

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

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

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

    fig = pp.pplot(Rs, Tes)
    fig = pp.pplot(fit_Rs, fit_tes, fig=fig, fmt='--', ylabel='Te')

    # dp/dr at the sep, multiply to make correct units.
    dpdr = -popt_p[1] * exp_fit(0, *popt_p) * 10**(18) * 1.609 * 10**(-19)
    nesep = exp_fit(0, *popt_ne) * 10**(18)
    print('dp/dr at separatrix (J/m3 or N/m2): {:.3e}'.format(dpdr))
    print('ne at separatrix (m-3):             {:.3e}'.format(nesep))
Esempio n. 10
0
def run(shot):
    conn = mds.Connection('localhost')
    ga_obj = gadata('pinj', shot, connection=conn)
    time = ga_obj.xdata
    pinj = ga_obj.zdata

    fig = pp.pplot(time,
                   pinj,
                   fmt='-',
                   xlabel='Time (ms)',
                   ylabel='PINJ (kW)',
                   xrange=[0, 6000])
    minmax = input(
        'Enter time min/max for analysis range (separated by commas): ').split(
            ',')

    min_idx = np.where(time > float(minmax[0]))[0][0]
    max_idx = np.where(time > float(minmax[1]))[0][0]

    avg_pinj = np.mean(pinj[min_idx:max_idx])

    # Convert from kW to MW.
    print('Average PINJ: {:.2f} MW'.format(avg_pinj / 1000))
Esempio n. 11
0
import numpy as np
import pretty_plots as pp

ip = np.array([
    0.995, 1.472, 1.472, 0.506, 0.508, 0.989, 0.989, 0.987, 1.474, 0.697,
    0.699, 0.989, 0.990, 0.991, 0.994, 0.993, 0.992, 0.991, 0.988, 0.988
])
lambda_ne = np.array([
    6.07, 4.78, 4.95, 15.15, 21.60, 11.26, 8.41, 8.02, 6.57, 10.86, 11.34,
    8.20, 8.31, 7.81, 9.47, 9.12, 11.13, 10.11, 6.44, 7.03
]) / 10.0

fig = pp.pplot(ip,
               lambda_ne,
               xlabel='IP (MA)',
               ylabel=r'$\mathrm{\lambda_{ne}}$' + ' (cm)')
Esempio n. 12
0
import pandas as pd
import numpy as np
import pretty_plots as pp

filename = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/My Slides and Sheets/2019/03/aprobe_totals.xlsx'
df = pd.read_excel(filename, sheet_name='A Probes', usecols=np.arange(0,
                                                                      7))[0:19]

x = df['# of lambdas'].values
y = df['ITF/OTF Total'].values
xr = np.array([])
yr = np.array([])
xf = np.array([])
yf = np.array([])
xr = np.concatenate([xr, x[:6], x[14:16]])
yr = np.concatenate([yr, y[:6], y[14:16]])
xf = np.concatenate([x[5:14], x[16:]])
yf = np.concatenate([y[5:14], y[16:]])

fig = pp.pplot(xr, yr, color=8, label='Reverse')
fig = pp.pplot(xf,
               yf,
               xlabel="# of " + r'$\mathrm{\lambda_{ne}}$' +
               "'s from separatrix",
               ylabel='Total ITF/OTF',
               label='Forward',
               fig=fig)
                    op_r  = np.append(op_r, r)

# Restrict to just outside the separatrix. Informal, but anything above Z = 0.75 is SOL here.
sol   = np.where(op_z > 0.75)[0]
op_z  = op_z[sol]
op_ne = op_ne[sol]
op_te = op_te[sol]

sol_ts   = np.where(z_vals > 0.75)[0]
z_vals   = z_vals[sol_ts]
avg_dens = avg_dens[sol_ts]
avg_temp = avg_temp[sol_ts]

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

popt_op, pcov_op = curve_fit(exp_fit, op_z, op_ne/1e18, maxfev=10000)
popt_ts, pcov_ts = curve_fit(exp_fit, z_vals, avg_dens/1e18, maxfev=10000)

fit_z = np.linspace(0.75, 0.85, 100)
fit_op = exp_fit(fit_z, *popt_op)
fit_ts = exp_fit(fit_z, *popt_ts)

fig = pp.pplot(fit_z, fit_op*1e18, fmt='--', color=8)
fig = pp.pplot(fit_z, fit_ts*1e18, fmt='--', color=6, fig=fig)
fig = pp.pplot(z_vals, avg_dens, fmt='.', label='TS', ms=20, fig=fig)
fig = pp.pplot(op_z, op_ne, fmt='.', label='OEDGE', fig=fig, xlabel='Z (m)', ylabel='ne (m-3)', color=8, ms=20)

print('OEDGE lambda ne: {:.2f} cm'.format(1/popt_op[1]*100))
print('TS lambda ne:    {:.2f} cm'.format(1/popt_ts[1]*100))
import pandas as pd
import pretty_plots as pp
import matplotlib.pyplot as plt



filename = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/' + \
           'energy_use_world.xlsx'
df = pd.read_excel(filename, skiprows=4)

fig = pp.pplot(df['Year'],
               df['Energy use: Total World quad Btu'],
               xlabel='Year',
               ylabel='World Energy Use (quad Btu)',
               fmt='-')

# Stack plot.

filename = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/' + \
           'world_energy_by_sector.xlsx'

df = pd.read_excel(filename, skiprows=4)

# These are the "Tableau 20" colors as RGB.
tableau20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),
             (44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),
             (148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),
             (227, 119, 194), (247, 182, 210), (127, 127, 127),
             (199, 199, 199), (188, 189, 34), (219, 219, 141), (23, 190, 207),
             (158, 218, 229)]
Esempio n. 15
0
xl_path = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/Slides, Sheets and Documents/2019/07/lp_with_a2.xlsx'
df = pd.read_excel(xl_path, skiprows=1, sheet_name='Sheet1')

all_lp_x = df['R-Rsep OMP (cm)'].values[:250]
all_lp_y = df['ne (1e18 m-3)'].values[:250]
bin_lp_x = df['R-Rsep OMP (cm).1'].values[:250]
bin_lp_x_err = df['Error (cm)'].values[:250]
bin_lp_y = df['ne (1e18 m-3).1'].values[:250]
bin_lp_y_err = df['Error'].values[:250]
bin_lp_x = bin_lp_x[~np.isnan(bin_lp_x)][2:]
bin_lp_y = bin_lp_y[~np.isnan(bin_lp_y)][2:]
bin_lp_x_err = bin_lp_x_err[~np.isnan(bin_lp_x_err)][2:]
bin_lp_y_err = bin_lp_y_err[~np.isnan(bin_lp_y_err)][2:]

fig = pp.pplot(all_lp_x, all_lp_y, alpha=0.1, ms=5, logy=True, color=20)
fig = pp.pplot(bin_lp_x,
               bin_lp_y,
               logy=True,
               yrange=[0.1, 10],
               xrange=[4, 14],
               fig=fig,
               color=20,
               xerr=bin_lp_x_err,
               yerr=bin_lp_y_err)

main_exp_a = 25.185
main_exp_b = -0.252
wind_exp_a = 23880
wind_exp_b = -0.845
Esempio n. 16
0
if 0 in plots:
    fig = plt.figure()
    ax1 = fig.add_subplot(111)
    ax1.plot(s, df1['Ti (eV)'], '-', color=pp.tableau20[6], lw=3)
    ax1.set_xlabel('s (m)', fontsize=fontsize)
    ax1.set_ylabel('Ti (eV)', color=pp.tableau20[6], fontsize=fontsize)
    ax1.tick_params(axis='y', labelcolor=pp.tableau20[6])
    ax2 = ax1.twinx()
    ax2.plot(s, df1['dTi/ds'], '-', color=pp.tableau20[8], lw=3)
    ax2.set_ylabel('dTi/ds (eV/m)', color=pp.tableau20[8], fontsize=fontsize)
    ax2.tick_params(axis='y', labelcolor=pp.tableau20[8])
    fig.tight_layout()
    fig.show()

if 1 in plots:
    fig = pp.pplot(s, df1['Ti (eV)'], fmt='-', xlabel='s (m)', ylabel='Ti (eV)')
    fig = pp.pplot(s, df1['dTi/ds'], fmt='-', xlabel='s (m)', ylabel='dTi/ds (eV/m)')

if 2 in plots:
    fig = pp.pplot(s, df2['M - R.2'], color=8, fmt='-', label='Reverse')
    fig = pp.pplot(s, df2['M - F.2'], color=6, fmt='-', label='Forward', fig=fig)

    s_look = [2.70802535, 27.0802535, 54.160507, 81.2407605, 97.4889126]
    r_look = [-0.5, -0.2, 0, 0.8, 0.5]
    f_look = [-0.5, 0.3, 0.5, 0.5, 0.3]

    fig = pp.pplot(s_look, r_look, color=8, ms=12, fig=fig)
    fig = pp.pplot(s_look, f_look, color=6, ms=12, fig=fig, xlabel='s (m)', ylabel='Mach Number')

if 3 in plots:
    fig = pp.pplot(s, df1['vTi (m/s)'], color=14, fmt='--')
Esempio n. 17
0
def plot_with_rbs(lams_path, rbs_path, u_or_d, cal_slope, cal_intercept, middle=2.0, r_shift=0, color=6, avg=False):
    """
    u_or_d: Either 'U' or 'D'.
    """

    # Load DataFrames.
    lams_df = pd.read_excel(lams_path, sheet_name='MapData')
    rbs_df  = pd.read_excel(rbs_path)

    # Get relevant RBS data.
    dist = np.array(rbs_df['Distance from Tip ' + u_or_d + ' (cm)'].values, dtype=np.float64)
    omp  = np.array(rbs_df['R-Rsep omp ' + u_or_d + ' (cm)'].values, dtype=np.float64)
    w_rbs    = rbs_df['W Areal Density ' + u_or_d + ' (1e15 W/cm2)'].values

    # Remove blanks.
    dist = dist[~np.isnan(dist)]
    omp = omp[~np.isnan(omp)]
    w_rbs = w_rbs[~np.isnan(w_rbs)]

    # Do a fit to get R-Rsep OMP for the LAMS data.
    p = np.polyfit(dist, omp, 1)
    lams_df['R-Rsep omp (cm)'] = p[1] + p[0] * lams_df['Axial Location [mm]'] / 10.0

    # Create a 2D DataFrame of just the Total W measurements (for RBS comparison).
    omp_locs = lams_df['R-Rsep omp (cm)'].unique()
    z_locs   = lams_df['z Location [mm]'].unique()
    total_df = pd.DataFrame()
    for z in z_locs:
        total_df[z] = lams_df[lams_df['z Location [mm]'] == z]['Total W'].values

    # Set index as the omp locations.
    total_df.set_index(omp_locs, inplace=True)

    if avg:
        r = total_df[middle].index.values
        #w = total_df.median(axis=1).values
        w = total_df.mean(axis=1).values
        w_err = total_df.mean(axis=1).values

    else:
        # Get the centerline data near where RBS was taken.
        r = total_df[middle].index.values
        w = total_df[middle].values

    # Use calibration to convert from counts to areal density.
    w = w * cal_slope + cal_intercept

    # Shift LAMS R data if asked.
    r = r + r_shift

    # Plot it.
    fig = pp.pplot(r, w, fmt='-', label='LAMS', color=color)
    fig = pp.pplot(omp, w_rbs, fmt='.', ms=15, fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='W Areal Density (1e15 cm-2)', label='RBS', color=color)

    fig, ax = plt.subplots()
    if avg:
        ax.errorbar(r, w, yerr=w_err)
    else:
        ax.plot(r, w, '-', label='LAMS', color=pp.tableau20[color])

    return {'LAMS Romp':r, 'LAMS W':w}
import pretty_plots as pp


test = '44'
filename = '/mnt/c/Users/Shawn/Documents/d3d_work/3DLIM Runs/colprobe-a8_test'+test+'.nc'
net = netCDF4.Dataset(filename)
print('Test: ' + test)

# 2D array of deposition data.
dep_arr = np.array(net.variables['NERODS3'][0] * -1)

# Location of each P bin, and its width. Currently they all have the same width,
# but it may end up such that there are custom widths so we leave it like this.
ps     = np.array(net.variables['PS'][:].data)
pwids  = np.array(net.variables['PWIDS'][:].data)

# Array of poloidal locations (i.e. the center of each P bin).
pol_locs = ps - pwids/2.0

# Distance cell centers along surface (i.e. the radial locations).
rad_locs = np.array(net.variables['ODOUTS'][:].data)

# Drop last row since it's garbage.
dep_arr = dep_arr[:-1, :]
pol_locs = pol_locs[:-1]

# Get data across probe closest to R = 10mm.
pol_slice = dep_arr[:, np.where(rad_locs > 0)[0][0]]

fig = pp.pplot(pol_locs, pol_slice, xrange=[-0.02,0.02])
df = pd.read_excel(filename, index_col=0)
df.drop(df.columns[-1], axis=1, inplace=True)
df.rename({'0.1': 0.0, '0.2': 0.0}, axis=1, inplace=True)

# Get each side of probe, and a centerline (P=0).
itf_x = df.iloc[df.index > 0.0][0].index.values * 100
itf_y = df.iloc[df.index > 0.0][0].values * -1
otf_x = df.iloc[df.index < 0.0][0].index.values * -1 * 100
otf_y = df.iloc[df.index < 0.0][0].values * -1


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


itf_popt, itf_pcov = curve_fit(exp_fit, itf_x, itf_y)
otf_popt, otf_pcov = curve_fit(exp_fit, otf_x, otf_y)
itf_x_fit = np.linspace(itf_x.min(), itf_x.max(), 100)
otf_x_fit = np.linspace(otf_x.min(), otf_x.max(), 100)
itf_y_fit = exp_fit(itf_x_fit, *itf_popt)
otf_y_fit = exp_fit(otf_x_fit, *otf_popt)

print('ITF Lambda = {:.2f}'.format(1 / itf_popt[1]))
print('OTF Lambda = {:.2f}'.format(1 / otf_popt[1]))

fig = None
fig = pp.pplot(itf_x_fit, itf_y_fit, '--', label='ITF Fit', color=6, fig=fig)
fig = pp.pplot(otf_x_fit, otf_y_fit, '--', label='OTF Fit', color=8, fig=fig)
fig = pp.pplot(itf_x, itf_y, '.', label='ITF', fig=fig)
fig = pp.pplot(otf_x, otf_y, '.', label='OTF', color=8, fig=fig)
Esempio n. 20
0
]) * 1E13

#neerr_unf = nebar_unf * 0.1
#neerr_fav = nebar_fav * 0.1

itfotf_unf = np.array([3.77, 5.25, 2.22, 2.50, 2.86])
itfotf_fav = np.array(
    [0.35, 0.45, 0.41, 0.63, 0.29, 0.87, 0.82, 0.53, 0.66, 1.08, 1.15, 1.42])

yerrs_unf = itfotf_unf * 0.1
yerrs_fav = itfotf_fav * 0.1

fig = pp.pplot(nebar_unf,
               itfotf_unf,
               yerr=yerrs_unf,
               color=8,
               logy=True,
               fmt='s',
               ms=13,
               label='Bx' + r'$\nabla$' + 'B' + r'$\uparrow$')
fig = pp.pplot(nebar_fav,
               itfotf_fav,
               yerr=yerrs_fav,
               color=6,
               logy=True,
               ms=13,
               label='Bx' + r'$\nabla$' + 'B' + r'$\downarrow$',
               fig=fig,
               xlabel='Plasma Density (cm-3)',
               ylabel='ITF/OTF W Content',
               yrange=[0.1, 10],
               xrange=[1e13, 9e13])
Esempio n. 21
0
def run(probe, psin_offset=0.0, identify_psin=True):

    # First load the probe Excel sheet.
    rbs_df = pd.read_excel(top_path + probe + '.xlsx')
    shot = probes[probe]

    # Get the psin and W data, grabbing the correct side.
    if probe in ['A2', 'A3', 'A4', 'A7', 'A8']:
        itf_side = 'D'
        otf_side = 'U'
    else:
        itf_side = 'U'
        otf_side = 'D'

    psin_itf = rbs_df['Psin ' + itf_side]
    psin_otf = rbs_df['Psin ' + otf_side]
    w_itf = rbs_df['W Areal Density ' + itf_side + ' (1e15 W/cm2)']
    w_otf = rbs_df['W Areal Density ' + otf_side + ' (1e15 W/cm2)']

    # Then grab the MAFOT data. Need to make sure I keep these in the same format.
    mafot_path = top_path + 'Connection Lengths/' + str(shot) + '/' + str(
        shot) + '.xlsx'
    mafot_itf_df = pd.read_excel(mafot_path,
                                 sheet_name='MAFOT ITF',
                                 skiprows=2)
    mafot_otf_df = pd.read_excel(mafot_path,
                                 sheet_name='MAFOT OTF',
                                 skiprows=2)

    # Clean up the data a bit.
    psin_itf = psin_itf[~np.isnan(psin_itf)]
    psin_otf = psin_otf[~np.isnan(psin_otf)]
    w_itf = w_itf[~np.isnan(w_itf)]
    w_otf = w_otf[~np.isnan(w_otf)]

    # Find closest index in mafot data to this psin.
    psin_mafot_itf = mafot_itf_df['psi'].values
    psin_mafot_otf = mafot_otf_df['psi'].values
    idx_itf = [(np.abs(psin_mafot_itf - psin + psin_offset)).argmin()
               for psin in psin_itf]
    idx_otf = [(np.abs(psin_mafot_otf - psin + psin_offset)).argmin()
               for psin in psin_otf]

    # Grab the connection lengths, convert from km to cm.
    itf_L = mafot_itf_df['Connection Length (km)'].values[idx_itf] * 100000
    otf_L = mafot_otf_df['Connection Length (km)'].values[idx_otf] * 100000

    # We may need help identifying what the psin_offset should be. Let's plot
    # it out on a log plot and see if it may be obvious.
    if identify_psin:
        fig1, ax1 = plt.subplots()
        ax1.set_xlabel('Psin')
        ax1.set_ylabel('W Areal Density', color='r')
        ax1.semilogy(psin_itf, w_itf, '.', color='r')
        ax1.tick_params(axis='y', labelcolor='r')
        ax1.set_xlim([1.1, 1.4])
        #ax1.set_ylim([5e2, None])
        ax2 = ax1.twinx()
        ax2.set_ylabel('Lconn (cm)')
        ax2.semilogy(psin_mafot_itf + psin_offset,
                     mafot_itf_df['Connection Length (km)'] * 100000,
                     '-',
                     color='k')
        ax2.set_title('ITF')
        fig1.tight_layout()
        fig1.show()

        fig2, ax3 = plt.subplots()
        ax3.set_xlabel('Psin')
        ax3.set_ylabel('W Areal Density', color='r')
        ax3.semilogy(psin_otf, w_otf, '.', color='r')
        ax3.tick_params(axis='y', labelcolor='r')
        ax3.set_xlim([1.1, 1.4])
        #ax3.set_ylim([5e2, None])
        ax4 = ax3.twinx()
        ax4.set_ylabel('Lconn (cm)')
        ax4.semilogy(psin_mafot_otf + psin_offset,
                     mafot_otf_df['Connection Length (km)'] * 100000,
                     '-',
                     color='k')
        ax4.set_title('OTF')
        #ax4.set_ylim([1e1, 1e3])
        fig2.tight_layout()
        fig2.show()

    # Calculate the W per cm.
    w_per_cm_itf = w_itf / itf_L
    w_per_cm_otf = w_otf / otf_L

    # Plot it out.
    fig = pp.pplot(psin_itf, w_per_cm_itf, color=8, label='ITF', fmt='-')
    fig = pp.pplot(psin_otf,
                   w_per_cm_otf,
                   color=6,
                   label='OTF',
                   fmt='-',
                   xlabel='Psin',
                   ylabel='W per Lconn',
                   fig=fig)
Esempio n. 22
0
def run(probe):
    """
    probe: Either 'a', 'b', or 'c'.
    """

    if probe == 'a':

        middle = 2.0

        a08itf = plot_with_rbs(a08itf_path, a08rbs_path, 'D', 0.5E-06, 0, color=8, middle=middle)
        a08otf = plot_with_rbs(a08otf_path, a08rbs_path, 'U', 0.5E-06, 0, color=8, middle=middle)
        a15itf = plot_with_rbs(a15itf_path, a15rbs_path, 'U', 5.015E-07, 0, r_shift=0, middle=middle)
        a15otf = plot_with_rbs(a15otf_path, a15rbs_path, 'D', 5.015E-07, 0, r_shift=0, middle=middle)

        ignore = 15

        fig = pp.pplot(a15itf['LAMS Romp'][ignore+55:], a15itf['LAMS W'][ignore+55:], fmt='-',  color=6, lw=7)
        fig = pp.pplot(a15otf['LAMS Romp'][ignore+90:], a15otf['LAMS W'][ignore+90:], fmt='-', color=6, lw=3, fig=fig)
        fig = pp.pplot(a08itf['LAMS Romp'][ignore:], a08itf['LAMS W'][ignore:], fmt='-',  color=8, lw=7, fig=fig)
        fig = pp.pplot(a08otf['LAMS Romp'][ignore:], a08otf['LAMS W'][ignore:], fmt='-', color=8, lw=3, fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='W Areal Density (1e15 cm-2)')

    elif probe == 'b':

        middle = 2.0

        # This is the actual calibration for B5. Very nice. Currently using same
        # value for B7 until we actually get to LAMS it.
        b05itf = plot_with_rbs(b05itf_path, b05rbs_path, 'D', 5.0E-07, 0, color=8, middle=middle)
        b05otf = plot_with_rbs(b05otf_path, b05rbs_path, 'U', 5.0E-07, 0, color=8, middle=middle)
        b07itf = plot_with_rbs(b07itf_path, b07rbs_path, 'U', 5.0E-07, 0, r_shift=0, middle=middle)
        b07otf = plot_with_rbs(b07otf_path, b07rbs_path, 'D', 5.0E-07, 0, r_shift=0, middle=middle)

        ignore = 0

        fig = pp.pplot(b07itf['LAMS Romp'][ignore:], b07itf['LAMS W'][ignore:], fmt='-',  color=6, lw=3)
        fig = pp.pplot(b07otf['LAMS Romp'][ignore:], b07otf['LAMS W'][ignore:], fmt='--', color=6, lw=3, fig=fig)
        fig = pp.pplot(b05itf['LAMS Romp'][ignore:], b05itf['LAMS W'][ignore:], fmt='-',  color=8, lw=3, fig=fig)
        fig = pp.pplot(b05otf['LAMS Romp'][ignore:], b05otf['LAMS W'][ignore:], fmt='--', color=8, lw=3, fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='W Areal Density (1e15 cm-2)')

    elif probe == 'c':

        middle = 1.25

        c05itf = plot_with_rbs(c05itf_path, c05rbs_path, 'D', 5.0E-07, 0, color=8, middle=middle)
        c05otf = plot_with_rbs(c05otf_path, c05rbs_path, 'U', 5.0E-07, 0, color=8, middle=middle)
        c07itf = plot_with_rbs(c07itf_path, c07rbs_path, 'U', 5.0E-07, 0, r_shift=0, middle=middle)
        c07otf = plot_with_rbs(c07otf_path, c07rbs_path, 'D', 5.0E-07, 0, r_shift=0, middle=middle)

        ignore = 0

        fig = pp.pplot(c07itf['LAMS Romp'][ignore:], c07itf['LAMS W'][ignore:], fmt='-',  color=6, lw=3)
        fig = pp.pplot(c07otf['LAMS Romp'][ignore:], c07otf['LAMS W'][ignore:], fmt='--', color=6, lw=3, fig=fig)
        fig = pp.pplot(c05itf['LAMS Romp'][ignore:], c05itf['LAMS W'][ignore:], fmt='-',  color=8, lw=3, fig=fig)
        fig = pp.pplot(c05otf['LAMS Romp'][ignore:], c05otf['LAMS W'][ignore:], fmt='--', color=8, lw=3, fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='W Areal Density (1e15 cm-2)')

    elif probe == 'a_rev':

        middle = 2.0

        a08itf = plot_with_rbs(a08itf_path, a08rbs_path, 'D', 0.5E-06, 0, color=8, middle=middle)
        a08otf = plot_with_rbs(a08otf_path, a08rbs_path, 'U', 0.5E-06, 0, color=8, middle=middle)

        ignore = 15

        fig = pp.pplot(a08itf['LAMS Romp'][ignore:], a08itf['LAMS W'][ignore:], fmt='-',  color=8, lw=3, label='ITF')
        fig = pp.pplot(a08otf['LAMS Romp'][ignore:], a08otf['LAMS W'][ignore:], fmt='--', color=8, lw=3, label='OTF', fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='W Areal Density (1e15 cm-2)')

    elif probe == 'a_for':

        middle = 2.5

        a15itf = plot_with_rbs(a15itf_path, a15rbs_path, 'U', 5.015E-07, 0, r_shift=0, middle=middle, avg=True)
        a15otf = plot_with_rbs(a15otf_path, a15rbs_path, 'D', 5.015E-07, 0, r_shift=0, middle=middle, avg=True)

        ignore = 80

        fig = pp.pplot(a15itf['LAMS Romp'][ignore:], a15itf['LAMS W'][ignore:], fmt='-',  color=6, lw=8, label='ITF')
        fig = pp.pplot(a15otf['LAMS Romp'][ignore+35:], a15otf['LAMS W'][ignore+35:], fmt='-', color=6, lw=3, label='OTF', fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='W Areal Density (1e15 cm-2)')
Esempio n. 23
0
import pandas as pd
import pretty_plots as pp


filename = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/' + \
           'My Slides and Sheets/2018-10/avg_lams_profs.xlsx'

df = pd.read_excel(filename,
                   sheet_name='Sheet3',
                   skiprows=[0, 1, 2],
                   usecols=[2, 3]).dropna()
fig = pp.pplot(df['Bottom to Top (mm)'],
               df['Norm. Counts'],
               fmt='-',
               xlabel='',
               ylabel='',
               color=0,
               lw=10)
if option == 0:
    for probe in probes:
        print('Now on probe ' + probe)
        filename = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/' + \
                   'Polodial_Scans/'+probe+'_Map.xlsx'
        sheet_name = 'Sheet2'

        df = pd.read_excel(filename, sheet_name=sheet_name).set_index('Radial [mm]')[:-1]

        # Let's look at the ratio of W between pol = 2 / pol = 0.5.
        ratio = df[np.arange(0,2.5,0.25)].sum(axis=1) / df[np.arange(2.5,5,0.25)].sum(axis=1)
        #ratio = df[2.0] / df[0.5]
        ratio_df[probe] = ratio
elif option == 1:
    for probe in probes:
        print('Now on probe ' + probe)
        filename = '/mnt/c/Users/Shawn/Google Drive/School/Tennessee/Research/' + \
                   'Polodial_Scans/'+probe+'_Map.xlsx'
        sheet_name = 'Sheet1'
        df = pd.read_excel(filename, sheet_name=sheet_name).set_index('Radial [mm]')[:-1]
        df = df.drop('Poloidal [mm]')[:202]

        ratio = df[np.arange(0,1.75,0.25)].sum(axis=1) / df[np.arange(1.75,4.5,0.25)].sum(axis=1)
        #ratio = df[1.0] / df[3.75] # For A probe at least, forward
        ratio_df[probe] = ratio


all_ratios = 1.0 / ratio_df.mean(axis=1)
fig = pp.pplot(ratio_df.index.values/10, all_ratios.values, fmt='-', yrange=[0,2.5],
               xlabel='Radial (cm)', ylabel='Top Half / Bottom Half')
sol   = np.where(op_r > rsep_omp)[0]
op_r  = op_r[sol]
op_ne = op_ne[sol]
op_te = op_te[sol]

sol_ts   = np.where(r_vals > rsep_omp)[0]
r_vals   = r_vals[sol_ts]
ne_omp = ne_omp[sol_ts]
te_omp = te_omp[sol_ts]

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

op_r   = op_r - rsep_omp
r_vals = r_vals - rsep_omp

popt_op, pcov_op = curve_fit(exp_fit, op_r, op_ne/1e18, maxfev=10000)
popt_ts, pcov_ts = curve_fit(exp_fit, r_vals, ne_omp/1e18, maxfev=10000)

fit_r = np.linspace(rsep_omp, r_omp.max(), 100) - rsep_omp
fit_op = exp_fit(fit_r, *popt_op)
fit_ts = exp_fit(fit_r, *popt_ts)

fig = pp.pplot(fit_r*100, fit_op*1e18, fmt='--', color=8)
fig = pp.pplot(fit_r*100, fit_ts*1e18, fmt='--', color=6, fig=fig)
fig = pp.pplot(r_vals*100, ne_omp, fmt='.', label='TS', ms=20, fig=fig)
fig = pp.pplot(op_r*100, op_ne, fmt='.', label='OEDGE', fig=fig, xlabel='R-Rsep OMP (cm)', ylabel='ne (m-3)', color=8, ms=20)

print('OEDGE lambda ne: {:.2f} cm'.format(1/popt_op[1]*100))
print('TS lambda ne:    {:.2f} cm'.format(1/popt_ts[1]*100))
def centerline(lim1, lim2, lim2_mult):

    #The deposition array.
    dep_arr1 = np.array(lim1.variables['NERODS3'][0] * -1)
    dep_arr2 = np.array(lim2.variables['NERODS3'][0] * -1)

    # Location of each P bin, and its width. Currently they all have the same width,
    # but it may end up such that there are custom widths so we leave it like this.
    ps1 = np.array(lim1.variables['PS'][:].data)
    ps2 = np.array(lim2.variables['PS'][:].data)
    pwids1 = np.array(lim1.variables['PWIDS'][:].data)
    pwids2 = np.array(lim2.variables['PWIDS'][:].data)

    # Array of poloidal locations (i.e. the center of each P bin).
    pol_locs1 = ps1 - pwids1 / 2.0
    pol_locs2 = ps2 - pwids2 / 2.0

    # Drop last row since it's garbage.
    dep_arr1 = dep_arr1[:-1, :]
    dep_arr2 = dep_arr2[:-1, :]
    pol_locs1 = pol_locs1[:-1]
    pol_locs2 = pol_locs2[:-1]

    # Distance cell centers along surface (i.e. the radial locations).
    rad_locs1 = np.array(lim1.variables['ODOUTS'][:].data)
    rad_locs2 = np.array(lim2.variables['ODOUTS'][:].data)

    # Get the centerline index (or closest to it).
    cline1 = np.abs(pol_locs1).min()
    cline2 = np.abs(pol_locs2).min()

    # Index the deposition array at the centerline for plotting.
    itf_x1 = rad_locs1[np.where(rad_locs1 > 0.0)[0]]
    itf_y1 = dep_arr1[np.where(pol_locs1 == cline1)[0],
                      np.where(rad_locs1 > 0.0)[0]]
    otf_x1 = rad_locs1[np.where(rad_locs1 < 0.0)[0]] * -1
    otf_y1 = dep_arr1[np.where(pol_locs1 == cline1)[0],
                      np.where(rad_locs1 < 0.0)[0]]
    itf_x2 = rad_locs2[np.where(rad_locs2 > 0.0)[0]]
    itf_y2 = dep_arr2[np.where(pol_locs2 == cline2)[0],
                      np.where(rad_locs2 > 0.0)[0]]
    otf_x2 = rad_locs2[np.where(rad_locs2 < 0.0)[0]] * -1
    otf_y2 = dep_arr2[np.where(pol_locs2 == cline2)[0],
                      np.where(rad_locs2 < 0.0)[0]]

    itf_tot = itf_y1 + itf_y2 * lim2_mult
    otf_tot = otf_y1 + otf_y2 * lim2_mult

    fig = pp.pplot(itf_x1, itf_tot, fmt='-', label='ITF')
    fig = pp.pplot(otf_x1, otf_tot, fmt='-', fig=fig, color=8)

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

    popt_itf, pcov_itf = curve_fit(exp_fit, itf_x1, itf_tot, maxfev=5000)
    popt_otf, pcov_otf = curve_fit(exp_fit, otf_x1, otf_tot, maxfev=5000)

    itf_x_fit = np.linspace(0.01, 0.14, 100)
    itf_y_fit = exp_fit(itf_x_fit, *popt_itf)
    otf_x_fit = np.linspace(0.01, 0.14, 100)
    otf_y_fit = exp_fit(otf_x_fit, *popt_otf)

    fig = pp.pplot(itf_x_fit, itf_y_fit, fmt='--', fig=fig)
    fig = pp.pplot(otf_x_fit,
                   otf_y_fit,
                   fmt='--',
                   fig=fig,
                   color=8,
                   xlabel='Distance along probe (m)',
                   ylabel='W Deposition (arbitrary units)',
                   label='OTF')

    print("\na * exp(-b * x):")
    print("  ITF: a={:5.2f}  b={:5.2f}  1/b={:5.2f} cm".format(
        popt_itf[0], popt_itf[1], 1 / popt_itf[1] * 100))
    print("  OTF: a={:5.2f}  b={:5.2f}  1/b={:5.2f} cm".format(
        popt_otf[0], popt_otf[1], 1 / popt_otf[1] * 100))
    print("Max ITF/OTF Ratio: {:.2f}".format(itf_tot.max() / otf_tot.max()))
    print("Total ITF/OTF Ratio: {:.2f}".format(itf_tot.sum() / otf_tot.sum()))
Esempio n. 27
0
fig = plt.figure(figsize=(10, 7.5))
ax1 = fig.add_subplot(111)
fig.gca().patch.set_color(
    cm.Reds(100))  # Fill in blank spots with low value color.
cont = ax1.contourf(X / 10, Y, norm(Z), cmap='Reds')
cbar = fig.colorbar(cont, ticks=np.linspace(0, 1, 6))
cbar.ax.set_ylabel('LAMS Counts', size=24, weight='bold')
cbar.ax.tick_params(labelsize=20)
ax1.set_xlabel('Axial Length (cm)', size=24, weight='bold')
ax1.set_ylabel('Z Location (mm)', size=24, weight='bold')
ax1.tick_params(labelsize=22)

# Throw each measurement location on.
ax1.plot(X / 10, Y, 'k.', ms=3)

fig.tight_layout()
fig.show()

# Make plot of the average poloidal profile.
avg_pol_counts = pd.read_excel(
    filename, sheet_name='Sheet2').set_index('Radial [mm]').loc['Average']
x = avg_pol_counts.index.values[:-1][::-1]
y = avg_pol_counts.values[:-1] / np.max(avg_pol_counts.values[:-1])
pp.pplot(x,
         y,
         fmt='-',
         xlabel='Z Location (mm)',
         ylabel='Axial Averaged Counts',
         weight='bold')
Esempio n. 28
0
"""

x3 = prof_df['Density at Probe Tip'].values
x3_err = x3 * 0.1
"""
fig = pp.pplot(x3, y2, xerr=x3_err, yerr=y2_err,
               xlabel='Density at Probe Tip (m-3)',
               ylabel='ITF/OTF Max W Ratio')
"""

x4o = prob_df['R-Rsep omp U (cm)'].values
y4o = prob_df['W Areal Density U (1e15 W/cm2)'].values
x4o_err = prob_df['R-Rsep omp Error U (cm)'].values
y4o_err = prob_df['W Areal Density Error U (1e15 W/cm2)'].values

x4i = prob_df['R-Rsep omp D (cm)'].values
y4i = prob_df['W Areal Density D (1e15 W/cm2)'].values
x4i_err = prob_df['R-Rsep omp Error D (cm)'].values
y4i_err = prob_df['W Areal Density Error D (1e15 W/cm2)'].values

fig = pp.pplot(x4i, y4i, xerr=x4i_err, yerr=y4i_err, label='ITF')
fig = pp.pplot(x4o,
               y4o,
               xerr=x4o_err,
               yerr=y4o_err,
               fig=fig,
               label='OTF',
               xlabel='R-Rsep at OMP (cm)',
               ylabel=r'W Areal Density (1e15 W/cm$\mathrm{^2}$)',
               color=8)
Esempio n. 29
0
ax1.tick_params(axis='both', which='both', labelsize=18)
#ax1.set_xlabel(xlabel, fontsize=fontsize, weight=weight)
ax1.set_ylabel('OTF/ITF Peaking', fontsize=26, weight='normal')

ax1.bar(for_idx, peaking[for_idx], color=pp.tableau20[6], label='Forward')
ax1.bar(rev_idx, peaking[rev_idx], color=pp.tableau20[8], label='Reverse')

ax1.legend(prop=dict(weight='normal', size=26))
ax1.set_xticks(np.arange(len(pnames)))
ax1.set_xticklabels(pnames, rotation=0)

#fig.tight_layout()
#fig.show()

fig = pp.pplot(peaking[for_idx],
               total[for_idx],
               xerr=np.full(len(peaking[for_idx]), 0.05),
               yerr=total_err[for_idx],
               label='Forward')
fig = pp.pplot(peaking[rev_idx],
               total[rev_idx],
               xerr=np.full(len(peaking[rev_idx]), 0.05),
               yerr=total_err[rev_idx],
               label='Reverse',
               fig=fig,
               color=8,
               xlabel='OTF/ITF Peaking',
               ylabel='ITF/OTF Total')
fig.axes[0].axhline(1.0, linestyle='--', linewidth=2, color='k', alpha=0.75)
fig.axes[0].axvline(1.0, linestyle='--', linewidth=2, color='k', alpha=0.75)
Esempio n. 30
0
    0., 0.001363767, 0.002727533, 0.006818833, 0, 0.0040913, 0.0040913,
    0.002727533, 0.008182599, 0.008182599, 0.013637666, 0.03545793,
    0.040912997, 0.07500716, 0.085917293, 0.11455639, 0.143195488, 0.175012889,
    0.217728965, 0.245, 0.280, 0.325, 0.384
])

np.random.seed(19680801)

wareal_low = wareal[:15] + 0.1 * wareal[:15] * np.random.randn(len(
    wareal[:15]))
wareal_med = wareal[:19] + 0.1 * wareal[:19] * np.random.randn(len(
    wareal[:19]))
wareal_hig = wareal + 0.1 * wareal * np.random.randn(len(wareal))

#pp.show_colors()
fig = pp.pplot(rminrsep, wareal_hig, fmt='-', label='Low', color=18)
fig = pp.pplot(rminrsep[:19],
               wareal_med,
               fmt='-',
               label='Medium',
               fig=fig,
               color=8)
fig = pp.pplot(rminrsep[:15],
               wareal_low,
               fmt='-',
               label='High',
               color=6,
               fig=fig,
               xlabel='R-Rsep (cm)',
               ylabel='W Areal Density (1e15 cm-2)')