[Yt-svn] yt: 2 new changesets

hg at spacepope.org hg at spacepope.org
Thu Apr 29 12:09:31 PDT 2010


hg Repository: yt
details:   yt/rev/ed94127de0a8
changeset: 1629:ed94127de0a8
user:      Matthew Turk <matthewturk at gmail.com>
date:
Thu Apr 29 12:09:09 2010 -0700
description:
Adding a non-local data image panner, to connect to remote ipcontrollers and
operate on them as though they were local. (for instance, only passing the
arrays back and forth over an ssh tunnel to use a chaco GUI locally)

hg Repository: yt
details:   yt/rev/a203d38d27eb
changeset: 1630:a203d38d27eb
user:      Matthew Turk <matthewturk at gmail.com>
date:
Thu Apr 29 12:09:28 2010 -0700
description:
Merging

diffstat:

 yt/extensions/image_panner/__init__.py  |   2 +-
 yt/extensions/image_panner/vm_panner.py |  59 +++++++++++++++++++++++++++++
 yt/lagos/HaloFinding.py                 |  17 +++++---
 3 files changed, 70 insertions(+), 8 deletions(-)

diffs (129 lines):

diff -r 1a91d9304a68 -r a203d38d27eb yt/extensions/image_panner/__init__.py
--- a/yt/extensions/image_panner/__init__.py	Thu Apr 29 12:34:33 2010 -0400
+++ b/yt/extensions/image_panner/__init__.py	Thu Apr 29 12:09:28 2010 -0700
@@ -23,4 +23,4 @@
 
 from vm_panner import VariableMeshPanner, WindowedVariableMeshPanner, \
                 MultipleWindowVariableMeshPanner, ImageSaver, \
-                PanningCeleritasStreamer
+                PanningCeleritasStreamer, NonLocalDataImagePanner
diff -r 1a91d9304a68 -r a203d38d27eb yt/extensions/image_panner/vm_panner.py
--- a/yt/extensions/image_panner/vm_panner.py	Thu Apr 29 12:34:33 2010 -0400
+++ b/yt/extensions/image_panner/vm_panner.py	Thu Apr 29 12:09:28 2010 -0700
@@ -63,6 +63,7 @@
 
     @property
     def bounds(self):
+        if not hasattr(self, 'pf'): self.pf = self.source.pf
         DLE, DRE = self.pf["DomainLeftEdge"], self.pf["DomainRightEdge"]
         ax = self.source.axis
         xax, yax = x_dict[ax], y_dict[ax]
@@ -340,6 +341,64 @@
         self.mec.execute("%s.callback(%s.buffer)" % (
             self._var_name, self._var_name), self.engine_id)
 
