コード例 #1
0
    def do_plots(self):
            mass=nar(self.mass)
            sim_color={'u05':'r','u10':'g','u11':'b'}[self.this_looper.out_prefix]
            fig, axes=plt.subplots(2,2)
            ax0 = axes[0][0]; ax1=axes[0][1]
            ax2 = axes[1][0]; ax3=axes[1][1]
            ax0.scatter(self.density_0,self.alpha,c=sim_color)
            ax1.scatter(mass,self.alpha,c=sim_color)

            fig2, axes2=plt.subplots(1,1)
            bx0 = axes2
            if 'collapse_times' in dir(): #collapse_time can be found from density_time.py
                ok = nar(collapse_times) > 0
                t_ok=nar(collapse_times)[ok]
                ax2.scatter(t_ok, nar(self.alpha)[ok])
                ax3.scatter(t_ok, nar(self.mass)[ok],c=nar(sim_color)[ok])
                bx0.scatter(t_ok, nar(self.density_0)[ok])
                #ax3.scatter(t_ok, nar(density_0)[ok],c=nar(sim_color)[ok])
                pdb.set_trace()

            davetools.axbonk(ax0,xlabel=r'$\langle \rho \rangle$',ylabel=r'$\alpha$',  xscale='log',yscale='linear')
            davetools.axbonk(ax1,xlabel=r'$M(t=0)$',              ylabel=r'$\alpha$',   xscale='log',yscale='linear')
            davetools.axbonk(ax2,xlabel=r'$t_c$',                 ylabel=r'$\alpha$', xscale='log',yscale='linear')
            davetools.axbonk(ax3,xlabel=r'$t_c$',                 ylabel=r'$M(t=0)$',  xscale='log',yscale='log')
            davetools.axbonk(bx0,xlabel=r'$t_c$',   ylabel=r'$\langle \rho \rangle$',  xscale='log',yscale='linear')
            ax3.set_xlim([t_ok.min(),t_ok.max()])
            ax3.set_ylim(self.mass.min(),self.mass.max())
            ax1.set_xlim(self.mass.min(),self.mass.max())
            outname = '%s/alpha_mass.png'%dl.output_directory
            fig.savefig(outname)
            outname2 = '%s/tc_rho.png'%dl.output_directory
            fig2.savefig(outname2)
            print(outname)
コード例 #2
0
    def plot_many_spectra(self,ts,prefix,fname='TEST.png', **kwargs):
        def dostuff(arr):
            return np.abs(arr[1:])#/np.abs(arr[2])  #np.abs((arr/arr[2])[1:])
        fig,ax=plt.subplots(1,1)
        k = ts['vspec'][0]
        ylimits=dt.extents()
        xlim=dt.extents()
        pos_k=slice(None)
        #this_k=(k/k[1])[pos_k]
        this_k=(k*2*np.pi)#[1:]
        this_k = 0.5*(this_k[1:]+this_k[:-1])
        ax.plot( this_k,dostuff(ts['aspec'][1][pos_k]),marker='*', label=r'$P(a)$');   ylimits(ts['aspec'][1][pos_k])# print('a lim',ylimits)
        ax.plot( this_k,dostuff(ts['vspec'][1][pos_k]),marker='*', label=r'$P(v)$');   ylimits(ts['vspec'][1][pos_k])# print('v lim',ylimits)
        ax.plot( this_k,dostuff(ts['dspec'][1][pos_k]),marker='*', label=r'$P(\rho)$');ylimits(ts['dspec'][1][pos_k])# print('d lim',ylimits)
        ax.plot( this_k,dostuff(ts['hspec'][1][pos_k]),marker='*', label=r'$P(H)$');   ylimits(ts['hspec'][1][pos_k])# print('h lim',ylimits)
        ell=ts['lcent']
        #this_ell=(ell/ell[1])[pos_k]
        this_ell=ell[:-1]#[1:] 
        ax.plot( this_ell,dostuff(ts['ClEE'][pos_k]),marker='*', label=r'$C_{\ell}^{EE}$'); ylimits(ts['ClEE'])# print(ylimits)
        ax.plot( this_ell,dostuff(ts['ClBB'][pos_k]),marker='*', label=r'$C_{\ell}^{BB}$'); ylimits(ts['ClBB'])# print(ylimits)
        ax.plot( this_ell,dostuff(ts['ClTE'][pos_k]),marker='*', label=r'$ClTE$') ; ylimits(ts['ClTE'])# print(ylimits)
        ax.plot( this_ell,dostuff(ts['ClTT'][pos_k]),marker='*', label=r'$ClTT$') ; ylimits(ts['ClTT'])# print(ylimits)
        ax.plot( this_ell,dostuff(ts['ClHH'][pos_k]),marker='*', label=r'$ClHH$') ; ylimits(ts['ClHH'])# print(ylimits)
        ax.plot( this_ell,dostuff(ts['ClTB'][pos_k]),marker='*', label=r'$ClTB$') ; ylimits(ts['ClTB'])# print(ylimits)
        ax.plot( this_ell,dostuff(ts['ClEB'][pos_k]),marker='*', label=r'$ClEB$') ; ylimits(ts['ClEB'])# print(ylimits)
        dt.powerline(ax, this_ell[1]*2, this_ell[1]*30, 1, -5./3,c='k',label='-5/3')
        dt.powerline(ax, this_ell[1]*2, this_ell[1]*30, 1, -2.5,c='k',label='-2.5',linestyle='--')
        #ax.plot( this_ell, np.abs(ts['pork'])[pos_k],marker='*', label=r'pork') ; ylimits(ts['ClTE']); print(ylimits)
        #ts['ColumnDensity']= np.abs(cmbtools.harm2cl( ts['Eh'], ts['Deltal'],ts['lbins']))
        #ax.plot(this_ell,np.abs(ts['ColumnDensity'][pos_k]),c='k')
        #ax.plot( ell/ell[1], ts['ClTB'],marker='*', label=r'$ClEB$')
        xlim(this_k)
        xlim(this_ell)
        
        ax.legend(loc=1)
        ts.limits=ylimits


        #dt.axbonk(ax,xlabel='k/k1',ylabel='power',xscale='log',yscale='log')
        dt.axbonk(ax,xlabel='k/k1',ylabel='power',xscale='log',yscale='log')
        #ax.set_xscale('symlog',linthreshx=1)
        #ax.set_xlim(xlim)
        #ax.set_ylim(1e-9,1e4)
        #ax.set_yscale('symlog',linthreshy=1e-28)
        #ax.set_ylim(ylimits)
        ax.set_ylim(1e-7,50)
        print("ylimits",ylimits)

        title="%s n%04d %s"%(prefix,ts['frame'],ts['axis'])
        print("POOT",title)
        ax.set_title(title)
        fig.savefig(fname)
        plt.close(fig)
