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

Bitbucket commits-noreply at bitbucket.org
Thu Apr 28 08:18:18 PDT 2011


2 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/dff4877a58fe/
changeset:   r4221:dff4877a58fe
branch:      yt
user:        brittonsmith
date:        2011-04-28 17:18:01
summary:     Added line of sight velocity to light ray tool.
affected #:  1 file (885 bytes)

--- a/yt/analysis_modules/light_ray/light_ray.py	Wed Apr 27 15:02:53 2011 -0400
+++ b/yt/analysis_modules/light_ray/light_ray.py	Thu Apr 28 11:18:01 2011 -0400
@@ -138,7 +138,7 @@
 
     def make_light_ray(self, seed=None, fields=None, 
                        solution_filename=None, data_filename=None,
-                       get_nearest_galaxy=False, **kwargs):
+                       get_nearest_galaxy=False, get_los_velocity=False, **kwargs):
         "Create a light ray and get field values for each lixel."
 
         # Calculate solution.
@@ -153,6 +153,9 @@
         if get_nearest_galaxy:
             all_fields.extend(['x', 'y', 'z', 'nearest_galaxy', 'nearest_galaxy_mass'])
             fields.extend(['x', 'y', 'z'])
+        if get_los_velocity:
+            all_fields.extend(['x-velocity', 'y-velocity', 'z-velocity', 'los_velocity'])
+            fields.extend(['x-velocity', 'y-velocity', 'z-velocity'])
 
         todo = na.arange(my_rank, len(self.light_ray_solution), my_size)
         for index in todo:
@@ -195,6 +198,17 @@
                     sub_data[field] = na.concatenate([sub_data[field], 
                                                       (sub_ray[field])])
 
+                if get_los_velocity:
+                    line_of_sight = sub_segment[1] - sub_segment[0]
+                    line_of_sight /= ((line_of_sight**2).sum())**0.5
+                    sub_vel = na.array([sub_ray['x-velocity'], 
+                                        sub_ray['y-velocity'],
+                                        sub_ray['z-velocity']])
+                    sub_data['los_velocity'] = na.concatenate([sub_data['los_velocity'], 
+                                                               (na.rollaxis(sub_vel, 1) * 
+                                                                line_of_sight).sum(axis=1)])
+                    del sub_vel
+
                 sub_ray.clear_data()
                 del sub_ray
 


http://bitbucket.org/yt_analysis/yt/changeset/f778bce8376a/
changeset:   r4222:f778bce8376a
branch:      yt
user:        brittonsmith
date:        2011-04-28 17:18:11
summary:     Merged.
affected #:  6 files (6.5 KB)

--- a/yt/gui/reason/extdirect_repl.py	Thu Apr 28 11:18:01 2011 -0400
+++ b/yt/gui/reason/extdirect_repl.py	Thu Apr 28 11:18:11 2011 -0400
@@ -35,6 +35,10 @@
 import urllib2
 import pprint
 import traceback
+import tempfile
+import base64
+import imp
+import threading
 
 from yt.funcs import *
 from yt.utilities.logger import ytLogger, ufstring
@@ -46,7 +50,6 @@
                          PayloadHandler
 from .bottle import response, request, route
 from .basic_repl import ProgrammaticREPL
-import threading
 
 try:
     import pygments
@@ -92,6 +95,54 @@
 
 lockit = MethodLock()
 
