[Yt-svn] commit/yt: 3 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri Sep 30 12:50:21 PDT 2011


3 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/01ba897f7554/
changeset:   01ba897f7554
branch:      yt
user:        MatthewTurk
date:        2011-09-30 15:51:38
summary:     First set of support code for off-axis projection helpers.  Right now,
weighting occurs post-interpolation inside the cells.  It's not clear yet to me
if this is preferable to pre-interpolation inside the cells.
affected #:  3 files (-1 bytes)

--- a/yt/utilities/_amr_utils/VolumeIntegrator.pyx	Wed Sep 28 09:42:43 2011 -0600
+++ b/yt/utilities/_amr_utils/VolumeIntegrator.pyx	Fri Sep 30 09:51:38 2011 -0400
@@ -267,9 +267,12 @@
 
 cdef np.float64_t FIT_get_value(FieldInterpolationTable *fit,
                             np.float64_t *dvs):
-    cdef np.float64_t bv, dy, dd, tf
+    cdef np.float64_t bv, dy, dd, tf, rv
     cdef int bin_id
-    if fit.pass_through == 1: return dvs[fit.field_id]
+    if fit.pass_through == 1:
+        rv = dvs[fit.field_id]
+        if fit.weight_field_id != -1: rv *= dvs[fit.weight_field_id]
+        return rv
     if dvs[fit.field_id] > fit.bounds[1] or dvs[fit.field_id] < fit.bounds[0]: return 0.0
     bin_id = <int> ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin)
     dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0
@@ -289,7 +292,6 @@
     # correspond to multiple tables, and each field table will only have
     # interpolate called once.
     cdef FieldInterpolationTable field_tables[6]
-    cdef np.float64_t istorage[6]
 
     # Here are the field tables that correspond to each of the six channels.
     # We have three emission channels, three absorption channels.
@@ -314,7 +316,6 @@
         self.tf_obj = tf_obj
 
         self.n_field_tables = tf_obj.n_field_tables
-        for i in range(6): self.istorage[i] = 0.0
 
         self.my_field_tables = []
         for i in range(self.n_field_tables):
@@ -345,7 +346,7 @@
     cdef void eval_transfer(self, np.float64_t dt, np.float64_t *dvs,
                                   np.float64_t *rgba, np.float64_t *grad):
         cdef int i, fid, use
-        cdef np.float64_t ta, tf, trgba[6], dot_prod
+        cdef np.float64_t ta, tf, istorage[6], trgba[6], dot_prod
         # NOTE: We now disable this.  I have left it to ease the process of
         # potentially, one day, re-including it.
         #use = 0
@@ -355,14 +356,15 @@
         #       (dvs[fid] <= self.field_tables[i].bounds[1]):
         #        use = 1
         #        break
+        for i in range(6): istorage[i] = 0.0
         for i in range(self.n_field_tables):
-            self.istorage[i] = FIT_get_value(&self.field_tables[i], dvs)
+            istorage[i] = FIT_get_value(&self.field_tables[i], dvs)
         # We have to do this after the interpolation
         for i in range(self.n_field_tables):
             fid = self.field_tables[i].weight_table_id
-            if fid != -1: self.istorage[i] *= self.istorage[fid]
+            if fid != -1: istorage[i] *= istorage[fid]
         for i in range(6):
-            trgba[i] = self.istorage[self.field_table_ids[i]]
+            trgba[i] = istorage[self.field_table_ids[i]]
             #print i, trgba[i],
         #print
         # A few words on opacity.  We're going to be integrating equation 1.23


--- a/yt/visualization/volume_rendering/camera.py	Wed Sep 28 09:42:43 2011 -0600
+++ b/yt/visualization/volume_rendering/camera.py	Fri Sep 30 09:51:38 2011 -0400
@@ -705,3 +705,20 @@
                              oc.volume, oc.fields, oc.log_fields,
                              oc.sub_samples, oc.pf)
         return (left_camera, right_camera)
+
+def off_axis_projection(pf, c, L, W, N, field, weight = None):
+    tf = ProjectionTransferFunction(weighted = weight is not None)
+    fields = [field]
+    if weight is not None:
+        fields.append(weight)
+    cam = pf.h.camera(c, L, W, N, tf, fields = fields,
+                      log_fields = [False] * len(fields))
+    vals = cam.snapshot()
+    image = vals[:,:,0].copy()
+    if weight is None:
+        dl = W * pf.units[pf.field_info[field].projection_conversion]
+        image *= dl
+    else:
+        image /= vals[:,:,1]
+    #if weight is not None: insert_ipython()
+    return vals, image


--- a/yt/visualization/volume_rendering/transfer_functions.py	Wed Sep 28 09:42:43 2011 -0600
+++ b/yt/visualization/volume_rendering/transfer_functions.py	Fri Sep 30 09:51:38 2011 -0400
@@ -561,7 +561,7 @@
         return image
 
 class ProjectionTransferFunction(MultiVariateTransferFunction):
