def electric_radial_average(sdf_data):
    ex = sdf_data.__dict__['Electric_Field_Ex']
    ey = sdf_data.__dict__['Electric_Field_Ey']

    x_grid = ex.grid_mid.data[0]
    y_grid = ex.grid_mid.data[1]
    ex = ex.data
    ey = ey.data

    X, Y = np.meshgrid(x_grid, y_grid)
    R, T = cart2polar(X, Y)

    er = np.multiply(ex, np.cos(T)) + np.multiply(ey, np.sin(T))
    et = np.multiply(ey, np.cos(T)) - np.multiply(ex, np.sin(T))

    o, r, t = reproject_image_into_polar(er,
                                         origin=None,
                                         Jacobian=False,
                                         dr=1,
                                         dt=None)

    o_ma = np.ma.masked_equal(o, 0.)
    avg = np.average(o_ma, axis=1)

    return avg, R, T
Beispiel #2
0
def Generalized_Ohm_radavg(sdfdata, species=None):
    # grid = sdfdata.__dict__["Grid_Grid_mid"].data
    grid = sdfdata.__dict__["Grid_Grid"].data

    x = grid[0]
    y = grid[1]

    dx = grid[0][1] - grid[0][0]
    dy = grid[1][1] - grid[1][0]

    p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data
    vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data
    vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data
    vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data
    w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data

    v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3
    v_5 = (np.sqrt(vx**2 + vy**2 + vz**2))**5

    p_list = list(zip(p_pos[0], p_pos[1]))


    v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3)
    v_5_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_5)

    # ax = plt.subplot(1, 2, 1)
    # im = ax.pcolormesh(v_3_dist, cmap=cm.coolwarm)

    # ax = plt.subplot(1, 2, 2)
    # im = ax.pcolormesh(v_5_dist,  cmap=cm.coolwarm)

    # plt.savefig('v5.png', dpi=600, bbox_inches="tight")

    avg_3, dummy_r, dummy_t = reproject_image_into_polar(v_3_dist, origin=None, Jacobian=False, dr=1, dt=None)
    o_ma = np.ma.masked_equal(avg_3, 0.)
    avg_3 = np.average(o_ma, axis=1)

    avg_5, dummy_r, dummy_t = reproject_image_into_polar(v_5_dist, origin=None, Jacobian=False, dr=1, dt=None)
    o_ma = np.ma.masked_equal(avg_5, 0.)
    avg_5 = np.average(o_ma, axis=1)

    const = -sc.m_e / (6 * sc.e)
    grad_num = np.gradient(avg_5, dx) #TODO: what to use for grid spacing radially

    return const * np.divide(grad_num, avg_3, where=avg_3!=0.0)
Beispiel #3
0
def __radial_average(x_grid, y_grid, field_x, field_y):
    X, Y = np.meshgrid(x_grid, y_grid)
    R, T = cart2polar(X, Y)

    er = np.multiply(field_x, np.cos(T)) + np.multiply(field_y, np.sin(T))
    dummy_et = np.multiply(field_y, np.cos(T)) - np.multiply(field_x, np.sin(T))

    o, dummy_r, dummy_t = reproject_image_into_polar(er, origin=None, Jacobian=False, dr=1, dt=None)

    o_ma = np.ma.masked_equal(o, 0.)
    avg = np.average(o_ma, axis=1)

    return avg, R, T
Beispiel #4
0
def density_radial_average(sdf_data, varname):
    dens = sdf_data.__dict__[varname]

    x_grid = dens.grid_mid.data[0]
    y_grid = dens.grid_mid.data[1]
    dens = dens.data

    X, Y = np.meshgrid(x_grid, y_grid)
    R, T = cart2polar(X, Y)

    o, r, t = reproject_image_into_polar(dens, origin=None, Jacobian=False, dr=1, dt=None)

    o_ma = np.ma.masked_equal(o, 0.)
    avg = np.average(o_ma, axis=1)

    return avg, R, T
Beispiel #5
0
def main():
    path = "/Users/stephendiiorio/Desktop/"
    fnums = ["restart0010"]
    fname = []
    for n in fnums:
        fname.append(path + n + ".sdf")

    for i in range(len(fname)):
        sdfdata = sdf.read(fname[i])

        ex = sdfdata.__dict__['Electric_Field_Ex'].data
        ey = sdfdata.__dict__['Electric_Field_Ey'].data

        x_grid = sdfdata.__dict__['Electric_Field_Ex'].grid_mid.data[0]
        y_grid = sdfdata.__dict__['Electric_Field_Ex'].grid_mid.data[1]

        # See https://www.mathworks.com/matlabcentral/answers/95758-how-can-i-convert-vector-fields-from-cartesian-to-polar-coordinate-system-in-matlab-7-10-r2010a for a discussion on how to create a radial vector field from a cartesian one.
        X, Y = np.meshgrid(x_grid, y_grid)

        R, T = cart2polar(X, Y)
        print(np.max(R), np.min(R))

        er = np.multiply(ex, np.cos(T)) + np.multiply(ey, np.sin(T))
        et = np.multiply(ey, np.cos(T)) - np.multiply(ex, np.sin(T))

        # See https://stackoverflow.com/questions/2164570/reprojecting-polar-to-cartesian-grid and the python package Ansel, where these functions are taken from, to see how to transform a cartesian image into polar coordinates.
        o, r, t = reproject_image_into_polar(er, origin=None, Jacobian=False, dr=1, dt=None)

        o_ma = np.ma.masked_equal(o, 0.)
        avg = np.average(o_ma, axis=1)

        fig, ax = plt.subplots()
        # im = ax.pcolormesh(o,  cmap=cm.coolwarm,  vmin=-8e8, vmax=8e8)
        # cb = fig.colorbar(im)
        im = ax.plot(avg)
        plt.ylim(-8e8, 8e8)
        plt.savefig('asdf.png', dpi=600, bbox_inches="tight")
