[GRASS-SVN] r53544 - sandbox/lucadelu

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 24 08:41:25 PDT 2012


Author: lucadelu
Date: 2012-10-24 08:41:24 -0700 (Wed, 24 Oct 2012)
New Revision: 53544

Modified:
   sandbox/lucadelu/r.li.setup.py
Log:
improvements in r.li.setup

Modified: sandbox/lucadelu/r.li.setup.py
===================================================================
--- sandbox/lucadelu/r.li.setup.py	2012-10-24 14:54:55 UTC (rev 53543)
+++ sandbox/lucadelu/r.li.setup.py	2012-10-24 15:41:24 UTC (rev 53544)
@@ -36,7 +36,7 @@
 from grass.script import core as grass
 from grass.script import raster as grast
 
-#@NOTE: r.li.setup writes in the settings file with 
+#@NOTE: r.li.setup writes in the settings file with
 ## r.li.windows.tcl:
 #exec echo "SAMPLINGFRAME $per_x|$per_y|$per_rl|$per_cl" >> $env(TMP).set
 
@@ -77,8 +77,7 @@
         self.panel = wx.Panel(parent=self, id=wx.ID_ANY)
         #box for select configuration file
         self.confilesBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
-                                        label=_('Available sampling area " \
-                                                "configuration files'))
+                                        label=_('Available sampling area configuration files'))
         self.listfileBox = wx.ListBox(parent=self.panel,  id=wx.ID_ANY,
                     choices=self.listfiles)
         ###BUTTONS
@@ -160,6 +159,7 @@
         confile = self.listfiles[self.listfileBox.GetSelections()[0]]
         self.listfileBox.Delete(self.listfileBox.GetSelections()[0])
         grass.try_remove(os.path.join(self.rlipath, confile))
+        self.listfiles = self.ListFiles()
         return
 
     def OnNew(self, event):
