[Yt-svn] yt: Adding docstrings to HaloFinding.

hg at spacepope.org hg at spacepope.org
Fri Jun 25 08:48:29 PDT 2010


hg Repository: yt
details:   yt/rev/cfe4f1529280
changeset: 1809:cfe4f1529280
user:      Stephen Skory <stephenskory at yahoo.com>
date:
Fri Jun 25 08:48:16 2010 -0700
description:
Adding docstrings to HaloFinding.

diffstat:

 yt/lagos/HaloFinding.py |  495 ++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 406 insertions(+), 89 deletions(-)

diffs (truncated from 757 to 300 lines):

diff -r b965f7e80d39 -r cfe4f1529280 yt/lagos/HaloFinding.py
--- a/yt/lagos/HaloFinding.py	Thu Jun 24 18:28:48 2010 -0700
+++ b/yt/lagos/HaloFinding.py	Fri Jun 25 08:48:16 2010 -0700
@@ -83,8 +83,11 @@
         self.overdensity = None
 
     def center_of_mass(self):
-        """
-        Calculate and return the center of mass.
+        r"""Calculate and return the center of mass.
+        
+        Examples
+        -------
+        >>> com = halos[0].center_of_mass()
         """
         c_vec = self.maximum_density_location() - na.array([0.5,0.5,0.5])
         pm = self["ParticleMassMsun"]
@@ -95,14 +98,22 @@
         return (com*pm).sum(axis=1)/pm.sum() + c_vec
 
     def maximum_density(self):
-        """
-        Return the HOP-identified maximum density.
+        r"""Return the HOP-identified maximum density. Not applicable to
+        FOF halos.
+        
+        Examples
+        -------
+        >>> max_dens = halos[0].maximum_density()
         """
         return self._max_dens[self.id][0]
 
     def maximum_density_location(self):
-        """
-        Return the location HOP identified as maximally dense.
+        r"""Return the location HOP identified as maximally dense. Not
+        applicable to FOF halos.
+        
+        Examples
+        -------
+        >>> max_dens_loc = halos[0].maximum_density_location()
         """
         return na.array([
                 self._max_dens[self.id][1],
@@ -110,14 +121,20 @@
                 self._max_dens[self.id][3]])
 
     def total_mass(self):
-        """
-        Returns the total mass in solar masses of the halo.
+        r"""Returns the total mass in solar masses of the halo.
+        
+        Examples
+        -------
+        >>> halos[0].total_mass()
         """
         return self["ParticleMassMsun"].sum()
 
     def bulk_velocity(self):
-        """
-        Returns the mass-weighted average velocity.
+        r"""Returns the mass-weighted average velocity in cm/s.
+        
+        Examples
+        --------
+        >>> bv = halos[0].bulk_velocity()
         """
         pm = self["ParticleMassMsun"]
         vx = (self["particle_velocity_x"] * pm).sum()
@@ -126,9 +143,12 @@
         return na.array([vx,vy,vz])/pm.sum()
 
     def rms_velocity(self):
-        """
-        Returns the mass-weighted RMS velocity for the halo
+        r"""Returns the mass-weighted RMS velocity for the halo
         particles in cgs units.
+        
+        Examples
+        --------
+        >>> rms_vel = halos[0].rms_velocity()
         """
         bv = self.bulk_velocity()
         pm = self["ParticleMassMsun"]
@@ -141,10 +161,21 @@
         return na.sqrt(ms) * pm.size
 
     def maximum_radius(self, center_of_mass=True):
-        """
-        Returns the maximum radius in the halo for all particles,
-        either from the point of maximum density or from the (default)
-        *center_of_mass*.
+        r"""Returns the maximum radius in the halo for all particles,
+        either from the point of maximum density or from the
+        center of mass.
+        
+        Parameters
+        ---------
+        center_of_mass : Boolean
+            True chooses the center of mass when calculating the maximum radius.
+            False chooses from the maximum density location for HOP halos
+            (it has no effect for FOF halos).
+            Default = True.
+        
+        Examples
+        --------
+        >>> radius = halos[0].maximum_radius()
         """
         if center_of_mass: center = self.center_of_mass()
         else: center = self.maximum_density_location()
@@ -163,9 +194,20 @@
             return self.data[key][self.indices]
 
     def get_sphere(self, center_of_mass=True):
-        """
-        Returns an EnzoSphere centered on either the point of maximum density
-        or the *center_of_mass*, with the maximum radius of the halo.
+        r"""Returns an EnzoSphere centered on either the point of maximum density
+        or the center of mass, with the maximum radius of the halo.
+        
+        Parameters
+        ----------
+        center_of_mass : Boolean
+            True chooses the center of mass when calculating the maximum radius.
+            False chooses from the maximum density location for HOP halos
+            (it has no effect for FOF halos).
+            Default = True.
+        
+        Examples
+        --------
+        >>> sp = halos[0].get_sphere()
         """
         if center_of_mass: center = self.center_of_mass()
         else: center = self.maximum_density_location()
@@ -191,11 +233,22 @@
         self._processing = False
 
     def virial_mass(self, virial_overdensity=200., bins=300):