コード例 #3
0
    def plot_eb(self,ts,fname='TEST.png', slopes=None):
        """plot spectra extracted from e&b.
        the function 'dostuff' treats normalization and slicing."""

        def dostuff(arr):
            return arr[1:]#/np.abs(arr[2])  #np.abs((arr/arr[2])[1:])
        def dostuff2(arr):
            return arr[1:]#/np.abs(arr[2])  #np.abs((arr/arr[2])[1:])

        fig,ax=plt.subplots(1,1)

        k = ts.vspec[0]
        ylimits=dt.extents()
        xlim=dt.extents()
        pos_k=slice(None)
        this_k=(k/k[1])[pos_k]
        this_k=(k*2*np.pi)#[1:]
        this_k = 0.5*(this_k[1:]+this_k[:-1])
        ell=ts.lcent
        #this_ell=(ell/ell[1])[pos_k]
        this_ell=ell[:-1]#[1:] 

        rEB = ts['ClEB']/(ts['ClEE']*ts['ClBB'])**0.5
        lab=r'$r_{EB}=C_{\ell}^{EB}/\sqrt{C_{\ell}^{EE}C_{\ell}^{EE}}$'
        ax.plot( this_k,dostuff2(ts['aspec'][1]),c='k',marker='*', label=r'$a$');   ylimits(ts['aspec'][1][pos_k])# print('a lim',ylimits)
        ax.plot( this_ell,dostuff2(ts['ClEE']),        marker='*', label=r'$EE$',c='g'); ylimits(rEB)# print(ylimits)
        if slopes is not None:
            slopes.plot(ax,'EE',label=r'$\alpha^{EE}$',c='r')
            
        ax.plot( this_ell,dostuff2(ts['ClBB']),        marker='*', label=r'$BB$',c='b'); ylimits(rEB)# print(ylimits)
        ax.plot( this_ell,dostuff(rEB),                marker='*', label=r'$r_{EB}$',c='m'); ylimits(rEB)# print(ylimits)
        dt.axbonk(ax,xlabel='k/k1',ylabel=lab,xscale='log',yscale='log')
        #ax.set_xscale('symlog',linthreshx=1)
        #ax.set_xlim(xlim)
        #ax.set_ylim(1e-9,1e4)
        #ax.set_ylim(ylimits)
        ax.set_yscale('symlog',linthreshy=1e-2)
        ax.set_ylim(-30,30)
        #print("ylimits",ylimits)

        title="%s n%04d %s"%(self.prefix,ts['frame'],ts['axis'])
        ax.legend(loc=0)
        ax.set_title(title)
        fig.savefig(fname)
        print("saved "+fname)
        plt.close(fig)
