예제 #1
0
파일: plot.py 프로젝트: tedoreve/PLUTO
def td(ty,t,E,rho,sigma,wdir):
    D = pp.pload(t,w_dir=wdir)   
    if ty == 'flux':
        for k in range(D.rho.shape[2]):
            for j in range(D.rho.shape[1]):
                for i in range(D.rho.shape[0]):
    #                if (i-D.rho.shape[0]/2)**2+(j-D.rho.shape[1]/2)**2+(k-D.rho.shape[2]/2)**2 > 30**2:
    #                    D.rho[k,j,i] = rho
                    if D.rho[k,j,i] > 10:
                        D.rho[k,j,i] = rho
        
        flux = D.rho*(D.bx1**2+D.bx2**2+D.bx3**2)**1.25*(D.vx1**2+D.vx2**2+D.vx3**2)**0
        flux = (flux-np.mean(flux))*1+np.mean(flux)*1
        flux = flux.sum(axis=0)
        flux = nd.gaussian_filter(flux,sigma=(sigma,sigma),order=0)

        fig = plt.figure(figsize=(7,6))
        ax = fig.add_subplot(111)
        neg = ax.imshow(np.log10(flux).T,origin='lower',extent=[D.x2[0],D.x2[-1],D.x3[0],D.x3[-1]])
        levels = np.arange(-5.5, -4, 0.5)
        plt.contour(np.log10(flux).T, levels,
                     origin='lower',
                     linewidths=2,
                     extent=[D.x1[0],D.x1[-1],D.x2[0],D.x2[-1]])
        cbar = fig.colorbar(neg,ax=ax)
        cbar.set_label(r'log(S)')
        ax.set_xlabel('l offset (pc)')
        ax.set_ylabel('b offset (pc)')
        ax.set_title(r't='+str(t)+r'$\ \mathregular{\rho}$='+str(rho)+' E='+str(E))
        fig.subplots_adjust(top=0.9,bottom=0.1,left=0.11,right=0.97)
        fig.savefig('t'+str(t)+'_density'+str(rho)+'_E'+str(E)+'.eps')
        fig.clear()
        ax = fig.add_subplot(111)
        ax.plot((np.rot90(np.eye(len(flux)))*flux.T).sum(axis=0))
        ax.set_xlim(0,256)
        fig.savefig('change.eps')
        
    elif ty == 'rho':
#        t = 850
        fig = plt.figure(figsize=(7,6))
        ax = fig.add_subplot(111)
        neg = ax.imshow(np.log10(D.rho[:,:,128]).T,origin='lower',extent=[D.x2[0],D.x2[-1],D.x3[0],D.x3[-1]])
        cbar = fig.colorbar(neg,ax=ax)
        cbar.set_label(r'log($\mathregular{\rho/cm^{-3}}$)')
        ax.set_xlabel('x offset (pc)')
        ax.set_ylabel('y offset (pc)')
        ax.set_title(r't='+str(t)+r'$\ \mathregular{\rho}$='+str(rho)+' E='+str(E))
        fig.subplots_adjust(top=0.9,bottom=0.1,left=0.11,right=0.97)
        T = pp.Tools()
        newdims = 2*(20,)
        Xmesh, Ymesh = np.meshgrid(D.x2.T,D.x3.T)
        xcong = T.congrid(Xmesh,newdims,method='linear')
        ycong = T.congrid(Ymesh,newdims,method='linear')
        velxcong = T.congrid(D.bx1[:,:,128].T,newdims,method='linear')
        velycong = T.congrid(D.bx2[:,:,128].T,newdims,method='linear')
        plt.gca().quiver(xcong, ycong, velxcong, velycong,color='w')
        plt.show()
        fig.savefig('rho-t='+str(t)+'_density='+str(rho)+'_E='+str(E)+'.eps') # Only to be saved as either .png or .jpg
    #    close()
    else: 
        print(D.x1.shape)
#        arr = np.meshgrid(D.x1,D.x2,D.x3)
#        mlab.points3d(arr[0][0:256:8,0:256:8,0:256:8], arr[1][0:256:8,0:256:8,0:256:8], arr[2][0:256:8,0:256:8,0:256:8], D.rho[0:256:8,0:256:8,0:256:8])
        vol = mlab.pipeline.volume(mlab.pipeline.scalar_field(np.log10(D.prs*D.rho)))
        ctf = ColorTransferFunction()
        ctf.add_hsv_point(-8, 0.8, 1, 1)
        ctf.add_hsv_point(-6.5, 0.45, 1, 1)
        ctf.add_hsv_point(-5.4, 0.15, 1, 1)

        vol._volume_property.set_color(ctf)
        vol._ctf = ctf
        vol.update_ctf = True
        otf = PiecewiseFunction()

        otf.add_point(-8, 0)
        otf.add_point(-5.7, 0.082)
        otf.add_point(-5.4, 0.0)

        vol._otf = otf
        vol._volume_property.set_scalar_opacity(otf)