-        """
-        Return the virial mass of the halo in Msun, using only the particles
-        in the halo (no baryonic information used).
-        Calculate using *bins* number of bins and *virial_overdensity* density
-        threshold. Returns -1 if the halo is not virialized.
+        r"""Return the virial mass of the halo in Msun, using only the particles
+        in the halo (no baryonic information used). Returns -1 if the halo is
+        not virialized.
+        
+        Parameters
+        ----------
+        virial_overdensity : Float
+            The overdensity threshold compared to the universal average when
+            calculating the virial mass. Default = 200.
+        bins : Integer
+            The number of spherical bins used to calculate overdensities.
+            Default = 300.
+        
+        Examples
+        --------
+        >>> vm = halos[0].virial_mass()
         """
         self.virial_info(bins=bins)
         vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins)
@@ -206,11 +259,22 @@
         
     
     def virial_radius(self, virial_overdensity=200., bins=300):
-        """
-        Return the virial radius of the halo in code units, using only the
-        particles in the halo (no baryonic information used).
-        Calculate using *bins* number of bins and *virial_overdensity* density
-        threshold. Returns -1 if the halo is not virialized.
+        r"""Return the virial radius of the halo in code units, using only the
+        particles in the halo (no baryonic information used). Returns -1 if the
+        halo is not virialized.
+
+        Parameters
+        ----------
+        virial_overdensity : Float
+            The overdensity threshold compared to the universal average when
+            calculating the virial radius. Default = 200.
+        bins : Integer
+            The number of spherical bins used to calculate overdensities.
+            Default = 300.
+        
+        Examples
+        --------
+        >>> vr = halos[0].virial_radius()
         """
         self.virial_info(bins=bins)
         vir_bin = self.virial_bin(virial_overdensity=virial_overdensity, bins=bins)
@@ -220,10 +284,9 @@
             return -1
 
     def virial_bin(self, virial_overdensity=200., bins=300):
-        """
-        Return the bin index for the virial radius for the given halo.
-        Returns -1 if the halo is not virialized to the set
-        *virial_overdensity*. 
+        r"""Returns the bin index of the virial radius of the halo. Generally,
+        it is better to call virial_radius instead, which calls this function
+        automatically.
         """
         self.virial_info(bins=bins)
         over = (self.overdensity > virial_overdensity)
@@ -234,10 +297,9 @@
             return -1
     
     def virial_info(self, bins=300):
-        """
-        Calculate the virial profile bins for this halo, using only the particles
-        in the halo (no baryonic information used).
-        Calculate using *bins* number of bins.
+        r"""Calculates the virial information for the halo. Generally, it is
+        better to call virial_radius or virial_mass instead, which calls this
+        function automatically.
         """
         # Skip if we've already calculated for this number of bins.
         if self.bin_count == bins and self.overdensity is not None:
@@ -295,8 +357,11 @@
         "rms_velocity"]
 
     def maximum_density(self):
-        """
-        Return the HOP-identified maximum density.
+        r"""Return the HOP-identified maximum density.
+        
+        Examples
+        -------
+        >>> max_dens = halos[0].maximum_density()
         """
         if self.max_dens_point is not None:
             return self.max_dens_point[0]
@@ -304,8 +369,11 @@
         return max
 
     def maximum_density_location(self):
-        """
-        Return the location HOP identified as maximally dense.
+        r"""Return the location HOP identified as maximally dense.
+        
+        Examples
+        -------
+        >>> max_dens_loc = halos[0].maximum_density_location()
         """
         if self.max_dens_point is not None:
             return self.max_dens_point[1:]
@@ -323,8 +391,11 @@
         return value
 
     def center_of_mass(self):
-        """
-        Calculate and return the center of mass.
+        r"""Calculate and return the center of mass.
+        
+        Examples
+        -------
+        >>> com = halos[0].center_of_mass()
         """
         # If it's precomputed, we save time!
         if self.CoM is not None:
@@ -348,8 +419,11 @@
         return global_com / global_mass
 
     def total_mass(self):
-        """
-        Returns the total mass in solar masses of the halo.
+        r"""Returns the total mass in solar masses of the halo.
+        
+        Examples
+        -------
+        >>> halos[0].total_mass()
         """
         if self.group_total_mass is not None:
             return self.group_total_mass
@@ -361,8 +435,11 @@
         return global_mass
 
     def bulk_velocity(self):
-        """
-        Returns the mass-weighted average velocity.
+        r"""Returns the mass-weighted average velocity in cm/s.
+        
+        Examples
+        --------
+        >>> bv = halos[0].bulk_velocity()
         """
         if self.bulk_vel is not None:
             return self.bulk_vel
@@ -384,8 +461,12 @@
         return global_bv[:3]/global_bv[3]
 
     def rms_velocity(self):
-        """
-        Returns the RMS velocity for the halo particles in cgs units.
+        r"""Returns the mass-weighted RMS velocity for the halo
+        particles in cgs units.
+        
+        Examples
+        --------
+        >>> rms_vel = halos[0].rms_velocity()



More information about the yt-svn mailing list