Ejemplo n.º 1
0
def generate_all_color_frames(shot, thin_every=1):
    """ Wrapper function to generate a frame for every timestep"""
    magdata = hdr.getMagData(shot)
    # speed things up
    count = 0
    for t in magdata.time[::thin_every]:
        generate_color_frame(shot, t, count)
        count += 1
Ejemplo n.º 2
0
def plot_color(shot, shot_num, num_probes=16):
    """ This code plot a 2-d graph, with colored arrows to indicated the third
        dimension. For example, in the straight wire test, this plots in the
        y-z plane since that's where most of the field is, and then has colored
        arrows to indicate how much field is in the x-directionself.
        TODO: add a key to show how the length of the arrow corresponds to
              to field strength

              also just worth noting and maybe worth fixing is that the color
              bar limits are set to be on the same axis as the y and z, but
              isn't actually the strength of the field. It was just to make the
              relative field equal to the other components

       -- KG 06/11/19
    """
    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)
    for probe_num in range(num_probes):
        Bx = sp.signal.detrend(magdata.fullData[0, probe_num, :])
        By = sp.signal.detrend(magdata.fullData[1, probe_num, :])
        Bz = sp.signal.detrend(magdata.fullData[2, probe_num, :])

        magmax_x = polyPeak_noPlot(magdata.time, Bx, [10, 100], axis='x')
        magmax_y = polyPeak_noPlot(magdata.time, By, [10, 100], axis='y')
        magmax_z = polyPeak_noPlot(magdata.time, Bz, [10, 100], axis='z')

        data[probe_num] = [magmax_x, magmax_y, magmax_z]

    position_vectors = get_probeLocs_meters()
    x = [position_vectors[i][0] for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] for i in range(len(position_vectors))]

    u = [data[i][0] for i in range(len(data))]
    v = [data[i][1] for i in range(len(data))]
    w = [data[i][2] for i in range(len(data))]
    # v[4] = v[4]*-1
    # v[5] = v[5]*-1
    v[6] = 0

    x = [position_vectors[i][0] for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] for i in range(len(position_vectors))]

    qq = plt.quiver(y, z, v, w, u, cmap=plt.cm.jet)
    plt.clim(-.004, .004)
    plt.colorbar(qq, cmap=plt.cm.jet)
    plt.xlabel("Y direction")
    plt.ylabel("Z direction")
    plt.xlim(-.004, .004)
    plt.ylim(-.004, .004)
    plt.title("Magnetic Data - Shot %s" % (shot_num))
    plt.show()
Ejemplo n.º 3
0
def get_data_slice(shot, t, num_probes=16):
    """Gets the data from the 4x4 probe setup AT A SPECIFIC SLICE OF TIME


       Returns data, the calibrated, integrated magentic field data

       Data has the dimensions of [probes][direction][time]
            - probes is the number of probes, from 0 to 15 typically
            - direction is the direction of the magnetic field
                - 0 is x-dir
                - 1 is y-dir
                - 2 is z-dir

       ie Bx of probe 5 (index starting from 0) can be found:

            Bx = data[5][0]

        Very time inefficent, so don't plan to use this often

        --KG 07/25/19
    """

    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)

    calibFile = 'calib-050119-4x4_lookup_final.txt'
    calibFile = os.path.join(os.getcwd() + '\\magcalib\\',
                             calibFile)  #change where caliv file is here
    calibFactor = np.loadtxt(calibFile)

    for probe in range(num_probes):
        Bx_all = cumtrapz(
            magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[0, probe, :],
                num_probes - 1), magdata.time)
        Bx = Bx_all[int(t)] * calibFactor[probe][0]

        By_all = cumtrapz(
            magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[1, probe, :],
                num_probes - 1), magdata.time)
        By = By_all[int(t)] * calibFactor[probe][1]

        Bz_all = cumtrapz(
            magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[2, probe, :],
                num_probes - 1), magdata.time)
        Bz = Bz_all[int(t)] * calibFactor[probe][2]

        data[probe] = [Bx, By, Bz]

    return data