@@ -196,7 +196,7 @@
     """
 
     def __init__(self, parent):
-        self.parent = parent  ## GMFrame
+        self.parent = parent
         self.wizard = wiz.Wizard(parent=parent, id=wx.ID_ANY,
                                  title=_("Create new configuration file for " \
                                  "r.li modules"))
@@ -287,25 +287,26 @@
             self.SF_W = self.gregion['w']
         elif self.startpage.region == 'key':
             self._temp_region()
-            self.SF_X = self.keyboardpage.col_up
-            self.SF_Y = self.keyboardpage.row_up
-            self.SF_RL = self.keyboardpage.row_len
-            self.SF_CL = self.keyboardpage.col_len
+            self.SF_X = float(self.keyboardpage.col_up)
+            self.SF_Y = float(self.keyboardpage.row_up)
+            self.SF_RL = float(self.keyboardpage.row_len)
+            self.SF_CL = float(self.keyboardpage.col_len)
             self.SF_N = self.gregion['n'] - (self.SF_NSRES * self.SF_Y)
             self.SF_S = self.gregion['n'] - (self.SF_NSRES * self.SF_Y + self.SF_RL)
             self.SF_W = self.gregion['w'] + (self.SF_EWRES * self.SF_X)
             self.SF_E = self.gregion['w'] + (self.SF_EWRES * self.SF_X + self.SF_CL)
-            per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
-            per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
-            per_rl = float(self.SF_RL) / float(self.rasterinfo['cols'])
-            per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
-            fil.write("SAMPLINGFRAME %s|%s|%s|%s\n" % (str(per_x), str(per_y),
-                                                       str(per_rl),  str(per_cl)))
+            self.per_x = float(self.SF_X) / float(self.rasterinfo['cols'])
+            self.per_y = float(self.SF_Y) / float(self.rasterinfo['rows'])
+            self.per_rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
+            self.per_cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
+            #import pdb; pdb.set_trace()
+            fil.write("SAMPLINGFRAME %r|%r|%r|%r\n" % (self.per_x, self.per_y,
+                                                       self.per_rl, self.per_cl))
 
     def _circle(self, radius, mask):
         """create a circle mask"""
-        self.CIR_RL = round((2 * radius) / self.rasterinfo['ewres'])
-        self.CIR_CL = round((2 * radius) / self.rasterinfo['nsres'])
+        self.CIR_RL = round((2 * float(radius)) / float(self.rasterinfo['ewres']))
+        self.CIR_CL = round((2 * float(radius)) / float(self.rasterinfo['nsres']))
         if not self.CIR_RL % 2:
             self.CIR_RL += 1
         if not self.CIR_CL % 2:
@@ -319,7 +320,7 @@
         xcenter = grass.region(complete=True)['center_easting']
         ycenter = grass.region(complete=True)['center_northing']
         grass.run_command('r.circle', flags='b', out=mask, max=radius,
-                          coordinate=[xcenter, ycenter])
+                          coordinate=[xcenter, ycenter], quiet=True)
         grass.del_temp_region()
         grass.use_temp_region()
         grass.run_command('g.region', rast=self.startpage.rast)
@@ -327,16 +328,17 @@
     def _write_area(self, fil):
         """Write the region"""
         if self.samplingareapage.samplingtype == 'whole':
-            x = float(self.SF_X) / float(self.rasterinfo['cols'])
             cl = float(self.SF_CL) / float(self.rasterinfo['cols'])
-            y = float(self.SF_Y) / float(self.rasterinfo['rows'])
             rl = float(self.SF_RL) / float(self.rasterinfo['rows'])
+            #this two variable are unused, problably to remove
+            x = float(self.SF_X) / float(self.rasterinfo['cols'])            
+            y = float(self.SF_Y) / float(self.rasterinfo['rows'])            
             if self.startpage.region == 'whole':
-                fil.write("SAMPLEAREA %s|%s|%s|%s\n" % (str(per_x), str(per_y),
-                                                        str(rl),  str(cl)))
+                fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
+                                                        rl, cl))
             elif self.startpage.region == 'key':
-                fil.write("SAMPLEAREA %s|%s|%s|%s\n" % (str(per_x), str(per_y),
-                                                        str(rl),  str(cl)))
+                fil.write("SAMPLEAREA %r|%r|%r|%r\n" % (self.per_x, self.per_y,
+                                                        rl, cl))
         elif self.samplingareapage.samplingtype == 'moving':
             if self.moving.boxtype == 'circle':
                 self._circle(self.moving.width, self.moving.height)
@@ -345,7 +347,7 @@
             else:
                 cl = float(self.moving.width) / float(self.rasterinfo['cols'])
                 rl = float(self.moving.height) / float(self.rasterinfo['rows'])
-            fil.write("SAMPLEAREA -1|-1|%s|%s" % (str(rl), str(cl)))
+            fil.write("SAMPLEAREA -1|-1|%r|%r" % (rl, cl))
             if self.moving.boxtype == 'circle':
                 fil.write("|%s" % self.moving.height)
             fil.write("\nMOVINGWINDOW\n")
@@ -357,15 +359,16 @@
             else:
                 cl = float(self.units.width) / float(self.rasterinfo['cols'])
                 rl = float(self.units.height) / float(self.rasterinfo['rows'])
-            fil.write("SAMPLEAREA -1|-1|%s|%s\n" % (str(rl), str(cl)))
+            fil.write("SAMPLEAREA -1|-1|%r|%r\n" % (rl, cl))
             if self.units.distrtype == 'non_overlapping':
-                fil.write("RANDOMNONOVERLAPPING %s\n" % str(NUMERO))
+                fil.write("RANDOMNONOVERLAPPING %s\n" % self.units.distr1)
             elif self.units.distrtype == 'systematic_contiguos':
                 fil.write("SYSTEMATICCONTIGUOUS\n")
             elif self.units.distrtype == 'stratified_random':
-                fil.write("STRATIFIEDRANDOM %s|%s" % (str(NUMERO), str(NUMERO)))
+                fil.write("STRATIFIEDRANDOM %s|%s\n" % (self.units.distr1,
+                                                      self.units.distr2))
             elif self.units.distrtype == 'systematic_noncontiguos':
-                fil.write("SYSTEMATICNONCONTIGUOUS %s\n" % str(NUMERO))
+                fil.write("SYSTEMATICNONCONTIGUOUS %s\n" % self.units.distr1)
             elif self.units.distrtype == 'centered_oversites':
                 fil.write("")
 
@@ -447,7 +450,7 @@
                                       majorDimension=1,
                                       style=wx.RA_SPECIFY_ROWS)
 
-        self.sampling_reg.EnableItem(2, False) # disable 'draw' for now
+        self.sampling_reg.EnableItem(2, False)  # disable 'draw' for now
         self.sampling_reg.SetItemToolTip(2, _("This option is not supported yet"))
         self.sizer.Add(item=self.sampling_reg,
                         flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
@@ -727,15 +730,6 @@
             self.sizer.Layout()
         except:
             pass
-        #self.regionBox = wx.GridBagSizer(vgap = 1, hgap = 2)
-        #self.regionLabel = wx.StaticText(parent = self, id = wx.ID_ANY,
-                        #label = _('Enter the number of region to draw'))
-        #self.regionTxt = wx.TextCtrl(parent = self, id = wx.ID_ANY, size=(50, -1))
-        #self.regionBox.Add(self.regionLabel, pos = (1, 1))
-        #self.regionBox.Add(self.regionTxt, pos = (1, 2))
-        #self.sizer.Add(self.regionBox, flag = wx.ALIGN_CENTER, pos = (6, 1))
-        #self.sizer.Layout()
-        #self.SetNext(self.parent.draw)
         gcmd.GMessage(parent=self, message=_("Function not supported yet"))
         return
 
@@ -776,7 +770,8 @@
         self.panelSizer = wx.GridBagSizer(5, 5)
         self.width = ''
         self.height = ''
-        self.boxtype = ''
+        self.boxtype = 'rectangle'
+        self.distrtype = 'non_overlapping'
         # type of shape
         self.typeBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
                                    majorDimension=1, style=wx.RA_SPECIFY_COLS,
@@ -785,8 +780,6 @@
 
         self.panelSizer.Add(self.typeBox, flag=wx.ALIGN_LEFT, pos=(0, 0),
                             span=(1, 2))
-
-
         self.widthLabel = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
         self.widthTxt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
                                     size=(250, -1))
@@ -809,8 +802,10 @@
         self.heightLabels = [_('Height size (in cells)? '),
                              _('Name of the circle mask')]
 
-        self.distributionBox = wx.RadioBox(parent=self.scrollPanel, id=wx.ID_ANY,
-                                           majorDimension=1, style=wx.RA_SPECIFY_COLS,
+        self.distributionBox = wx.RadioBox(parent=self.scrollPanel,
+                                           id=wx.ID_ANY,
+                                           majorDimension=1,
+                                           style=wx.RA_SPECIFY_COLS,
                                            label= " %s " % _("Select method of sampling unit distribution"),
                                            choices=[_('Random non overlapping'),
                                                     _('Systematic contiguos'),
@@ -818,6 +813,7 @@
                                                     _('Systematic non contiguos'),
                                                     _('Centered over sites')]
                                             )
+        self.distributionBox.EnableItem(5, False)  # disable 'draw' for now
         self.panelSizer.Add(item=self.distributionBox, pos=(3, 0), span=(1, 2),
                     flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
 
@@ -825,25 +821,27 @@
                                          label=_("What number of Sampling " \
                                          "Units to use?"))
         self.distr1Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
-                                     size=(250, -1)) 
+                                     size=(250, -1))
         self.panelSizer.Add(item=self.distr1Label, pos=(4, 0),
                     flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
         self.panelSizer.Add(item=self.distr1Txt, pos=(4, 1),
-                    flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL) 
-
-        self.distr2Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY)
+                    flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        self.distr2Label = wx.StaticText(parent=self.scrollPanel, id=wx.ID_ANY,
+                                         label="")
         self.distr2Txt = wx.TextCtrl(parent=self.scrollPanel, id=wx.ID_ANY,
                                      size=(250, -1))
         self.panelSizer.Add(item=self.distr2Label, pos=(5, 0),
                     flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
         self.panelSizer.Add(item=self.distr2Txt, pos=(5, 1),
-                    flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL) 
+                    flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
         self.panelSizer.Hide(self.distr2Txt)
 
         self.typeBox.Bind(wx.EVT_RADIOBOX, self.OnType)
         self.distributionBox.Bind(wx.EVT_RADIOBOX, self.OnDistr)
         self.widthTxt.Bind(wx.EVT_TEXT, self.OnWidth)
         self.heightTxt.Bind(wx.EVT_TEXT, self.OnHeight)
+        self.distr1Txt.Bind(wx.EVT_TEXT, self.OnDistr1)
+        self.distr2Txt.Bind(wx.EVT_TEXT, self.OnDistr2)
         #self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
         self.sizer.Add(item=self.scrollPanel, pos=(0, 0), flag=wx.EXPAND)
         self.sizer.AddGrowableCol(0)
@@ -905,7 +903,13 @@
     def OnHeight(self, event):
         self.height = event.GetString()
 
+    def OnDistr1(self, event):
+        self.distr1 = event.GetString()
 
+    def OnDistr2(self, event):
+        self.distr2 = event.GetString()
+
+
 class MovingWindows(TitledPage):
     """!Set values from keyboard for sample units"""
 
@@ -1067,6 +1071,27 @@
                        flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
         self.sizer.Add(item=self.shapeheighttxt, border=5, pos=(8, 1),
                        flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        #units type
+        self.unitslabel = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+        self.unitstxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+        self.sizer.Add(item=self.unitslabel, border=5, pos=(9, 0),
+                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        self.sizer.Add(item=self.unitstxt, border=5, pos=(9, 1),
+                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        self.unitsmorelabel = wx.StaticText(parent=self, id=wx.ID_ANY,
+                                            label="")
+        self.unitsmoretxt = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+        self.sizer.Add(item=self.unitsmorelabel, border=5, pos=(10, 0),
+                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        self.sizer.Add(item=self.unitsmoretxt, border=5, pos=(10, 1),
+                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        self.unitsmorelabel2 = wx.StaticText(parent=self, id=wx.ID_ANY,
+                                            label="")
+        self.unitsmoretxt2 = wx.StaticText(parent=self, id=wx.ID_ANY, label="")
+        self.sizer.Add(item=self.unitsmorelabel2, border=5, pos=(11, 0),
+                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
+        self.sizer.Add(item=self.unitsmoretxt2, border=5, pos=(11, 1),
+                       flag=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.ALL)
 
     def OnEnterPage(self, event):
         """!Insert values into text controls for summary of location
