[GRASS-SVN] r38059 - grass-addons/vector/v.krige
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 24 11:03:06 EDT 2009
Author: aghisla
Date: 2009-06-24 11:03:06 -0400 (Wed, 24 Jun 2009)
New Revision: 38059
Modified:
grass-addons/vector/v.krige/v.krige.py
Log:
cleaned unuseful self. references, started refactoring on notebook page creation
Modified: grass-addons/vector/v.krige/v.krige.py
===================================================================
--- grass-addons/vector/v.krige/v.krige.py 2009-06-24 14:33:33 UTC (rev 38058)
+++ grass-addons/vector/v.krige/v.krige.py 2009-06-24 15:03:06 UTC (rev 38059)
@@ -93,11 +93,13 @@
style=FN.FNB_BOTTOM |
FN.FNB_NO_NAV_BUTTONS |
FN.FNB_FANCY_TABS | FN.FNB_NO_X_BUTTON)
-
- self.__createAutomapPage()
- self.__createGstatPage()
- self.__createGeoRPage()
+ for Rpackage in ["automap", "gstat", "geoR"]:
+ self.createPage(package = Rpackage)
+ #self.__createAutomapPage()
+ #self.__createGstatPage()
+ #self.__createGeoRPage()
+
#@TODO(anne): check this dependency at the beginning.
if self.RPackagesBook.GetPageCount() == 0:
wx.MessageBox(parent=self,
@@ -123,9 +125,16 @@
Sizer.Add(ButtonSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=self.border)
self.SetSizerAndFit(Sizer)
- # consider refactor this!
+ #@TODO: consider refactor this!
+ def createPage(self, package):
+ if robjects.r.require(package) and robjects.r.require('spgrass6'):
+
+ setattr(self, "RBook"+package+"Panel", ()) #get class name? is it possible?
+ self.AutomapPanel = RBookAutomapPanel(self, id=wx.ID_ANY)
+ self.RPackagesBook.AddPage(page=self.AutomapPanel, text=package)
+ else:
+ pass
def __createAutomapPage(self):
- # 1. check if the package automap exists
if robjects.r.require('automap') and robjects.r.require('spgrass6'):
self.AutomapPanel = RBookAutomapPanel(self, id=wx.ID_ANY)
self.RPackagesBook.AddPage(page=self.AutomapPanel, text="automap")
@@ -160,28 +169,28 @@
#-1: get the selected notebook page. The user shall know that he/she can modify settings in all
# pages, but only the selected one will be executed when Run is pressed.
- self.SelectedPanel = self.RPackagesBook.GetCurrentPage()
+ SelectedPanel = self.RPackagesBook.GetCurrentPage()
#0. require packages. See creation of the notebook pages and note after import directives.
#1. get the data in R format, i.e. SpatialPointsDataFrame
- self.InputData = robjects.r.readVECT6(self.InputDataMap.GetValue(), type= 'point')
+ InputData = robjects.r.readVECT6(self.InputDataMap.GetValue(), type= 'point')
#2. collect options
- self.Column = self.InputDataColumn.GetValue()
+ Column = self.InputDataColumn.GetValue()
#@TODO(anne): pick up parameters if user chooses to set variogram parameters.
#3. Fit variogram
self.parent.log.write(_("Variogram fitting"))
- self.Formula = robjects.r['as.formula'](robjects.r.paste(self.Column, "~ 1"))
- Variogram = self.SelectedPanel.FitVariogram(self.Formula, self.InputData)
+ Formula = robjects.r['as.formula'](robjects.r.paste(Column, "~ 1"))
+ Variogram = SelectedPanel.FitVariogram(Formula, InputData)
# print variogram?
-# robjects.r.plot(Variogram.r['exp_var'], Variogram.r['var_model'])
+ #robjects.r.plot(Variogram.r['exp_var'], Variogram.r['var_model']) #does not work.
+ #see if it caused by automap/gstat dedicated plot function.
self.parent.log.write(_("Variogram fitted."))
#4. Kriging
-# self.parent.log.write('Kriging...')
- ## AUTOMAP
- #@TODO(anne): the prediced values grid is autogenerated without projection. wait for patch.
- #self.KrigingResult = robjects.r.autoKrige(self.Formula, self.InputData)
+ self.parent.log.write('Kriging...')
+ SelectedPanel.DoKriging()
+
# self.parent.log.write('Kriging performed..')
#5. Format output
@@ -223,7 +232,7 @@
# unlock options as soon as they are available. Stone soup!
VariogramSizer = wx.StaticBoxSizer(wx.StaticBox(self, id=wx.ID_ANY,
- label=_("Variogram fitting")), wx.VERTICAL)
+ label=_("Variogram fitting")), wx.VERTICAL)
VariogramCheckBox = wx.CheckBox(self, id=wx.ID_ANY, label=_("Auto-fit variogram"))
VariogramCheckBox.SetValue(state = True) # check it by default
ParametersSizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
@@ -253,10 +262,10 @@
self.SetSizerAndFit(Sizer)
- def FitVariogram():
+ def FitVariogram(self, *args, **kwargs):
pass
- def DoKriging():
+ def DoKriging(self, *args, **kwargs):
pass
def HideOptions(self, event):
@@ -265,17 +274,29 @@
class RBookAutomapPanel(RBookPanel):
""" Subclass of RBookPanel, with specific automap options and kriging functions. """
- def __init__(self, parent, *args, **kwargs):
- RBookPanel.__init__(self, parent, *args, **kwargs)
+ #def __init__(self, parent, *args, **kwargs):
+ # RBookPanel.__init__(self, parent, *args, **kwargs)
def FitVariogram(self, Formula, InputData):
return robjects.r.autofitVariogram(Formula, InputData)
def DoKriging():
- #BUG: remove grid creation when automap command will be corrected.
- #PredictionGrid = grass.run_command("v.mkgrid")
+ #BUG: automap autoKrige() does not seem to handle projected data.
+ #current workaround would be create projected grid with estimation locations..
pass
+
+class RBookGstatPanel(RBookPanel):
+ """ Subclass of RBookPanel, with specific gstat options and kriging functions. """
+ #def __init__(self, parent, *args, **kwargs):
+ # RBookPanel.__init__(self, parent, *args, **kwargs)
+ def FitVariogram(self, Formula, InputData):
+ return robjects.r.autofitVariogram(Formula, InputData)
+
+ def DoKriging():
+
+ pass
+
def main(argv=None):
if argv is None:
argv = sys.argv
More information about the grass-commit
mailing list