Пример #1
0
def orbElemsVsRadius(s,rBinEdges,average=False):
    """
    Computes the orbital elements for disk particles about a binary system in given radial bins.
    Assumes center of mass has v ~ 0

    Parameters
    ----------

    s: Tipsy snapshot
    rBinEdges: numpy array
        Radial bin edges [AU] preferably calculated using binaryUtils.calcDiskRadialBins
    average: bool
        True -> average over all particles in bin, false -> randomly select 1 particle in bin
        
    Returns
    -------
    orbElems: numpy array
        6 x len(rBinEdges) - 1 containing orbital elements at each radial bin
        as e, a, i, Omega, w, nu
    """
    
    #Read snapshot and pull out values of interest
    stars = s.stars
    gas = s.gas    
    M = np.sum(stars['mass'])
    zero = SimArray(np.zeros(3).reshape((1, 3)),'cm s**-1') 
    orbElems = np.zeros((6,len(rBinEdges)-1))    
    
    #Gas orbiting about system center of mass
    com = computeCOM(stars,gas)
   
    #Loop over radial bins calculating orbital elements
    for i in range(0,len(rBinEdges)-1):
        if average: #Average over all gas particles in subsection
            rMask = np.logical_and(gas['rxy'].in_units('au') > rBinEdges[i], gas['rxy'].in_units('au') < rBinEdges[i+1])
            if i > 0:
                #Include mass of disk interior to given radius
                mass = M + np.sum(gas[gas['rxy'] < rBinEdges[i]]['mass'])
            else:
                mass = M
            g = gas[rMask]
            N = len(g)
            if N > 0:
                orbElems[:,i] = np.sum(AddBinary.calcOrbitalElements(g['pos'],com,g['vel'],zero,mass,g['mass']),axis=-1)/N
            else: #If there are no particles in the bin, set it as a negative number to mask out later
                orbElems[:,i] = -1.0
        else: #Randomly select 1 particle in subsection for calculations
            rMask = np.logical_and(gas['rxy'].in_units('au') > rBinEdges[i], gas['rxy'].in_units('au') < rBinEdges[i+1])
            if i > 0:            
                mass = M + np.sum(gas[gas['rxy'] < rBinEdges[i]]['mass'])
            else:
                mass = M
            g = gas[rMask]            
            index = np.random.randint(0,len(g))
            particle = g[index]
            orbElems[:,i] = AddBinary.calcOrbitalElements(com,particle['pos'],zero,particle['vel'],mass,particle['mass'])
            
    return orbElems
Пример #2
0
    def computeOrbElems(self):
        """
        Compute the Kepler orbital elements.

        Input: Self (must have r, v set and in proper units)

        Output: sets and returns e,a,i,...
        """
        # Compute orbital elements from binary center of mass frame Cartesian
        # coordinates
        assert (self.state != 'Kepler' or self.state != 'kepler'), "Already have orbital elements."        
        
        zeroR = SimArray([[0.0, 0.0, 0.0]],'cm')
        zeroV = SimArray([[0.0, 0.0, 0.0]],'cm s**-1')
        oe = AddBinary.calcOrbitalElements(
            self.r,
            zeroR,
            self.v,
            zeroV,
            self.m1,
            self.m2)

        # Set orbital elements, return them as well
        self.assignOrbElems(oe)
        return oe
Пример #3
0
    def computeOrbElems(self):
        """
        Compute the Kepler orbital elements.

        Input: Self (must have r, v set and in proper units)

        Output: sets and returns e,a,i,...
        """
        # Compute orbital elements from binary center of mass frame Cartesian
        # coordinates
        assert (self.state != 'Kepler' or self.state != 'kepler'), "Already have orbital elements."        
        
        zeroR = SimArray([[0.0, 0.0, 0.0]],'cm')
        zeroV = SimArray([[0.0, 0.0, 0.0]],'cm s**-1')
        oe = AddBinary.calcOrbitalElements(
            self.r,
            zeroR,
            self.v,
            zeroV,
            self.m1,
            self.m2)

        # Set orbital elements, return them as well
        self.assignOrbElems(oe)
        return oe
Пример #4
0
def orbElemsVsRadius(s, rBinEdges, average=False):
    """
    Computes the orbital elements for disk particles about a binary system in given radial bins.
    Assumes center of mass has v ~ 0

    Parameters
    ----------

    s: Tipsy snapshot
    rBinEdges: numpy array
        Radial bin edges [AU] preferably calculated using binaryUtils.calcDiskRadialBins
    average: bool
        True -> average over all particles in bin, false -> randomly select 1 particle in bin
        
    Returns
    -------
    orbElems: numpy array
        6 x len(rBinEdges) - 1 containing orbital elements at each radial bin
        as e, a, i, Omega, w, nu
    """

    #Read snapshot and pull out values of interest
    stars = s.stars
    gas = s.gas
    M = np.sum(stars['mass'])
    zero = SimArray(np.zeros(3).reshape((1, 3)), 'cm s**-1')
    orbElems = np.zeros((6, len(rBinEdges) - 1))

    #Gas orbiting about system center of mass
    com = computeCOM(stars, gas)

    #Loop over radial bins calculating orbital elements
    for i in range(0, len(rBinEdges) - 1):
        if average:  #Average over all gas particles in subsection
            rMask = np.logical_and(
                gas['rxy'].in_units('au') > rBinEdges[i],
                gas['rxy'].in_units('au') < rBinEdges[i + 1])
            if i > 0:
                #Include mass of disk interior to given radius
                mass = M + np.sum(gas[gas['rxy'] < rBinEdges[i]]['mass'])
            else:
                mass = M
            g = gas[rMask]
            N = len(g)
            if N > 0:
                orbElems[:, i] = np.sum(AddBinary.calcOrbitalElements(
                    g['pos'], com, g['vel'], zero, mass, g['mass']),
                                        axis=-1) / N
            else:  #If there are no particles in the bin, set it as a negative number to mask out later
                orbElems[:, i] = -1.0
        else:  #Randomly select 1 particle in subsection for calculations
            rMask = np.logical_and(
                gas['rxy'].in_units('au') > rBinEdges[i],
                gas['rxy'].in_units('au') < rBinEdges[i + 1])
            if i > 0:
                mass = M + np.sum(gas[gas['rxy'] < rBinEdges[i]]['mass'])
            else:
                mass = M
            g = gas[rMask]
            index = np.random.randint(0, len(g))
            particle = g[index]
            orbElems[:, i] = AddBinary.calcOrbitalElements(
                com, particle['pos'], zero, particle['vel'], mass,
                particle['mass'])

    return orbElems