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

Bitbucket commits-noreply at bitbucket.org
Thu Apr 14 07:23:26 PDT 2011


2 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/6f09395aa425/
changeset:   r4124:6f09395aa425
branch:      yt
user:        MatthewTurk
date:        2011-04-14 16:22:50
summary:     Adding mechanism for passing data to widgets.  Adding ability to change fields
in plot window widget.  Adding a few fixes for choosing in the combo boxes.

The solution for the plot window is not going to be needed once "add_field" or
"set_field" have been implemented.
affected #:  4 files (3.5 KB)

--- a/yt/gui/reason/extdirect_repl.py	Wed Apr 13 15:42:28 2011 -0400
+++ b/yt/gui/reason/extdirect_repl.py	Thu Apr 14 10:22:50 2011 -0400
@@ -281,7 +281,7 @@
         response.headers["content-disposition"] = "attachment;"
         return cs
 
-    def _add_widget(self, widget_name):
+    def _add_widget(self, widget_name, widget_data_name = None):
         # This should be sanitized
         widget = self.locals[widget_name]
         uu = str(uuid.uuid1()).replace("-","_")
@@ -289,11 +289,16 @@
         widget._ext_widget_id = varname
         # THIS BREAKS THE SCRIPT DOWNLOAD!
         # We need to make the variable be bound via an execution mechanism
+        command = "%s = %s\n" % (varname, widget_name)
         payload = {'type': 'widget',
                    'widget_type': widget._widget_name,
-                   'varname': varname}
+                   'varname': varname,
+                   'data': None}
+        widget._ext_widget_id = varname
+        if widget_data_name is not None:
+            payload['data'] = self.locals[widget_data_name]
         self.payload_handler.add_payload(payload)
-        return "%s = %s\n" % (varname, widget_name)
+        return command
 
     @lockit
     def create_proj(self, pfname, axis, field, weight):
@@ -311,6 +316,9 @@
         _tpw = PWViewerExtJS(_tsl, (DLE[_txax], DRE[_txax], DLE[_tyax], DRE[_tyax]), setup = False)
         _tpw._current_field = _tfield
         _tpw.set_log(_tfield, True)
+        _twidget_data = {'fields': list(set(_tpf.h.field_list +
+                                        _tpf.h.derived_field_list)),
+                         'initial_field': _tfield}
         """ % dict(pfname = pfname,
                    axis = inv_axis_names[axis],
                    weight = weight,
@@ -318,15 +326,23 @@
         # There is a call to do this, but I have forgotten it ...
         funccall = "\n".join((line.strip() for line in funccall.splitlines()))
         self.execute(funccall)
-        self.execute(self._add_widget('_tpw'))
+        self.execute(self._add_widget('_tpw', '_twidget_data'))
 
     @lockit
-    def create_slice(self, pfname, center, axis, field):
+    def create_slice(self, pfname, center, axis, field, onmax):
+        if not onmax: 
+            center_string = \
+              "na.array([%(c1)0.20f,%(c2)0.20f, %(c3)0.20f],dtype='float64')" \
+                % dict(c1 = float(center[0]),
+                       c2 = float(center[1]),
+                       c3 = float(center[2]))
+        else:
+            center_string = "_tpf.h.find_max('Density')[1]"
         funccall = """
         _tpf = %(pfname)s
-        _tcenter = na.array([%(c1)0.20f, %(c2)0.20f, %(c3)0.20f], dtype='float64')
         _taxis = %(axis)s
         _tfield = "%(field)s"
+        _tcenter = %(center_string)s
         _tcoord = _tcenter[_taxis]
         _tsl = _tpf.h.slice(_taxis, _tcoord, center = _tcenter)
         _txax, _tyax = x_dict[_taxis], y_dict[_taxis]
@@ -335,16 +351,18 @@
         _tpw = PWViewerExtJS(_tsl, (DLE[_txax], DRE[_txax], DLE[_tyax], DRE[_tyax]), setup = False)
         _tpw._current_field = _tfield
         _tpw.set_log(_tfield, True)