-    def __init__(self, x_bounds = (-1e60, 1e60)):
+    def __init__(self, x_bounds = (-1e60, 1e60), weighted = False):
         r"""A transfer function that defines a simple projection.
 
         To generate an interpolated, off-axis projection through a dataset,
@@ -587,13 +587,15 @@
         self.nbins = 2
         self.linear_mapping = TransferFunction(x_bounds, 2)
         self.linear_mapping.pass_through = 1
-        self.add_field_table(self.linear_mapping, 0)
-        self.alpha = TransferFunction(x_bounds, 2)
-        self.alpha.y *= 0.0
-        self.alpha.y += 1.0
-        self.add_field_table(self.alpha, 0)
+        if weighted:
+            self.add_field_table(self.linear_mapping, 0, weight_field_id = 1)
+            self.add_field_table(self.linear_mapping, 1)
+        else:
+            self.add_field_table(self.linear_mapping, 0)
         self.link_channels(0, [0,1,2]) # same emission for all rgb
-        self.link_channels(2, [3,4,5]) # this will remove absorption
+        if weighted:
+            self.link_channels(1, [1])
+        self.link_channels(3, [3,4,5]) # this will remove absorption
 
 class PlanckTransferFunction(MultiVariateTransferFunction):
     def __init__(self, T_bounds, rho_bounds, nbins=256,


http://bitbucket.org/yt_analysis/yt/changeset/2d53bdc6d77f/
changeset:   2d53bdc6d77f
branch:      yt
user:        MatthewTurk
date:        2011-09-30 16:33:30
summary:     Changed the ProjectionTransferFunction around again a bit to make it work more
nicely with multiple projected fields and have now settled on the ability to
perform interpolation only on the pre-weighted quantity.  Advanced users can do
intra-cell interpolation.
affected #:  2 files (-1 bytes)

--- a/yt/visualization/volume_rendering/camera.py	Fri Sep 30 09:51:38 2011 -0400
+++ b/yt/visualization/volume_rendering/camera.py	Fri Sep 30 10:33:30 2011 -0400
@@ -707,10 +707,16 @@
         return (left_camera, right_camera)
 
 def off_axis_projection(pf, c, L, W, N, field, weight = None):
-    tf = ProjectionTransferFunction(weighted = weight is not None)
+    # We manually modify the ProjectionTransferFunction to get it to work the
+    # way we want, with a second field that's also passed through.
     fields = [field]
     if weight is not None:
-        fields.append(weight)
+        # This is a temporary field, which we will remove at the end.
+        pf.field_info.add_field("temp_weightfield",
+            function=lambda a,b:b[field]*b[weight])
+        fields = ["temp_weightfield", weight]
+        tf = ProjectionTransferFunction(n_fields = 2)
+    tf = ProjectionTransferFunction(n_fields = len(fields))
     cam = pf.h.camera(c, L, W, N, tf, fields = fields,
                       log_fields = [False] * len(fields))
     vals = cam.snapshot()
@@ -720,5 +726,5 @@
         image *= dl
     else:
         image /= vals[:,:,1]
-    #if weight is not None: insert_ipython()
+        pf.field_info._field_list.pop("temp_weightfield")
     return vals, image


--- a/yt/visualization/volume_rendering/transfer_functions.py	Fri Sep 30 09:51:38 2011 -0400
+++ b/yt/visualization/volume_rendering/transfer_functions.py	Fri Sep 30 10:33:30 2011 -0400
@@ -561,7 +561,7 @@
         return image
 
 class ProjectionTransferFunction(MultiVariateTransferFunction):
-    def __init__(self, x_bounds = (-1e60, 1e60), weighted = False):
+    def __init__(self, x_bounds = (-1e60, 1e60), n_fields = 1):
         r"""A transfer function that defines a simple projection.
 
         To generate an interpolated, off-axis projection through a dataset,
@@ -572,9 +572,11 @@
 
         Parameters
         ----------
-        x_boudns : tuple of floats, optional
+        x_bounds : tuple of floats, optional
             If any of your values lie outside this range, they will be
             truncated.
+        n_fields : int, optional
+            How many fields we're going to project and pass through
 
         Notes
         -----