Ejemplo n.º 4
0
def generate_all_3d_frames(shot, thin_every=1):
    """ Wrapper function to generate a frame for every timestep"""
    magdata = hdr.getMagData(shot)
    # speed things up
    count = 0
    for t in magdata.time[::thin_every]:
        # for t in magdata.time:
        print("Progress: %s / %s" %
              (str(count), str(len(magdata.time) // thin_every)))
        if (t > 20 and t < 150):
            generate_3d_frame(shot, t, count)

        count += 1
Ejemplo n.º 5
0
def get_data(shot, num_probes=16):
    """Gets the data from the 4x4 probe setup at ALL TIMES

    Returns data, the calibrated, integrated magentic field data
    using lookup calibration.

    Data has the dimensions of [probes][direction]
        - probes is the number of probes, from 0 to 15 typically
        - direction is the direction of the magnetic field
            - 0 is x-dir
            - 1 is y-dir
            - 2 is z-dir

    ie Bx of probe 5 (index starting from 0) can be found:

        Bx = data[5][0]

    ASSUMES THE CALIBRATION FILE IS IN magcalib
    (feel free to change that tho)"""

    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)

    calibFile = 'calib-050119-4x4_lookup_final.txt'
    calibFile = os.path.join(os.getcwd() + '\\magcalib\\',
                             calibFile)  #change where caliv file is here
    calibFactor = np.loadtxt(calibFile)

    for probe in range(num_probes):
        Bx_all = cumtrapz(
            magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[0, probe, :],
                num_probes - 1), magdata.time)
        Bx = Bx_all * calibFactor[probe][0]

        By_all = cumtrapz(
            magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[1, probe, :],
                num_probes - 1), magdata.time)
        By = By_all * calibFactor[probe][1]

        Bz_all = cumtrapz(
            magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[2, probe, :],
                num_probes - 1), magdata.time)
        Bz = Bz_all * calibFactor[probe][2]

        data[probe] = [Bx, By, Bz]

    return magdata.time, data
Ejemplo n.º 6
0
def plot_2d(shot, num_probes=16):
    '''Plots a black and white plot of the magentic data for a given shot
    '''
    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)
    for probe_num in range(num_probes):
        Bx = sp.signal.detrend(magdata.fullData[0, probe_num, :])
        By = sp.signal.detrend(magdata.fullData[1, probe_num, :])
        Bz = sp.signal.detrend(magdata.fullData[2, probe_num, :])

        magmax_x = polyPeak_noPlot(magdata.time, Bx, [10, 100], axis='x')
        magmax_y = polyPeak_noPlot(magdata.time, By, [10, 100], axis='y')
        magmax_z = polyPeak_noPlot(magdata.time, Bz, [10, 100], axis='z')

        data[probe_num] = [magmax_x, magmax_y, magmax_z]

    # Get position vectors in meters
    position_vectors = get_probeLocs_meters()

    # x = np. a
    x = [position_vectors[i][0] for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] for i in range(len(position_vectors))]

    u = [data[i][0] for i in range(len(data))]
    v = [data[i][1] for i in range(len(data))]

    # v[6] = 0
    w = [data[i][2] for i in range(len(data))]

    x = [position_vectors[i][0] for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] for i in range(len(position_vectors))]

    qq = plt.quiver(y, z, u, w)
    plt.plot()

    # print(position_vectors)
    lim = .08

    plt.xlabel("X direction (m)")
    plt.ylabel("Z direction (m)")

    plt.xlim(-lim, lim)
    plt.ylim(-lim, lim)
    plt.title("Straight Wire Test")
    plt.show()