예제 #2
0
def td(ty, t, E, rho, sigma, wdir):
    D = pp.pload(t, w_dir=wdir)
    if ty == 'flux':
        for k in range(D.rho.shape[2]):
            for j in range(D.rho.shape[1]):
                for i in range(D.rho.shape[0]):
                    #                if (i-D.rho.shape[0]/2)**2+(j-D.rho.shape[1]/2)**2+(k-D.rho.shape[2]/2)**2 > 30**2:
                    #                    D.rho[k,j,i] = rho
                    if D.rho[k, j, i] > 10:
                        D.rho[k, j, i] = rho

        flux = D.rho * (D.bx1**2 + D.bx2**2 +
                        D.bx3**2)**1.25 * (D.vx1**2 + D.vx2**2 + D.vx3**2)**0
        flux = (flux - np.mean(flux)) * 1 + np.mean(flux) * 1
        flux = flux.sum(axis=0)
        flux = nd.gaussian_filter(flux, sigma=(sigma, sigma), order=0)

        fig = plt.figure(figsize=(7, 6))
        ax = fig.add_subplot(111)
        neg = ax.imshow(np.log10(flux).T,
                        origin='lower',
                        extent=[D.x2[0], D.x2[-1], D.x3[0], D.x3[-1]])
        levels = np.arange(-5.5, -4, 0.5)
        plt.contour(np.log10(flux).T,
                    levels,
                    origin='lower',
                    linewidths=2,
                    extent=[D.x1[0], D.x1[-1], D.x2[0], D.x2[-1]])
        cbar = fig.colorbar(neg, ax=ax)
        cbar.set_label(r'log(S)')
        ax.set_xlabel('l offset (pc)')
        ax.set_ylabel('b offset (pc)')
        ax.set_title(r't=' + str(t) + r'$\ \mathregular{\rho}$=' + str(rho) +
                     ' E=' + str(E))
        fig.subplots_adjust(top=0.9, bottom=0.1, left=0.11, right=0.97)
        fig.savefig('t' + str(t) + '_density' + str(rho) + '_E' + str(E) +
                    '.eps')
        fig.clear()
        ax = fig.add_subplot(111)
        ax.plot((np.rot90(np.eye(len(flux))) * flux.T).sum(axis=0))
        ax.set_xlim(0, 256)
        fig.savefig('change.eps')

    elif ty == 'rho':
        #        t = 850
        fig = plt.figure(figsize=(7, 6))
        ax = fig.add_subplot(111)
        neg = ax.imshow(np.log10(D.rho[:, :, 128]).T,
                        origin='lower',
                        extent=[D.x2[0], D.x2[-1], D.x3[0], D.x3[-1]])
        cbar = fig.colorbar(neg, ax=ax)
        cbar.set_label(r'log($\mathregular{\rho/cm^{-3}}$)')
        ax.set_xlabel('x offset (pc)')
        ax.set_ylabel('y offset (pc)')
        ax.set_title(r't=' + str(t) + r'$\ \mathregular{\rho}$=' + str(rho) +
                     ' E=' + str(E))
        fig.subplots_adjust(top=0.9, bottom=0.1, left=0.11, right=0.97)
        T = pp.Tools()
        newdims = 2 * (20, )
        Xmesh, Ymesh = np.meshgrid(D.x2.T, D.x3.T)
        xcong = T.congrid(Xmesh, newdims, method='linear')
        ycong = T.congrid(Ymesh, newdims, method='linear')
        velxcong = T.congrid(D.bx1[:, :, 128].T, newdims, method='linear')
        velycong = T.congrid(D.bx2[:, :, 128].T, newdims, method='linear')
        plt.gca().quiver(xcong, ycong, velxcong, velycong, color='w')
        plt.show()
        fig.savefig('rho-t=' + str(t) + '_density=' + str(rho) + '_E=' +
                    str(E) + '.eps')  # Only to be saved as either .png or .jpg
    #    close()
    else:
        print(D.x1.shape)
        #        arr = np.meshgrid(D.x1,D.x2,D.x3)
        #        mlab.points3d(arr[0][0:256:8,0:256:8,0:256:8], arr[1][0:256:8,0:256:8,0:256:8], arr[2][0:256:8,0:256:8,0:256:8], D.rho[0:256:8,0:256:8,0:256:8])
        vol = mlab.pipeline.volume(
            mlab.pipeline.scalar_field(np.log10(D.prs * D.rho)))
        ctf = ColorTransferFunction()
        ctf.add_hsv_point(-8, 0.8, 1, 1)
        ctf.add_hsv_point(-6.5, 0.45, 1, 1)
        ctf.add_hsv_point(-5.4, 0.15, 1, 1)

        vol._volume_property.set_color(ctf)
        vol._ctf = ctf
        vol.update_ctf = True
        otf = PiecewiseFunction()

        otf.add_point(-8, 0)
        otf.add_point(-5.7, 0.082)
        otf.add_point(-5.4, 0.0)

        vol._otf = otf
        vol._volume_property.set_scalar_opacity(otf)