[Yt-svn] yt: 4 new changesets

hg at spacepope.org hg at spacepope.org
Wed Jun 23 21:38:30 PDT 2010


hg Repository: yt
details:   yt/rev/3f85775fb19f
changeset: 1790:3f85775fb19f
user:      Matthew Turk <matthewturk at gmail.com>
date:
Tue Jun 22 20:09:42 2010 -0700
description:
Fixing typo

hg Repository: yt
details:   yt/rev/50075512cdfd
changeset: 1791:50075512cdfd
user:      Matthew Turk <matthewturk at gmail.com>
date:
Wed Jun 23 17:57:04 2010 -0700
description:
Adding docstrings to transfer function

hg Repository: yt
details:   yt/rev/4be2007924ab
changeset: 1792:4be2007924ab
user:      Matthew Turk <matthewturk at gmail.com>
date:
Wed Jun 23 21:38:09 2010 -0700
description:
Changed to xrange in particle vertex addition in point cloud in VTK

hg Repository: yt
details:   yt/rev/94d7be0b4df4
changeset: 1793:94d7be0b4df4
user:      Matthew Turk <matthewturk at gmail.com>
date:
Wed Jun 23 21:38:26 2010 -0700
description:
Merge

diffstat:

 yt/extensions/StarAnalysis.py                      |    4 +-
 yt/extensions/volume_rendering/TransferFunction.py |  110 +++++++++++++++++++++-
 yt/reason/tvtk_interface.py                        |    7 +-
 3 files changed, 114 insertions(+), 7 deletions(-)

diffs (183 lines):

diff -r 97fa3280f8bf -r 94d7be0b4df4 yt/extensions/StarAnalysis.py
--- a/yt/extensions/StarAnalysis.py	Tue Jun 22 15:59:19 2010 -0700
+++ b/yt/extensions/StarAnalysis.py	Wed Jun 23 21:38:26 2010 -0700
@@ -127,7 +127,7 @@
         # Use the center of the time_bin, not the left edge.
         fp.write("#time\tlookback\tredshift\tMsol/yr\tMsol/yr/Mpc3\tMsol\tcumMsol\t\n")
         for i, time in enumerate((self.time_bins[1:] + self.time_bins[:-1])/2.):