Ejemplo n.º 7
0
def probe_calib(shot, probe_num, position_vector, dir):
    magdata = hdr.getMagData(shot)

    uncalibB_x=sp.signal.detrend(magdata.iUnCalibData[0,probe_num,:])
    uncalibB_y=sp.signal.detrend(magdata.iUnCalibData[1,probe_num,:])
    uncalibB_z=sp.signal.detrend(magdata.iUnCalibData[2,probe_num,:])

    magmax_x = polyPeak_noPlot(magdata.time,uncalibB_x,[10,100], axis = 'x')
    magmax_y = polyPeak_noPlot(magdata.time,uncalibB_y,[10,100], axis = 'y')
    magmax_z = polyPeak_noPlot(magdata.time,uncalibB_z,[10,100], axis = 'z')

    guntime,east,west=loadcurrent(shot)
    currmax = polyPeak_noPlot(guntime,east,[10,100],axis = 'current')

    helmB=helmholtz2(position_vector,currmax)
    if dir == 2 :#r - z direction of probe is along axis of Helmholtz coil
        # r shots : x,y,z - > r,t,z
        helmB = [ 1*helmB[2], 1*helmB[0], 1*helmB[1] ]
    elif dir == 0:#t-  x direction of probe is along axis of Helmholtz coil
    #### NEED TO VERIFY WHETHER THIS IS CORRECT
        # t shots : x,y,z - > r,t,z
        helmB = [ 1*helmB[0], 1*helmB[2], 1*helmB[1] ]
    elif dir ==1:#z - y direction of probe is along axis of Helmholtz coil
        # same as t, but different transform below
        # ADL 20190501 (coils are in same positions, but field directions rotate
        # z shots : x,y,z - > r,t,z
        helmB = [ 1*helmB[0], 1*helmB[1], 1*helmB[2] ]

    ratio_x = magmax_x/helmB[0]
    ratio_y = magmax_y/helmB[1]
    ratio_z = magmax_z/helmB[2]
    # print 'Mag Max = ', magmax
    # print 'HelmB = ', helmB
    # print 'Ratio = ', ratio
    # return ratio_x,ratio_y, ratio_z, currmax,helmB

    return ratio_x, ratio_y, ratio_z, currmax, helmB
Ejemplo n.º 8
0
def bfield_movie(shot, dir=2, num_probes=16):
    """
    based on bfield_shape, but this will trace out the magnetic feild though
    time?


    --KG 06/14/19
    """
    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)
    for probe_num in range(num_probes):
        Bx = sp.signal.detrend(magdata.fullData[0, probe_num, :])
        By = sp.signal.detrend(magdata.fullData[1, probe_num, :])
        Bz = sp.signal.detrend(magdata.fullData[2, probe_num, :])

        magmax_x = polyPeak_noPlot(magdata.time, Bx, [10, 100], axis='x')
        magmax_y = polyPeak_noPlot(magdata.time, By, [10, 100], axis='y')
        magmax_z = polyPeak_noPlot(magdata.time, Bz, [10, 100], axis='z')

        data[probe_num] = [magmax_x, magmax_y, magmax_z]
    # position_vectors = get_probeLocs_meters(dir)
    position_vectors = get_probeLocs_calib_setup(2)
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    x = [position_vectors[i][0] for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] for i in range(len(position_vectors))]

    u = [data[i][0] for i in range(len(data))]
    v = [data[i][1] for i in range(len(data))]
    w = [data[i][2] for i in range(len(data))]

    dead_chans = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0]
    good_u = np.ma.masked_array(u, dead_chans)
    good_v = np.ma.masked_array(v, dead_chans)
    good_w = np.ma.masked_array(w, dead_chans)

    dead_u = np.ma.masked_array(u, np.logical_not(dead_chans))
    dead_v = np.ma.masked_array(v, np.logical_not(dead_chans))
    dead_w = np.ma.masked_array(w, np.logical_not(dead_chans))

    col_map = plt.get_cmap('Blues')
    ax.quiver(x,
              y,
              z,
              good_u,
              good_v,
              good_w,
              length=0.01,
              normalize=True,
              cmap=col_map)
    ax.quiver(x,
              y,
              z,
              dead_u,
              dead_v,
              dead_w,
              length=0.01,
              normalize=True,
              color='r')

    ax.set_xlabel("X direction")
    ax.set_ylabel("Y direction")
    ax.set_zlabel("Z direction")
    ax.set_zlim(-.05, 0.05)
    ax.set_xlim(-.05, 0.05)
    ax.set_ylim(-.05, 0.05)
    plt.axis('equal')
    # plt.xlim()
    # ax.set_title("Stright Wire test")
    plt.show()