+        _tfield_list = _tpf.h.field_list + _tpf.h.derived_field_list
+        _tfield_list.sort()
+        _twidget_data = {'fields': _tfield_list,
+                         'initial_field': _tfield}
         """ % dict(pfname = pfname,
-                   c1 = float(center[0]),
-                   c2 = float(center[1]),
-                   c3 = float(center[2]),
+                   center_string = center_string,
                    axis = inv_axis_names[axis],
                    field=field)
         # There is a call to do this, but I have forgotten it ...
         funccall = "\n".join((line.strip() for line in funccall.splitlines()))
         self.execute(funccall)
-        self.execute(self._add_widget('_tpw'))
+        self.execute(self._add_widget('_tpw', '_twidget_data'))
 
     def _test_widget(self):
         class tt(object):


--- a/yt/gui/reason/html/js/functions.js	Wed Apr 13 15:42:28 2011 -0400
+++ b/yt/gui/reason/html/js/functions.js	Thu Apr 14 10:22:50 2011 -0400
@@ -72,7 +72,8 @@
             new_log = true;
         } else if (payload['type'] == 'widget') {
             var widget_type = payload['widget_type'];
-            var widget = new widget_types[widget_type](payload['varname']);
+            var widget = new widget_types[widget_type](payload['varname'],
+                                                       payload['data']);
             widget_list[widget.id] = widget;
         } else if (payload['type'] == 'widget_payload') {
             var widget = widget_list[payload['widget_id']];
@@ -158,7 +159,7 @@
     var win = new Ext.Window({
         layout:'fit',
         width:320,
-        height:200,
+        height:250,
         modal:true,
         resizable:false,
         draggable:false,
@@ -196,6 +197,25 @@
                 store:['X','Y','Z'],
                 width: 90,
                 allowBlank:false,
+                value: 'X',
+                triggerAction: 'all',
+            },{
+                xtype:'checkbox',
+                fieldLabel: 'Center on Max',
+                id: 'max_dens',
+                width: 90,
+                allowBlank:false,
+                handler: function(checkbox, checked) {
+                    if (checked == true) {
+                        this.ownerCt.get("slice_x_center").disable();
+                        this.ownerCt.get("slice_y_center").disable();
+                        this.ownerCt.get("slice_z_center").disable();
+                    } else {
+                        this.ownerCt.get("slice_x_center").enable();
+                        this.ownerCt.get("slice_y_center").enable();
+                        this.ownerCt.get("slice_z_center").enable();
+                    }
+                }
             },{
                 xtype:'combo',
                 fieldLabel: 'Field',
@@ -203,6 +223,8 @@
                 store:node.attributes.objdata.field_list,
                 width: 200,
                 allowBlank:false,
+                value: 'Density',
+                triggerAction: 'all',
             }],
             buttons: [
                 {
@@ -213,9 +235,10 @@
                                       Ext.get("slice_z_center").getValue()];
                         var axis = Ext.get("slice_axis").getValue();
                         var field = Ext.get("slice_field").getValue();
+                        var onmax = Ext.get("max_dens").getValue();
                         yt_rpc.ExtDirectREPL.create_slice({
                             pfname:node.attributes.objdata.varname,
-                            center: center, axis:axis, field:field},
+                            center: center, axis:axis, field:field, onmax:onmax},
                           handle_result);
                         win.close();
                     }
@@ -244,7 +267,7 @@
     var win = new Ext.Window({
         layout:'fit',
         width:370,
-        height:170,
+        height:220,
         modal:true,
         resizable:false,
         draggable:false,
@@ -261,6 +284,15 @@
                 store:['X','Y','Z'],
                 width: 90,
                 allowBlank:false,
+                triggerAction: 'all',
+                value: 'X',
+            },{
+                xtype:'checkbox',
+                fieldLabel: 'Center on Max',
+                id: 'max_dens',
+                width: 90,
+                allowBlank:false,
+                /* No handler, because no center */
             },{
                 xtype:'combo',
                 fieldLabel: 'Field',
@@ -268,6 +300,8 @@
                 store:node.attributes.objdata.field_list,
                 width: 230,
                 allowBlank:false,
+                triggerAction: 'all',
+                value: 'Density'
             },{
                 xtype:'combo',
                 fieldLabel: 'Weight Field',
@@ -275,6 +309,8 @@
                 store:['None'].concat(node.attributes.objdata.field_list),
                 width: 230,
                 allowBlank:false,
+                triggerAction: 'all',
+                value: 'None'
             }],
             buttons: [
                 {
@@ -283,9 +319,11 @@
                         var axis = Ext.get("axis").getValue();
                         var field = Ext.get("field").getValue();
                         var weight = Ext.get("weightField").getValue();
+                        var onmax = Ext.get("max_dens").getValue();
                         yt_rpc.ExtDirectREPL.create_proj({
                                 pfname: node.attributes.objdata.varname,
-                                axis: axis, field: field, weight: weight},
+                                axis: axis, field: field, weight: weight,
+                                onmax: onmax},
                               handle_result);
                         win.close();
                     }


--- a/yt/gui/reason/html/js/widget_plotwindow.js	Wed Apr 13 15:42:28 2011 -0400
+++ b/yt/gui/reason/html/js/widget_plotwindow.js	Thu Apr 14 10:22:50 2011 -0400
@@ -31,8 +31,9 @@
 
 
 
-var WidgetPlotWindow = function(python_varname) {
+var WidgetPlotWindow = function(python_varname, widget_data) {
     this.id = python_varname;
+    this.widget_data = widget_data;
     this.print_python = function(b, e) {
         yt_rpc.ExtDirectREPL.execute(
             {code:'print "' + python_varname + '"'},
@@ -225,6 +226,23 @@
                             logging_store.add(record, number_log_records++);
                         }); 
                     }
+                },{
+                    xtype: 'combo',
+                    text: 'Field',
+                    x: 10,
+                    y: 315,
+                    width: 80,
+                    store:widget_data['fields'],
+                    value:widget_data['initial_field'],
+                    editable: false,
+                    triggerAction: 'all',
+                    listeners: {change: function(form, newValue, oldValue) {
+                        alert(newValue);
+                        yt_rpc.ExtDirectREPL.execute(
+                            {code:python_varname + '.set_current_field("' +
+                                newValue + '")'},
+                            cell_finished);
+                    }}
                 }
             ]
         }


--- a/yt/visualization/plot_window.py	Wed Apr 13 15:42:28 2011 -0400
+++ b/yt/visualization/plot_window.py	Thu Apr 14 10:22:50 2011 -0400
@@ -307,6 +307,14 @@
     def get_metadata(self):
         pass
 
+    @invalidate_data
+    def set_current_field(self, field):
+        self._current_field = field
+        self._frb[field]
+        if self._frb.pf.field_info[field].take_log:
+            self._field_transform[field] = na.log
+        else:
+            self._field_transform[field] = lambda x: x
 
 
 class YtPlot(object):


http://bitbucket.org/yt_analysis/yt/changeset/7988b94ddeee/
changeset:   r4125:7988b94ddeee
branch:      yt
user:        MatthewTurk
date:        2011-04-14 16:23:06
summary:     Merging
affected #:  1 file (1.3 KB)

--- a/yt/data_objects/object_finding_mixin.py	Thu Apr 14 10:22:50 2011 -0400
+++ b/yt/data_objects/object_finding_mixin.py	Thu Apr 14 10:23:06 2011 -0400
@@ -107,6 +107,41 @@
         ind = na.where(mask == 1)
         return self.grids[ind], ind
 
+    def find_field_value_at_point(self, fields, coord):
+        r"""Find the value of fields at a point.
+        
+        Returns the values [field1, field2,...] of the fields at the given
+        (x,y,z) point. Returns a list of field values in the same order
+        as the input *fields*.
+        
+        Parameters
+        ---------
+        fields : string or list of strings
+            The field(s) that will be returned.
+        
+        coord : list or array of floats
+            The location for which field values will be returned.
+        
+        Examples
+        --------
+        >>> pf.h.find_field_value_at_point(['Density', 'Temperature'],
+            [0.4, 0.3, 0.8])
+        [2.1489e-24, 1.23843e4]
+        """
+        # Get the most-refined grid at this coordinate.
+        this = self.find_point(coord)[0][-1]
+        cellwidth = (this.RightEdge - this.LeftEdge) / this.ActiveDimensions
+        mark = na.zeros(3).astype('int')
+        # Find the index for the cell containing this point.
+        for dim in xrange(len(coord)):
+            mark[dim] = int((coord[dim] - this.LeftEdge[dim]) / cellwidth[dim])
+        out = []
+        fields = ensure_list(fields)
+        # Pull out the values and add it to the out list.
+        for field in fields:
+            out.append(this[field][mark[0], mark[1], mark[2]])
+        return out
+
     def find_slice_grids(self, coord, axis):
         """
         Returns the (objects, indices) of grids that a slice intersects along

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