Beispiel #6
0
def higher_order(sdfdata, species=None):
    # grid = sdfdata.__dict__["Grid_Grid_mid"].data
    grid = sdfdata.__dict__["Grid_Grid"].data

    x = grid[0]
    y = grid[1]

    dx = grid[0][1] - grid[0][0]
    dy = grid[1][1] - grid[1][0]

    p_pos = sdfdata.__dict__[get_varname("Grid_Particles", species)].data
    vx = sdfdata.__dict__[get_varname("Particles_Vx", species)].data
    vy = sdfdata.__dict__[get_varname("Particles_Vy", species)].data
    vz = sdfdata.__dict__[get_varname("Particles_Vz", species)].data
    w = sdfdata.__dict__[get_varname("Particles_Weight", species)].data

    p_list = list(zip(p_pos[0], p_pos[1]))


    limit = 1e20

    v_r = np.sqrt(vx**2 + vy**2)# + vz**2) #NOTE: might need to get rid of vz. can then use cart2polar for v_r and v_t
    v_r_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_r)
    avg_r, r, dummy_t = reproject_image_into_polar(v_r_dist, origin=None, Jacobian=False, dr=1, dt=None)
    o_ma = np.ma.masked_equal(avg_r, 0.)
    avg_r = np.average(o_ma, axis=1)

    fig1, ax1 = plt.subplots(2, sharex=True)
    ax1[0].plot(avg_r)
    ax1[1].plot(np.clip(avg_r, -limit, limit))
    fig1.savefig('vr.png', dpi=600, bbox_inches="tight")
    plt.close(fig1)


    v_t = np.arctan2(vx, vy)
    v_t_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_t)
    avg_t, r, t = reproject_image_into_polar(v_t_dist, origin=None, Jacobian=False, dr=1, dt=None)
    o_ma = np.ma.masked_equal(avg_t, 0.)
    avg_t = np.average(o_ma, axis=1)

    fig2, ax2 = plt.subplots(2, sharex=True)
    ax2[0].plot(avg_t)
    ax2[1].plot(np.clip(avg_t, -limit, limit))
    fig2.savefig('vt.png', dpi=600, bbox_inches="tight")
    plt.close(fig2)


    v_3 = (np.sqrt(vx**2 + vy**2 + vz**2))**3
    v_3_dist = first_order_weight_2d(x, y, dx, dy, p_list, weight=w, values=v_3)
    avg_3, r, t = reproject_image_into_polar(v_3_dist, origin=None, Jacobian=False, dr=1, dt=None)
    o_ma = np.ma.masked_equal(avg_3, 0.)
    avg_3 = np.average(o_ma, axis=1)

    fig3, ax3 = plt.subplots(2, sharex=True)
    ax3[0].plot(avg_3)
    ax3[1].plot(np.clip(avg_3, -limit, limit))
    fig3.savefig('avg_v3.png', dpi=600, bbox_inches="tight")
    plt.close(fig3)


    r = np.linspace(0.0, np.max(np.sqrt(x**2 + y**2)), num=avg_r.size)

    num_1 = np.multiply(r, avg_3)
    num_1 = np.multiply(avg_r, num_1)
    num_1 = np.multiply(avg_r, num_1)

    fig4, ax4 = plt.subplots(2, sharex=True)
    ax4[0].plot(num_1)
    ax4[1].plot(np.clip(num_1, -limit, limit))
    fig4.savefig('num1_before_grad', dpi=600, bbox_inches="tight")
    plt.close(fig4)

    num_1 = np.gradient(num_1, dx) #TODO: what to use for grid spacing radially

    fig5, ax5 = plt.subplots(2, sharex=True)
    ax5[0].plot(num_1)
    ax5[1].plot(np.clip(num_1, -limit, limit))
    fig5.savefig('num1.png', dpi=600, bbox_inches="tight")
    plt.close(fig5)


    num_2 = np.multiply(avg_r, avg_t)
    num_2 = np.multiply(avg_3, num_2)

    fig6, ax6 = plt.subplots(2, sharex=True)
    ax6[0].plot(num_2)
    ax6[1].plot(np.clip(num_2, -limit, limit))
    fig6.savefig('num2_before_grad.png', dpi=600, bbox_inches="tight")
    plt.close(fig6)

    num_2 = np.gradient(num_2, max(x.size, y.size)) #TODO: what to use for grid spacing theta

    fig7, ax7 = plt.subplots(2, sharex=True)
    ax7[0].plot(num_2)
    ax7[1].plot(np.clip(num_2, -limit, limit))
    fig7.savefig('num2.png', dpi=600, bbox_inches="tight")
    plt.close(fig7)


    # num = np.divide(num_1 + num_2, r, where=r!=0.0)
    num = np.divide(num_1, r, where=r!=0.0)
    fig8, ax8 = plt.subplots(2, sharex=True)
    ax8[0].plot(num)
    ax8[1].plot(np.clip(num, -limit, limit))
    fig8.savefig('num.png', dpi=600, bbox_inches="tight")
    plt.close(fig8)

    const = -sc.m_e / (2 * sc.e)
    final = const * np.divide(num, avg_3, where=avg_3!=0.0)
    fig9, ax9 = plt.subplots(2, sharex=True)
    ax9[0].plot(final)
    ax9[1].plot(np.clip(final, -limit, limit))
    fig9.savefig('final.png', dpi=600, bbox_inches="tight")
    plt.close(fig9)

    return final#const * np.divide(num, avg_3, where=avg_3!=0.0)