[Yt-svn] yt: Adding docstrings to the merger tree & star analysis stuff.
hg at spacepope.org
hg at spacepope.org
Thu Jun 24 18:28:57 PDT 2010
hg Repository: yt
details: yt/rev/b965f7e80d39
changeset: 1808:b965f7e80d39
user: Stephen Skory <stephenskory at yahoo.com>
date:
Thu Jun 24 18:28:48 2010 -0700
description:
Adding docstrings to the merger tree & star analysis stuff.
diffstat:
yt/extensions/StarAnalysis.py | 134 ++++++++++++++++++++++++++++++++++----------
yt/extensions/merger_tree.py | 125 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 228 insertions(+), 31 deletions(-)
diffs (truncated from 376 to 300 lines):
diff -r 64664f2a8d97 -r b965f7e80d39 yt/extensions/StarAnalysis.py
--- a/yt/extensions/StarAnalysis.py Thu Jun 24 17:18:15 2010 -0700
+++ b/yt/extensions/StarAnalysis.py Thu Jun 24 18:28:48 2010 -0700
@@ -37,6 +37,32 @@
class StarFormationRate(object):
def __init__(self, pf, data_source=None, star_mass=None,
star_creation_time=None, volume=None, bins=300):
+ r"""Calculates the star formation rate for a given population of
+ star particles.
+
+ Parameters
+ ----------
+ pf : EnzoStaticOutput object
+ data_source : AMRRegion object, optional
+ The region from which stars are extracted for analysis. If this
+ is not supplied, the next three must be, otherwise the next
+ three do not need to be specified.
+ star_mass : Ordered array or list of floats
+ The mass of the stars to be analyzed in units of Msun.
+ star_creation_time : Ordered array or list of floats
+ The creation time for the stars in code units.
+ volume : Float
+ The volume of the region for the specified list of stars.
+ bins : Integer
+ The number of time bins used for binning the stars. Default = 300.
+
+ Examples
+ --------
+
+ >>> pf = load("RedshiftOutput0000")
+ >>> sp = pf.h.sphere([0.5,0.5,0.5], [.1])
+ >>> sfr = StarFormationRate(pf, sp)
+ """
self._pf = pf
self._data_source = data_source
self.star_mass = star_mass
@@ -101,8 +127,7 @@
self.time_bins_dt = self.time_bins[1:] - self.time_bins[:-1]
def write_out(self, name="StarFormationRate.out"):
- """
- Write out the star analysis to a text file *name*. The columns are in
+ r"""Write out the star analysis to a text file *name*. The columns are in
order:
1) Time (yrs)
2) Look-back time (yrs)
@@ -111,6 +136,15 @@
5) Star formation rate in this bin per year per Mpc**3 (Msol/yr/Mpc**3)
6) Stars formed in this time bin (Msol)
7) Cumulative stars formed up to this time bin (Msol)
+
+ Parameters
+ ---------
+ name : String
+ The name of the file to write to. Default = StarFormationRate.out.
+
+ Examples
+ -------
+ >>> sfr.write_out("stars-SFR.out")
"""
fp = open(name, "w")
if self.mode == 'data_source':
@@ -177,14 +211,24 @@
class SpectrumBuilder(object):
def __init__(self, pf, bcdir="", model="chabrier"):
- """
- Initialize the data to build a summed flux spectrum for a
+ r"""Initialize the data to build a summed flux spectrum for a
collection of stars using the models of Bruzual & Charlot (2003).
- :param pf (object): Yt pf object.
- :param bcdir (string): Path to directory containing Bruzual &
- Charlot h5 fit files.
- :param model (string): Choice of Initial Metalicity Function model,
- 'chabrier' or 'salpeter'.
+ This function loads the necessary data tables into memory and
+ must be called before analyzing any star particles.
+
+ Parameters
+ ----------
+ pf : EnzoStaticOutput object
+ bcdir : String
+ Path to directory containing Bruzual & Charlot h5 fit files.
+ model : String
+ Choice of Initial Metalicity Function model, 'chabrier' or
+ 'salpeter'. Default = 'chabrier'.
+
+ Examples
+ -------
+ >>> pf = load("RedshiftOutput0000")
+ >>> spec = SpectrumBuilder(pf, "/home/user/bc/", model="salpeter")
"""
self._pf = pf
self.bcdir = bcdir
@@ -223,25 +267,37 @@
def calculate_spectrum(self, data_source=None, star_mass=None,
star_creation_time=None, star_metallicity_fraction=None,
star_metallicity_constant=None, min_age=0.):
- """
- For the set of stars, calculate the collective spectrum.
+ r"""For the set of stars, calculate the collective spectrum.
Attached to the output are several useful objects:
final_spec: The collective spectrum in units of flux binned in wavelength.
wavelength: The wavelength for the spectrum bins, in Angstroms.
total_mass: Total mass of all the stars.
avg_mass: Average mass of all the stars.
avg_metal: Average metallicity of all the stars.
- :param data_source (object): A yt data_source that defines a portion
- of the volume from which to extract stars.
- :param star_mass (array, float): An array of star masses in Msun units.
- :param star_creation_time (array, float): An array of star creation
- times in code units.
- :param star_metallicity_fraction (array, float): An array of star
- metallicity fractions, in code units (which is not Z/Zsun).
- :param star_metallicity_constant (float): If desired, override the star
- metallicity fraction of all the stars to the given value.
- :param min_age (float): Removes young stars below this number (in years
- from the spectrum. Default: 0 (all stars).
+
+ Parameters
+ ---------
+ data_source : AMRRegion object, optional
+ The region from which stars are extracted for analysis. If this is
+ not specified, the next three parameters must be supplied.
+ star_mass : Array or list of floats
+ An array of star masses in Msun units.
+ star_creation_time : Array or list of floats
+ An array of star creation times in code units.
+ star_metallicity_fraction : Array or list of floats
+ An array of star metallicity fractions, in code
+ units (which is not Z/Zsun, rather just Z).
+ star_metallicity_constant : Float
+ If desired, override the star
+ metallicity fraction of all the stars to the given value.
+ min_age : Float
+ Removes young stars younger than this number (in years)
+ from the spectrum. Default: 0 (all stars).
+
+ Examples
+ --------
+ >>> sp = pf.h.sphere([0.5,0.5,0.5], [.1])
+ >>> spec.calculate_spectrum(data_source=sp, min_age = 1.e6)
"""
# Initialize values
self.final_spec = na.zeros(self.wavelength.size, dtype='float64')
@@ -364,12 +420,19 @@
def write_out(self, name="sum_flux.out"):
- """
- Write out the summed flux to a file. The file has two columns:
+ r"""Write out the summed flux to a file. The file has two columns:
1) Wavelength (Angstrom)
2) Flux (Luminosity per unit wavelength, L_sun Ang^-1,
L_sun = 3.826 * 10^33 ergs s^-1.)
- :param name (string): Name of file to write to.
+
+ Parameters
+ ----------
+ name : String
+ Name of file to write to. Default = "sum_flux.out"
+
+ Examples
+ -------
+ >>> spec.write_out("spec.out")
"""
fp = open(name, 'w')
for i, wave in enumerate(self.wavelength):
@@ -377,15 +440,24 @@
fp.close()
def write_out_SED(self, name="sum_SED.out", flux_norm=5200.):
- """
- Write out the summed SED to a file. The file has two columns:
+ r"""Write out the summed SED to a file. The file has two columns:
1) Wavelength (Angstrom)
2) Relative flux normalized to the flux at *flux_norm*.
- It also will attach an array *f_nu* which is the normalized flux,
+ It also will attach to the SpectrumBuilder object
+ an array *f_nu* which is the normalized flux,
identical to the disk output.
- :param name (string): Name of file to write to.
- :param flux_norm (float): Wavelength of the flux to normalize the
- distribution against.
+
+ Parameters
+ ---------
+ name : String
+ Name of file to write to. Default = "sum_SED.out"
+ flux_norm : Float
+ Wavelength of the flux to normalize the distribution against.
+ Default = 5200 Ang.
+
+ Examples
+ -------
+ >>> spec.write_out_SED(name = "SED.out", flux_norm = 6000.)
"""
# find the f_nu closest to flux_norm
fn_wavelength = na.argmin(abs(self.wavelength - flux_norm))
diff -r 64664f2a8d97 -r b965f7e80d39 yt/extensions/merger_tree.py
--- a/yt/extensions/merger_tree.py Thu Jun 24 17:18:15 2010 -0700
+++ b/yt/extensions/merger_tree.py Thu Jun 24 18:28:48 2010 -0700
@@ -96,6 +96,54 @@
halo_finder_function=HaloFinder, halo_finder_threshold=80.0,
FOF_link_length=0.2, dm_only=False, refresh=False, sleep=1,
index=True):
+ r"""Build a merger tree of halos over a time-ordered set of snapshots.
+ This will run a halo finder to find the halos first if it hasn't already
+ been done. The output is a SQLite database file, which may need to
+ be stored on a different disk than the data snapshots. See the full
+ documentation for details.
+
+ Parameters
+ ---------
+ restart_files : List of strings
+ A list containing the paths to the forward time-ordered set of
+ data snapshots.
+ database : String
+ Name of SQLite database file. Default = "halos.db".
+ halo_finder_function : HaloFinder name
+ The name of the halo finder to use if halo finding is run by
+ the merger tree. Options: HaloFinder, FOFHaloFinder, parallelHF.
+ Note that this is not a string, so no quotes. Default = HaloFinder.
+ halo_finder_threshold : Float
+ If using HaloFinder or parallelHF, the value of the density threshold
+ used when halo finding. Default = 80.0.
+ FOF_link_length : Float
+ If using FOFHaloFinder, the linking length between particles.
+ Default = 0.2.
+ dm_only : Boolean
+ When halo finding, whether to restrict to only dark matter particles.
+ Default = False.
+ refresh : Boolean
+ True forces the halo finder to run even if the halo data has been
+ detected on disk. Default = False.
+ sleep : Float
+ Due to the nature of the SQLite database and network file systems,
+ it is crucial that all tasks see the database in the same state at
+ all times. This parameter specifies how long in seconds the merger
+ tree waits between checks to ensure the database is synched across
+ all tasks. Default = 1.
+ index : Boolean
+ SQLite databases can have added to them an index which greatly
+ speeds up future queries of the database,
+ at the cost of doubling the disk space used by the file.
+ Default = True.
+
+ Examples:
+ >>> rf = ['/scratch/user/sim1/DD0000/data0000',
+ ... '/scratch/user/sim1/DD0001/data0001',
+ ... '/scratch/user/sim1/DD0002/data0002']
+ >>> MergerTree(rf, database = '/home/user/sim1-halos.db',
+ ... halo_finder_function=parallelHF)
+ """
self.restart_files = restart_files # list of enzo restart files
self.with_halos = na.ones(len(restart_files), dtype='bool')
self.database = database # the sqlite database of haloes.
@@ -652,16 +700,46 @@
class MergerTreeConnect(DatabaseFunctions):
def __init__(self, database='halos.db'):
+ r"""Create a convenience object for accessing data from the halo database.
+
+ Parameters
+ ----------
+ database : String
+ The name of the halo database to access. Default = 'halos.db'.
+
+ Examples
+ -------
+ >>> mtc = MergerTreeConnect('/home/user/sim1-halos.db')
+ """
self.database = database
result = self._open_database()
if not result:
return None
def close(self):
+ r"""Cleanly close access to the database.
+
+ Examples
+ --------
+ >>> mtc.close()
+ """
# To be more like typical Python open/close.
self._close_database()
def query(self, string):
+ r"""Performs a query of the database and returns the results as a list
+ of tuple(s), even if the result is singular.
+
+ Parameters
+ ----------
+ string : String
+ The SQL query of the database.
+
+ Examples
+ -------
+ >>> results = mtc.query("SELECT GlobalHaloID from Halos where SnapHaloID = 0 and \
+ ... SnapZ = 0;")
More information about the yt-svn
mailing list