Ejemplo n.º 9
0
def plots_4_doc(shot, num_probes=16):
    """ This plots the magentic field from every single probe one at a timeself.
        The advantage is that is also calculates what the helmholtz field at
        that point should be and plots it (as a function of time) and also
        current all one one plot, making it easy to find the ratio, and also
        verify it vizually. However, to make this function run in a reasonable
        amount of time, I thinned the data for the calulated helmholtz field,
        so that it only calculates every 10th point, meaning it is less
        accurate at actually producing the ratio (becuase it may not find the
        true peak )


        TODO:
            - check if the units for the third plot are ok???
            - Add y-units


        -- KG 06/13/19"""
    # data = [[0] *3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)

    probe_locs = get_probeLocs_calib_setup(shot)
    for probe_num in range(num_probes):
        # Bz=sp.signal.detrend(magdata.fullData[2,probe_num,:])
        # Bx=sp.signal.detrend(magdata.fullData[0,probe_num,:])
        # By=sp.signal.detrend(magdata.fullData[1,probe_num,:])
        ratio = 1
        timeb, Bx, By, Bz = load_smallbdot(shot)

        data = hdr.getquikData(shot)
        fig, (ax1, ax2, ax3) = plt.subplots(3, 1, sharex=True)
        # Bz=cumtrapz(data.unCalibData[2,1,:]-mj.get_gaussian_moving_avg(data.time, data.unCalibData[2,1,:], 1), data.time)
        Bz = sp.signal.detrend(
            cumtrapz(data.unCalibData[1, probe_num, :], data.time))
        if (abs(np.max(Bz)) > abs(np.min(Bz))):
            print("Max %d, min %d, abs: %d" %
                  (np.max(Bz), np.min(Bz), abs(np.min(Bz))))
            Bz = Bz * -1
            ratio = -1

        Bz += np.abs(np.min(Bz))
        btime = data.time[:len(Bz)]
        ax1.plot(btime, Bz)
        ax1.set_title("By - integrated")
        ax1.set_xlim(-25, 175)

        time, eastcurrent, westcurrent = loadcurrent(shot)
        ax2.plot(time[::10], eastcurrent[::10])
        ax2.set_title("Current")

        r = probe_locs[1]
        # helmB = helmholtz_listcomp(r,eastcurrent)
        status = 0
        max = len(eastcurrent) / 100
        helmB = np.zeros((3, max))
        i = 0
        while i + 100 < len(eastcurrent):
            # currmax = polyPeak_noPlot(time,eastcurrent,[10,100],axis = 'current')
            x, y, z = helmholtz2(r, eastcurrent[i])
            helmB[0][status] = x
            helmB[1][status] = y
            helmB[2][status] = z
            status += 1
            i += 100
        # thin the thing
        thinned_time = time[::100]
        thinned_time = thinned_time[:len(helmB[2])]
        helmB[2] = helmB[2] * -1
        max_measured = np.max(Bz)
        max_theoretical = np.max(helmB[2])
        ratio = ratio * max_theoretical / max_measured

        print("Shot: %s, probe %d, Ratio around: %d" %
              (shot[:6], probe_num, ratio))
        ax3.plot(thinned_time, helmB[2])
        ax3.set_title("Predicted B based on current and location in helmholtz")
        print("Ratio is: %d" % (ratio))
        plt.show()
Ejemplo n.º 10
0
def generate_color_frame(shot, t, count, num_probes=16):
    plt.close("all")
    """ saves a frame instead of returning it ! """
    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)
    # print(len(magdata.time))
    calibFile = 'calib-050119-4x4_lookup_1.txt'
    calibFile = os.path.join(os.getcwd(), calibFile)
    calibFactor = np.loadtxt(calibFile)

    for probe in range(num_probes):
        Bx_all = cumtrapz(
            magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[0, probe, :],
                num_probes - 1), magdata.time)
        Bx = Bx_all[int(t)] * calibFactor[probe][0]

        By_all = cumtrapz(
            magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[1, probe, :],
                num_probes - 1), magdata.time)
        By = By_all[int(t)] * calibFactor[probe][1]

        Bz_all = cumtrapz(
            magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[2, probe, :],
                num_probes - 1), magdata.time)
        Bz = Bz_all[int(t)] * calibFactor[probe][2]

        data[probe] = [Bx, By, Bz]

        # Get position vectors in meters
    position_vectors = get_probeLocs_SSX_setup()

    u = [data[i][0] for i in range(len(data))]
    v = [data[i][1] for i in range(len(data))]
    w = [data[i][2] for i in range(len(data))]

    # too big, so I just zero it out
    # v[6] = 0

    x = [position_vectors[i][0] for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] for i in range(len(position_vectors))]

    # qq = plt.quiver(y,z, v,w, u)
    # plt.plot()

    qq = plt.quiver(y, z, v, w, u, cmap=plt.cm.jet)
    scale_arrow = plt.quiver(.9, .9, .1, 0, label=".1 Tesla")
    cbar = plt.colorbar(qq, cmap=plt.cm.jet)
    cbar.set_label("Magnetic Field Strength (T)")
    # cbar.set_norm((-.085,.085))
    cbar.set_clim(-.085, .085)
    plt.xlabel("Y direction")
    plt.ylabel("Z direction")
    plt.xlim(-.085, .085)
    plt.ylim(-.085, .085)
    plt.title("Magnetic Data - Shot %s. Time: %s" % (shot, str(t)))
    path = os.getcwd()
    path = path + '/mag_images/'
    path = path + 'mag-' + str(count) + '.png'

    plt.savefig(path)