-            line = "%1.5e\t%1.5e\t%1.5e\t%1.5e\t%1.5e\t%1.5e\t%1.5e\n" % \
+            line = "%1.5e %1.5e %1.5e %1.5e %1.5e %1.5e %1.5e\n" % \
             (time * tc / YEAR, # Time
             (self.time_now - time * tc)/YEAR, # Lookback time
             self.cosm.ComputeRedshiftFromTime(time * tc), # Redshift
@@ -320,7 +320,7 @@
             # Add this flux to the total, weighted by mass.
             self.final_spec += na.power(10., int_flux) * star[4]
         # Normalize.
-        self.total_mass = sum(self.star_mass)
+        self.total_mass = na.sum(self.star_mass)
         self.avg_mass = na.mean(self.star_mass)
         tot_metal = sum(self.star_metal * self.star_mass)
         self.avg_metal = math.log10(tot_metal / self.total_mass / Zsun)
diff -r 97fa3280f8bf -r 94d7be0b4df4 yt/extensions/volume_rendering/TransferFunction.py
--- a/yt/extensions/volume_rendering/TransferFunction.py	Tue Jun 22 15:59:19 2010 -0700
+++ b/yt/extensions/volume_rendering/TransferFunction.py	Wed Jun 23 21:38:26 2010 -0700
@@ -397,10 +397,27 @@
         >>> tf = ColorTransferFunction( (-10.0, -5.0) )
         >>> tf.add_step(-6.0, -5.0, [1.0, 1.0, 1.0, 1.0])
         """
-        for tf, v in zip(self.funcs, height):
+        for tf, v in zip(self.funcs, value):
             tf.add_step(start, stop, v)
 
     def plot(self, filename):
+        r"""Save an image file of the transfer function.
+
+        This function loads up matplotlib, plots all of the constituent
+        transfer functions and saves.
+
+        Parameters
+        ----------
+        filename : string
+            The file to save out the plot as.
+
+        Examples
+        --------
+
+        >>> tf = ColorTransferFunction( (-10.0, -5.0) )
+        >>> tf.add_layers(8)
+        >>> tf.plot("sample.png")
+        """
         from matplotlib import pyplot
         from matplotlib.ticker import FuncFormatter
         pyplot.clf()
@@ -428,6 +445,37 @@
         pyplot.savefig(filename)
 
     def sample_colormap(self, v, w, alpha=None, colormap="gist_stern"):
+        r"""Add a Gaussian based on an existing colormap.
+
+        Constructing pleasing Gaussians in a transfer function can pose some
+        challenges, so this function will add a single Gaussian whose colors
+        are taken from a colormap scaled between the bounds of the transfer
+        function.  As with `TransferFunction.add_gaussian`, the value is
+        calculated as :math:`f(x) = h \exp{-(x-x_0)^2 / w)` but with the height
+        for each color calculated from the colormap.
+
+        Parameters
+        ----------
+        v : float
+            The value at which the Gaussian is to be added.
+        w : float
+            The relative width (:math:`w` in the above equation.)
+        alpha : float, optional
+            The alpha value height for the Gaussian
+        colormap : string, optional
+            An acceptable colormap.  See either raven.color_maps or
+            http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps .
+
+        See Also
+        --------
+        ColorTransferFunction.add_layers : Many-at-a-time adder
+
+        Examples
+        --------
+
+        >>> tf = ColorTransferFunction( (-10.0, -5.0) )
+        >>> tf.sample_colormap(-7.0, 0.01, 'algae')
+        """
         rel = (v - self.x_bounds[0])/(self.x_bounds[1] - self.x_bounds[0])
         cmap = get_cmap(colormap)
         r,g,b,a = cmap(rel)
@@ -438,6 +486,44 @@
 
     def add_layers(self, N, w=None, mi=None, ma=None, alpha = None,
                    colormap="gist_stern"):
+        r"""Add a set of Gaussians based on an existing colormap.
+
+        Constructing pleasing Gaussians in a transfer function can pose some
+        challenges, so this function will add several evenly-spaced Gaussians
+        whose colors are taken from a colormap scaled between the bounds of the
+        transfer function.   For each Gaussian to be added,
+        `ColorTransferFunction.sample_colormap` is called.
+
+        Parameters
+        ----------
+        N : int
+            How many Gaussians to add
+        w : float
+            The relative width of each Gaussian.  If not included, it is
+            calculated as 0.001 * (max_val - min_val) / N
+        mi : float, optional
+            If only a subset of the data range is to have the Gaussians added,
+            this is the minimum for that subset
+        ma : float, optional
+            If only a subset of the data range is to have the Gaussians added,
+            this is the maximum for that subset
+        alpha : list of floats, optional
+            The alpha value height for each Gaussian.  If not supplied, it is
+            calculated as the logspace between -2.0 and 0.0.
+        colormap : string, optional
+            An acceptable colormap.  See either raven.color_maps or
+            http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps .
+
+        See Also
+        --------
+        ColorTransferFunction.sample_colormap : Single Gaussian adder
+
+        Examples
+        --------
+
+        >>> tf = ColorTransferFunction( (-10.0, -5.0) )
+        >>> tf.add_layers(8)
+        """
         dist = (self.x_bounds[1] - self.x_bounds[0])
         if mi is None: mi = self.x_bounds[0] + dist/(10.0*N)
         if ma is None: ma = self.x_bounds[1] - dist/(10.0*N)
@@ -447,7 +533,27 @@
             self.sample_colormap(v, w, a, colormap=colormap)
 
 class ProjectionTransferFunction(MultiVariateTransferFunction):
-    def __init__(self, x_bounds = (-1e30, 1e30)):
+    def __init__(self, x_bounds = (-1e60, 1e60)):
+        r"""A transfer function that defines a simple projection.
+
+        To generate an interpolated, off-axis projection through a dataset,
+        this transfer function should be used.  It will create a very simple
+        table that merely sums along each ray.  Note that the end product will
+        need to be scaled by the total width through which the rays were cast,
+        a piece of information inacessible to the transfer function.
+
+        Parameters
+        ----------
+        x_boudns : tuple of floats, optional
+            If any of your values lie outside this range, they will be
+            truncated.
+
+        Notes
+        -----
+        When you use this transfer function, you may need to explicitly disable
+        logging of fields.
+
+        """
         MultiVariateTransferFunction.__init__(self)
         self.x_bounds = x_bounds
         self.nbins = 2
diff -r 97fa3280f8bf -r 94d7be0b4df4 yt/reason/tvtk_interface.py
--- a/yt/reason/tvtk_interface.py	Tue Jun 22 15:59:19 2010 -0700
+++ b/yt/reason/tvtk_interface.py	Wed Jun 23 21:38:26 2010 -0700
@@ -649,10 +649,11 @@
     def display_points(self):
         dd = self.pf.h.all_data()
         points = tvtk.Points()
-        points.data = na.array([ dd["particle_position_%s" % ax] for ax in 'xyz' ]).transpose()
-        mass = na.log10(dd["ParticleMassMsun"])
+        good = (dd["creation_time"] > 0.0)
+        points.data = na.array([ dd["particle_position_%s" % ax][good] for ax in 'xyz' ]).transpose()
+        mass = na.log10(dd["ParticleAge"][good])
         self.conn = tvtk.CellArray()
-        for i in range(mass.shape[0]):
+        for i in xrange(mass.shape[0]):
             self.conn.insert_next_cell(1)
             self.conn.insert_cell_point(i)
         self.points = points



More information about the yt-svn mailing list