[GRASS-SVN] r48822 - in grass/trunk/gui/wxpython: gui_modules icons

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 16 00:53:52 EDT 2011


Author: cmbarton
Date: 2011-10-15 21:53:51 -0700 (Sat, 15 Oct 2011)
New Revision: 48822

Modified:
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/wxplot.py
   grass/trunk/gui/wxpython/gui_modules/wxplot_dialogs.py
   grass/trunk/gui/wxpython/icons/icon.py
Log:
wxgui: enhancements and fixes to analysis modules. Added scatterplot. Also added statistics displays for profile, histogram, and scatterplot.

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-10-15 20:12:47 UTC (rev 48821)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-10-16 04:53:51 UTC (rev 48822)
@@ -1258,7 +1258,7 @@
         
     def _toolbarData(self):
         """!Toolbar data"""
-        icons = Icons['profile']
+        icons = Icons['plot']
         return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
                                       self.parent.OnSelectRaster),
                                      ('transect', icons["transect"],
@@ -1275,6 +1275,8 @@
                                      ('unzoom', Icons['displayWindow']['zoomBack'],
                                       self.parent.OnRedraw),
                                      (None, ),
+                                     ('statistics', icons['statistics'],
+                                      self.parent.OnStats),
                                      ('datasave', icons["save"],
                                       self.parent.SaveProfileToFile),
                                      ('image', Icons['displayWindow']["saveFile"],
@@ -1433,7 +1435,7 @@
         
     def _toolbarData(self):
         """!Toolbar data"""
-        icons = Icons['profile']
+        icons = Icons['plot']
         return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
                                       self.parent.OnSelectRaster),
                                      (None, ),
@@ -1448,6 +1450,8 @@
                                      ('unzoom', Icons['displayWindow']['zoomBack'],
                                       self.parent.OnRedraw),
                                      (None, ),
+                                     ('statistics', icons['statistics'],
+                                      self.parent.OnStats),
                                      ('image', Icons['displayWindow']["saveFile"],
                                       self.parent.SaveToFile),
                                      ('print', Icons['displayWindow']["print"],
@@ -1472,7 +1476,8 @@
         
     def _toolbarData(self):
         """!Toolbar data"""
-        icons = Icons['profile']
+        icons = Icons['plot']
+#        icons2 = Icons['modeler']
         return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
                                       self.parent.OnSelectRaster),
                                      (None, ),
@@ -1487,6 +1492,8 @@
                                      ('unzoom', Icons['displayWindow']['zoomBack'],
                                       self.parent.OnRedraw),
                                      (None, ),
+                                     ('statistics', icons['statistics'],
+                                      self.parent.OnRegression),
                                      ('image', Icons['displayWindow']["saveFile"],
                                       self.parent.SaveToFile),
                                      ('print', Icons['displayWindow']["print"],

Modified: grass/trunk/gui/wxpython/gui_modules/wxplot.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxplot.py	2011-10-15 20:12:47 UTC (rev 48821)
+++ grass/trunk/gui/wxpython/gui_modules/wxplot.py	2011-10-16 04:53:51 UTC (rev 48822)
@@ -722,8 +722,25 @@
         self.SetGraphStyle()
         p = self.CreatePlotList()
         self.DrawPlot(p)
+ 
+    def OnStats(self, event):
+        """!Displays regression information in messagebox
+        """
+        message = []
+        title = _('Statistics for Map(s) Histogrammed')
+
+        for r in self.rasterList:
+            rast = r.split('@')[0] 
+            ret = grass.read_command('r.univar', map = r, flags = 'e', quiet = True)
+            stats = _('Statistics for %s\n\n%s\n') % (rast, ret)
+            message.append(stats)
+            
+        stats = dialogs.PlotStatsFrame(self, id = wx.ID_ANY, message = message, 
+                                      title = title)
+
+        if stats.Show() == wx.ID_CLOSE:
+            stats.Destroy()       
         
-        
 class ProfileFrame(AbstractPlotFrame):
     """!Mainframe for displaying profile of one or more raster maps. Uses wx.lib.plot.
     """
@@ -808,8 +825,7 @@
 
         #
         # create list of coordinate points for r.profile
-        #
-                
+        #                
         dist = 0
         cumdist = 0
         self.coordstr = ''
@@ -867,26 +883,26 @@
                 pass
 
         #
-        # create datalist for each raster map
+        # create datalist of dist/value pairs and y labels for each raster map
         #    
+        self.ylabel = ''
+        i = 0
+
         for r in self.raster.iterkeys():
-            self.raster[r]['datalist'] = []  
-            self.raster[r]['datalist'] = self.CreateDatalist(r, self.coordstr)
+            self.raster[r]['datalist'] = []
+            datalist = self.CreateDatalist(r, self.coordstr)
+            if len(datalist) > 0:   
+                self.raster[r]['datalist'] = datalist
 
-            # update title
-            self.ptitle += ' %s ,' % r.split('@')[0]
+                # update ylabel to match units if they exist           
+                if self.raster[r]['units'] != '':
+                    self.ylabel += '%s (%d),' % (r['units'], i)
+                i += 1
 
+                # update title
+                self.ptitle += ' %s ,' % r.split('@')[0]
+
         self.ptitle = self.ptitle.rstrip(',')
-
-        #
-        # set ylabel to match units if they exist
-        #
-        self.ylabel = ''
-        i = 0
-        for r in self.rasterList:
-            if self.raster[r]['units'] != '':
-                self.ylabel += '%s (%d),' % (r['units'], i)
-            i += 1
             
         if self.ylabel == '':
             self.ylabel = _('Raster values')
@@ -921,8 +937,12 @@
             
         for line in ret.splitlines():
             dist, elev = line.strip().split(' ')
-            if elev != 'nan':
-                datalist.append((dist,elev))
+            if dist == None or dist == '' or dist == 'nan' or \
+                elev == None or elev == '' or elev == 'nan':
+                continue
+            dist = float(dist)
+            elev = float(elev)
+            datalist.append((dist,elev))
 
         return datalist
 
@@ -1029,6 +1049,42 @@
 
         dlg.Destroy()
         
+    def OnStats(self, event):
+        """!Displays regression information in messagebox
+        """
+        message = []
+        title = _('Statistics for Profile(s)')
+
+        for r in self.raster.iterkeys():
+            try:
+                rast = r.split('@')[0] 
+                statstr = 'Profile of %s\n\n' % rast
+
+                iterable = (i[1] for i in self.raster[r]['datalist'])            
+                a = numpy.fromiter(iterable, numpy.float)
+                
+                statstr += 'n: %f\n' % a.size
+                statstr += 'minimum: %f\n' % numpy.amin(a)
+                statstr += 'maximum: %f\n' % numpy.amax(a)
+                statstr += 'range: %f\n' % numpy.ptp(a)
+                statstr += 'mean: %f\n' % numpy.mean(a)
+                statstr += 'standard deviation: %f\n' % numpy.std(a)
+                statstr += 'variance: %f\n' % numpy.var(a)
+                cv = numpy.std(a)/numpy.mean(a)
+                statstr += 'coefficient of variation: %f\n' % cv
+                statstr += 'sum: %f\n' % numpy.sum(a)
+                statstr += 'median: %f\n' % numpy.median(a)
+                statstr += 'distance along transect: %f\n\n' % self.transect_length       
+                message.append(statstr)
+            except:
+                pass
+            
+        stats = dialogs.PlotStatsFrame(self, id = wx.ID_ANY, message = message, 
+                                      title = title)
+
+        if stats.Show() == wx.ID_CLOSE:
+            stats.Destroy()       
+        
 class ScatterFrame(AbstractPlotFrame):
     """!Mainframe for displaying bivariate scatter plot of two raster maps. Uses wx.lib.plot.
     """
@@ -1174,7 +1230,6 @@
                                   quiet = True,
                                   read = True)
             
-            
             if not ret:
                 return datalist
             
@@ -1230,4 +1285,34 @@
         self.SetGraphStyle()
         p = self.CreatePlotList()
         self.DrawPlot(p)
-        
+    
+    def OnRegression(self, event):
+        """!Displays regression information in messagebox
+        """
+        message = []
+        title = _('Regression Statistics for Scatterplot(s)')
+
+        for rpair in self.rasterList:
+            if isinstance(rpair, tuple) == False: continue
+            rast1, rast2 = rpair
+            rast1 = rast1.split('@')[0] 
+            rast2 = rast2.split('@')[0] 
+            ret = grass.parse_command('r.regression.line', 
+                                      map1 = rast1, 
+                                      map2 = rast2, 
+                                      flags = 'g', quiet = True,
+                                      parse = (grass.parse_key_val, { 'sep' : '=' }))
+            eqtitle = _('Regression equation for %s vs. %s:\n\n')  % (rast1, rast2)
+            eq = _('   %s = %s + %s(%s)\n\n') % (rast2, ret['a'], ret['b'], rast1)
+            num = _('N = %s\n') % ret['N']
+            rval = _('R = %s\n') % ret['R']
+            rsq = _('R-squared = %f\n') % pow(float(ret['R']), 2)
+            ftest = _('F = %s\n') % ret['F']
+            str = eqtitle + eq + num + rval + rsq + ftest
+            message.append(str)
+            
+        stats = dialogs.PlotStatsFrame(self, id = wx.ID_ANY, message = message, 
+                                      title = title)
+
+        if stats.Show() == wx.ID_CLOSE:
+            stats.Destroy()       
\ No newline at end of file

Modified: grass/trunk/gui/wxpython/gui_modules/wxplot_dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxplot_dialogs.py	2011-10-15 20:12:47 UTC (rev 48821)
+++ grass/trunk/gui/wxpython/gui_modules/wxplot_dialogs.py	2011-10-16 04:53:51 UTC (rev 48822)
@@ -24,6 +24,7 @@
 
 import wx
 import wx.lib.colourselect as  csel
+import wx.lib.scrolledpanel as scrolled
 
 import globalvar
 import gcmd
@@ -219,7 +220,101 @@
         
     def OnSetScattertypes(self, event):
         self.scattertype = event.GetString()
+        
+class PlotStatsFrame(wx.Frame):
+    def __init__(self, parent, id, message = '', title = '',
+                 style = wx.DEFAULT_FRAME_STYLE, **kwargs):
+        """!Dialog to display and save statistics for plots
+        """
+        wx.Frame.__init__(self, parent, id, style = style, **kwargs)
+        self.SetLabel(_("Statistics"))
+        
+        sp = scrolled.ScrolledPanel(self, -1, size=(400, 400),
+                                    style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="Statistics" )
+                
 
+        #
+        # initialize variables
+        #
+        self.parent = parent
+        self.message = message 
+        self.title = title   
+        self.CenterOnParent()  
+        
+        #
+        # Display statistics
+        #
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        txtSizer = wx.BoxSizer(wx.VERTICAL)
+
+        statstitle = wx.StaticText(parent = self, id = wx.ID_ANY, label = self.title)
+        sizer.Add(item = statstitle, proportion = 0,
+                  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
+        line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
+        sizer.Add(item = line, proportion = 0,
+                  flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)
+        for stats in self.message:
+            statstxt = wx.StaticText(parent = sp, id = wx.ID_ANY, label = stats)
+            statstxt.SetBackgroundColour("WHITE")
+            txtSizer.Add(item = statstxt, proportion = 1, 
+                         flag = wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
+            line = wx.StaticLine(parent = sp, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL) 
+            txtSizer.Add(item = line, proportion = 0,
+                         flag = wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border = 3)      
+
+        sp.SetSizer(txtSizer)
+        sp.SetAutoLayout(1)
+        sp.SetupScrolling() 
+
+        sizer.Add(item = sp, proportion = 1, 
+                  flag = wx.GROW | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 3)
+
+        line = wx.StaticLine(parent = self, id = wx.ID_ANY, size = (20, -1), style = wx.LI_HORIZONTAL)
+        sizer.Add(item = line, proportion = 0,
+                  flag = wx.GROW |wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, border = 3)
+
+        #
+        # buttons
+        #
+        btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+
+        btn_clipboard = wx.Button(self, id = wx.ID_COPY, label = _('C&opy'))
+        btn_clipboard.SetToolTipString(_("Copy regression statistics the clipboard (Ctrl+C)"))
+        btnSizer.Add(item = btn_clipboard, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = 5)
+        
+        btnCancel = wx.Button(self, wx.ID_CLOSE)
+        btnCancel.SetDefault()
+        btnSizer.Add(item = btnCancel, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)        
+
+        sizer.Add(item = btnSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = 5)
+
+        # bindings
+        btnCancel.Bind(wx.EVT_BUTTON, self.OnClose)
+        btn_clipboard.Bind(wx.EVT_BUTTON, self.OnCopy)
+        
+        self.SetSizer(sizer)
+        sizer.Fit(self)
+
+    def OnCopy(self, event):
+        """!Copy the regression stats to the clipboard
+        """
+        str = self.title + '\n'
+        for item in self.message:
+            str += item
+            
+        rdata = wx.TextDataObject()
+        rdata.SetText(str)
+        
+        if wx.TheClipboard.Open():
+            wx.TheClipboard.SetData(rdata)
+            wx.TheClipboard.Close()
+            wx.MessageBox(_("Regression statistics copied to clipboard"))
+        
+    def OnClose(self, event):
+        """!Button 'Close' pressed
+        """
+        self.Close(True)
+
 class HistRasterDialog(wx.Dialog):
     def __init__(self, parent, id = wx.ID_ANY, 
                  title = _("Select raster map or imagery group to histogram"),

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2011-10-15 20:12:47 UTC (rev 48821)
+++ grass/trunk/gui/wxpython/icons/icon.py	2011-10-16 04:53:51 UTC (rev 48822)
@@ -300,17 +300,19 @@
                                       label = _('Undo'),
                                       desc = _('Undo previous changes')),
         },
-    'profile' : {
+    'plot' : {
         'draw'         : MetaIcon(img = iconSet.get('show', wx.ART_ERROR),
-                                  label = _('Draw/re-draw profile')),
+                                  label = _('Draw/re-draw plot')),
         'transect'     : MetaIcon(img = iconSet.get('layer-raster-profile', wx.ART_ERROR),
                                   label = _('Draw transect in map display window to profile')),
         'options'      : MetaIcon(img = iconSet.get('settings', wx.ART_ERROR),
-                                  label = _('Profile options')),
+                                  label = _('Plot options')),
+        'statistics'   : MetaIcon(img = iconSet.get('check', wx.ART_ERROR),
+                                  label = _('Plot statistics')),
         'save'         : MetaIcon(img = iconSet.get('save', wx.ART_ERROR),
                                   label = _('Save profile data to CSV file')),
         'quit'         : MetaIcon(img = iconSet.get('quit', wx.ART_ERROR),
-                                  label = _('Quit Profile Analysis Tool'))
+                                  label = _('Quit plot tool'))
         },
     'georectify' : {
         'gcpSet'    : MetaIcon(img = iconSet.get('gcp-create', wx.ART_ERROR),



More information about the grass-commit mailing list