@@ -582,20 +584,18 @@
         logging of fields.
 
         """
+        if n_fields > 3:
+            raise NotImplementedError
         MultiVariateTransferFunction.__init__(self)
         self.x_bounds = x_bounds
         self.nbins = 2
         self.linear_mapping = TransferFunction(x_bounds, 2)
         self.linear_mapping.pass_through = 1
-        if weighted:
-            self.add_field_table(self.linear_mapping, 0, weight_field_id = 1)
-            self.add_field_table(self.linear_mapping, 1)
-        else:
-            self.add_field_table(self.linear_mapping, 0)
-        self.link_channels(0, [0,1,2]) # same emission for all rgb
-        if weighted:
-            self.link_channels(1, [1])
-        self.link_channels(3, [3,4,5]) # this will remove absorption
+        self.link_channels(0, [0,1,2]) # same emission for all rgb, default
+        for i in range(n_fields):
+            self.add_field_table(self.linear_mapping, i)
+            self.link_channels(i, i)
+        self.link_channels(n_fields, [3,4,5]) # this will remove absorption
 
 class PlanckTransferFunction(MultiVariateTransferFunction):
     def __init__(self, T_bounds, rho_bounds, nbins=256,


http://bitbucket.org/yt_analysis/yt/changeset/a32614c85cf2/
changeset:   a32614c85cf2
branch:      yt
user:        MatthewTurk
date:        2011-09-30 16:42:59
summary:     Adding a docstring, adding import of off_axis_projection to both
volume_rendering/api.py and yt/mods.py, to make it available.  Example code:

http://paste.yt-project.org/show/1839/
affected #:  3 files (-1 bytes)

--- a/yt/mods.py	Fri Sep 30 10:33:30 2011 -0400
+++ b/yt/mods.py	Fri Sep 30 10:42:59 2011 -0400
@@ -103,7 +103,7 @@
 
 from yt.visualization.volume_rendering.api import \
     ColorTransferFunction, PlanckTransferFunction, ProjectionTransferFunction, \
-    HomogenizedVolume, Camera
+    HomogenizedVolume, Camera, off_axis_projection
 
 for name, cls in callback_registry.items():
     exec("%s = cls" % name)


--- a/yt/visualization/volume_rendering/api.py	Fri Sep 30 10:33:30 2011 -0400
+++ b/yt/visualization/volume_rendering/api.py	Fri Sep 30 10:42:59 2011 -0400
@@ -41,4 +41,5 @@
 from image_handling import export_rgba, import_rgba, \
                            plot_channel, plot_rgb
 from software_sampler import VolumeRendering
-from camera import Camera, PerspectiveCamera, StereoPairCamera
+from camera import Camera, PerspectiveCamera, StereoPairCamera, \
+    off_axis_projection


--- a/yt/visualization/volume_rendering/camera.py	Fri Sep 30 10:33:30 2011 -0400
+++ b/yt/visualization/volume_rendering/camera.py	Fri Sep 30 10:42:59 2011 -0400
@@ -87,7 +87,7 @@
             the volume rendering mechanism.
         sub_samples : int, optional
             The number of samples to take inside every cell per ray.
-        pf : `~yt.lagos.StaticOutput`
+        pf : `~yt.data_objects.api.StaticOutput`
             For now, this is a require parameter!  But in the future it will become
             optional.  This is the parameter file to volume render.
         use_kd: bool, optional
@@ -706,7 +706,50 @@
                              oc.sub_samples, oc.pf)
         return (left_camera, right_camera)
 
-def off_axis_projection(pf, c, L, W, N, field, weight = None):
+def off_axis_projection(pf, center, normal_vector, width, resolution,
+                        field, weight = None):
+    r"""Project through a parameter file, off-axis, and return the image plane.
+
+    This function will accept the necessary items to integrate through a volume
+    at an arbitrary angle and return the integrated field of view to the user.
+    Note that if a weight is supplied, it will multiply the pre-interpolated
+    values together, then create cell-centered values, then interpolate within
+    the cell to conduct the integration.
+
+    Parameters
+    ----------
+    pf : `~yt.data_objects.api.StaticOutput`
+        This is the parameter file to volume render.
+    center : array_like
+        The current "center" of the view port -- the focal point for the
+        camera.
+    normal_vector : array_like
+        The vector between the camera position and the center.
+    width : float or list of floats
+        The current width of the image.  If a single float, the volume is
+        cubical, but if not, it is front/back, left/right, top/bottom.
+    resolution : int or list of ints
+        The number of pixels in each direction.
+    field : string
+        The field to project through the volume
+    weight : optional, default None
+        If supplied, the field will be pre-multiplied by this, then divided by
+        the integrated value of this field.  This returns an average rather
+        than a sum.
+
+    Returns
+    -------
+    image : array
+        An (N,N) array of the final integrated values, in float64 form.
+
+    Examples
+    --------
+
+    >>> image = off_axis_projection(pf, [0.5, 0.5, 0.5], [0.2,0.3,0.4],
+                      0.2, N, "Temperature", "Density")
+    >>> write_image(na.log10(image), "offaxis.png")
+
+    """
     # We manually modify the ProjectionTransferFunction to get it to work the
     # way we want, with a second field that's also passed through.
     fields = [field]
@@ -717,14 +760,15 @@
         fields = ["temp_weightfield", weight]
         tf = ProjectionTransferFunction(n_fields = 2)
     tf = ProjectionTransferFunction(n_fields = len(fields))
-    cam = pf.h.camera(c, L, W, N, tf, fields = fields,
+    cam = pf.h.camera(center, normal_vector, width, resolution, tf,
+                      fields = fields,
                       log_fields = [False] * len(fields))
     vals = cam.snapshot()
-    image = vals[:,:,0].copy()
+    image = vals[:,:,0]
     if weight is None:
-        dl = W * pf.units[pf.field_info[field].projection_conversion]
+        dl = width * pf.units[pf.field_info[field].projection_conversion]
         image *= dl
     else:
         image /= vals[:,:,1]
         pf.field_info._field_list.pop("temp_weightfield")
-    return vals, image
+    return image

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list