@@ -1102,6 +1127,19 @@
                 self.shapeheightlabel.SetLabel(_("Heigth size:"))
             self.shapewidthtxt.SetLabel(self.parent.units.width)
             self.shapeheighttxt.SetLabel(self.parent.units.height)
+            self.unitslabel.SetLabel(_("Method of distribution:"))
+            self.unitstxt.SetLabel(self.parent.units.distrtype)
+            if self.parent.units.distrtype == 'non_overlapping':
+                self.unitsmorelabel.SetLabel(_("Number sampling units:"))
+                self.unitsmoretxt.SetLabel(self.parent.units.distr1)
+            elif self.parent.units.distrtype == 'systematic_noncontiguos':
+                self.unitsmorelabel.SetLabel(_("Distance between units:"))
+                self.unitsmoretxt.SetLabel(self.parent.units.distr1)
+            elif self.parent.units.distrtype == 'stratified_random':
+                self.unitsmorelabel.SetLabel(_("Number row strates:"))
+                self.unitsmoretxt.SetLabel(self.parent.units.distr1)
+                self.unitsmorelabel2.SetLabel(_("Number column strates:"))
+                self.unitsmoretxt2.SetLabel(self.parent.units.distr2)
         elif self.parent.samplingareapage.samplingtype == 'moving':
             self.shapelabel.SetLabel(_('Type of shape:'))
             self.shapetxt.SetLabel(self.parent.moving.boxtype)



More information about the grass-commit mailing list