コード例 #4
0
    def scatter_clee(self,fname):
        fig,ax=plt.subplots(1,1,figsize=(12,8))

        N = self.Q.shape

        #build the ell 
        rxa,rya = np.mgrid[ 0:N[0]:1,
                          0:N[0]//2+1:1]

        rxa[self.N[1]//2:,:] = rxa[:self.N[1]//2,:]- N[0]/2 #self.lmax #N[0]#*self.Deltal[0]/2
        rx=rxa*self.Deltal[0] 
        ry=rya*self.Deltal[0] 
            
        ell = np.sqrt(rx**2+ry**2)

        ####
        #here is code to plot r, and ensure it's right. 
        #fig2,ax2=plt.subplots(1,1,figsize=(8,8))
        #the transposei is to make 'x' be the horizontal axis.
        #ax2.imshow(ell.transpose(),origin='lower',interpolation='nearest')
        #fig.colorbar(ppp)
        #fig.savefig(fname)
        #fig2.savefig('/home/dcollins4096/PigPen/test.png')

        #compute the spectra.
        #Take out the normalization
        spectra = (np.abs(self.Eharm)**2).flatten()
        this_ClEE = cmbtools.harm2cl(self.Eharm,self.Deltal,self.lbins)
        this_ClEE *= (2*np.pi)**2*(self.Delta[0])**2/self.Deltal[0]**2
        
        #overplot bins, to see aliasing
        for l in self.lbins:
            ax.plot( [l,l], [1e-11,100],c=[0.5]*4)
        ax.plot( [np.pi]*2, [1e-11,100],c='k')
        ax.scatter( ell.flatten(), spectra,s=0.1)
        dt.axbonk(ax,xlabel='ell',ylabel='CEE')
        ax.set_xscale('symlog',linthreshx=self.Deltal[0])
        ax.set_yscale('symlog',linthreshy=1e-9)
        ax.set_ylim( 0, spectra.max())
        ax.set_xlim( ell.min(), ell.max()*1.1)
        ax.plot( self.lcent, this_ClEE,marker='*')

        fig.savefig(fname)
        print(fname)
        plt.close(fig)
コード例 #5
0
    def plot_2eb(self,ts0,ts1,slopes0=None,slopes1=None,fname='TEST.png', slopes=None):
        """plot spectra extracted from e&b.
        the function 'dostuff' treats normalization and slicing."""

        def dostuff(arr):
            return arr[1:]#/np.abs(arr[2])  #np.abs((arr/arr[2])[1:])
        def dostuff2(arr):
            return arr[1:]#/np.abs(arr[2])  #np.abs((arr/arr[2])[1:])

        fig,axes=plt.subplots(1,2)
        ax0 = axes[0]; ax1 = axes[1]
        for ns,ts in enumerate([ts0,ts1]):
            slopes = [slopes0,slopes1][ns] #this is clunky, sorry.
            ax=axes[ns]
            ylimits=dt.extents()
            xlim=dt.extents()
            ell=ts.lcent
            this_ell=ell[:-1]#[1:] 

            lab=r'$C_\ell^{EE}$'
            ax.plot( this_ell,dostuff2(ts['ClEE']),        marker='*', label=r'$EE$',c='g')
            #the slope value is added to the label in slopes.plot
            if slopes is not None:
                slopes.plot(ax,'EE',label=r'$\alpha^{EE}$',c='r',norm=1)#ts.bin_style=='5deg')
                
            #ax.plot( this_ell,dostuff2(ts['ClBB']),        marker='*', label=r'$BB$',c='b')
            dt.axbonk(ax,xlabel='k/k1',ylabel=lab,xscale='log',yscale='log')
            ax.set_yscale('symlog',linthreshy=1e-10)
            #ax.set_yscale('log')
            ax.set_ylim(0,0.5e-3)
            ax.set_xlim(0.01,2*np.pi)
            #ax.set_ylim(0,1e-3)
            title=["new binning","old binning"][ns]
            ax.legend(loc=0)
            ax.set_title(title)
        fig.savefig(fname)
        print("saved "+fname)
        plt.close(fig)
コード例 #6
0
    #miniscrubber computes distance, r^2, several other quantities
    tmap=rainbow_map(ms.ntimes)

    asort =  np.argsort(thtr.times)
    density = thtr.c([core_id],'density')
    if (asort != sorted(asort)).any():
        print("Warning: times not sorted.")
    n0=asort[0]
    tsorted = thtr.times[asort]

    fig, axd1=plt.subplots(1,1)

    for n_count,n_time in enumerate(asort):
        time=thtr.times[n_time]
        if time == 0:
            continue
        c=tmap(n_count,ms.nparticles)
        this_r=ms.r[:,n_time]+0
        r_un = nar(sorted(np.unique(this_r)))

        axd1.scatter(density[:,n_time],np.abs(costheta[:,n_time]),c=c,label=thtr.times[n_time],s=0.1)
        #axd1.plot(r_un, 100*(r_un/1e-2)**-2,c='k',linewidth=0.1)

    davetools.axbonk(axd1,xscale='log',yscale='linear',ylabel=r'$cos \theta$',xlabel=r'$\rho$',
                     ylim=[0,1], xlim=rho_extents.minmax)
    outname = '%s/density_abs_angle_c%04d'%(dl.output_directory,core_id)
    fig.savefig(outname)
    print("saved "+outname)
    plt.close(fig)

コード例 #7
0
                                      rel_vz_mean**2)
            print(v_total_average)
            rat = v_radial_average / v_total_average
            if rat < -1:
                pdb.set_trace()
            ratarray.append(rat)
            axd1.scatter(v_radial_average, rat, marker='s', c='k')
            #axd1.plot([-10,0],[10,0],c='k')
            #axd1.scatter( harmonic_r, mean_vr, c=c[0:1], marker='*')

    limits = np.abs(vel_ext.minmax).max()
    limits = [-limits, limits]
    #axd1.plot([ms.r.min(),ms.r.max()], [1,1], c=[0.5]*4)
    labs = ['vx', 'vy', 'vz', 'vtotal']
    for iii, ax4i in enumerate([ax40, ax41, ax42, ax43]):
        davetools.axbonk(ax4i, xlabel='r', ylabel=labs[iii], ylim=limits)
        ax4i.set_xscale('symlog', linthreshx=1. / 2048)
        ax4i.set_yscale('symlog', linthreshy=2)
        ax4i.set_xlim([0, 1])
    ax43.set_ylim([0, limits[1]])
    if 0:
        davetools.axbonk(axd1,
                         xscale='linear',
                         yscale='linear',
                         xlabel='vr_rel',
                         ylabel=r'$v_r/v_{total}$')
        #xlim=[-15,15], ylim=[0,15])
        outname = '%s/ratio_c%04d' % (dl.output_directory, core_id)
    if 0:
        davetools.axbonk(axd1,
                         xscale='linear',
コード例 #8
0
                    this_r,
                    this_field[:, n_time],
                    statistic='mean',
                    bins=r_bins)
                label = None
                if n_count == 0:
                    label = field
                axd1.plot(r_centers, bin_means, c=c, label=label)
                #axd1.scatter(this_r,this_field[:,n_time],c=cxx,label=labels.get(field,field),s=0.1,marker='*')

            #r_un = nar(sorted(np.unique(this_r)))
            #axd1.plot(r_un, 100*(r_un/1e-2)**-2,c='k',linewidth=0.1)

        #davetools.axbonk(axd1,xscale='log',yscale='log',xlabel='r',ylabel=r'$E_G,E_B$', xlim=r_extents.minmax, ylim=grav_extents.minmax)
        davetools.axbonk(axd1,
                         xscale='log',
                         yscale='log',
                         xlabel='r',
                         ylabel=r'$E_G,E_B$',
                         xlim=r_extents.minmax,
                         ylim=density_extents)
        axd1.legend(loc=1)
        axd1.set_yscale('symlog', linthreshy=1e-3)
        #axd1.legend(loc=0)
        outname = '%s/%s_radius_c%04d' % (dl.output_directory, output_prefix,
                                          core_id)
        axd1.set_title("core %d %s" % (core_id, frame_stuff))
        fig.savefig(outname)
        print("saved " + outname)
        plt.close(fig)
コード例 #9
0
    def run(self, core_list=None):
        dx = 1. / 2048
        nx = 1. / dx
        thtr = self.this_looper.tr
        all_cores = np.unique(thtr.core_ids)
        if core_list is None:
            core_list = all_cores

        thtr.sort_time()

        if self.rho_extents is None:
            self.rho_extents = davetools.extents()
            self.r_extents = davetools.extents()
            for nc, core_id in enumerate(all_cores):
                ms = trackage.mini_scrubber(thtr, core_id)
                if ms.nparticles < 20:
                    continue
                density = thtr.c([core_id], 'density')[:, 0]
                self.rho_extents(density)
                self.r_extents(ms.r)

        tsorted = thtr.times
        self.core_list = core_list
        fig, axd = plt.subplots(2, 2)
        axd1 = axd[0][0]
        axd2 = axd[0][1]  #sorry
        axd3 = axd[1][0]
        axd4 = axd[1][1]

        ds = self.this_looper.load(0)
        ad = ds.all_data()
        axd2.hist(np.log10(ad['density'].v.flatten()),
                  histtype='step',
                  color='k')
        rmcore = rainbow_map(len(core_list))
        for nc, core_id in enumerate(core_list):
            ms = trackage.mini_scrubber(thtr, core_id)
            self.ms = ms
            if ms.nparticles < 10:
                continue
            self.cores_used.append(core_id)

            tmap = rainbow_map(ms.ntimes)
            asort = np.argsort(thtr.times)
            density = thtr.c([core_id], 'density')
            n0 = asort[0]
            tsorted = thtr.times[asort]

            #fig, axd1=plt.subplots(1,1)

            for n_count, n_time in enumerate(asort[0:1]):
                mask2 = ms.compute_unique_mask(core_id,
                                               dx=1. / 2048,
                                               frame=n_count)
                time = thtr.times[n_time]
                c = tmap(n_count, mask2.sum())
                c = rmcore(nc, mask2.sum())
                this_r = ms.r[:, n_time] + 0
                r_un = nar(sorted(np.unique(this_r)))

                axd1.scatter(this_r[mask2],
                             density[mask2, n_time],
                             c=c,
                             label=thtr.times[n_time],
                             s=0.1)
                axd2.hist(np.log10(density[mask2, n_time]),
                          histtype='step',
                          color=c[0])
                axd1.plot(r_un, 100 * (r_un / 1e-2)**-2, c='k', linewidth=0.1)
                axd3.scatter(density[mask2, n_time].mean(),
                             density[mask2, n_time].std())

            davetools.axbonk(axd1,
                             xscale='log',
                             yscale='log',
                             xlabel='r',
                             ylabel=r'$\rho$',
                             xlim=self.r_extents.minmax,
                             ylim=self.rho_extents.minmax)
            davetools.axbonk(axd2,
                             xscale='linear',
                             yscale='log',
                             xlabel='r',
                             ylabel=r'$\rho$',
                             xlim=np.log10(self.rho_extents.minmax))
        #outname = '%s/density_radius_c%04d'%(dl.output_directory,core_id)
        outname = '%s/density_radius_n0000.png' % (dl.output_directory)
        fig.savefig(outname)
        print("saved " + outname)
        plt.close(fig)
コード例 #10
0
            one_label=True

            for npart in list(range(ms.nparticles))[::10]:
                if one_label:
                    label=field
                    one_label=False
                else:
                    label=None


                axd1.plot(thtr.times, this_field[npart,:], c=c,label=label)
            if 0:
                growth = this_field >= 0
                death = ~growth
                axd1.plot(thtr.times, this_field[growth].mean(axis=0),c=c)
                axd1.plot(thtr.times, this_field[death].mean(axis=0),c=c)



        #davetools.axbonk(axd1,xscale='log',yscale='log',xlabel='r',ylabel=r'$E_G,E_B$', xlim=r_extents.minmax, ylim=all_extents.minmax)
        davetools.axbonk(axd1,xscale='linear',yscale='linear',xlabel='t',ylabel=r'$E_G,E_B$')
        axd1.legend(loc=0)
        axd1.set_yscale('symlog',linthreshy=1e+1)
        axd1.set_ylim(all_extents.minmax)
        #axd1.legend(loc=0)
        outname = '%s/%s_time_c%04d'%(dl.output_directory,output_prefix,core_id)
        axd1.set_title("core %d %s"%(core_id,frame_stuff))
        fig.savefig(outname)
        print("saved "+outname)
        plt.close(fig)
コード例 #11
0
                    if n_count == 0:
                        label = field
                    axd1.plot(r_centers, bin_means_b, c=c, label=label)

#                axd1.scatter(this_r,arr,c=cxx,label=labels.get(field,field),s=0.1,marker='*')
                print("N pos %d N neg %d Ntot %d FG %d" %
                      ((arr >= 0).sum(),
                       (arr < 0).sum(), arr.size, field_growth.sum()))

            #r_un = nar(sorted(np.unique(this_r)))
            #axd1.plot(r_un, 100*(r_un/1e-2)**-2,c='k',linewidth=0.1)

        #davetools.axbonk(axd1,xscale='log',yscale='log',xlabel='r',ylabel=r'$E_G,E_B$', xlim=r_extents.minmax, ylim=all_extents.minmax)
        davetools.axbonk(axd1,
                         xscale='log',
                         yscale='linear',
                         xlabel='r',
                         ylabel=r'$E_G,E_B$',
                         xlim=[r_min, r_extents.minmax[1]],
                         ylim=all_extents)
        #axd1.legend(loc=1)
        axd1.set_yscale('symlog', linthreshy=1e-3)
        axd1.set_ylim(all_extents.minmax)
        #axd1.legend(loc=0)
        outname = '%s/%s_radius_c%04d' % (dl.output_directory, output_prefix,
                                          core_id)
        axd1.set_title("core %d %s" % (core_id, frame_stuff))
        fig.savefig(outname)
        print("saved " + outname)
        plt.close(fig)
コード例 #12
0
    def run(self, core_list=None):
        thtr = self.this_looper.tr
        all_cores = np.unique(thtr.core_ids)
        if core_list is None:
            core_list = all_cores

        thtr.sort_time()
        rm = rainbow_map(len(all_cores))
        if self.rho_extents is None:
            self.rho_extents = davetools.extents()
            self.r_extents = davetools.extents()
            for nc, core_id in enumerate(all_cores):
                ms = trackage.mini_scrubber(thtr, core_id)
                if ms.nparticles == 1:
                    continue
                density = thtr.c([core_id], 'density')
                self.rho_extents(density)
                self.r_extents(ms.r)

        plt.close('all')
        fig, axd1 = plt.subplots(1, 1)
        fig4, ax4 = plt.subplots(2, 2)
        ax40 = ax4[0][0]
        ax41 = ax4[0][1]
        ax42 = ax4[1][0]
        ax43 = ax4[1][1]

        if self.vel_ext is None:
            #If we haven't done it yet, we'll need to run the velocity extents.
            self.vel_ext = extents()
            print("doing velocity extents")
            for nc, core_id in enumerate(core_list):
                ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)
                sigma2 = np.sqrt(
                    (ms.rel_vx**2 + ms.rel_vy**2 + ms.rel_vx**2).mean(axis=0))
                self.vel_ext(sigma2)
                self.vel_ext(ms.rel_vx)
                self.vel_ext(ms.rel_vy)
                self.vel_ext(ms.rel_vz)
                self.vel_ext(ms.rel_vmag)

        print('make plots')
        for nc, core_id in enumerate(core_list):

            #miniscrubber computes distance, r^2, several other quantities
            ms = trackage.mini_scrubber(thtr, core_id, do_velocity=True)

            for ax in [axd1, ax40, ax41, ax42, ax43]:
                ax.clear()

            tmap = rainbow_map(ms.ntimes)
            if ms.nparticles == 1:
                continue

            asort = np.argsort(thtr.times)
            density = thtr.c([core_id], 'density')
            if (asort != sorted(asort)).any():
                print("Warning: times not sorted.")
            n0 = asort[0]
            tsorted = thtr.times[asort]

            if ms.nparticles < 100:
                this_slice = slice(None)
            else:
                this_slice = slice(None, None, 10)
            for npart in list(range(ms.nparticles))[this_slice]:
                ax40.set_title("%s particles" % ms.nparticles)
                this_r = ms.r[npart, :] + 0
                this_r[this_r < 1. / 2048] = 1. / 2048
                r_un = nar(sorted(np.unique(this_r)))
                this_t = thtr.times
                c = [0.5] * 3
                outname4 = '%s/%s_vi_t_rel_volume_centroid_c%04d' % (
                    dl.output_directory, self.this_looper.out_prefix, core_id)
                ax40.plot(this_t, ms.rel_vx[npart, :], c=c, lw=.1)
                ax41.plot(this_t, ms.rel_vy[npart, :], c=c, lw=.1)
                ax42.plot(this_t, ms.rel_vz[npart, :], c=c, lw=.1)

                ax43.plot(this_t, ms.rel_vmag[npart, :], c=c, lw=.1)

            mean_vmag = np.mean(ms.rel_vmag, axis=0)
            sigma2 = np.sqrt(
                (ms.rel_vx**2 + ms.rel_vy**2 + ms.rel_vx**2).mean(axis=0))
            ax43.plot(this_t, mean_vmag, c='r')
            ax43.plot(this_t, sigma2, 'r:')

            unique_mask = ms.compute_unique_mask(core_id, dx=1. / 2048)
            um = unique_mask
            mean_vmag = np.mean(ms.rel_vmag[um], axis=0)
            sigma2 = np.sqrt((ms.rel_vx[um]**2 + ms.rel_vy[um]**2 +
                              ms.rel_vx[um]**2).mean(axis=0))
            ax43.plot(this_t, mean_vmag, c='g')
            ax43.plot(this_t, sigma2, 'g:')

            ax43.plot(this_t, np.mean(np.abs(ms.vr_rel), axis=0), c='b')

            #axd1.plot([ms.r.min(),ms.r.max()], [1,1], c=[0.5]*4)
            limits = np.abs(self.vel_ext.minmax).max()
            limits = [-limits, limits]

            labs = ['vx', 'vy', 'vz', 'vtotal']
            for iii, ax4i in enumerate([ax40, ax41, ax42, ax43]):
                davetools.axbonk(ax4i,
                                 xlabel='r',
                                 ylabel=labs[iii],
                                 xscale='linear',
                                 ylim=limits)
                ax4i.set_yscale('symlog', linthresh=2)
                #ax4i.set_yscale('linear')
            ax43.set_ylim([0, limits[1]])
            if 0:
                davetools.axbonk(axd1,
                                 xscale='linear',
                                 yscale='linear',
                                 xlabel='vr_rel',
                                 ylabel=r'$v_r/v_{total}$')
                #xlim=[-15,15], ylim=[0,15])
                outname = '%s/ratio_c%04d' % (dl.output_directory, core_id)
            if 0:
                davetools.axbonk(axd1,
                                 xscale='linear',
                                 yscale='linear',
                                 xlabel='vr_rel',
                                 ylabel=r'$rel_v2$',
                                 xlim=[-15, 15],
                                 ylim=[0, 15])
                outname = '%s/vr_vtotal_c%04d' % (dl.output_directory, core_id)
            if 0:
                davetools.axbonk(axd1,
                                 xscale='log',
                                 yscale='log',
                                 xlabel='r',
                                 ylabel=r'$v$',
                                 xlim=r_extents.minmax,
                                 ylim=rho_extents.minmax)
                axd1.set_xscale('symlog', linthresh=1. / 2048)
                axd1.set_xlim([0, 1])
                axd1.set_yscale('symlog', linthresh=1.)
                axd1.set_ylim([0, 15])
                outname = '%s/vr_vtotal_c%04d' % (dl.output_directory, core_id)

            #outname = '%s/vr_vtotal_c%04d'%(dl.output_directory,core_id)
            #fig.savefig(outname)
            #print("saved "+outname)
            fig4.savefig(outname4)
            print("saved " + outname4)
            plt.close(fig4)
