Beispiel #1
0
    def _calculate_angular_quantities(self):
        """Calculate angular momentum, spin, max_vphi and max_vr."""
        pos  = self.obj.yt_dataset.arr(self.obj.data_manager.pos[self.global_indexes],  self.obj.units['length'])
        vel  = self.obj.yt_dataset.arr(self.obj.data_manager.vel[self.global_indexes],  self.obj.units['velocity'])
        mass = self.obj.yt_dataset.arr(self.obj.data_manager.mass[self.global_indexes], self.obj.units['mass'])
        ptype = self.obj.yt_dataset.arr(self.obj.data_manager.ptype[self.global_indexes], self.obj.units['mass'])

        px = mass * vel[:,0]
        py = mass * vel[:,1]
        pz = mass * vel[:,2]        
        x  = (pos[:,0] - self.pos[0]).to('km')
        y  = (pos[:,1] - self.pos[1]).to('km')
        z  = (pos[:,2] - self.pos[2]).to('km')

        Lx = np.sum( y*pz - z*py )
        Ly = np.sum( z*px - x*pz )
        Lz = np.sum( x*py - y*px )
        L  = np.sqrt(Lx**2 + Ly**2 + Lz**2)
        
        #self.angular_momentum        = self.obj.yt_dataset.quan(L, Lx.units)
        self.angular_momentum_vector = self.obj.yt_dataset.arr([Lx.d,Ly.d,Lz.d], Lx.units)

        
        # Bullock spin or lambda prime
        #self.spin = self.angular_momentum / (1.4142135623730951 *
        if self.virial_quantities['r200'] > 0:
            self.virial_quantities['spin_param'] = self.obj.yt_dataset.quan(L, Lx.units) / (1.4142135623730951 *
                                             self.masses['total'] *
                                             self.virial_quantities['circular_velocity'].to('km/s') *
                                             self.virial_quantities['r200'].to('km'))
        else:
            self.virial_quantities['spin_param'] = self.obj.yt_dataset.quan(0.0, '')

        PHI   = np.arctan2(Ly.d,Lx.d)
        THETA = np.arccos(Lz.d/L.d)
        
        ex = np.sin(THETA) * np.cos(PHI)
        ey = np.sin(THETA) * np.sin(PHI)
        ez = np.cos(THETA)

        from caesar.utils import rotator
        ALPHA = np.arctan2(Ly.d, Lz.d)
        p     = rotator(np.array([ex,ey,ez]), ALPHA)
        BETA  = np.arctan2(p[0],p[2])
        self.rotation_angles = dict(ALPHA=ALPHA, BETA=BETA)

        ## need max_vphi and max_vr
        rotated_pos = rotator(pos.d, ALPHA, BETA)
        rotated_vel = rotator(vel.d, ALPHA, BETA)

        r    = np.sqrt(rotated_pos[:,0]**2 + rotated_pos[:,1]**2)
        vphi = (rotated_vel[:,0] * -1. * rotated_pos[:,1] + rotated_vel[:,1] * rotated_pos[:,0]) / r
        vr   = (rotated_vel[:,0] *       rotated_pos[:,0] + rotated_vel[:,1] * rotated_pos[:,1]) / r

        self.max_vphi = self.obj.yt_dataset.quan(np.max(vphi), self.obj.units['velocity'])
        self.max_vr   = self.obj.yt_dataset.quan(np.max(vr)  , self.obj.units['velocity'])
Beispiel #2
0
def group_vis(group, rotate=True):
    """Function to visualize a :class:`group.Group` with VTK.

    Parameters
    ----------
    group : :class:`group.Group`
        Group to visualize.
    rotate : boolean
        If true the positions are rotated so that the angular momentum 
        vector is aligned with the z-axis.

    """
    DM = group.obj.data_manager    
    v  = vtk.vtk_render()

    if group.ngas > 0:
        pos = DM.pos[DM.glist[group.glist]]
        if rotate:
            pos = rotator(pos, group.rotation_angles['ALPHA'],
                          group.rotation_angles['BETA'])
        v.point_render(pos, color=[0,0,1])
        
    if group.nstar > 0:
        pos = DM.pos[DM.slist[group.slist]]
        if rotate:
            pos = rotator(pos, group.rotation_angles['ALPHA'],
                          group.rotation_angles['BETA'])        
        v.point_render(pos, color=[1,1,0])

    if hasattr(group, 'ndm') and group.ndm > 0:
        pos = DM.pos[DM.dmlist[group.dmlist]]
        if rotate:
            pos = rotator(pos, group.rotation_angles['ALPHA'],
                          group.rotation_angles['BETA'])        
        v.point_render(pos, color=[1,0,0])
    
    v.render(focal_point=group.pos.d)