+def deliver_image(im):
+    if hasattr(im, 'read'):
+        img_data = base64.b64encode(im.read())
+    elif isinstance(im, types.StringTypes) and \
+         im.endswith(".png"):
+        img_data = base64.b64encode(open(im).read())
+    elif isinstance(im, types.StringTypes):
+        img_data = im
+    else:
+        raise RuntimeError
+    ph = PayloadHandler()
+    payload = {'type':'png_string',
+               'image_data':img_data}
+    ph.add_payload(payload)
+
+def reason_pylab():
+    def _canvas_deliver(canvas):
+        tf = tempfile.TemporaryFile()
+        canvas.print_png(tf)
+        tf.seek(0)
+        img_data = base64.b64encode(tf.read())
+        tf.close()
+        deliver_image(img_data)
+    def reason_draw_if_interactive():
+        if matplotlib.is_interactive():
+            figManager =  Gcf.get_active()
+            if figManager is not None:
+                _canvas_deliver(figManager.canvas)
+    def reason_show(mainloop = True):
+        # We ignore mainloop here
+        for manager in Gcf.get_all_fig_managers():
+            _canvas_deliver(manager.canvas)
+    # Matplotlib has very nice backend overriding.
+    # We should really use that.  This is just a hack.
+    import matplotlib
+    new_agg = imp.new_module("reason_agg")
+    import matplotlib.backends.backend_agg as bagg
+    new_agg.__dict__.update(bagg.__dict__)
+    new_agg.__dict__.update(
+        {'show': reason_show,
+         'draw_if_interactive': reason_draw_if_interactive})
+    sys.modules["reason_agg"] = new_agg
+    bagg.draw_if_interactive = reason_draw_if_interactive
+    from matplotlib._pylab_helpers import Gcf
+    import pylab, matplotlib
+    matplotlib.rcParams["backend"] = "module://reason_agg"
+    pylab.switch_backend("module://reason_agg")
+
 class ExtDirectREPL(ProgrammaticREPL, BottleDirectRouter):
     _skip_expose = ('index')
     my_name = "ExtDirectREPL"
@@ -132,9 +183,11 @@
         self.payload_handler = PayloadHandler()
         # Now we load up all the yt.mods stuff, but only after we've finished
         # setting up.
-        self.execute("from yt.mods import *")
+        reason_pylab()
+        self.execute("from yt.mods import *\nimport pylab\npylab.ion()")
         self.execute("from yt.data_objects.static_output import _cached_pfs", hide = True)
         self.locals['load_script'] = ext_load_script
+        self.locals['deliver_image'] = deliver_image
         self._setup_logging_handlers()
 
         # Setup our heartbeat
@@ -380,8 +433,7 @@
         DLE, DRE = _tpf.domain_left_edge, _tpf.domain_right_edge
         from yt.visualization.plot_window import PWViewerExtJS
         _tpw = PWViewerExtJS(_tsl, (DLE[_txax], DRE[_txax], DLE[_tyax], DRE[_tyax]), setup = False)
-        _tpw._current_field = _tfield
-        _tpw._field_transform["%(field)s"] = na.log
+        _tpw.set_current_field("%(field)s")
         _tfield_list = list(set(_tpf.h.field_list + _tpf.h.derived_field_list))
         _tfield_list.sort()
         _tcb = _tpw._get_cbar_image()
@@ -420,8 +472,7 @@
         DLE, DRE = _tpf.domain_left_edge, _tpf.domain_right_edge
         from yt.visualization.plot_window import PWViewerExtJS
         _tpw = PWViewerExtJS(_tsl, (DLE[_txax], DRE[_txax], DLE[_tyax], DRE[_tyax]), setup = False)
-        _tpw._current_field = _tfield
-        _tpw.set_log(_tfield, True)
+        _tpw.set_current_field("%(field)s")
         _tfield_list = list(set(_tpf.h.field_list + _tpf.h.derived_field_list))
         _tfield_list.sort()
         _tcb = _tpw._get_cbar_image()


--- a/yt/gui/reason/html/js/widget_plotwindow.js	Thu Apr 28 11:18:01 2011 -0400
+++ b/yt/gui/reason/html/js/widget_plotwindow.js	Thu Apr 28 11:18:11 2011 -0400
@@ -114,10 +114,10 @@
                     xtype: 'panel',
                     id: 'ticks_' + python_varname,
                     layout: 'absolute',
-                    y: 10,
+                    y: 0,
                     x: 540,
