[GRASS-SVN] r66889 - grass-addons/grass7/raster/r.vif

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Nov 22 08:42:29 PST 2015


Author: pvanbosgeo
Date: 2015-11-22 08:42:29 -0800 (Sun, 22 Nov 2015)
New Revision: 66889

Modified:
   grass-addons/grass7/raster/r.vif/r.vif.py
Log:
First changes to make it possible to define variables that should be retained, irrespective of the vif value

Modified: grass-addons/grass7/raster/r.vif/r.vif.py
===================================================================
--- grass-addons/grass7/raster/r.vif/r.vif.py	2015-11-22 09:22:18 UTC (rev 66888)
+++ grass-addons/grass7/raster/r.vif/r.vif.py	2015-11-22 16:42:29 UTC (rev 66889)
@@ -42,6 +42,16 @@
 #% multiple: yes
 #%end
 
+#%option
+#% key: retain
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: variables to retain
+#% key_desc: name
+#% required: no
+#% multiple: yes
+#%end
+
 #%option G_OPT_F_OUTPUT
 #% key:file
 #% description: Name of output text file
@@ -66,7 +76,7 @@
 #%end
 
 # Test purposes
-#options = {"maps":"bio1,bio5,bio6", "output":"bb", "nsp":"100", "maxvif":"100"}
+#options = {"maps":"bio1,bio5,bio6", "output":"bb", "nsp":"100", "retain":"bio1,bio2", "maxvif":"100", "file":"aa.txt"}
 #flags = {"m":True, "k":True, "n":False, "i":True, "k":True}
 
 #=======================================================================
@@ -81,6 +91,7 @@
 import math
 import tempfile
 import string
+import collections
 import numpy as np
 import grass.script as grass
 
@@ -104,6 +115,18 @@
     IPF = options['maps']
     IPF = IPF.split(',')
     IPFn = [i.split('@')[0] for i in IPF]
+    IPR = options['retain']
+    if IPR != '':
+        IPR = IPR.split(',')
+        IPRn = [i.split('@')[0] for i in IPR]
+        iprn = collections.Counter(IPRn)
+        ipfn = collections.Counter(IPFn)
+        IPFn = list((ipfn-iprn).elements())
+        ipr = collections.Counter(IPR)
+        ipf = collections.Counter(IPF)
+        IPF = list((ipf-ipr).elements())
+        if len(IPFn) == 0:
+            grass.fatal("No variables to remove")
     OPF = options['file']
     if OPF == '':
         OPF = tempfile.mkstemp()[1]
@@ -146,6 +169,8 @@
     # Open text file for writing and write heading
     text_file = open(OPF, "w")
 
+HIER GEBLEVEN... NU NOG UITVOGELEN HOE DE VARIABLES ALTIJD BEWAARD BLIJVEN
+
     # Calculate VIF and write results to text file
     rvifmx = MXVIF + 1
     IPF2 = IPF[:]



More information about the grass-commit mailing list