+class ProxySource(object):
+    # This proxies only the things we know we need
+    # Note that we assume we will only have a single engine.
+    def __init__(self, mec, idnum, source_varname):
+        self.mec = mec
+        self.idnum = idnum
+        self.source_varname = source_varname
+        self.mec.execute("_tmp_%s = %s.axis" % (
+            self.idnum, self.source_varname))
+        self.axis = self.mec.pull("_tmp_%s" % self.idnum)[0]
+
+    def keys(self):
+        self.mec.execute("_tmp_%s = %s.keys()" % (
+            self.idnum, self.source_varname))
+        keys = self.mec.pull("_tmp_%s" % self.idnum)[0]
+        dd = dict( (k, None) for k in keys )
+        return dd
+
+    @property
+    def pf(self):
+        self.mec.execute("_tmp_%s = %s.pf['DomainLeftEdge']" % (
+            self.idnum, self.source_varname))
+        DLE = self.mec.pull("_tmp_%s" % self.idnum)[0]
+        self.mec.execute("_tmp_%s = %s.pf['DomainRightEdge']" % (
+            self.idnum, self.source_varname))
+        DRE = self.mec.pull("_tmp_%s" % self.idnum)[0]
+        return dict(DomainLeftEdge = DLE, DomainRightEdge = DRE)
+
+class ProxyFixedResolutionBuffer(dict):
+    pass
+
+class NonLocalDataImagePanner(VariableMeshPanner):
+    def __init__(self, mec, source_varname, size, field,
+                 callback = None, viewport_callback = None):
+        self.source_varname = source_varname
+        self._var_name = "_image_panner_%s" % (id(self))
+        self.mec = mec
+        self.mec.execute("import yt.extensions.image_panner")
+        self.mec.execute("%s = yt.extensions.image_panner.VariableMeshPanner(" % (
+                        self._var_name) +
+                          "%s, (%s, %s), '%s')" % (
+                        source_varname, size[0], size[1], field))
+
+        ps = ProxySource(mec, id(self), source_varname)
+        self._prfb = ProxyFixedResolutionBuffer()
+
+        VariableMeshPanner.__init__(self, ps, size, field,
+                        callback, viewport_callback)
+
+    def _regenerate_buffer(self):
+        args = (self.xlim, self.ylim)
+        self.mec.push({'_tmp_%s' % id(self) : args})
+        self.mec.execute("%s.set_limits(*_tmp_%s)" % (self._var_name, id(self)))
+        self.mec.execute("_tmp_%s = %s.buffer" % (id(self), self._var_name))
+        self._prfb[self.field] = self.mec.pull("_tmp_%s" % (id(self)))[0]
+        self._prfb.bounds = self.xlim + self.ylim
+        self._buffer = self._prfb
+
 class ImageSaver(object):
     def __init__(self, tile_id):
         """
diff -r 1a91d9304a68 -r a203d38d27eb yt/lagos/HaloFinding.py
--- a/yt/lagos/HaloFinding.py	Thu Apr 29 12:34:33 2010 -0400
+++ b/yt/lagos/HaloFinding.py	Thu Apr 29 12:09:28 2010 -0700
@@ -44,6 +44,8 @@
 import math, sys, itertools, gc
 from collections import defaultdict
 
+TINY = 1.e-40
+
 class Halo(object):
     """
     A data source that returns particle information about the members of a
@@ -265,13 +267,14 @@
             mark += 1
         # Set up the radial bins.
         # Multiply min and max to prevent issues with digitize below.
-        self.radial_bins = na.logspace(math.log10(min(dist)*.99), 
-            math.log10(max(dist)*1.01), num=self.bin_count+1)
+        self.radial_bins = na.logspace(math.log10(min(dist)*.99 + TINY), 
+            math.log10(max(dist)*1.01 + 2*TINY), num=self.bin_count+1)
         # Find out which bin each particle goes into, and add the particle
         # mass to that bin.
         inds = na.digitize(dist, self.radial_bins) - 1
-        for index in na.unique(inds):
-            self.mass_bins[index] += sum(self["ParticleMassMsun"][inds==index])
+        if self["particle_position_x"].size > 1:
+            for index in na.unique(inds):
+                self.mass_bins[index] += sum(self["ParticleMassMsun"][inds==index])
         # Now forward sum the masses in the bins.
         for i in xrange(self.bin_count):
             self.mass_bins[i+1] += self.mass_bins[i]
@@ -531,9 +534,9 @@
         dist_max = self._mpi_allmax(dist_max)
         # Set up the radial bins.
         # Multiply min and max to prevent issues with digitize below.
-        self.radial_bins = na.logspace(math.log10(dist_min*.99), 
-            math.log10(dist_max*1.01), num=self.bin_count+1)
-        if self.indices is not None:
+        self.radial_bins = na.logspace(math.log10(dist_min*.99 + TINY), 
+            math.log10(dist_max*1.01 + 2*TINY), num=self.bin_count+1)
+        if self.indices is not None and self.indices.size > 1:
             # Find out which bin each particle goes into, and add the particle
             # mass to that bin.
             inds = na.digitize(dist, self.radial_bins) - 1



More information about the yt-svn mailing list