-                    width: 40,
-                    height: 400,
+                    width: 100,
+                    height: 420,
                     items : [],
                     border: false,
                 }, {   xtype: 'multislider',
@@ -334,9 +334,9 @@
                     xtype: 'panel',
                     layout: 'vbox',
                     id: 'rhs_panel_' + python_varname,
-                    width: 300,
+                    width: 250,
                     height: 460,
-                    x: 590, y: 10,
+                    x: 690, y: 10,
                     layoutConfig: {
                         align: 'stretch',
                         pack: 'start',
@@ -383,21 +383,22 @@
         metadata_string = payload['metadata_string'];
         ticks.removeAll();
         Ext.each(payload['ticks'], function(tick, index) {
+            console.log(tick);
             ticks.add({xtype:'panel',
                        width: 10, height:1,
                        style: 'background-color: #000000;',
                        html:' ',
-                       x:0, y: tick[0]});
+                       x:0, y: 10 + tick[0]});
             ticks.add({xtype:'panel',
-                       width: 30, height:15,
+                       width: 90, height:15,
                        border: false,
                        style: 'font-family: "Inconsolata", monospace;' +
                               'font-size: 12px;',
-                       html: ' ' + tick[2] + ' ',
-                       x:12, y: tick[0]-6});
+                       html: '' + tick[2] + '',
+                       x:12, y: 4 + tick[0]});
             examine = tick;
         });
-        //examine = ticks;
+        examine = payload['ticks'];
         ticks.doLayout();
     }
 


--- a/yt/visualization/loglocator.py	Thu Apr 28 11:18:01 2011 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-##
-## This is a modified version of the LogLocator used in Matplotlib.
-## It is subject to the terms of the BSD license, and copyright is held by the
-## original authors.
-##
-
-import math
-import numpy as na
-
-def is_decade(x,base=10):
-    if x == 0.0:
-        return True
-    lx = math.log(x)/math.log(base)
-    return lx==int(lx)
-
-class LogLocator(object):
-    """
-    Determine the tick locations for log axes
-    """
-
-    def __init__(self, base=10.0, subs=[1.0], numdecs=4):
-        """
-        place ticks on the location= base**i*subs[j]
-        """
-        self.base(base)
-        self.subs(subs)
-        self.numticks = 15
-        self.numdecs = numdecs
-
-    def base(self,base):
-        """
-        set the base of the log scaling (major tick every base**i, i interger)
-        """
-        self._base=base+0.0
-
-    def subs(self,subs):
-        """
-        set the minor ticks the log scaling every base**i*subs[j]
-        """
-        if subs is None:
-            self._subs = None  # autosub
-        else:
-            self._subs = na.asarray(subs)+0.0
-
-    def _set_numticks(self):
-        self.numticks = 15  # todo; be smart here; this is just for dev
-
-    def __call__(self, vmin, vmax):
-        'Return the locations of the ticks'
-        b=self._base
-
-        if vmin <= 0.0:
-            raise ValueError(
-                "Data has no positive values, and therefore can not be log-scaled.")
-
-        vmin = math.log(vmin)/math.log(b)
-        vmax = math.log(vmax)/math.log(b)
-
-        if vmax<vmin:
-            vmin, vmax = vmax, vmin
-
-        numdec = math.floor(vmax)-math.ceil(vmin)
-
-        if self._subs is None: # autosub
-            if numdec>10: subs = na.array([1.0])
-            elif numdec>6: subs = na.arange(2.0, b, 2.0)
-            else: subs = na.arange(2.0, b)
-        else:
-            subs = self._subs
-
-        stride = 1
-        while numdec/stride+1 > self.numticks:
-            stride += 1
-
-        decades = na.arange(math.floor(vmin),
-                             math.ceil(vmax)+stride, stride)
-        if len(subs) > 1 or (len(subs == 1) and subs[0] != 1.0):
-            ticklocs = []
-            for decadeStart in b**decades:
-                ticklocs.extend( subs*decadeStart )
-        else:
-            ticklocs = b**decades
-
-        return na.array(ticklocs)
-
-if __name__ == "__main__":
-    ll = LogLocator()
-    print ll(1e-24, 5e-25)
-    print ll(1e-24, 1e-28)
-    print ll(1e-24, 1e-35)