コード例 #13
0
      ax2.plot(proj.lcent, avg_ratio,label='E/B ratio',c='k')
      ax2.plot(xslope, ymean,label='average ratio %0.2f'%mean_quantity,c='r')
      ax2.set_title('ratio %0.2f'%mean_quantity)
      ax2.legend(loc=0)
      ##------
      ee_slopes[i]=avg_slopes_ee[0]
      bb_slopes[i]=avg_slopes_bb[0]
      eb_ratios[i]=mean_quantity
      ee_slopes=np.array(ee_slopes)
      bb_slopes=np.array(bb_slopes)
      eb_ratios=np.array(eb_ratios)
      print('ee_slopes =')
      print(ee_slopes)
      ##------
      ax1.plot(proj.lcent,avg_clee,label='ClEE',c='g')
      ax1.plot(proj.lcent,avg_clbb,label='ClBB',c='b')
      dt.axbonk(ax1,xlabel='k',ylabel='ClEE and ClBB',xscale='log',yscale='log')
      #ax1.set_ylim((10**(-6)),300)
      fig1.savefig("%s/%s_cl_average_new.png"%(plot_dir,longprefix))
#      dt.axbonk(ax2,xlabel='k',ylabel='ratio',xscale='log',yscale='log')
      dt.axbonk(ax2,xlabel='k',ylabel='ratio',xscale='log')
      ax2.set_ylim(0,10)
      fig2.savefig("%s/%s_ratio_average.png"%(plot_dir,longprefix))
      fig1.clf()
      fig2.clf()
    Fptr = h5py.File("slopes_ratios_dict_%s.h5"%axes,'w')
    Fptr.create_dataset("ee_slopes", data=ee_slopes)
    Fptr.create_dataset("bb_slopes", data=bb_slopes)
    Fptr.create_dataset("eb_ratios", data=eb_ratios)
    Fptr.close()