Beispiel #3
0
    # theta = np.array([90,90, 90, 90,0,180]) * np.pi/180.
    # phi = np.array([0, 90,180,270,0,  0]) * np.pi/180.
    np.random.seed(0)
    _N = 50
    theta = np.arccos(1 - 2 * np.random.rand(_N))  #* (180 / np.pi)
    phi = 2 * np.pi * np.random.rand(_N)  #* (180 / np.pi)
    alpha, beta = transform_coods(theta, phi, tol=15)

    A_V[s] = {i: np.zeros(len(spos)) for i in np.arange(len(alpha))}

    # for i,(_a,_b,ax) in enumerate(zip(alpha,beta,axes)):
    for i, (_a, _b) in enumerate(zip(alpha, beta)):

        if (_a != 0.) | (_b != 0.):
            print("Rotating (idx: %d | alpha=%f, beta=%f)" % (i, _a, _b))
            _spos = rotator(spos.copy(), _a, _b)
            _gpos = rotator(gpos.copy(), _a, _b)
            _hcood = rotator(hcood.copy(), _a, _b)
        else:
            _spos = spos.copy()
            _gpos = gpos.copy()
            _hcood = hcood.copy()

#         if s==0:
#             mask = np.random.rand(len(_gpos)) < 0.5
#             ax.scatter(_gpos[mask,0],_gpos[mask,1],s=1,alpha=0.01,label=i)
#             ax.scatter(_hcood[0],_hcood[1],s=5)
#             ax.legend(); ax.set_aspect('equal')

        for ip in np.arange(len(spos)):
            A_V[s][i][ip] = _star_AV(ip, idir, igstart, igend, _spos, _gpos,
    # theta = np.array([90,90, 90, 90,0,180]) * np.pi/180.
    # phi = np.array([0, 90,180,270,0,  0]) * np.pi/180.
    np.random.seed(0); _N = 50
    theta = np.arccos(1 - 2 * np.random.rand(_N)) #* (180 / np.pi)
    phi   = 2 * np.pi * np.random.rand(_N) #* (180 / np.pi)
    alpha,beta = transform_coods(theta,phi,tol=15)

    A_V[s] = {int(i): list(np.zeros(np.sum(_smask))) for i in np.arange(len(alpha))}
    A_V_gas[s] = {int(i): list(np.zeros(np.sum(_gmask))) for i in np.arange(len(alpha))}

    # for i,(_a,_b,ax) in enumerate(zip(alpha,beta,axes)):
    for i,(_a,_b) in enumerate(zip(alpha,beta)):
    
        if (_a != 0.) | (_b != 0.):
            print("Rotating (idx: %d | alpha=%f, beta=%f)"%(i,_a,_b))
            _spos = rotator(spos[_smask].copy(), _a, _b)
            _gpos = rotator(gpos[_gmask].copy(), _a, _b)
            _hcood = rotator(hcood.copy(), _a,_b)
        else:
            _spos = spos[_smask].copy(); _gpos = gpos[_gmask].copy(); _hcood = hcood.copy() 
   
#         if s==0:
#             mask = np.random.rand(len(_gpos)) < 0.5
#             ax.scatter(_gpos[mask,0],_gpos[mask,1],s=1,alpha=0.01,label=i)
#             ax.scatter(_hcood[0],_hcood[1],s=5)
#             ax.legend(); ax.set_aspect('equal')


        for ip in np.arange(np.sum(_smask)):
            A_V[s][i][int(ip)] = _star_AV(ip, idir, igstart, igend, _spos, _gpos, 
                                  gm[_gmask], gZ[_gmask], ghsm[_gmask],