[GRASS-SVN] r66777 - in grass/trunk: gui/wxpython/modules scripts/v.krige
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 10 13:53:54 PST 2015
Author: marisn
Date: 2015-11-10 13:53:54 -0800 (Tue, 10 Nov 2015)
New Revision: 66777
Modified:
grass/trunk/gui/wxpython/modules/vkrige.py
grass/trunk/scripts/v.krige/v.krige.html
grass/trunk/scripts/v.krige/v.krige.py
Log:
v.krige:
* introduce kappa smoothing parameter of the Matern model;
* use correct model names;
* allow to reuse automatic fit values.
Modified: grass/trunk/gui/wxpython/modules/vkrige.py
===================================================================
--- grass/trunk/gui/wxpython/modules/vkrige.py 2015-11-10 16:14:53 UTC (rev 66776)
+++ grass/trunk/gui/wxpython/modules/vkrige.py 2015-11-10 21:53:54 UTC (rev 66777)
@@ -233,7 +233,7 @@
if not hasattr(SelectedPanel, 'VariogramCheckBox') or not SelectedPanel.VariogramCheckBox.IsChecked():
command.append("model=" + '%s' % SelectedPanel.ModelChoicebox.GetStringSelection().split(" ")[0])
- for i in ['Sill', 'Nugget', 'Range']:
+ for i in ['Sill', 'Nugget', 'Range', 'Kappa']:
if getattr(SelectedPanel, i+"ChextBox").IsChecked():
command.append(i.lower() + "=" + '%s' % getattr(SelectedPanel, i+'Ctrl').GetValue())
@@ -317,15 +317,24 @@
self.LeftSizer.Add(self.PlotButton, proportion = 0, flag = wx.ALL, border = parent.border)
self.LeftSizer.Add(self.ParametersSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
- self.ParametersList = ["Sill", "Nugget", "Range"]
- MinValues = [0,0,1]
+ self.ParametersList = ["Sill", "Nugget", "Range", "Kappa"]
+ MinValues = [0,0,1,0.1]
for n in self.ParametersList:
setattr(self, n+"ChextBox", wx.CheckBox(self,
id = self.ParametersList.index(n),
label = _(n + ":")))
- setattr(self, n+"Ctrl", (wx.SpinCtrl(self,
+ # Kappa must be float
+ if n == "Kappa":
+ setattr(self, n+"Ctrl", (wx.SpinCtrlDouble(self,
id = wx.ID_ANY,
min = MinValues[self.ParametersList.index(n)],
+ max = maxint,
+ inc = 0.1,
+ initial = 0.5)))
+ else:
+ setattr(self, n+"Ctrl", (wx.SpinCtrl(self,
+ id = wx.ID_ANY,
+ min = MinValues[self.ParametersList.index(n)],
max = maxint)))
getattr(self, n+"ChextBox").Bind(wx.EVT_CHECKBOX,
self.UseValue,
@@ -404,14 +413,16 @@
self.VariogramCheckBox.Bind(wx.EVT_CHECKBOX, self.HideOptions)
self.VariogramCheckBox.SetValue(state = True) # check it by default
- ModelFactor = robjects.r.vgm().rx('long')
- ModelList = robjects.r.levels(ModelFactor[0])
+ # Get list of available models. Show long name but use short one
+ ModelFactor = robjects.r.vgm()
+ ModelList = robjects.r.levels(ModelFactor[1])
+ self.ModelListShort = robjects.r.levels(ModelFactor[0])
#@FIXME: no other way to let the Python pick it up..
# and this is te wrong place where to load this list. should be at the very beginning.
self.ModelChoicebox = wx.Choice(self, id = wx.ID_ANY, choices = ModelList)
# disable model parameters' widgets by default
- for n in ["Sill", "Nugget", "Range"]:
+ for n in ["Sill", "Nugget", "Range", "Kappa"]:
getattr(self, n+"Ctrl").Enable(False)
self.ModelChoicebox.Enable(False)
@@ -431,7 +442,7 @@
def HideOptions(self, event):
self.ModelChoicebox.Enable(not event.IsChecked())
- for n in ["Sill", "Nugget", "Range"]:
+ for n in ["Sill", "Nugget", "Range", "Kappa"]:
if not event.IsChecked():
getattr(self, n+"Ctrl").Enable(True)
getattr(self, n+ "ChextBox").SetValue(True)
@@ -459,14 +470,15 @@
#~ isblock = self.KrigingRadioBox.GetStringSelection() == "Block kriging")
if hasattr(self, 'VariogramCheckBox') and self.VariogramCheckBox.IsChecked():
self.model = ''
- for each in ("Sill","Nugget","Range"):
+ for each in ("Sill","Nugget","Range","Kappa"):
if getattr(self, each+'ChextBox').IsChecked():
setattr(self, each.lower(), getattr(self, each+"Ctrl").GetValue())
else:
setattr(self, each.lower(), robjects.r('''NA'''))
+
else:
- self.model = self.ModelChoicebox.GetStringSelection().split(" ")[0]
- for each in ("Sill","Nugget","Range"):
+ self.model = self.ModelListShort[self.ModelChoicebox.GetSelection()]
+ for each in ("Sill","Nugget","Range","Kappa"):
if getattr(self, each+'ChextBox').IsChecked(): #@FIXME will be removed when chextboxes will be frozen
setattr(self, each.lower(), getattr(self, each+"Ctrl").GetValue())
@@ -481,8 +493,28 @@
model = self.model,
sill = self.sill,
nugget = self.nugget,
- range = self.range)
+ range = self.range,
+ kappa = self.kappa)
+ ''' Fill parameters with autofitted values '''
+ if hasattr(self, 'VariogramCheckBox') and self.VariogramCheckBox.IsChecked():
+ for i in range(len(self.ModelListShort)):
+ if self.ModelListShort[i] == self.controller.Variogram['model']:
+ self.ModelChoicebox.SetSelection(i)
+ break
+ if not getattr(self, 'SillChextBox').IsChecked():
+ self.sill = self.controller.Variogram['variogrammodel'][1][1]
+ self.SillCtrl.SetValue(self.sill)
+ if not getattr(self, 'NuggetChextBox').IsChecked():
+ self.nugget = self.controller.Variogram['variogrammodel'][1][0]
+ self.NuggetCtrl.SetValue(self.nugget)
+ if not getattr(self, 'RangeChextBox').IsChecked():
+ self.range = self.controller.Variogram['variogrammodel'][2][1]
+ self.RangeCtrl.SetValue(self.range)
+ if not getattr(self, 'KappaChextBox').IsChecked():
+ self.kappa = self.controller.Variogram['variogrammodel'][3][1]
+ self.KappaCtrl.SetValue(self.kappa)
+
# use R plot function, in a separate window.
thread.start_new_thread(self.plot, ())
Modified: grass/trunk/scripts/v.krige/v.krige.html
===================================================================
--- grass/trunk/scripts/v.krige/v.krige.html 2015-11-10 16:14:53 UTC (rev 66776)
+++ grass/trunk/scripts/v.krige/v.krige.html 2015-11-10 21:53:54 UTC (rev 66777)
@@ -17,6 +17,9 @@
of parameters or powerful hardware. See Isaaks and Srivastava's book,
exhaustive and clear even if a bit outdated.
+<p>Auto-fit variogram option will update sill, nugget, range and kappa values
+with fitted ones. Enabling the values will pass them to auto-fit and thus
+preserve from modification and thus they might differ from fitted ones.
<h3>Dependencies</h3>
Modified: grass/trunk/scripts/v.krige/v.krige.py
===================================================================
--- grass/trunk/scripts/v.krige/v.krige.py 2015-11-10 16:14:53 UTC (rev 66776)
+++ grass/trunk/scripts/v.krige/v.krige.py 2015-11-10 21:53:54 UTC (rev 66777)
@@ -83,6 +83,13 @@
#% description: Automatically fixed if not set
#% required : no
#%end
+#%option
+#% key: kappa
+#% type: double
+#% label: Kappa value
+#% description: Automatically fixed if not set
+#% required : no
+#%end
#%option G_OPT_R_OUTPUT
#% key: output_var
#% label: Name for output variance raster map
@@ -190,7 +197,7 @@
Formula = robjects.Formula(column + "~" + predictor)
return Formula
- def FitVariogram(self, formula, inputdata, sill, nugget, range, model = ''):
+ def FitVariogram(self, formula, inputdata, sill, nugget, range, kappa, model = ''):
""" Fits variogram either automagically either specifying all parameters.
Returns a list containing data and model variograms. """
@@ -202,7 +209,11 @@
#print (nugget.r_repr(), sill, range)
DottedParams['fix.values'] = robjects.r.c(nugget, range, sill)
- VariogramModel = robjects.r.autofitVariogram(formula, inputdata, **DottedParams)
+ if not type(kappa) == float:
+ # autofit gives strange results if kappa is NA
+ VariogramModel = robjects.r.autofitVariogram(formula, inputdata, **DottedParams)
+ else:
+ VariogramModel = robjects.r.autofitVariogram(formula, inputdata, kappa=kappa, **DottedParams)
#print robjects.r.warnings()
Variograms['datavariogram'] = VariogramModel.rx('exp_var')[0]
Variograms['variogrammodel'] = VariogramModel.rx('var_model')[0]
@@ -216,7 +227,8 @@
model = robjects.r.vgm(psill = sill,
model = model,
nugget = nugget,
- range = range))
+ range = range,
+ kappa = kappa))
Variograms['datavariogram'] = DataVariogram
Variograms['variogrammodel'] = VariogramModel
Variograms['model'] = model
@@ -242,7 +254,7 @@
map = name,
history = 'Model chosen by automatic fitting: ' + variograms['model'])
- def Run(self, input, column, output, package, sill, nugget, range, logger, \
+ def Run(self, input, column, output, package, sill, nugget, range, kappa, logger, \
overwrite, model, block, output_var, command, **kwargs):
""" Wrapper for all functions above. """
@@ -270,7 +282,8 @@
model = model,
sill = sill,
nugget = nugget,
- range = range)
+ range = range,
+ kappa = kappa)
logger.message(_("Variogram fitting complete."))
logger.message(_("Kriging..."))
@@ -365,9 +378,12 @@
command = command.join("%s=%s " % (k, v) for k, v in notnulloptions.items())
# re-cast integers from strings, as parser() cast everything to string.
- for each in ("sill","nugget","range"):
+ for each in ("sill","nugget","range","kappa"):
if options[each] is not '':
- options[each] = int(options[each])
+ if each == "kappa":
+ options[each] = float(options[each])
+ else:
+ options[each] = int(options[each])
else:
options[each] = robjects.r('''NA''')
@@ -382,6 +398,7 @@
sill = options['sill'],
nugget = options['nugget'],
range = options['range'],
+ kappa = options['kappa'],
output_var = options['output_var'],
command = command,
logger = grass)
More information about the grass-commit
mailing list