[GRASS-SVN] r37787 - grass-addons/vector/v.autokrige2

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 9 10:59:11 EDT 2009


Author: aghisla
Date: 2009-06-09 10:59:11 -0400 (Tue, 09 Jun 2009)
New Revision: 37787

Modified:
   grass-addons/vector/v.autokrige2/v.autokrige2.py
Log:
size fixed - R packages available create their notebook pages 
accordingly. no functionality provided until now.


Modified: grass-addons/vector/v.autokrige2/v.autokrige2.py
===================================================================
--- grass-addons/vector/v.autokrige2/v.autokrige2.py	2009-06-09 13:38:10 UTC (rev 37786)
+++ grass-addons/vector/v.autokrige2/v.autokrige2.py	2009-06-09 14:59:11 UTC (rev 37787)
@@ -20,6 +20,14 @@
 import sys
 import grass
 
+try:
+  import rpy2.robjects as robjects
+#  import rpy2.rpy_classic as rpy
+except ImportError:
+  print "Rpy2 not found. Please install it and re-run."
+
+#@TODO(anne): check availiability of automap or gstat or geoR.
+
 #classes in alphabetical order
 
 class KrigingPanel(wx.Panel):
@@ -58,6 +66,8 @@
         """Get list of tables for given location and mapset"""
         vectors = grass.list_grouped('vect')[self.gisenv['MAPSET']]
 
+        #@WARNING: this cycle is quite time-consuming. 
+        # see if it is possible to postpone this filtering, and immediately show the dialog.
         for n in vectors:
             if grass.vector_info_topo(n)['points'] == 0:
                 vectors.remove(n)
@@ -65,7 +75,7 @@
         if vectors == []:
             wx.MessageBox(parent=self,
                           message=("No vector maps available. Check if the location is correct."),
-                          caption=("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+                          caption=("Missing Input Data"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
         return sorted(vectors)
 
 class KrigingModule(wx.Frame):
@@ -81,10 +91,11 @@
         # debug: remove before flight
         self.log.write("Under construction.")
         
-        #@TODO(anne): set minimum size around objects.
+        self.Panel = KrigingPanel(self)
+        # size. It is the minimum size. No way to get it in a single command.
+        self.SetMinSize(self.GetBestSize())
+        self.SetSize(self.GetBestSize())
         
-        self.Panel = KrigingPanel(self)
-        self.Fit()        
     
 class Log:
     """
@@ -106,33 +117,52 @@
         self.__createAutomapPage()
         self.__createGstatPage()
         self.__createGeoRPage()
+        if self.GetPageCount() == 0:
+            wx.MessageBox(parent=self,
+                          message=("No R package with kriging functions available. Install either automap, gstat or geoR."),
+                          caption=("Missing Dependency"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
     
     # consider refactor this!
     def __createAutomapPage(self):
-        self.AutomapPanel = wx.Panel(self, -1)
-        self.AddPage(page=self.AutomapPanel, text="automap")
-        
-        self.VariogramList = ["Auto-fit variogram", "Choose variogram parameters"]
-        VariogramRadioBox = wx.RadioBox(self.AutomapPanel, -1, "Variogram Fitting", (-1,-1), wx.DefaultSize, 
-            self.VariogramList, 1, wx.RA_SPECIFY_COLS)
-        self.KrigingList = ["Ordinary kriging"]
-        KrigingRadioBox = wx.RadioBox(self.AutomapPanel, -1, "Kriging techniques", (-1,-1), wx.DefaultSize, 
-            self.KrigingList, 1, wx.RA_SPECIFY_COLS)
-        
-        Sizer = wx.BoxSizer(wx.VERTICAL)
-        Sizer.Add(VariogramRadioBox, 0, wx.EXPAND, 5)
-        Sizer.Add(KrigingRadioBox, 0, wx.EXPAND, 5)   
-        self.AutomapPanel.SetSizerAndFit(Sizer)
-        
-        # add stuff to panel
+        # 1. check if the package automap exists
+        if robjects.r.require('automap'):
+            self.AutomapPanel = wx.Panel(self, -1)
+            self.AddPage(page=self.AutomapPanel, text="automap")
+            
+            # unlock options as soon as they are available. Stone soup!
+            self.VariogramList = ["Auto-fit variogram"]#, "Choose variogram parameters"] 
+            VariogramRadioBox = wx.RadioBox(self.AutomapPanel, -1, "Variogram Fitting", (-1,-1), wx.DefaultSize, 
+                self.VariogramList, 1, wx.RA_SPECIFY_COLS)
+            self.KrigingList = ["Ordinary kriging"]
+            KrigingRadioBox = wx.RadioBox(self.AutomapPanel, -1, "Kriging techniques", (-1,-1), wx.DefaultSize, 
+                self.KrigingList, 1, wx.RA_SPECIFY_COLS)
+            RunButton = wx.Button(self.AutomapPanel, -1, 'Run')
+            
+            RunButton.Bind(wx.EVT_BUTTON, self.OnRunButton)
+            
+            Sizer = wx.BoxSizer(wx.VERTICAL)
+            Sizer.Add(VariogramRadioBox, 0, wx.EXPAND, 5)
+            Sizer.Add(KrigingRadioBox, 0, wx.EXPAND, 5)
+            Sizer.Add(RunButton, 0, wx.ALIGN_RIGHT, 5)
+            self.AutomapPanel.SetSizerAndFit(Sizer)
+        else:
+            pass
+
     def __createGstatPage(self):
-        self.GstatPanel = wx.Panel(self, -1)
-        self.AddPage(page=self.GstatPanel, text="gstat")
-        # add stuff to panel
+        if robjects.r.require('gstat'):
+            self.GstatPanel = wx.Panel(self, -1)
+            self.AddPage(page=self.GstatPanel, text="gstat")
+            # add stuff to panel
+        else:
+            pass
+
     def __createGeoRPage(self):
-        self.GeoRPanel = wx.Panel(self, -1)
-        self.AddPage(page=self.GeoRPanel, text="geoR")
-        # add stuff to panel
+        if robjects.r.require('geoR'):
+            self.GeoRPanel = wx.Panel(self, -1)
+            self.AddPage(page=self.GeoRPanel, text="geoR")
+            # add stuff to panel
+        else:
+            pass
        
     def __getColumns(self, driver, database, table):
         """Get list of column of given table"""
@@ -148,10 +178,17 @@
             columns.append(column)
         return columns
         
+    def OnRunButton(self):
+        """ Execute R analysis. """
+        
+        pass
+        
 #main
 def main(argv=None):
     if argv is None:
         argv = sys.argv
+        
+    #@TODO(anne): add command line arguments acceptance.
 
     """if len(argv) != 2:
         print >> sys.stderr, __doc__
@@ -166,9 +203,8 @@
     ##some applications might require image handlers
     #wx.InitAllImageHandlers()
 
-#    app = wx.PySimpleApp() # deprecated?
     app = wx.App()
-    k = KrigingModule(parent=None, size=(600,300))
+    k = KrigingModule(parent=None)
     k.Show()
     app.MainLoop()
 



More information about the grass-commit mailing list