Ejemplo n.º 11
0
def generate_3d_frame(shot, t, count, num_probes=16):
    """ saves a frame instead of returning it """
    plt.close("all")
    data = [[0] * 3 for i in range(num_probes)]
    magdata = hdr.getMagData(shot)
    # print(len(magdata.time))
    calibFile = 'calib-050119-4x4_lookup_1.txt'
    calibFile = os.path.join(os.getcwd(), calibFile)
    calibFactor = np.loadtxt(calibFile)

    for probe in range(num_probes):
        Bx_all = cumtrapz(
            magdata.unCalibData[0, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[0, probe, :],
                num_probes - 1), magdata.time)
        Bx = Bx_all[int(t)] * calibFactor[probe][0]

        By_all = cumtrapz(
            magdata.unCalibData[1, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[1, probe, :],
                num_probes - 1), magdata.time)
        By = By_all[int(t)] * calibFactor[probe][1]

        Bz_all = cumtrapz(
            magdata.unCalibData[2, probe, :] - mj.get_gaussian_moving_avg(
                magdata.time, magdata.unCalibData[2, probe, :],
                num_probes - 1), magdata.time)
        Bz = Bz_all[int(t)] * calibFactor[probe][2]

        data[probe] = [Bx, By, Bz]

        # Get position vectors in meters
    position_vectors = get_probeLocs_SSX_setup_cm()

    u = [data[i][0] for i in range(len(data))]
    v = [data[i][1] for i in range(len(data))]
    w = [data[i][2] for i in range(len(data))]

    # too big, so I just zero it out
    # v[6] = 0
    """
    In SSX setup:

        x -> -z
        y -> theta
        z -> -r

    """
    x = [position_vectors[i][0] * -1 for i in range(len(position_vectors))]
    y = [position_vectors[i][1] for i in range(len(position_vectors))]
    z = [position_vectors[i][2] * -1 for i in range(len(position_vectors))]

    # qq = plt.quiver(y,z, v,w, u)
    # plt.plot()

    iffy_chans = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0]
    good_u = np.ma.masked_array(u, iffy_chans)
    good_v = np.ma.masked_array(v, iffy_chans)
    good_w = np.ma.masked_array(w, iffy_chans)

    dead_chans = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    dead_u = np.ma.masked_array(u, np.logical_not(dead_chans))
    dead_v = np.ma.masked_array(v, np.logical_not(dead_chans))
    dead_w = np.ma.masked_array(w, np.logical_not(dead_chans))

    fixed_chans = np.logical_xor(iffy_chans, dead_chans)
    fixed_u = np.ma.masked_array(u, np.logical_not(fixed_chans))
    fixed_v = np.ma.masked_array(v, np.logical_not(fixed_chans))
    fixed_w = np.ma.masked_array(w, np.logical_not(fixed_chans))

    fig = plt.figure()
    ax = fig.gca(projection='3d')
    col_map = plt.get_cmap('Blues')

    # ax.quiver(x,y,z,good_u,good_v,good_w, length=0.01, normalize=False,cmap = col_map, label = "Calibrated probes" )
    # ax.quiver(x,y,z,dead_u,dead_v,dead_w, length=0.01, normalize=False, color = 'r', label = "Broken components")
    # ax.quiver(x,y,z,fixed_u,fixed_v,fixed_w, length=0.01, normalize=False,color = 'g', label = "interpolated components")

    # Q = ax.quiver(x,y,z,good_u,good_v,good_w, length=0.05,  normalize=False, pivot = 'middle', cmap = col_map)
    # ax.quiver(x,y,z,dead_u,dead_v,dead_w, length=0.05,  normalize=False, pivot = 'mid',  color = 'r')
    # ax.quiver(x,y,z,fixed_u,fixed_v,fixed_w, length=0.05,  normalize=False, pivot = 'mid', color = 'g')

    ax.quiver3D(x,
                y,
                z,
                good_u,
                good_v,
                good_w,
                length=0.02,
                arrow_length_ratio=.4,
                pivot='middle',
                normalize=False,
                cmap=col_map)
    ax.quiver3D(x,
                y,
                z,
                dead_u,
                dead_v,
                dead_w,
                length=0.02,
                arrow_length_ratio=.4,
                pivot='middle',
                normalize=False,
                color='r')
    ax.quiver3D(x,
                y,
                z,
                fixed_u,
                fixed_v,
                fixed_w,
                length=0.02,
                arrow_length_ratio=.4,
                pivot='middle',
                normalize=False,
                color='g')

    # qk = Q.quiverkey(Q, .92,.92, .1, label = ".1 Tesla")
    # ax.plot(np.zeros(100),np.zeros(100),'cyan--', alpha = .3)

    #set up the  pivot = 'mid',midline
    N = 100
    lim = 8.5

    #workaround quiverkey:
    ax.quiver(0,
              0,
              0,
              100,
              0,
              0,
              length=0.02,
              arrow_length_ratio=.4,
              pivot='middle',
              color='c',
              label='100 Gauss')

    # ax.plot(np.linspace(-lim, lim, N), np.zeros(N), 'k--', alpha  = 0.6, label = "midline")
    ax.plot(np.linspace(-lim, lim, N), np.zeros(N), 'k--', alpha=0.6)
    plt.legend()

    # add the sca;le
    # plt.legend(loc= 'upper right')

    #add cylinder:
    # Xc,Yc,Zc = generate_cyl_dat()
    # Xc[Xc>lim]= np.nan
    # Xc[Xc<-lim]= np.nan
    # Yc[Yc>lim]= np.nan
    # Yc[Yc<-lim]= np.nan
    # Zc[Zc>lim]= np.nan
    # Zc[Zc<-lim]= np.nan
    # ax.plot_surface(Xc, Yc, Zc,  color = 'tan', alpha=0.3)

    #add edge of SSX
    # z = np.empty(N)
    # z.fill(0.08025)
    # x = np.linspace(-lim, lim, N)

    # X, Z = np.meshgrid(x,z)
    # Y =

    # ax.plot(np.linspace(-lim, lim, N), z, 'y--', alpha  = 0.6, label = "midline")
    # ax.plot_surface(,   z, 'y--', alpha  = 0.6, label = "edge of SSX")

    #add title/labels
    ax.set_xlabel("$\\hat{Z}$, cm")
    ax.set_ylabel("$\\hat{\\theta}, cm$")
    ax.set_zlabel("$\\hat{R}, cm$")
    ax.set_zlim3d(-lim, lim)
    ax.set_xlim3d(-lim, lim)
    ax.set_ylim3d(-lim, lim)
    # plt.zlim(-lim, lim)
    # plt.xlim(-lim, lim)
    # plt.ylim(-lim, lim)
    plt.axis('equal')
    # plt.title("Magnetic Data - Shot %s. \n $\\bf{Time}$: %.2f $\\it{\mu s}$ " %(shot[7:], t))
    plt.title("Magnetic Data - Shot %s. \n $\\bf{Time}$: %.2f $\\it{\mu s}$ " %
              (shot, t))
    path = os.getcwd()
    path = path + '/mag_images/'

    #quick fix to make sure the ordering makes sense:
    str_count = str(count)
    if count < 10:
        str_count = '0' + str_count

    if count < 100:
        str_count = '0' + str_count

    if count < 1000:
        str_count = '0' + str_count

    path = path + str_count + '-mag' + '.png'

    plt.savefig(path)
