Exemple #1
0
def simple_rho(this_looper,core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr=this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times=thtr.times[mask]/colors.tff
    rho_all = thtr.track_dict['density']
    rho_min=rho_all.min()
    rho_max=rho_all.max()
    for core_id in core_list:
        fig,ax=plt.subplots(1,1)

        quan = thtr.c([core_id],'density')[:,mask]
        bins = np.geomspace(rho_min,rho_max,64)
        XX,YY,HH,VV,plot=heat_map.heat_map( quan, times, ax=ax, bins=bins,hist_norm=True, zlim=[5e-3,3e-1])
        axbonk(ax,xlabel=r'$t/t_{ff}$', ylabel=r'$\rho/\rho_0$',yscale='log')
        norm = mpl.colors.LogNorm( HH[HH>0].min(), HH.max())
        fig.colorbar(plot)


        outname='plots_to_sort/%s_rho_t_heat_c%04d.png'%(this_looper.sim_name,core_id)
        fig.savefig(outname)
        print(outname)
Exemple #2
0
def simple_rho(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    rho_all = thtr.track_dict['density']
    rho_min = rho_all.min()
    rho_max = rho_all.max()
    B_all = thtr.track_dict['magnetic_field_strength']
    B_min = B_all.min()
    B_max = B_all.max()
    for core_id in core_list:
        fig, ax_square = plt.subplots(2, 2)
        ax = ax_square.flatten()

        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=False)
        ms.particle_pos(core_id)

        if ms.nparticles < 1000:
            sl = slice(None)
            c = [0.5] * 4
        else:
            sl = slice(None, None, 10)
            #c=[0,0,0,0.1]
            c = [0.1] * 4

        rho = ms.density[sl].transpose()
        rho = rho[mask, :]
        B = thtr.c([core_id], 'magnetic_field_strength')[sl].transpose()[
            mask, :]  #/colors.mean_field[this_looper.sim_name]

        ax[0].plot(times, rho, c=c, linewidth=0.1)
        axbonk(ax[0],
               xlabel=r'$t/t_{ff}$',
               ylabel=r'$\rho$',
               yscale='log',
               ylim=[rho_min, rho_max])

        ax[1].plot(times, B, c=c, linewidth=0.1)
        axbonk(ax[1], xlabel=r'$t/t_{ff}$', ylabel='B', yscale='log')

        ax[2].plot(times, np.log10(B) / np.log10(rho), c=c, linewidth=0.1)
        ax[2].set_yscale('symlog', linthresh=1)

        ax[3].scatter(rho[0, :], B[0, :])
        ax[3].scatter(rho[-1, :], B[-1, :])
        ax[3].plot(rho, B, c=c, linewidth=0.1)
        axbonk(ax[3], xscale='log', yscale='log', xlabel='rho', ylabel='B')

        outname = 'plots_to_sort/%s_b_and_rho_t_c%04d.png' % (
            this_looper.sim_name, core_id)
        fig.savefig(outname)
        print(outname)
Exemple #3
0
def simple_rho(this_looper,core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr=this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times=thtr.times[mask]+0 #the zero makes a copy
    times.shape=times.size,1
    times=times/colors.tff
    G = colors.G
    gx = thtr.track_dict['grav_x']
    gy = thtr.track_dict['grav_y']
    gz = thtr.track_dict['grav_z']
    GE2 = -1/(8*np.pi)*(gx*gx+gy*gy+gz*gz)
    ge_min=GE2.min()
    ge_max=GE2.max()
    for core_id in core_list:
        fig,ax=plt.subplots(1,1)

            
        ms = trackage.mini_scrubber(thtr,core_id, do_velocity=False)
        #ms.particle_pos(core_id)

        if ms.nparticles < 1000:
            sl=slice(None)
            c=[0.5]*4
        else:
            sl = slice(None,None,10)
            #c=[0,0,0,0.1]
            c=[0.1]*4

        rho = ms.density[sl].transpose()
        rho = rho[mask,:]
        gx = thtr.c([core_id],'grav_x')[sl].transpose()[mask,:]
        gy = thtr.c([core_id],'grav_y')[sl].transpose()[mask,:]
        gz = thtr.c([core_id],'grav_z')[sl].transpose()[mask,:]
        GE2 = 1/(8*np.pi*G)*(gx*gx+gy*gy+gz*gz)

        ax.plot(times , GE2, c=c, linewidth=0.1)
        axbonk(ax,xlabel=r'$t/t_{ff}$', ylabel=r'$(\nabla \phi)^2/8 pi G$',yscale='log', ylim=[ge_min,ge_max])
        ax2=ax.twinx()
        c=[1.0,0.1,0.1,0.1]
        ax2.plot(times , rho, c=c, linewidth=0.1)
        axbonk(ax2,xlabel=r'$t/t_{ff}$', ylabel=r'$\rho$',yscale='log')

        outname='plots_to_sort/%s_GE_t_c%04d.png'%(this_looper.sim_name,core_id)
        fig.savefig(outname)
        print(outname)
Exemple #4
0
def vr_vt(this_looper, core_list=None, symlog=False):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times = times / colors.tff
    vr_extents = extents()
    fig, ax = plt.subplots(1, 2, figsize=(12, 8))
    axlist = ax.flatten()

    for core_id in core_list:
        for aaa in axlist:
            aaa.clear()
        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)

        vr = ms.vr_rel[:, mask]
        vt = np.sqrt(ms.vt2_rel[:, mask])
        #r  = ms.r[:,mask]
        #omega = vt/r
        #print(omega.min(),omega.max())
        Nlin = 32
        Nlog = 32
        if symlog:
            bins1 = np.geomspace(1, 20, Nlog)
            bins2 = np.linspace(-1, 1, Nlin)
            bins = np.unique(np.concatenate([-bins1[::-1], bins2, bins1]))
        else:
            bins = np.linspace(-16, 16, 65)

        vvv = [vr, vt]
        for nv, v in enumerate(vvv):
            label = [r'$v_r$', r'$v_t$', r'$\omega$'][nv]
            stuff = heat_map.heat_map(v, times, ax=axlist[nv], bins=bins)
            axlist[nv].plot(times, times * 0, c='k')
            axlist[nv].plot(times, times * 0 + 1, c='k')
            axlist[nv].plot(times, times * 0 - 1, c='k')
            axbonk(axlist[nv], xlabel=r'$t/t_{ff}$', ylabel=label)
            if symlog:
                axlist[nv].set_yscale('symlog', linthresh=1)

        outname = '/home/dccollins/PigPen/%s_vr_vt_c%04d.png' % (
            this_looper.sim_name, core_id)
        fig.savefig(outname)
        print(outname)
Exemple #5
0
def div_v_hair(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    rho_all = thtr.track_dict['density']
    rho_min = rho_all.min()
    rho_max = rho_all.max()
    B_all = thtr.track_dict['magnetic_field_strength']
    B_min = B_all.min()
    B_max = B_all.max()
    fig, ax = plt.subplots(1, 1)
    RM = np.zeros([len(times), len(core_list)])
    BM = np.zeros([len(times), len(core_list)])
    DivV = np.zeros([len(times), len(core_list)])
    AllDivV = thtr.track_dict['velocity_divergence']
    MinDivV = AllDivV.min()
    MaxDivV = AllDivV.max()
    for nc, core_id in enumerate(core_list):
        ax.clear()
        #print("%s %d"%(this_looper.sim_name,core_id))

        dv = thtr.c([core_id], 'cell_volume').transpose()[mask, :]
        Div = thtr.c([core_id], 'velocity_divergence').transpose()[mask, :]
        mean_div = (Div * dv).sum(axis=1) / dv.sum(axis=1)
        DivV[:, nc] = mean_div
        ax.plot(times, Div, c=[0.5] * 4, linewidth=0.1)

        axbonk(ax, xlabel='t', ylabel='DivV')  #,xscale='log',yscale='log')
        ax.set_yscale('symlog', linthresh=250)
        ax.plot(times, times * 0 + 250, c=[0.5] * 4)
        ax.plot(times, times * 0 - 250, c=[0.5] * 4)
        ax.set_ylim([MinDivV, MaxDivV])
        outname = 'plots_to_sort/%s_divv_c%04d.png' % (this_looper.sim_name,
                                                       core_id)
        fig.savefig(outname)
        print(outname)
    plt.close('all')
Exemple #6
0
def simple_rho(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    rho_all = thtr.track_dict['density']
    rho_min = rho_all.min()
    rho_max = rho_all.max()
    for core_id in core_list:
        fig, ax = plt.subplots(1, 1)

        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=False)
        ms.particle_pos(core_id)

        if ms.nparticles < 1000:
            sl = slice(None)
            c = [0.5] * 4
        else:
            sl = slice(None, None, 10)
            #c=[0,0,0,0.1]
            c = [0.1] * 4

        rho = ms.density[sl].transpose()
        rho = rho[mask, :]

        ax.plot(times, rho, c=c, linewidth=0.1)
        axbonk(ax,
               xlabel=r'$t/t_{ff}$',
               ylabel=r'$\rho$',
               yscale='log',
               ylim=[rho_min, rho_max])

        outname = 'plots_to_sort/%s_rho_t_c%04d.png' % (this_looper.sim_name,
                                                        core_id)
        fig.savefig(outname)
        print(outname)
Exemple #7
0
def simple_v(this_looper, core_list=None, symlog=False):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    vr_extents = extents()
    fig, ax = plt.subplots(2, 2, figsize=(12, 12))
    fig.subplots_adjust(wspace=0, hspace=0)
    ax[0][0].xaxis.tick_top()
    ax[0][1].xaxis.tick_top()
    ax[0][1].xaxis.set_label_position('top')
    ax[0][0].xaxis.set_label_position('top')
    ax[1][1].yaxis.tick_right()
    ax[0][1].yaxis.tick_right()
    ax[1][1].yaxis.set_label_position('right')
    ax[0][1].yaxis.set_label_position('right')
    for core_id in core_list:
        axlist = ax.flatten()
        for aaa in axlist:
            aaa.clear()

        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)
        ms.particle_pos(core_id)

        if ms.nparticles < 1000:
            sl = slice(None)
            c = [0.5] * 4
        else:
            sl = slice(None, None, 10)
            #c=[0,0,0,0.1]
            c = [0.1] * 4

        vx = ms.raw_vx[sl].transpose()[mask, :]
        vy = ms.raw_vy[sl].transpose()[mask, :]
        vz = ms.raw_vz[sl].transpose()[mask, :]
        vr = ms.rel_vmag[sl].transpose()[mask, :]
        vr_extents(vr)
        vvv = [vx, vy, vz, vr]
        fig2, ax2 = plt.subplots(1, 1)
        for nv, v in enumerate(vvv):
            axlist[nv].plot(times, v, c=c, linewidth=0.1)
            label = [r'$v_x$', r'$v_y$', r'$v_z$', r'$|(v-\bar{v})|$'][nv]
            vext = [-20, 20]

            axlist[nv].plot(times, times * 0, c='k', linewidth=0.2)
            axlist[nv].plot(times, times * 0 + 1, c='k', linewidth=0.2)
            axlist[nv].plot(times, times * 0 - 1, c='k', linewidth=0.2)
            axbonk(axlist[nv], xlabel=r'$t/t_{ff}$', ylabel=label, ylim=vext)
            if symlog:
                axlist[nv].set_yscale('symlog', linthresh=1)

            ax2.hist(v[-1, :], histtype='step', label=label)
        ax2.legend(loc=0)
        logornot = ""
        if symlog:
            logornot = "_symlog"
        fig2.savefig('plots_to_sort/vhist_%s%s.png' %
                     (this_looper.sim_name, logornot))

        outname = 'plots_to_sort/%s_v_t_c%04d.png' % (this_looper.sim_name,
                                                      core_id)
        fig.savefig(outname)
        print(outname)
    print("VR extents", vr_extents.minmax)
    for nset, superset in enumerate(stuff):
        if nset != 1:
            continue

        core_list = list(superset)
        color_dict = colors.make_core_cmap(core_list, cmap='tab20c', seed=-1)
        frame_list = set_looper.tr.frames[::10]
        set_looper.out_prefix = '%s_full_S%02d' % (this_simname, nset)
else:
    core_list = np.unique(set_looper.core_ids)[:2]
    frame_list = set_looper.tr.frames[::10]
#frame_list=set_looper.tr.frames #[::10]
if 1:
    import movie_frames
    reload(movie_frames)
    movie_mask = movie_frames.quantized_mask(set_looper)
    frame_list = set_looper.tr.frames[movie_mask]
    frame_list = frame_list[frame_list > 71]
core_list = [323]
frame_list = frame_list[-1:]
color_dict = colors.make_core_cmap(core_list, cmap='tab20c', seed=-1)

if 1:
    set_looper.ds_list = {}
    derived = []
    #derived=[xtra_energy.add_b_over_rho]
    derived = [xtra_energy.add_energies]
    mono = core_proj.core_proj_multiple(set_looper,
                                        axis_list=[0],
                                        color_dict=color_dict,
                                        frame_list=frame_list,
Exemple #9
0
def simple_v(this_looper, core_list=None, symlog=False):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times = times / colors.tff
    vr_extents = extents()
    fig, ax = plt.subplots(2, 2, figsize=(12, 12))
    fig.subplots_adjust(wspace=0, hspace=0)
    ax[0][0].xaxis.tick_top()
    ax[0][1].xaxis.tick_top()
    ax[0][1].xaxis.set_label_position('top')
    ax[0][0].xaxis.set_label_position('top')
    ax[1][1].yaxis.tick_right()
    ax[0][1].yaxis.tick_right()
    ax[1][1].yaxis.set_label_position('right')
    ax[0][1].yaxis.set_label_position('right')
    for core_id in core_list:
        axlist = ax.flatten()
        for aaa in axlist:
            aaa.clear()
        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)

        vx = ms.raw_vx[:, mask]
        vy = ms.raw_vx[:, mask]
        vz = ms.raw_vx[:, mask]
        vr = ms.rel_vmag[:, mask]
        vr_extents(vr)
        vvv = [vx, vy, vz, vr]
        Nlin = 32
        Nlog = 32
        if symlog:
            bins1 = np.geomspace(1, 16, Nlog)
            bins2 = np.linspace(-1, 1, Nlin)
            bins = np.unique(np.concatenate([-bins1[::-1], bins2, bins1]))
        else:
            bins = np.linspace(-16, 16, 65)
        #fig2,ax2=plt.subplots(1,1)
        #ax2.plot(bins)
        #fig2.savefig('/home/dccollins/PigPen/bins.png')

        for nv, v in enumerate(vvv):
            label = [r'$v_x$', r'$v_y$', r'$v_z$', r'$v_r$'][nv]

            stuff = heat_map.heat_map(v, times, ax=axlist[nv], bins=bins)
            axlist[nv].plot(times, times * 0, c='k')
            axlist[nv].plot(times, times * 0 + 1, c='k')
            axlist[nv].plot(times, times * 0 - 1, c='k')
            axbonk(axlist[nv], xlabel=r'$t/t_{ff}$', ylabel=label)
            if symlog:
                axlist[nv].set_yscale('symlog', linthresh=1)

        if symlog:
            logornot = "_symlog"
        else:
            logornot = ""
        outname = 'plots_to_sort/%s_v_t_heat_c%04d%s.png' % (
            this_looper.sim_name, core_id, logornot)
        fig.savefig(outname)
        print(outname)
    print("VR extents", vr_extents.minmax)
Exemple #10
0
reload(time_line)
import movie_frames

if 1:
    import three_loopers_u500 as TL5
    this_looper = TL5.loops['u503']

if 1:
    core_list = [223]
    core_list = [76]
    full_core_list = np.unique(this_looper.tr.core_ids)
    core_list = full_core_list

if 0:
    movie_mask = movie_frames.quantized_mask(this_looper)
    times = this_looper.tr.times[movie_mask] / colors.tff
    frames = this_looper.tr.frames[movie_mask]

if 0:
    #hair movie
    #fig, ax = plt.subplots(1,1,figsize=(12,8))
    fig, ax = plt.subplots(1, 1, figsize=(8, 8))
    thing = movie_hair.flow(this_looper)
    thing.run(core_list=core_list,
              frames='reg',
              external_ax=ax,
              external_fig=fig)

if 1:
    #velocity heat map for each core.
Exemple #11
0
def rho_ke_ge(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    frames = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[frames] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    rho_all = thtr.track_dict['density']
    rho_min = rho_all.min()
    rho_max = rho_all.max()
    for core_id in core_list:
        if 0:
            fig, ax = plt.subplots(3, 1, figsize=(8, 12))
            fig.subplots_adjust(hspace=0, wspace=0)
            ax0 = ax[0]
            ax1 = ax[1]
            ax2 = ax[2]
        fig, ax = plt.subplots(1, 1)

        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)
        ms.particle_pos(core_id)

        if ms.nparticles < 1000:
            sl = slice(None)
            c = [0.5] * 4
        else:
            sl = slice(None, None, 10)
            #c=[0,0,0,0.1]
            c = [0.1] * 4

        phi = thtr.c([core_id], 'PotentialField')[sl].transpose()
        phi = phi[frames, :]
        rho = ms.density[sl].transpose()
        rho = rho[frames, :]
        vx = ms.raw_vx[sl].transpose()
        vx = vx[frames, :]
        vy = ms.raw_vy[sl].transpose()
        vy = vy[frames, :]
        vz = ms.raw_vz[sl].transpose()
        vz = vz[frames, :]

        v2 = vx**2 + vy**2 + vz**2
        ke = 0.5 * v2
        ge = 0.5 * phi

        ax0 = ax
        ax1 = ax
        ax2 = ax
        ax1 = ax0.twinx()
        ax2 = ax1
        c0 = [1.0, 0.5, 0.5, 0.5]
        ax0.plot(times, rho, c=c0, linewidth=0.1)
        axbonk(ax0,
               xlabel=r'$t/t_{ff}$',
               ylabel=r'$\rho$',
               yscale='log',
               ylim=[rho_min, rho_max])

        c1 = [0.5, 1.0, 0.5, 0.5]
        ax1.plot(times, ke, c=c1, linewidth=0.1)
        axbonk(ax1, xlabel=r'$t/t_{ff}$', ylabel=r'$KE$', yscale='log')

        c2 = [0.5, 0.5, 1.0, 0.5]
        ax2.plot(times, np.abs(ge), c=c2, linewidth=0.1)
        axbonk(ax2, xlabel=r'$t/t_{ff}$', ylabel=r'$GE$', yscale='log')

        outname = 'plots_to_sort/%s_rho_ke_ge_t_c%04d.png' % (
            this_looper.sim_name, core_id)
        fig.savefig(outname)
        print(outname)
Exemple #12
0
def GE_pearson(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    name = this_looper.sim_name
    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    G = colors.G
    #gx = thtr.track_dict['grav_x']
    #gy = thtr.track_dict['grav_y']
    #gz = thtr.track_dict['grav_z']
    #GE2 = -1/(8*np.pi)*(gx*gx+gy*gy+gz*gz)
    #ge_min=GE2.min()
    #ge_max=GE2.max()
    PearsonR = np.zeros([len(core_list), len(times)])
    PearsonP = np.zeros([len(core_list), len(times)])
    PearsonRho = np.zeros([len(core_list), len(times)])
    PeakRho = np.zeros([len(core_list), len(times)])
    for nc, core_id in enumerate(core_list):
        print('GE pearson %s %d' % (name, core_id))

        ms = trackage.mini_scrubber(thtr, core_id, do_velocity=False)
        #ms.particle_pos(core_id)

        if ms.nparticles < 1000:
            sl = slice(None)
            c = [0.5] * 4
        else:
            sl = slice(None, None, 10)
            #c=[0,0,0,0.1]
            c = [0.1] * 4

        rho = ms.density[sl]
        rho = rho[:, mask]

        PeakRho[nc, :] = rho.max(axis=0)

        gx = thtr.c([core_id], 'grav_x')[sl][:, mask]
        gy = thtr.c([core_id], 'grav_y')[sl][:, mask]
        gz = thtr.c([core_id], 'grav_z')[sl][:, mask]
        GE2 = 1 / (8 * np.pi * G) * (gx * gx + gy * gy + gz * gz)

        RRR = ms.r[sl][:, mask]
        for n in range(GE2.shape[1]):
            the_x = np.log(RRR[:, n])
            the_y = np.log(GE2[:, n])
            #the_y=rho[:,n]
            r, p = scipy.stats.pearsonr(the_x, the_y)
            PearsonR[nc, n] = r
            PearsonP[nc, n] = p
            the_y = np.log(rho[:, n])
            r, p = scipy.stats.pearsonr(the_x, the_y)
            PearsonRho[nc, n] = r

    if 0:
        fig, ax = plt.subplots(1, 2)
        ax[0].plot(times, PearsonR)
        #ax[0].boxplot(PearsonR)
        #ax[1].boxplot(PearsonRho)
        fig.savefig('plots_to_sort/phi_box_%s.png' % name)

    return {
        'PR': PearsonR,
        'PP': PearsonP,
        'Prho': PearsonRho,
        'T': times,
        'PeakRho': PeakRho
    }

    if 0:
        fig, ax = plt.subplots(1, 1)
        ax.plot(times, GE2, c=c, linewidth=0.1)
        axbonk(ax,
               xlabel=r'$t/t_{ff}$',
               ylabel=r'$(\nabla \phi)^2/8 pi G$',
               yscale='log',
               ylim=[ge_min, ge_max])
        ax2 = ax.twinx()
        c = [1.0, 0.1, 0.1, 0.1]
        ax2.plot(times, rho, c=c, linewidth=0.1)
        axbonk(ax2, xlabel=r'$t/t_{ff}$', ylabel=r'$\rho$', yscale='log')

        outname = 'plots_to_sort/%s_GE_t_c%04d.png' % (this_looper.sim_name,
                                                       core_id)
        fig.savefig(outname)
        print(outname)
Exemple #13
0
def div_v_hair(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    DivV = np.zeros([len(times), len(core_list)])
    for nc, core_id in enumerate(core_list):

        dv = thtr.c([core_id], 'cell_volume').transpose()[mask, :]
        Div = thtr.c([core_id], 'velocity_divergence').transpose()[mask, :]
        mean_div = (Div * dv).sum(axis=1) / dv.sum(axis=1)
        DivV[:, nc] = mean_div

    fig, ax = plt.subplots(1, 1)
    DivVall = thtr.track_dict['velocity_divergence']
    DivVall_early = DivVall[:, :50].flatten()
    YYY = np.mgrid[0:1:DivVall_early.size * 1j]
    print(YYY.size)
    ax.plot(sorted(DivVall_early), YYY)
    outname = 'plots_to_sort/%s_divv_early_hist.png' % (this_looper.sim_name)
    axbonk(ax, xlim=[-1000, 1000])
    fig.savefig(outname)
    print(outname)

    if 0:
        fig, ax = plt.subplots(1, 1)
        rho_min = RM.min()
        rho_max = RM.max()
        B_min = BM.min()
        B_max = BM.max() / 2
        print(B_min, B_max)
        for iframe in range(times.size):
            ax.clear()
            ax.plot(RM[:iframe, :], BM[:iframe, :], c=[0.5] * 4, linewidth=0.1)
            axbonk(ax,
                   xlabel='rho',
                   ylabel='B',
                   xscale='log',
                   yscale='log',
                   xlim=[rho_min, rho_max],
                   ylim=[B_min, B_max])
            outname = 'plots_to_sort/MeanBvsRho_%s_i%04d.png' % (
                this_looper.sim_name, iframe)
            fig.savefig(outname)
            print(outname)
    if 0:
        fig, ax = plt.subplots(1, 1)
        ax.plot(times, RM, c=[1, 0.5, 0.5, 0.5], linewidth=0.1)
        ax.plot(times, BM, c=[0.5, 1.0, 0.5, 0.5], linewidth=0.1)
        ax.plot(times, np.abs(DivV), c=[0.5, 0.5, 1.0, 0.5], linewidth=0.1)
        #ax.plot(times,BM/RM,c=[0.5,0.5,1.0,0.5],linewidth=0.1)

        X = nar([times.flatten()] * BM.shape[1]).transpose().flatten()
        Y = np.log((BM / RM).flatten())
        pfit = np.polyfit(X, np.exp(Y), 1)
        ax.set_title('log10 B/Rho = B0 e^(%.1f t)' % (pfit[0]))
        #print(pfit)
        #ax.clear()
        #ax.scatter(X,10**Y)
        ax.plot(times, times * pfit[0] + pfit[1], c='k')

        #ax.plot(times,RM/BM**2,c=[0.5,0.5,1.0,0.5],linewidth=0.1)
        outname = 'plots_to_sort/b_and_rho_%s.png' % (this_looper.sim_name)
        axbonk(ax, xlabel='t/tff', ylabel='B,rho', yscale='log')
        fig.savefig(outname)
        print(outname)
Exemple #14
0
    def run(self, core_list=None, symlog=False, do_plots=False, atool=None):
        this_looper = self.this_looper

        if core_list is None:
            core_list = np.unique(this_looper.tr.core_ids)

        thtr = this_looper.tr
        mask = movie_frames.quantized_mask(this_looper).flatten()
        times = thtr.times[mask] + 0  #the zero makes a copy
        times.shape = times.size, 1
        times = times / colors.tff
        vr_extents = extents()

        if do_plots:
            fig, ax = plt.subplots(2, 2, figsize=(12, 12))
            axlist = ax.flatten()
            fig.subplots_adjust(wspace=0, hspace=0)
            ax[0][0].xaxis.tick_top()
            ax[0][1].xaxis.tick_top()
            ax[0][1].xaxis.set_label_position('top')
            ax[0][0].xaxis.set_label_position('top')
            ax[1][1].yaxis.tick_right()
            ax[0][1].yaxis.tick_right()
            ax[1][1].yaxis.set_label_position('right')
            ax[0][1].yaxis.set_label_position('right')

            ax5 = ax[0][0].twinx()

        self.sigma_3d = np.zeros([len(core_list), len(times)])

        for nc, core_id in enumerate(core_list):
            ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)

            if do_plots:
                for aaa in ax.flatten():
                    aaa.clear()
                ax5.clear()
            if ms.nparticles < 1000:
                sl = slice(None)
                c = [0.5] * 4
            else:
                sl = slice(None, None, 10)
                #c=[0,0,0,0.1]
                c = [0.1] * 4

            #ms.particle_pos(core_id)
            ms.get_central_at_once(core_id)

            vx = ms.rel_vx[sl].transpose()[mask, :]
            vy = ms.rel_vy[sl].transpose()[mask, :]
            vz = ms.rel_vz[sl].transpose()[mask, :]
            vr = ms.rel_vmag[sl].transpose()[mask, :]
            vr_extents(vr)
            vvv = [vx, vy, vz, vr]
            if do_plots:
                for nv, v in enumerate(vvv):
                    axlist[nv].plot(times, v, c=c, linewidth=0.1)
                    label = [r'$v_x$', r'$v_y$', r'$v_z$',
                             r'$|(v-\bar{v})|$'][nv]
                    vext = [-20, 20]

                    axlist[nv].plot(times, times * 0, c='k', linewidth=0.2)
                    axlist[nv].plot(times, times * 0 + 1, c='k', linewidth=0.2)
                    axlist[nv].plot(times, times * 0 - 1, c='k', linewidth=0.2)
                    axbonk(axlist[nv],
                           xlabel=r'$t/t_{ff}$',
                           ylabel=label,
                           ylim=vext)
                    if symlog:
                        axlist[nv].set_yscale('symlog', linthresh=1)
                axlist[3].set_ylim([0, vext[1]])

                if atool is not None:
                    ax5.plot(times,
                             atool.Alpha_rho_r[nc, :],
                             c='r',
                             label=r'$\alpha$')
                    ax5.plot(times,
                             atool.Pearson_rho_r[nc, :],
                             c='g',
                             label=r'$r-\rho$')
                    ax5.plot(times,
                             atool.Pearson_GE_r[nc, :],
                             c='b',
                             label=r'$r-GE$')
                    ax5.set_ylim(-2.5, 2.5)
                    ax5.legend(loc=2)

                logornot = ""
                if symlog:
                    logornot = "_symlog"

                outname = 'plots_to_sort/%s_v_t_c%04d.png' % (
                    this_looper.sim_name, core_id)
                fig.savefig(outname)
                print(outname)
Exemple #15
0
def simple_rho(this_looper, core_list=None):

    if core_list is None:
        core_list = np.unique(this_looper.tr.core_ids)

    thtr = this_looper.tr
    mask = movie_frames.quantized_mask(this_looper).flatten()
    times = thtr.times[mask] + 0  #the zero makes a copy
    times.shape = times.size, 1
    times = times / colors.tff
    rho_all = thtr.track_dict['density']
    rho_min = rho_all.min()
    rho_max = rho_all.max()
    B_all = thtr.track_dict['magnetic_field_strength']
    B_min = B_all.min()
    B_max = B_all.max()
    fig, ax = plt.subplots(1, 1)
    RM = np.zeros([len(times), len(core_list)])
    BM = np.zeros([len(times), len(core_list)])
    DivV = np.zeros([len(times), len(core_list)])
    for nc, core_id in enumerate(core_list):
        #print("%s %d"%(this_looper.sim_name,core_id))

        rho = thtr.c([core_id], 'density').transpose()[mask, :]

        dv = thtr.c([core_id], 'cell_volume').transpose()[mask, :]
        B = thtr.c([core_id], 'magnetic_field_strength').transpose()[
            mask, :] / colors.mean_field[this_looper.sim_name]
        rho_mean = (rho * dv).sum(axis=1) / dv.sum(axis=1)
        RM[:, nc] = rho_mean
        B_mean = (B * dv).sum(axis=1) / dv.sum(axis=1)
        BM[:, nc] = B_mean

        Div = thtr.c([core_id], 'velocity_divergence').transpose()[mask, :]
        mean_div = (Div * dv).sum(axis=1) / dv.sum(axis=1)
        DivV[:, nc] = mean_div

        ax.plot(rho_mean, B_mean, c=[0.5] * 4, linewidth=0.1)
        axbonk(ax, xlabel='rho', ylabel='B', xscale='log', yscale='log')
    outname = 'plots_to_sort/%s_mean_b_and_rho.png' % (this_looper.sim_name)
    fig.savefig(outname)
    print(outname)
    plt.close('all')

    if 0:
        fig, ax = plt.subplots(1, 1)
        rho_min = RM.min()
        rho_max = RM.max()
        B_min = BM.min()
        B_max = BM.max() / 2
        print(B_min, B_max)
        for iframe in range(times.size):
            ax.clear()
            ax.plot(RM[:iframe, :], BM[:iframe, :], c=[0.5] * 4, linewidth=0.1)
            axbonk(ax,
                   xlabel='rho',
                   ylabel='B',
                   xscale='log',
                   yscale='log',
                   xlim=[rho_min, rho_max],
                   ylim=[B_min, B_max])
            outname = 'plots_to_sort/MeanBvsRho_%s_i%04d.png' % (
                this_looper.sim_name, iframe)
            fig.savefig(outname)
            print(outname)
    if 1:
        fig, ax = plt.subplots(1, 1)
        ax.plot(times, RM, c=[1, 0.5, 0.5, 0.5], linewidth=0.1)
        ax.plot(times, BM, c=[0.5, 1.0, 0.5, 0.5], linewidth=0.1)
        #ax.plot(times,np.abs(DivV),c=[0.5,0.5,1.0,0.5],linewidth=0.1)
        ax.plot(times, BM / RM, c=[0.5, 0.5, 1.0, 0.5], linewidth=0.1)

        if 1:
            X = nar([times.flatten()] * BM.shape[1]).transpose().flatten()
            Y = np.log((BM / RM).flatten())
            pfit = np.polyfit(X, np.exp(Y), 1)
            ax.set_title('log10 B/Rho = B0 e^(%.1f t)' % (pfit[0]))
            #print(pfit)
            #ax.clear()
            #ax.scatter(X,10**Y)
            ax.plot(times, times * pfit[0] + pfit[1], c='k')
        if 0:
            X = nar([times.flatten()] * BM.shape[1]).transpose().flatten()
            Y = np.log((BM / RM).flatten())
            pfit = np.polyfit(X, Y, 1)
            ax.set_title('log10 B/Rho = B0 e^(%.1f t)' % (pfit[0]))
            print(pfit)
            #ax.clear()
            #ax.scatter(X,10**Y)
            ax.plot(times, np.exp(times * pfit[0] + pfit[1]), c='k')

        #ax.plot(times,RM/BM**2,c=[0.5,0.5,1.0,0.5],linewidth=0.1)
        outname = 'plots_to_sort/b_and_rho_%s.png' % (this_looper.sim_name)
        axbonk(ax, xlabel='t/tff', ylabel='B,rho', yscale='log')
        fig.savefig(outname)
        print(outname)