--- a/yt/visualization/plot_window.py	Thu Apr 28 11:18:01 2011 -0400
+++ b/yt/visualization/plot_window.py	Thu Apr 28 11:18:11 2011 -0400
@@ -33,7 +33,7 @@
 from .fixed_resolution import \
     FixedResolutionBuffer
 from .plot_modifications import get_smallest_appropriate_unit
-from .loglocator import LogLocator
+from .tick_locators import LogLocator, LinearLocator
 
 from yt.funcs import *
 from yt.utilities.amr_utils import write_png_to_file
@@ -346,7 +346,8 @@
             zoom_fac = na.log10(x_width*self._frb.pf['unitary'])/na.log10(min_zoom)
             zoom_fac = 100.0*max(0.0, zoom_fac)
             ticks = self.get_ticks(self._frb[field].min(),
-                                   self._frb[field].max())
+                                   self._frb[field].max(), 
+                                   take_log = self._frb.pf.field_info[field].take_log)
             payload = {'type':'png_string',
                        'image_data':img_data,
                        'metadata_string': self.get_metadata(field),
@@ -355,18 +356,26 @@
             payload.update(addl_keys)
             ph.add_payload(payload)
 
-    def get_ticks(self, mi, ma, height = 400):
+    def get_ticks(self, mi, ma, height = 400, take_log = False):
         # This will eventually change to work with non-logged fields
-        ll = LogLocator() 
-        tick_locs = ll(mi, ma)
         ticks = []
-        mi = na.log10(mi)
-        ma = na.log10(ma)
-        for v1,v2 in zip(tick_locs, na.log10(tick_locs)):
-            if v2 < mi or v2 > ma: continue
-            p = height - height * (v2 - mi)/(ma - mi)
-            ticks.append((p,v1,v2))
-            #print v1, v2, mi, ma, height, p
+        if take_log:
+            ll = LogLocator() 
+            tick_locs = ll(mi, ma)
+            mi = na.log10(mi)
+            ma = na.log10(ma)
+            for v1,v2 in zip(tick_locs, na.log10(tick_locs)):
+                if v2 < mi or v2 > ma: continue
+                p = height - height * (v2 - mi)/(ma - mi)
+                ticks.append((p,v1,v2))
+                #print v1, v2, mi, ma, height, p
+        else:
+            ll = LinearLocator()
+            tick_locs = ll(mi, ma)
+            for v in tick_locs:
+                p = height - height * (v - mi)/(ma-mi)
+                ticks.append((p,v,"%0.3e" % (v)))
+
         return ticks
 
     def _get_cbar_image(self, height = 400, width = 40):


--- a/yt/visualization/profile_plotter.py	Thu Apr 28 11:18:01 2011 -0400
+++ b/yt/visualization/profile_plotter.py	Thu Apr 28 11:18:11 2011 -0400
@@ -37,7 +37,7 @@
     BinnedProfile1D, \
     BinnedProfile2D
 from .plot_types import ProfilePlot, PhasePlot
-from .loglocator import LogLocator
+from .tick_locators import LogLocator
 
 def invalidate_plot(f):
     @wraps(f)


--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yt/visualization/tick_locators.py	Thu Apr 28 11:18:11 2011 -0400
@@ -0,0 +1,163 @@
+##
+## This is a modified version of the LogLocator used in Matplotlib.
+## It is subject to the terms of the BSD license, and copyright is held by the
+## original authors.
+##
+
+import math
+import numpy as na
+
+def is_decade(x,base=10):
+    if x == 0.0:
+        return True
+    lx = math.log(x)/math.log(base)
+    return lx==int(lx)
+
+class LogLocator(object):
+    """
+    Determine the tick locations for log axes
+    """
+
+    def __init__(self, base=10.0, subs=[1.0], numdecs=4):
+        """
+        place ticks on the location= base**i*subs[j]
+        """
+        self.base(base)
+        self.subs(subs)
+        self.numticks = 15
+        self.numdecs = numdecs
+
+    def base(self,base):
+        """
+        set the base of the log scaling (major tick every base**i, i interger)
+        """
+        self._base=base+0.0
+
+    def subs(self,subs):
+        """
+        set the minor ticks the log scaling every base**i*subs[j]
+        """
+        if subs is None:
+            self._subs = None  # autosub
+        else:
+            self._subs = na.asarray(subs)+0.0
+
+    def _set_numticks(self):
+        self.numticks = 15  # todo; be smart here; this is just for dev
+
+    def __call__(self, vmin, vmax):
+        'Return the locations of the ticks'
+        b=self._base
+
+        if vmin <= 0.0:
+            raise ValueError(
+                "Data has no positive values, and therefore can not be log-scaled.")
+
+        vmin = math.log(vmin)/math.log(b)
+        vmax = math.log(vmax)/math.log(b)
+
+        if vmax<vmin:
+            vmin, vmax = vmax, vmin
+
+        numdec = math.floor(vmax)-math.ceil(vmin)
+
+        if self._subs is None: # autosub
+            if numdec>10: subs = na.array([1.0])
+            elif numdec>6: subs = na.arange(2.0, b, 2.0)
+            else: subs = na.arange(2.0, b)
+        else:
+            subs = self._subs
+
+        stride = 1
+        while numdec/stride+1 > self.numticks:
+            stride += 1
+
+        decades = na.arange(math.floor(vmin),
+                             math.ceil(vmax)+stride, stride)
+        if len(subs) > 1 or (len(subs == 1) and subs[0] != 1.0):
+            ticklocs = []
+            for decadeStart in b**decades:
+                ticklocs.extend( subs*decadeStart )
+        else:
+            ticklocs = b**decades
+
+        return na.array(ticklocs)
+
+
+class LinearLocator(object):
+    """
+    Determine the tick locations
+
+    The first time this function is called it will try to set the
+    number of ticks to make a nice tick partitioning.  Thereafter the
+    number of ticks will be fixed so that interactive navigation will
+    be nice
+    """
+
+
+    def __init__(self, numticks = None, presets=None):
+        """
+        Use presets to set locs based on lom.  A dict mapping vmin, vmax->locs
+        """
+        self.numticks = numticks
+        if presets is None:
+            self.presets = {}
+        else:
+            self.presets = presets
+
+    def __call__(self, vmin, vmax):
+        'Return the locations of the ticks'
+
+        # vmin, vmax = self.axis.get_view_interval()
+        # vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05)
+        if vmax<vmin:
+            vmin, vmax = vmax, vmin
+
+        if (vmin, vmax) in self.presets:
+            return self.presets[(vmin, vmax)]
+
+        if self.numticks is None:
+            self._set_numticks()
+
+
+
+        if self.numticks==0: return []
+        ticklocs = na.linspace(vmin, vmax, self.numticks)
+
+        #return self.raise_if_exceeds(ticklocs)
+        return ticklocs
+
+
+    def _set_numticks(self):
+        self.numticks = 11  # todo; be smart here; this is just for dev
+
+    # def view_limits(self, vmin, vmax):
+    #     'Try to choose the view limits intelligently'
+
+    #     if vmax<vmin:
+    #         vmin, vmax = vmax, vmin
+
+    #     if vmin==vmax:
+    #         vmin-=1
+    #         vmax+=1
+
+    #     exponent, remainder = divmod(math.log10(vmax - vmin), 1)
+
+    #     if remainder < 0.5:
+    #         exponent -= 1
+    #     scale = 10**(-exponent)
+    #     vmin = math.floor(scale*vmin)/scale
+    #     vmax = math.ceil(scale*vmax)/scale
+
+    #     return mtransforms.nonsingular(vmin, vmax)
+
+
+if __name__ == "__main__":
+    ll = LogLocator()
+    print ll(1e-24, 5e-25)
+    print ll(1e-24, 1e-28)
+    print ll(1e-24, 1e-35)
+    lll = LinearLocator()
+    print lll(-1e-24, 1e-24)
+    print lll(-2.3, 1.3)
+    print lll(10,23.)

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