Ejemplo n.º 12
0
def get_just_time(shot):
    magdata = hdr.getMagData(shot)
    return magdata.time
Ejemplo n.º 13
0
def process_mjmag_data(shot):
    """ This returns uncalibrated data...?"""
    # data = dtq.getMJMagData(shot)
    data = hdr.getMagData(shot)
    #print data.settings

    #recast array into [3,25]
    Bdot25 = np.zeros([3, 25, 8192])
    # Bdot25 = np.zeros([3,25,8192])

    #1
    Bdot25[0, 0, :] = data.Bdot[0, 0, :]
    Bdot25[1, 0, :] = data.Bdot[1, 0, :]
    #2
    Bdot25[0, 1, :] = data.Bdot[0, 1, :]
    Bdot25[1, 1, :] = data.Bdot[1, 1, :]
    #3
    Bdot25[0, 2, :] = data.Bdot[0, 2, :]
    Bdot25[1, 2, :] = data.Bdot[1, 2, :]
    #4
    Bdot25[0, 3, :] = data.Bdot[0, 3, :]
    Bdot25[1, 3, :] = data.Bdot[1, 3, :]
    #5
    Bdot25[0, 4, :] = data.Bdot[0, 4, :]
    Bdot25[1, 4, :] = data.Bdot[1, 4, :]
    #6
    Bdot25[0, 5, :] = data.Bdot[0, 5, :]
    Bdot25[1, 5, :] = data.Bdot[1, 5, :]
    #7
    Bdot25[0, 6, :] = data.Bdot[0, 6, :]
    Bdot25[1, 6, :] = data.Bdot[1, 6, :]
    #8
    Bdot25[0, 7, :] = data.Bdot[0, 7, :]
    Bdot25[1, 7, :] = data.Bdot[1, 7, :]
    #9
    Bdot25[0, 8, :] = data.Bdot[0, 8, :]
    Bdot25[1, 8, :] = data.Bdot[1, 8, :]
    #10
    Bdot25[0, 9, :] = data.Bdot[0, 9, :]
    Bdot25[1, 9, :] = data.Bdot[1, 9, :]
    #11
    Bdot25[0, 10, :] = data.Bdot[0, 10, :]
    Bdot25[1, 10, :] = data.Bdot[1, 10, :]
    #12
    Bdot25[0, 11, :] = data.Bdot[0, 11, :]
    Bdot25[1, 11, :] = data.Bdot[1, 11, :]
    #13
    Bdot25[0, 12, :] = data.Bdot[0, 12, :]
    Bdot25[1, 12, :] = data.Bdot[1, 12, :]
    Bdot25[2, 12, :] = data.Bdot[2, 2, :]
    #14
    Bdot25[0, 13, :] = data.Bdot[0, 13, :]
    Bdot25[1, 13, :] = data.Bdot[1, 13, :]
    Bdot25[2, 13, :] = data.Bdot[2, 1, :]
    #15
    Bdot25[0, 14, :] = data.Bdot[0, 14, :]
    Bdot25[1, 14, :] = data.Bdot[1, 14, :]
    Bdot25[2, 14, :] = data.Bdot[2, 0, :]
    #16
    Bdot25[0, 15, :] = data.Bdot[0, 15, :]
    Bdot25[1, 15, :] = data.Bdot[1, 15, :]
    #17
    Bdot25[0, 16, :] = data.Bdot[2, 3, :]
    Bdot25[1, 16, :] = data.Bdot[2, 12, :]
    #18
    Bdot25[0, 17, :] = data.Bdot[2, 4, :]
    Bdot25[1, 17, :] = data.Bdot[2, 13, :]
    #19
    Bdot25[0, 18, :] = data.Bdot[2, 5, :]
    Bdot25[1, 18, :] = data.Bdot[2, 14, :]
    #20
    Bdot25[0, 19, :] = data.Bdot[2, 6, :]
    Bdot25[1, 19, :] = data.Bdot[2, 15, :]
    #21
    Bdot25[0, 20, :] = data.Bdot[2, 7, :]
    #22
    Bdot25[0, 21, :] = data.Bdot[2, 8, :]
    #23
    Bdot25[0, 22, :] = data.Bdot[2, 9, :]
    #24
    Bdot25[0, 23, :] = data.Bdot[2, 10, :]
    #25
    Bdot25[0, 24, :] = data.Bdot[2, 11, :]

    #reintegrate with later start times
    B25 = np.zeros([3, 25, 7391])
    timeB = data.time[801:]
    for i in np.arange(3):
        for j in np.arange(25):
            #bzero = Bdot25[i,j,:]-np.mean(Bdot25[i,j,800:8000])
            bzero = plt.detrend_linear(Bdot25[i, j, 800:])
            bint = sp.cumtrapz(bzero, data.time[800:])
            B25[i, j, :] = bint

    #compute Bmod
    Bmod25 = np.zeros([25, 7391])
    for j in np.arange(25):
        Bmod25[j, :] = np.sqrt(B25[0, j, :]**2 + B25[1, j, :]**2 +
                               B25[2, j, :]**2)
    return (data.time, Bdot25, timeB, B25, Bmod25, data)