GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vkrige.py
Go to the documentation of this file.
1 """
2 MODULE: v_krige_wxGUI
3 
4 AUTHOR(S): Anne Ghisla <a.ghisla AT gmail.com>
5 
6 PURPOSE: Dedicated GUI for v.krige script.
7 
8 DEPENDS: R 2.x, packages gstat, maptools and spgrass6, optional: automap
9 
10 COPYRIGHT: (C) 2009 by the GRASS Development Team
11 
12 This program is free software under the GNU General Public
13 License (>=v2). Read the file COPYING that comes with GRASS
14 for details.
15 """
16 
17 #@TODO move here imports related to wxGUI
18 
19 ### generic imports
20 import os, sys
21 from tempfile import gettempdir
22 import time
23 import thread
24 ## i18N
25 import gettext
26 gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
27 
28 ### dependencies to be checked once, as they are quite time-consuming. cfr. grass.parser.
29 # GRASS binding
30 try:
31  import grass.script as grass
32 except ImportError:
33  sys.exit(_("No GRASS-python library found."))
34 ### wxGUI imports
35 
36 GUIModulesPath = os.path.join(os.getenv("GISBASE"), "etc", "wxpython", "gui_modules")
37 sys.path.append(GUIModulesPath)
38 
39 import globalvar
40 import gselect
41 import goutput
42 import menuform
43 from preferences import globalSettings as UserSettings
44 #import help
45 
46 import wx
47 import wx.lib.flatnotebook as FN
48 #import wx.lib.plot as plot # for plotting the variogram.
49 
50 # global variables
51 maxint = 1e6 # instead of sys.maxint, not working with SpinCtrl on 64bit [reported by Bob Moskovitz]
52 
53 
54 #@TODO move away functions not regarding the GUI
55 
56 class KrigingPanel(wx.Panel):
57  """ Main panel. Contains all widgets except Menus and Statusbar. """
58  def __init__(self, parent, Rinstance, controller, *args, **kwargs):
59  wx.Panel.__init__(self, parent, *args, **kwargs)
60 
61  self.parent = parent
62  self.border = 4
63 
64  # 1. Input data
65  InputBoxSizer = wx.StaticBoxSizer(wx.StaticBox(self, id = wx.ID_ANY, label = _("Input Data")),
66  orient = wx.HORIZONTAL)
67 
68  flexSizer = wx.FlexGridSizer(cols = 3, hgap = 5, vgap = 5)
69  flexSizer.AddGrowableCol(1)
70 
71  flexSizer.Add(item = wx.StaticText(self, id = wx.ID_ANY, label = _("Point dataset:")),
72  flag = wx.ALIGN_CENTER_VERTICAL)
73  self.InputDataMap = gselect.VectorSelect(parent = self,
74  ftype = 'points',
75  updateOnPopup = False)
76  self.InputDataMap.SetFocus()
77  flexSizer.Add(item = self.InputDataMap, flag = wx.ALIGN_CENTER_VERTICAL)
78 
79  RefreshButton = wx.Button(self, id = wx.ID_REFRESH)
80  RefreshButton.Bind(wx.EVT_BUTTON, self.OnButtonRefresh)
81  flexSizer.Add(item = RefreshButton, flag = wx.ALIGN_CENTER_VERTICAL)
82 
83  flexSizer.Add(item = wx.StaticText(self, id = wx.ID_ANY, label = _("Numeric column:")),
84  flag = wx.ALIGN_CENTER_VERTICAL)
85  self.InputDataColumn = gselect.ColumnSelect(self, id = wx.ID_ANY)
86  self.InputDataColumn.SetSelection(0)
87  flexSizer.Add(item = self.InputDataColumn)
88 
89  self.InputDataMap.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnInputDataChanged)
90 
91  InputBoxSizer.Add(item = flexSizer)
92 
93  # 2. Kriging. In book pages one for each R package. Includes variogram fit.
94  KrigingSizer = wx.StaticBoxSizer(wx.StaticBox(self, id = wx.ID_ANY, label = _("Kriging")), wx.HORIZONTAL)
95 
96  self.RPackagesBook = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
97  style = FN.FNB_BOTTOM |
98  FN.FNB_NO_NAV_BUTTONS |
99  FN.FNB_FANCY_TABS | FN.FNB_NO_X_BUTTON)
100 
101  for Rpackage in ["gstat"]: # , "geoR"]: #@TODO: enable it if/when it'll be implemented.
102  self.CreatePage(package = Rpackage, Rinstance = Rinstance, controller = controller)
103 
104  ## Command output. From menuform module, cmdPanel class
105  self.goutput = goutput.GMConsole(parent = self, margin = False,
106  notebook = self.RPackagesBook)
107  self.goutputId = self.RPackagesBook.GetPageCount()
108  self.outpage = self.RPackagesBook.AddPage(self.goutput, text = _("Command output"))
109 
110  self.RPackagesBook.SetSelection(0)
111  KrigingSizer.Add(self.RPackagesBook, proportion = 1, flag = wx.EXPAND)
112 
113  # 3. Output Parameters.
114  OutputSizer = wx.StaticBoxSizer(wx.StaticBox(self, id = wx.ID_ANY, label = _("Output")), wx.HORIZONTAL)
115 
116  OutputParameters = wx.GridBagSizer(hgap = 5, vgap = 5)
117  OutputParameters.AddGrowableCol(1)
118  OutputParameters.Add(item = wx.StaticText(self, id = wx.ID_ANY, label = _("Name for the output raster map:")),
119  flag = wx.ALIGN_CENTER_VERTICAL,
120  pos = (0, 0))
121  self.OutputMapName = gselect.Select(parent = self, id = wx.ID_ANY,
122  type = 'raster',
123  mapsets = [grass.gisenv()['MAPSET']])
124  OutputParameters.Add(item = self.OutputMapName, flag = wx.EXPAND | wx.ALL,
125  pos = (0, 1))
126  self.VarianceRasterCheckbox = wx.CheckBox(self, id = wx.ID_ANY, label = _("Export variance map as well: "))
127  self.VarianceRasterCheckbox.SetValue(state = True)
128  OutputParameters.Add(item = self.VarianceRasterCheckbox,
129  flag = wx.ALIGN_CENTER_VERTICAL,
130  pos = (1, 0))
131  self.OutputVarianceMapName = gselect.Select(parent = self, id = wx.ID_ANY,
132  type = 'raster',
133  mapsets = [grass.gisenv()['MAPSET']])
134  self.VarianceRasterCheckbox.Bind(wx.EVT_CHECKBOX, self.OnVarianceCBChecked)
135  OutputParameters.Add(item = self.OutputVarianceMapName, flag = wx.EXPAND | wx.ALL,
136  pos = (1, 1))
137 
138  self.OverwriteCheckBox = wx.CheckBox(self, id = wx.ID_ANY,
139  label = _("Allow output files to overwrite existing files"))
140  self.OverwriteCheckBox.SetValue(UserSettings.Get(group='cmd', key='overwrite', subkey='enabled'))
141  OutputParameters.Add(item = self.OverwriteCheckBox,
142  pos = (2, 0), span = (1, 2))
143 
144  OutputSizer.Add(OutputParameters, proportion = 0, flag = wx.EXPAND | wx.ALL, border = self.border)
145 
146  # 4. Run Button and Quit Button
147  ButtonSizer = wx.BoxSizer(wx.HORIZONTAL)
148  HelpButton = wx.Button(self, id = wx.ID_HELP)
149  HelpButton.Bind(wx.EVT_BUTTON, self.OnHelpButton)
150  QuitButton = wx.Button(self, id = wx.ID_EXIT)
151  QuitButton.Bind(wx.EVT_BUTTON, self.OnCloseWindow)
152  self.RunButton = wx.Button(self, id = wx.ID_ANY, label = _("&Run")) # no stock ID for Run button..
153  self.RunButton.Bind(wx.EVT_BUTTON, self.OnRunButton)
154  self.RunButton.Enable(False) # disable it on loading the interface, as input map is not set
155  ButtonSizer.Add(HelpButton, proportion = 0, flag = wx.ALIGN_LEFT | wx.ALL, border = self.border)
156  ButtonSizer.Add(QuitButton, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = self.border)
157  ButtonSizer.Add(self.RunButton, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = self.border)
158 
159  # Main Sizer. Add each child sizer as soon as it is ready.
160  Sizer = wx.BoxSizer(wx.VERTICAL)
161  Sizer.Add(InputBoxSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = self.border)
162  Sizer.Add(KrigingSizer, proportion = 1, flag = wx.EXPAND | wx.ALL, border = self.border)
163  Sizer.Add(OutputSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = self.border)
164  Sizer.Add(ButtonSizer, proportion = 0, flag = wx.ALIGN_RIGHT | wx.ALL, border = self.border)
165  self.SetSizerAndFit(Sizer)
166 
167  # last action of __init__: update imput data list.
168  # it's performed in the few seconds gap while user examines interface before clicking anything.
169  #@TODO: implement a splashcreen IF the maps cause a noticeable lag [markus' suggestion]
170  self.InputDataMap.GetElementList()
171 
172  def CreatePage(self, package, Rinstance, controller):
173  """ Creates the three notebook pages, one for each R package """
174  for package in ["gstat"]:
175  classobj = eval("RBook"+package+"Panel")
176  setattr(self, "RBook"+package+"Panel", (classobj(self,
177  id = wx.ID_ANY,
178  Rinstance = Rinstance,
179  controller = controller)))
180  self.RPackagesBook.AddPage(page = getattr(self, "RBook"+package+"Panel"), text = package)
181 
182  def OnButtonRefresh(self, event):
183  """ Forces refresh of list of available layers. """
184  self.InputDataMap.GetElementList()
185 
186  def OnCloseWindow(self, event):
187  """ Cancel button pressed"""
188  self.parent.Close()
189  event.Skip()
190 
191  def OnHelpButton(self, event):
192  # file = os.path.join(os.getenv("GISBASE"), "docs", "html", "v.krige.html")
193  # file = os.path.join(os.path.curdir, "description.html")
194  # @TODO fix HelpWindow
195  # helpFrame = help.HelpWindow(parent=self, id=wx.ID_ANY,
196  # title=_("GRASS - Help page for v.krige"),
197  # size=(640, 480),
198  # file=file)
199  # helpFrame.Show(True)
200 
201  grass.run_command('g.manual', entry = 'v.krige')
202 
203  event.Skip()
204 
205  def OnInputDataChanged(self, event):
206  """ Refreshes list of columns and fills output map name TextCtrl """
207  MapName = event.GetString()
208  self.InputDataColumn.InsertColumns(vector = MapName,
209  layer = 1, excludeKey = True,
210  type = ['integer', 'double precision'])
211  self.InputDataColumn.SetSelection(0)
212  self.RunButton.Enable(self.InputDataColumn.GetSelection() is not -1)
213  self.RBookgstatPanel.PlotButton.Enable(self.InputDataColumn.GetSelection() is not -1)
214 
215  if self.InputDataColumn.GetSelection() is not -1:
216  self.OutputMapName.SetValue(MapName.split("@")[0]+"_kriging")
217  self.OutputVarianceMapName.SetValue(MapName.split("@")[0]+"_kriging_var")
218  else:
219  self.OutputMapName.SetValue('')
220  self.OutputVarianceMapName.SetValue('')
221 
222  def OnRunButton(self,event):
223  """ Execute R analysis. """
224  #@FIXME: send data to main method instead of running it here.
225 
226  #-1: get the selected notebook page. The user shall know that [s]he can modify settings in all
227  # pages, but only the selected one will be executed when Run is pressed.
228  SelectedPanel = self.RPackagesBook.GetCurrentPage()
229 
230  if self.RPackagesBook.GetPageText(self.RPackagesBook.GetSelection()) == 'Command output':
231  self.goutput.WriteError("No parameters for running. Please select \"gstat\" tab, check parameters and re-run.")
232  return False # no break invoked by above function
233 
234  # mount command string as it would have been written on CLI
235  command = ["v.krige", "input=" + self.InputDataMap.GetValue(),
236  "column=" + self.InputDataColumn.GetValue(),
237  "output=" + self.OutputMapName.GetValue(),
238  "package=" + '%s' % self.RPackagesBook.GetPageText(self.RPackagesBook.GetSelection())]
239 
240  if not hasattr(SelectedPanel, 'VariogramCheckBox') or not SelectedPanel.VariogramCheckBox.IsChecked():
241  command.append("model=" + '%s' % SelectedPanel.ModelChoicebox.GetStringSelection().split(" ")[0])
242 
243  for i in ['Sill', 'Nugget', 'Range']:
244  if getattr(SelectedPanel, i+"ChextBox").IsChecked():
245  command.append(i.lower() + "=" + '%s' % getattr(SelectedPanel, i+'Ctrl').GetValue())
246 
247  if SelectedPanel.KrigingRadioBox.GetStringSelection() == "Block kriging":
248  command.append("block=" + '%s' % SelectedPanel.BlockSpinBox.GetValue())
249  if self.OverwriteCheckBox.IsChecked():
250  command.append("--overwrite")
251  if self.VarianceRasterCheckbox.IsChecked():
252  command.append("output_var=" + self.OutputVarianceMapName.GetValue())
253 
254  # give it to the output console
255  #@FIXME: it runs the command as a NEW instance. Reimports data, recalculates variogram fit..
256  #otherwise I can use Controller() and mimic RunCmd behaviour.
257  self.goutput.RunCmd(command, switchPage = True)
258 
259  def OnVarianceCBChecked(self, event):
260  self.OutputVarianceMapName.Enable(event.IsChecked())
261 
262 class KrigingModule(wx.Frame):
263  """ Kriging module for GRASS GIS. Depends on R and its packages gstat and geoR. """
264  def __init__(self, parent, Rinstance, controller, *args, **kwargs):
265  wx.Frame.__init__(self, parent, *args, **kwargs)
266  # setting properties and all widgettery
267  self.SetTitle(_("Kriging Module"))
268  self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_dialog.ico'), wx.BITMAP_TYPE_ICO))
269  self.log = Log(self)
270  self.CreateStatusBar()
271  self.log.message(_("Ready."))
272 
273  self.Panel = KrigingPanel(self, Rinstance, controller)
274  self.SetMinSize(self.GetBestSize())
275  self.SetSize(self.GetBestSize())
276 
277 class Log:
278  """ The log output is redirected to the status bar of the containing frame. """
279  def __init__(self, parent):
280  self.parent = parent
281 
282  def message(self, text_string):
283  """ Updates status bar """
284  self.parent.SetStatusText(text_string.strip())
285 
286 class RBookPanel(wx.Panel):
287  """ Generic notebook page with shared widgets and empty kriging functions. """
288  def __init__(self, parent, *args, **kwargs):
289  wx.Panel.__init__(self, parent, *args, **kwargs)
290 
291  self.parent = parent
292 
293  self.VariogramSizer = wx.StaticBoxSizer(wx.StaticBox(self,
294  id = wx.ID_ANY,
295  label = _("Variogram fitting")),
296  wx.HORIZONTAL)
297  self.LeftSizer = wx.BoxSizer(wx.VERTICAL)
298  self.RightSizer = wx.BoxSizer(wx.VERTICAL)
299  self.ParametersSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
300 
301  self.VariogramSizer.Add(self.LeftSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
302  self.VariogramSizer.Add(self.RightSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
303 
304  # left side of Variogram fitting. The checkboxes and spinctrls.
305  self.PlotButton = wx.Button(self, id = wx.ID_ANY, label = _("Plot/refresh variogram")) # no stock ID for Run button..
306  self.PlotButton.Bind(wx.EVT_BUTTON, self.OnPlotButton)
307  self.PlotButton.Enable(False) # grey it out until a suitable layer is available
308  self.LeftSizer.Add(self.PlotButton, proportion = 0, flag = wx.ALL, border = parent.border)
309  self.LeftSizer.Add(self.ParametersSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
310 
311  self.ParametersList = ["Sill", "Nugget", "Range"]
312  MinValues = [0,0,1]
313  for n in self.ParametersList:
314  setattr(self, n+"ChextBox", wx.CheckBox(self,
315  id = self.ParametersList.index(n),
316  label = _(n + ":")))
317  setattr(self, n+"Ctrl", (wx.SpinCtrl(self,
318  id = wx.ID_ANY,
319  min = MinValues[self.ParametersList.index(n)],
320  max = maxint)))
321  getattr(self, n+"ChextBox").Bind(wx.EVT_CHECKBOX,
322  self.UseValue,
323  id = self.ParametersList.index(n))
324  setattr(self, n+"Sizer", (wx.BoxSizer(wx.HORIZONTAL)))
325  self.ParametersSizer.Add(getattr(self, n+"ChextBox"),
326  flag = wx.ALIGN_CENTER_VERTICAL,
327  pos = (self.ParametersList.index(n),0))
328  self.ParametersSizer.Add(getattr(self, n+"Ctrl"),
329  flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL,
330  pos = (self.ParametersList.index(n),1))
331 
332  # right side of the Variogram fitting. The plot area.
333  #Plot = wx.StaticText(self, id= wx.ID_ANY, label = "Check Plot Variogram to interactively fit model.")
334  #PlotPanel = wx.Panel(self)
335  #self.PlotArea = plot.PlotCanvas(PlotPanel)
336  #self.PlotArea.SetInitialSize(size = (250,250))
337  #self.RightSizer.Add(PlotPanel, proportion=0, flag= wx.EXPAND|wx.ALL, border=parent.border)
338 
339  self.KrigingSizer = wx.StaticBoxSizer(wx.StaticBox(self,
340  id = wx.ID_ANY,
341  label = _("Kriging techniques")),
342  wx.VERTICAL)
343 
344  KrigingList = ["Ordinary kriging", "Block kriging"]#, "Universal kriging"] #@FIXME: i18n on the list?
345  self.KrigingRadioBox = wx.RadioBox(self,
346  id = wx.ID_ANY,
347  choices = KrigingList,
348  majorDimension = 1,
349  style = wx.RA_SPECIFY_COLS)
350  self.KrigingRadioBox.Bind(wx.EVT_RADIOBOX, self.HideBlockOptions)
351  self.KrigingSizer.Add(self.KrigingRadioBox, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
352 
353  # block kriging parameters. Size.
354  BlockSizer = wx.BoxSizer(wx.HORIZONTAL)
355  BlockLabel = wx.StaticText(self, id = wx.ID_ANY, label = _("Block size:"))
356  self.BlockSpinBox = wx.SpinCtrl(self, id = wx.ID_ANY, min = 1, max = maxint)
357  self.BlockSpinBox.Enable(False) # default choice is Ordinary kriging so block param is disabled
358  BlockSizer.Add(BlockLabel, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = parent.border)
359  BlockSizer.Add(self.BlockSpinBox, flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = parent.border)
360  self.KrigingSizer.Add(BlockSizer, flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, border = parent.border)
361 
362  self.Sizer = wx.BoxSizer(wx.VERTICAL)
363  self.Sizer.Add(self.VariogramSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
364  self.Sizer.Add(self.KrigingSizer, proportion = 0, flag = wx.EXPAND | wx.ALL, border = parent.border)
365 
366  def HideBlockOptions(self, event):
367  self.BlockSpinBox.Enable(event.GetInt() == 1)
368 
369  def OnPlotButton(self,event):
370  """ Plots variogram with current options. """
371  pass
372 
373  def UseValue(self, event):
374  """ Enables/Disables the SpinCtrl in respect of the checkbox. """
375  n = self.ParametersList[event.GetId()]
376  getattr(self, n+"Ctrl").Enable(event.IsChecked())
377 
379  """ Subclass of RBookPanel, with specific gstat options and kriging functions. """
380  def __init__(self, parent, Rinstance, controller, *args, **kwargs):
381  RBookPanel.__init__(self, parent, *args, **kwargs)
382 
383  # assigns Rinstance, that comes from the GUI call of v.krige.py.
384  robjects = Rinstance
385  self.controller = controller
386 
387  if robjects.r.require('automap')[0]:
388  self.VariogramCheckBox = wx.CheckBox(self, id = wx.ID_ANY, label = _("Auto-fit variogram"))
389  self.LeftSizer.Insert(0,
390  self.VariogramCheckBox,
391  proportion = 0,
392  flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL,
393  border = 4)
394  self.SetSizerAndFit(self.Sizer)
395  self.VariogramCheckBox.Bind(wx.EVT_CHECKBOX, self.HideOptions)
396  self.VariogramCheckBox.SetValue(state = True) # check it by default
397 
398  ModelFactor = robjects.r.vgm().rx('long')
399  ModelList = robjects.r.levels(ModelFactor[0])
400  #@FIXME: no other way to let the Python pick it up..
401  # and this is te wrong place where to load this list. should be at the very beginning.
402  self.ModelChoicebox = wx.Choice(self, id = wx.ID_ANY, choices = ModelList)
403 
404  # disable model parameters' widgets by default
405  for n in ["Sill", "Nugget", "Range"]:
406  getattr(self, n+"Ctrl").Enable(False)
407  self.ModelChoicebox.Enable(False)
408 
409  VariogramSubSizer = wx.BoxSizer(wx.HORIZONTAL)
410  VariogramSubSizer.Add(item = wx.StaticText(self,
411  id = wx.ID_ANY,
412  label = _("Model: ")),
413  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
414  border = 4)
415  VariogramSubSizer.Add(item = self.ModelChoicebox,
416  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL,
417  border = 4)
418 
419  self.LeftSizer.Insert(2, item = VariogramSubSizer)
420 
421  self.SetSizerAndFit(self.Sizer)
422 
423  def HideOptions(self, event):
424  self.ModelChoicebox.Enable(not event.IsChecked())
425  for n in ["Sill", "Nugget", "Range"]:
426  if not event.IsChecked():
427  getattr(self, n+"Ctrl").Enable(True)
428  getattr(self, n+ "ChextBox").SetValue(True)
429  getattr(self, n+ "ChextBox").Enable(False) # grey it out keeping it checked.. improvable
430  else:
431  getattr(self, n+"Ctrl").Enable(False)
432  getattr(self, n+ "ChextBox").SetValue(False)
433  getattr(self, n+ "ChextBox").Enable(True)
434  #@FIXME: was for n in self.ParametersSizer.GetChildren(): n.Enable(False) but doesn't work
435 
436  def OnPlotButton(self,event):
437  """ Plots variogram with current options. """
438  ## BIG WARNING: smell of code duplication. Fix this asap. emminchia!
439  #controller = Controller() # sed, if needed,
440  #controller = self.controller
441  map = self.parent.InputDataMap.GetValue()
442  column = self.parent.InputDataColumn.GetValue()
443 
444  # import data or pick them up
445  if globals()["InputData"] is None:
446  globals()["InputData"] = controller.ImportMap(map = map,
447  column = column)
448  # fit the variogram or pick it up
449  Formula = controller.ComposeFormula(column = column,
450  isblock = self.KrigingRadioBox.GetStringSelection() == "Block kriging",
451  inputdata = globals()['InputData'])
452  #if globals()["Variogram"] is None:
453  if hasattr(self, 'VariogramCheckBox') and self.VariogramCheckBox.IsChecked():
454  self.model = ''
455  for each in ("Sill","Nugget","Range"):
456  if getattr(self, each+'ChextBox').IsChecked():
457  setattr(self, each.lower(), getattr(self, each+"Ctrl").GetValue())
458  else:
459  setattr(self, each.lower(), robjects.r('''NA'''))
460  else:
461  self.model = self.ModelChoicebox.GetStringSelection().split(" ")[0]
462  for each in ("Sill","Nugget","Range"):
463  if getattr(self, each+'ChextBox').IsChecked(): #@FIXME will be removed when chextboxes will be frozen
464  setattr(self, each.lower(), getattr(self, each+"Ctrl").GetValue())
465 
466  globals()["Variogram"] = controller.FitVariogram(Formula,
467  InputData,
468  model = self.model,
469  sill = self.sill,
470  nugget = self.nugget,
471  range = self.range)
472 
473  # use R plot function, in a separate window.
474  thread.start_new_thread(self.plot, ())
475 
476  def plot(self):
477  #robjects.r.X11()
478  #robjects.r.png("variogram.png")
479  textplot = robjects.r.plot(Variogram['datavariogram'], Variogram['variogrammodel'])
480  print textplot
481  self.refresh()
482  #robjects.r['dev.off']()
483 
484  def refresh(self):
485  while True:
486  rinterface.process_revents()
487  time.sleep(0.1)
488 
490  """ Subclass of RBookPanel, with specific geoR options and kriging functions. """
491  def __init__(self, parent, *args, **kwargs):
492  RBookPanel.__init__(self, parent, *args, **kwargs)
493  #@TODO: change these two lines as soon as geoR f(x)s are integrated.
494  for n in self.GetChildren():
495  n.Hide()
496  self.Sizer.Add(wx.StaticText(self, id = wx.ID_ANY, label = _("Work in progress! No functionality provided.")))
497  self.SetSizerAndFit(self.Sizer)