コード例 #14
0
if 1:
    #plot the shell averaged spaces
    fig, ax = plt.subplots(1, 1)
    ff, empty = shell_average(rhohat1, filename="./spectra_hat.h5")
    k, p = dt.dpy("./spectra_hat.h5", ['k', 'power'])
    p = np.abs(p)
    ok = slice(None)  #k>0
    kok = k[ok] * np.pi * 2

    ax.plot(kok, p[ok] / p[ok].max(), c='k', marker='o', label='Spec_tool')
    the_y = rs['ClBB']
    the_x = rs['lbins'][:-1]
    ax.plot(the_x, the_y / the_y.max(), c='b', marker='o', label='cmbtool')
    ax.legend(loc=0)
    dt.axbonk(ax, xlabel='k', ylabel='rho(||k||)', yscale='log')
    ax.set_xscale('symlog', linthreshx=1)
    ax.set_xlim(0, max([the_x.max(), kok.max()]))

    fig.savefig('shells.png')
"""

shell_average(rhohat, filename="./spectra_hat.h5")
#plave(rhohat,"rhohat.png")
#plt.scatter(x.flatten(),y.flatten(),c='r')
if 0:
    ff = Filter.FourierFilter(rhohat)
    rmap = dt.rainbow_map(ff.nx)
    for bbb in range(ff.nx):
        these = ff.get_shell(bbb)
        ax.scatter( x[these], y[these],c=rmap(bbb,these.sum()))
コード例 #15
0
    def run(self,core_list=None):
        dx=1./2048
        nx = 1./dx
        thtr = self.this_looper.tr
        all_cores = np.unique(thtr.core_ids)
        if core_list is None:
            core_list = all_cores

        thtr.sort_time()

        if self.rho_extents is None: 
            self.rho_extents=davetools.extents()
            self.r_extents=davetools.extents()
            for nc,core_id in enumerate(all_cores):
                ms = trackage.mini_scrubber(thtr,core_id)
                if ms.nparticles < 20:
                    continue
                density = thtr.c([core_id],'density')
                self.rho_extents(density)
                self.r_extents(ms.r)

        tsorted = thtr.times
        self.core_list=core_list

        ds= self.this_looper.load(0)
        ad = ds.all_data()
        rmcore=rainbow_map(len(core_list))
        for nc,core_id in enumerate(core_list):
            ms = trackage.mini_scrubber(thtr,core_id)
            self.ms = ms
            if ms.nparticles < 10:
                continue
            self.cores_used.append(core_id)
            fig, axd=plt.subplots(2,2)
            axd1 = axd[0][0]; axd2=axd[0][1]#sorry
            axd3 = axd[1][0]; axd4=axd[1][1]

            tmap=rainbow_map(ms.ntimes)
            asort =  np.argsort(thtr.times)
            density = thtr.c([core_id],'density')
            n0=asort[0]
            tsorted = thtr.times[asort]

            gx = thtr.c([core_id],'grav_x')
            gy = thtr.c([core_id],'grav_y')
            gz = thtr.c([core_id],'grav_z')
            grav = 1/(8*np.pi)*(gx*gx+gy*gy+gz*gz)
            grav = np.abs(thtr.c([core_id],'PotentialField'))

            #fig, axd1=plt.subplots(1,1)

            for n_count,n_time in enumerate(asort):
                mask2 = ms.compute_unique_mask(core_id, dx=1./2048,frame=n_count)
                mask2[:]=True
                time=thtr.times[n_time]
                c=tmap(n_count,mask2.sum())
                #c=rmcore(nc, mask2.sum())
                this_r=ms.r[:,n_time]+0
                this_r[ this_r<1/2048]=1/2048
                r_un = nar(sorted(np.unique(this_r)))

                mask2 = mask2 * (this_r > 0)

                axd1.scatter(this_r[mask2],density[mask2,n_time],c=c,label=thtr.times[n_time],s=0.1)
                axd2.hist(np.log10(density[mask2,n_time]), histtype='step',color=c[0])

                axd3.scatter( this_r[mask2], grav[mask2, n_time], c=c,s=0.1)

                the_x = np.log(this_r[mask2]); the_y=np.log(density[mask2,n_time])
                r,p=scipy.stats.pearsonr(the_x,the_y)
                axd4.scatter( thtr.times[n_time], r, c=tmap(n_count,1))
                
                the_x = np.log(this_r[mask2]); the_y=np.log(grav[mask2,n_time])
                r,p=scipy.stats.pearsonr(the_x,the_y)
                axd4.scatter( thtr.times[n_time], r, c=tmap(n_count,1),marker='*')

            davetools.axbonk(axd1,xscale='log',yscale='log',xlabel='r',ylabel=r'$\rho$',
                             xlim=[1/2048,self.r_extents.minmax[1]], ylim=self.rho_extents.minmax)
            davetools.axbonk(axd2,xscale='linear',yscale='log',xlabel='r',ylabel=r'$\rho$',
                             xlim=np.log10(self.rho_extents.minmax))
            axbonk(axd3,xscale='log',yscale='log',xlabel='r',ylabel='GE')
            outname = '%s/density_radius_c%04d.png'%(dl.output_directory,core_id)
            #outname = '%s/density_radius_n0000.png'%(dl.output_directory)
            fig.savefig(outname)
            print("saved "+outname)
            plt.close(fig)
コード例 #16
0
        for iframe, frame in enumerate(frame_list):
            for core_id in this_looper.snaps[frame]:
                snap = this_looper.snaps[frame][core_id]
                if len(snap.R_mag) < 3:
                    continue
                #rrr, vvv = np.meshgrid(radbins,velbins)
                axa.scatter(snap.R_mag,
                            snap.V_radial,
                            c=tmap(iframe, snap.R_mag.size),
                            s=0.1,
                            label=str(frame))
        DT.axbonk(axa,
                  xscale='log',
                  yscale='linear',
                  xlabel='R_mag',
                  ylabel='V_rel',
                  xlim=ext_r,
                  ylim=ext_v)
        axa.set_yscale('symlog', linthreshy=vel_linthresh)
        axa.set_xscale('symlog', linthreshx=2 * rmin)
        outname = 'image_tracks/vel_hist_c%04d.png' % core_id
        print(outname)
        #axa.legend(loc=0)
        fig.savefig(outname)

        plt.close('all')
        fig, ax = plt.subplots(1, 1)
        norm = mpl.colors.LogNorm(vmin=1, vmax=velhist_global.max())
        cmap = mpl.cm.jet
        cmap.set_under('w')
コード例 #17
0
        c=tmap(n_count)
        histout=ax201.hist( np.log10(this_d), color=c,histtype='step')
        hist, bins, wut=histout
        bc = 0.5*(bins[1:]+bins[:-1])
        fit_stuff=gauss_fit(bc, hist)
        #axd4.plot( bc, gauss_me( bc, fit_stuff['norm_est'], fit_stuff['vbar_est'], fit_stuff['sigma_est']))
        if 'fit_norm' in fit_stuff:
            axd4.plot( bc, gauss_me( bc, fit_stuff['fit_norm'], fit_stuff['fit_center'], fit_stuff['fit_width']),c=c)
            widths.append(fit_stuff['fit_width'])

            means.append(fit_stuff['fit_center'])
            timelist.append(this_time)

        x_un=nar(sorted(np.unique(this_x)))
        #ax201.plot(x_un, 1e-2*x_un**0,c='k',linewidth=0.1)
    davetools.axbonk(axd1,xscale='log',yscale='log',xlabel='r',ylabel=r'$\rho$',
                     xlim=r_extents.minmax, ylim=rho_extents.minmax)
    davetools.axbonk(axd2,xscale='log',yscale='log',xlabel='r',ylabel=r'$\rho$')
    #                 xlim=r_extents.minmax, ylim=rho_extents.minmax)
    davetools.axbonk(axd4,xscale='linear',yscale='log',xlabel='rho',ylabel='N',ylim=[1,50])
    davetools.axbonk(axd3,xscale='linear',yscale='log',xlabel='t',ylabel=r'$\alpha$')
                     #xlim=x_extents.minmax, ylim=alpha_extents.minmax)
    davetools.axbonk(ax201,xscale='linear',yscale='log',xlabel='rho',ylabel='N')
    outname = '/home/dcollins4096/PigPen/density_rescale_c%04d'%core_id
    fig.savefig(outname)
    print("saved "+outname)
    plt.close(fig)

    ax200.plot(timelist,widths,label='width')
    ax200.plot(timelist,means,label='means')
    ax202.plot(timelist_1,r2_list,marker='*')
    #ax203.plot(timelist_1,density_mean_l,marker='*',c='k')
コード例 #18
0
            ax2.clear()
            ax3.clear()

        ax0.scatter(this_at.density_0,this_at.alpha,c=sim_color[this_at.this_looper.out_prefix])
        ax1.scatter(this_at.mass,this_at.alpha,c=sim_color[this_at.this_looper.out_prefix])
        print('col',len(this_dt.collapse_times))
        print('alph', len(this_at.alpha))
        c=sim_color[this_at.this_looper.out_prefix]
        ok = nar(this_dt.collapse_times) > 0
        t_ok=nar(this_dt.collapse_times)[ok]
        ax2.scatter(t_ok, nar(this_at.alpha)[ok],c=c)
        ax3.scatter(t_ok, nar(this_at.mass)[ok],c=c)
        bx0.scatter(t_ok, nar(this_at.density_0)[ok])
        #ax3.scatter(t_ok, nar(density_0)[ok],c=nar(sim_color)[ok])
        mass_ext(nar(this_at.mass))

        davetools.axbonk(ax0,xlabel=r'$\langle \rho \rangle$',ylabel=r'$\alpha$',  xscale='log',yscale='linear')
        davetools.axbonk(ax1,xlabel=r'$M(t=0)$',              ylabel=r'$\alpha$',   xscale='log',yscale='linear')
        davetools.axbonk(ax2,xlabel=r'$t_c$',                 ylabel=r'$\alpha$', xscale='log',yscale='linear')
        davetools.axbonk(ax3,xlabel=r'$t_c$',                 ylabel=r'$M(t=0)$',  xscale='log',yscale='log')
        davetools.axbonk(bx0,xlabel=r'$t_c$',   ylabel=r'$\langle \rho \rangle$',  xscale='log',yscale='linear')
        ax3.set_xlim([t_ok.min(),t_ok.max()])
        ax3.set_ylim(mass_ext.minmax)
        ax1.set_xlim(mass_ext.minmax)
        outname = '%s/alpha_mass.png'%dl.output_directory
        outname = '%s/%s_alpha_mass.png'%(dl.output_directory,this_dt.this_looper.out_prefix)
        fig.savefig(outname)
        outname2 = '%s/tc_rho.png'%dl.output_directory
        fig2.savefig(outname2)
        print(outname)
コード例 #19
0
    tsorted = thtr.times[asort]

    fig, axd1 = plt.subplots(1, 1)

    for n_count, n_time in enumerate(asort):
        time = thtr.times[n_time]
        if time == 0:
            continue
        c = tmap(n_count, ms.nparticles)
        this_r = ms.r[:, n_time] + 0
        r_un = nar(sorted(np.unique(this_r)))

        axd1.scatter(this_r,
                     density[:, n_time],
                     c=c,
                     label=thtr.times[n_time],
                     s=0.1)
        axd1.plot(r_un, 100 * (r_un / 1e-2)**-2, c='k', linewidth=0.1)

    davetools.axbonk(axd1,
                     xscale='log',
                     yscale='log',
                     xlabel='r',
                     ylabel=r'$\rho$',
                     xlim=r_extents.minmax,
                     ylim=rho_extents.minmax)
    outname = '%s/density_radius_c%04d' % (dl.output_directory, core_id)
    fig.savefig(outname)
    print("saved " + outname)
    plt.close(fig)
コード例 #20
0
class alpha_tool():
    def __init__(self,this_looper):
        self.this_looper=this_looper

        self.rho_extents=davetools.extents()
        self.r_extents=davetools.extents()
        self.alpha = []
        self.mass = []
        self.density_0=[]
        self.mean_div = []
        self.alpha_dict={}
        self.ft_lst_rho0=[]
        self.ft_lst_r0=[]
        self.ft_lst_alpha=[]
        self.mini_alphas={}
        self.collapse_times=[]
        self.cores_used=[]

    def run(self, core_list=None, do_all_plots=False):
        thtr = self.this_looper.tr
        all_cores = np.unique(thtr.core_ids)
        if core_list is None:
            core_list=all_cores
        rm = rainbow_map(len(all_cores))

        if len(self.rho_extents.minmax) == 0:
            for nc,core_id in enumerate(all_cores):
                ms = trackage.mini_scrubber(thtr,core_id)
                if ms.nparticles == 1:
                    continue
                density = thtr.c([core_id],'density')
                self.rho_extents(density)
                self.r_extents(ms.r)

        self.r_extents.minmax[0]=0.5/2048
        asort =  np.argsort(thtr.times)
        if (asort != sorted(asort)).any():
            print("Warning: times not sorted.")

        for nc,core_id in enumerate(core_list):

            #miniscrubber computes distance, r^2, several other quantities
            ms = trackage.mini_scrubber(thtr,core_id)
            if ms.nparticles < 3:
                continue
            self.cores_used.append(core_id)


            density = thtr.c([core_id],'density')

            if 1:
                #collapse time
                if (density>1e3).any():
                    first_collapse_index = np.where( (density>1e3).sum(axis=0) >0 )[0][0] 
                    t_collapse = thtr.times[first_collapse_index]
                    self.collapse_times.append(t_collapse)
                else:
                    t_collapse = -1
                    self.collapse_times.append(t_collapse)

            #Compute alpha
            #compute mean initial density.
            this_r = ms.r.flatten()
            min_r = 1./2048
            this_r[ this_r < min_r ] = min_r    
            fit = scatter_fit.scatter_fit(plt,this_r,density.flatten())
            self.alpha.append(fit['fit'][0])
            self.alpha_dict[core_id]=self.alpha[-1]
            self.density_0.append( density[:,0].mean()) #this is not good

            this_rho = density.flatten()
            popt, pcov = curve_fit(powerlaw, this_r, np.log10(this_rho), p0=[1,1,-2])
            fit_rho0, fit_r0, fit_alpha = popt
            self.ft_lst_rho0.append(fit_rho0)
            self.ft_lst_r0.append(fit_r0)
            self.ft_lst_alpha.append(fit_alpha)

            #compute initial mass.
            for nf in [0]:
                dx=1./2048
                nx=2048
                x =np.floor(thtr.c([core_id],'x')/dx)[:,nf]
                y =np.floor(thtr.c([core_id],'y')/dx)[:,nf]
                z =np.floor(thtr.c([core_id],'z')/dx)[:,nf]
                this_density = density[:,nf]
                cell_volume = thtr.c([core_id],'cell_volume')[:,nf]
                index = x + nx*(y * nx*z)
                ar = np.argsort(index)
                rs = np.argsort(ar)
                isorted=index[ar]
                mask = np.ones_like(this_density,dtype='bool')
                mask[1:] = isorted[1:]-isorted[:-1] != 0
                mask2 = mask[ rs]
                self.mass.append((this_density[mask2]*cell_volume[mask2]).sum())

            if do_all_plots:
                fig, axes=plt.subplots(1,2)
                axd1 = axes[0]; axd2 = axes[1]
                #other_fit = other_fit(this_r, density.flatten())
                this_r = np.array([min_r, 0.3])
                #this_r[ this_r < min_r] = min_r
                axd1.plot( this_r, 10**powerlaw(this_r, popt[0],popt[1],popt[2]))
                #axd1.plot( this_r, 0.1*(this_r/0.3)**alpha[-1],c='k')
                #axd1.plot( this_r, 0.1*(this_r/0.3)**-0.5,c=[0.9]*3)
                #axd1.plot( this_r, 0.1*(this_r/0.3)**-1.0,c=[0.9]*3)
                #axd1.plot( this_r, 0.1*(this_r/0.3)**-1.5,c=[0.9]*3)
                #axd1.plot( this_r, 0.1*(this_r/0.3)**-2.0,c=[0.9]*3)
                #axd1.plot( this_r, 0.1*(this_r/0.3)**-2.5,c=[0.9]*3)
                tmap=rainbow_map(ms.ntimes)
                self.mini_alphas[core_id]=[]
                time_list_dumb=[]
                color_list_dumb=[]

                for n_count,n_time in enumerate(asort):
                    time=thtr.times[n_time]
                    if time == 0:
                        continue
                    c=tmap(n_count,ms.nparticles)
                    time_list_dumb.append(time)
                    color_list_dumb.append(c[0])
                    this_r=ms.r[:,n_time]+0
                    this_r[ this_r < min_r] = min_r
                    this_density=density[:,n_time]
                    #popt, pcov = curve_fit(powerlaw, this_r, np.log10(this_density), p0=[1,1,-2])
                    lilfit=np.polyfit( np.log10(this_r), np.log10(this_density), 1)
                    axd1.scatter(this_r,this_density,c=c,label=thtr.times[n_time],s=0.1)
                    axd1.plot( this_r, 10**(lilfit[0]*np.log10(this_r)+lilfit[1]),c=c[0])
                    self.mini_alphas[core_id].append(lilfit[0])


                title=""
                title+=r'$\alpha = %0.3f\ \rho_0 = $%s$ r_0=$%s'%(self.alpha[-1], expform(fit_rho0),expform(fit_r0))
                axd1.set_title(title)
                axbonk(axd1,xscale='log',yscale='log',xlabel='r',ylabel=r'$\rho$',
                                 xlim=self.r_extents.minmax, ylim=self.rho_extents.minmax)
                axd1.set_ylim(self.rho_extents.minmax)
                axd1.set_xlim(self.r_extents.minmax)

                axd2.scatter(time_list_dumb, self.mini_alphas[core_id],c=color_list_dumb)
                axd2.plot(time_list_dumb, self.mini_alphas[core_id],c=[0.5]*3)
                #axd2.plot(time_list_dumb, [fit_alpha]*len(time_list_dumb),c='k')
                axd2.plot(time_list_dumb, [-1]*len(time_list_dumb),  c=[0.5]*4)
                axd2.plot(time_list_dumb, [-0.5]*len(time_list_dumb),c=[0.5]*4)
                axd2.plot(time_list_dumb, [-1.5]*len(time_list_dumb),c=[0.5]*4)
                axd2.plot(time_list_dumb, [-2]*len(time_list_dumb),  c=[0.5]*4)

                axbonk(axd2,xlabel=r'$t$',ylabel=r'$\alpha(t)$',ylim=[-4,2])
                #axbonk(axd2,xscale='log',yscale='log',xlabel='r',ylabel=r'$\rho$',
                #                 xlim=r_extents.minmax, ylim=rho_extents.minmax)
                outname = '%s/%s_density_radius_c%04d'%(dl.output_directory,self.this_looper.out_prefix,core_id)
                fig.savefig(outname)
                print("saved "+outname)
                plt.close(fig)


    def do_plots(self):
            mass=nar(self.mass)
            sim_color={'u05':'r','u10':'g','u11':'b'}[self.this_looper.out_prefix]
            fig, axes=plt.subplots(2,2)
            ax0 = axes[0][0]; ax1=axes[0][1]
            ax2 = axes[1][0]; ax3=axes[1][1]
            ax0.scatter(self.density_0,self.alpha,c=sim_color)
            ax1.scatter(mass,self.alpha,c=sim_color)

            fig2, axes2=plt.subplots(1,1)
            bx0 = axes2
            if 'collapse_times' in dir(): #collapse_time can be found from density_time.py
                ok = nar(collapse_times) > 0
                t_ok=nar(collapse_times)[ok]
                ax2.scatter(t_ok, nar(self.alpha)[ok])
                ax3.scatter(t_ok, nar(self.mass)[ok],c=nar(sim_color)[ok])
                bx0.scatter(t_ok, nar(self.density_0)[ok])
                #ax3.scatter(t_ok, nar(density_0)[ok],c=nar(sim_color)[ok])
                pdb.set_trace()

            davetools.axbonk(ax0,xlabel=r'$\langle \rho \rangle$',ylabel=r'$\alpha$',  xscale='log',yscale='linear')
            davetools.axbonk(ax1,xlabel=r'$M(t=0)$',              ylabel=r'$\alpha$',   xscale='log',yscale='linear')
            davetools.axbonk(ax2,xlabel=r'$t_c$',                 ylabel=r'$\alpha$', xscale='log',yscale='linear')
            davetools.axbonk(ax3,xlabel=r'$t_c$',                 ylabel=r'$M(t=0)$',  xscale='log',yscale='log')
            davetools.axbonk(bx0,xlabel=r'$t_c$',   ylabel=r'$\langle \rho \rangle$',  xscale='log',yscale='linear')
            ax3.set_xlim([t_ok.min(),t_ok.max()])
            ax3.set_ylim(self.mass.min(),self.mass.max())
            ax1.set_xlim(self.mass.min(),self.mass.max())
            outname = '%s/alpha_mass.png'%dl.output_directory
            fig.savefig(outname)
            outname2 = '%s/tc_rho.png'%dl.output_directory
            fig2.savefig(outname2)
            print(outname)

    if 0:
        mass=nar(mass)
        fig, axes=plt.subplots(2,2)
        ax0 = axes[0][0]; ax1=axes[0][1]
        ax2 = axes[1][0]; ax3=axes[1][1]
        ax0.scatter(density_0,alpha)
        ax1.scatter(mass,alpha)
        #ax2.scatter(total_volume,alpha)
        #ax3.scatter(total_volume,mass)
        davetools.axbonk(ax0,ylabel=r'$\alpha$', xlabel=r'$\langle \rho \rangle$', xscale='log',yscale='linear')
        davetools.axbonk(ax1,ylabel=r'$\alpha$', xlabel=r'$M(t=0)$', xscale='log',yscale='linear')
        #vol_lim=[min(total_volume),max(total_volume)]
        mass_lim=[min(mass),max(mass)]
        davetools.axbonk(ax2,ylabel=r'$\alpha$', xlabel=r'$V(t=0)$', xscale='log',yscale='linear',xlim=vol_lim)
        davetools.axbonk(ax3,ylabel=r'$M(t=0)$', xlabel=r'$V(t=0)$', xscale='log',yscale='log',xlim=vol_lim,ylim=mass_lim)
        ax1.set_xlim(mass.min(),mass.max())
        outname = '%s/alpha_mass.png'%dl.output_directory
        fig.savefig(outname)
        print(outname)


#plt.clf()
#alpha=np.array(alpha)
#ft_lst_alpha=np.array(ft_lst_alpha)
#plt.scatter(alpha,1-(alpha/ft_lst_alpha))
#plt.savefig('plots_to_sort/alpha_alpha.png')
#plt.close('all')

#fig,ax=plt.subplots(1,1)
#ax.scatter(ft_lst_rho0,ft_lst_r0)
#axbonk(ax,xlabel=r'$\rho_0$',ylabel=r'$r_0$',xscale='log',yscale='log')
#fig.savefig('plots_to_sort/rho0_r0.png')


    if 'alpha_proxy' not in dir() and False:
        do_all_plots=True
        div_v=[]
        v_over_r=[]
        divv_extents=davetools.extents()
        divv_extents( thtr.track_dict['velocity_divergence'])
        proxy_extents=davetools.extents()
        for nc,core_id in enumerate(core_list):
            #miniscrubber computes distance, r^2, several other quantities
            ms = trackage.mini_scrubber(thtr,core_id)
            if ms.nparticles == 1:
                continue
            density = thtr.c([core_id],'density')
            div_v = thtr.c([core_id],'velocity_divergence')
            mag_v = thtr.c([core_id],'velocity_magnitude')
            divv_extents(div_v)
            if do_all_plots:
                tmap=rainbow_map(ms.ntimes)
                fig, axes=plt.subplots(2,2)
                ax00=axes[0][0]; ax01=axes[0][1]
                ax10=axes[1][0]; ax11=axes[1][1]

                for n_count,n_time in enumerate(asort):
                    time=thtr.times[n_time]
                    if time == 0:
                        continue
                    c=tmap(n_count,ms.nparticles)
                    this_r=ms.r[:,n_time]+0

                    ax00.scatter(this_r,div_v[:,n_time],c=c,label=thtr.times[n_time],s=0.1)
                    ax01.scatter(this_r,mag_v[:,n_time],c=c,label=thtr.times[n_time],s=0.1)


                    alpha_proxy = div_v[:,n_time]/mag_v[:,n_time]*ms.r[:,n_time]
                    proxy_extents(alpha_proxy)
                    ax10.scatter(this_r,alpha_proxy.flatten(),c=c,label=thtr.times[n_time],s=0.1)
                davetools.axbonk(ax00,xscale='log',yscale='linear',xlabel='r',ylabel=r'$\nabla\cdot v$',
                                 xlim=r_extents.minmax, ylim=rho_extents.minmax)
                ax00.set_yscale('symlog',linthreshy=1)
                ax00.set_ylim(-5e5,5e5)

                davetools.axbonk(ax01,xscale='log',yscale='log',xlabel='r',ylabel=r'$|v|$',
                                 xlim=r_extents.minmax, ylim=rho_extents.minmax)
                ax01.set_yscale('symlog',linthreshy=1)
                ax01.set_ylim(0,100)

                ax10.plot([1e-3,1e-1], [alpha_dict[core_id],alpha_dict[core_id]],c='k')
                ax10.plot([1e-3,1e-1], [-0.5,-0.5],c=[0.5]*4)
                ax10.plot([1e-3,1e-1], [-3,-3],c=[0.5]*4)
                davetools.axbonk(ax10,xscale='log',yscale='linear',xlabel='r',ylabel=r'$\nabla\cdot v/(v/r)$',
                                 xlim=r_extents.minmax, ylim=rho_extents.minmax)
                ax10.set_yscale('symlog',linthreshy=0.1)
                ax10.set_ylim(proxy_extents.minmax)

                outname = '%s/divergence_proxy_c%04d'%(dl.output_directory,core_id)
                fig.savefig(outname)
                print("saved "+outname)
                plt.close(fig)
コード例 #21
0
        print("Warning: times not sorted.")
    n0=asort[0]
    tsorted = thtr.times[asort]
    tmap=rainbow_map(ms.ntimes)
    norm = mpl.colors.Normalize()
    norm.autoscale( np.log10(density[:,n0]))
    cmap = mpl.cm.jet
    color_map = mpl.cm.ScalarMappable(norm=norm,cmap=cmap)
    
    norm_theta = mpl.colors.Normalize()
    norm_theta.autoscale( [-1,1])
    cmap = mpl.cm.jet
    color_map_theta = mpl.cm.ScalarMappable(norm=norm_theta,cmap=cmap)

    fig, axd1=plt.subplots(1,1)
    ax=axd1

    for npart in list(range(ms.nparticles)[particle_slice]):
        #c = color_map.to_rgba(np.log10(density[npart,n0]))
        c1 = color_map_theta.to_rgba(costheta[npart,n0+1])
        the_y = costheta[npart,:][1:]
        the_t = thtr.times[1:]
        ax.scatter( the_t, the_y,c=[c1]*len(the_y),linewidth=.1)#linestyle=':')
        ax.plot( the_t, the_y,c=c,linewidth=.1)#linestyle=':')
    davetools.axbonk(axd1,xscale='linear',yscale='linear',ylabel=r'$cos \theta$',xlabel=r'$t$')
    outname = '%s/angle_time_c%04d'%(dl.output_directory,core_id)
    fig.savefig(outname)
    print("saved "+outname)
    plt.close(fig)