[GRASS-SVN] r68115 - grass-addons/grass7/raster/r.niche.similarity

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Mar 23 02:05:24 PDT 2016


Author: pvanbosgeo
Date: 2016-03-23 02:05:24 -0700 (Wed, 23 Mar 2016)
New Revision: 68115

Modified:
   grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.html
   grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.py
Log:
r.niche.similarity addon: fix how intermediate files are removed + cleanup code

Modified: grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.html
===================================================================
--- grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.html	2016-03-23 09:01:45 UTC (rev 68114)
+++ grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.html	2016-03-23 09:05:24 UTC (rev 68115)
@@ -34,10 +34,10 @@
 <ul>
 <li>Warren, D. L., Glor, R. E., & Turelli, M. 2008. 
 Environmental Niche Equivalency Versus Conservatism: Quantitative 
-Approaches to Niche Evolution. Evolution 62(11): 2868–2883</li>
+Approaches to Niche Evolution. Evolution 62(11): 2868-2883</li>
 <li> Warren, D. L., R. E. Glor, and M. Turelli. 2010. ENMTools: a 
 toolbox for comparative studies of environmental niche models. Ecography 
-33:607–611.</li>
+33:607-611.</li>
 <li>Robert J. Hijmans, Steven Phillips, John 
 Leathwick and Jane Elith (2013). dismo: Species distribution 
 modeling. R package version 0.8-5. 

Modified: grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.py
===================================================================
--- grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.py	2016-03-23 09:01:45 UTC (rev 68114)
+++ grass-addons/grass7/raster/r.niche.similarity/r.niche.similarity.py	2016-03-23 09:05:24 UTC (rev 68115)
@@ -95,26 +95,9 @@
 
 def cleanup():
     for rast in clean_rast:
-        grass.run_command("g.remove",
+        grass.run_command("g.remove", flags="f",
         type="rast", name=rast, quiet=True)
 
-
-def fileexist(fname, suffix):
-    k = 0
-    fname2 = fname[:]
-    fname2 = fname2.split('.')
-    while os.path.isfile(fname):
-        k = k + 1
-        opft = fname.split('.')
-        if len(opft) == 1:
-            fname = opft[0] + "_" + str(k)
-        else:
-            fname = fname2[0] + suffix + str(k) + "." + fname2[1]
-    if k > 0:
-        grass.info("there is already a file " + fname2[0] + ".")
-        grass.info("Using " + fname + " instead")
-    return fname
-
 ##----------------------------------------------------------------------------
 ## main function
 ##----------------------------------------------------------------------------
@@ -129,8 +112,6 @@
     OPF = options['output']
     if OPF == '':
         OPF = tempfile.mkstemp()[1]
-    else:
-        OPF = fileexist(OPF, "v_")
     flag_i = flags['i']
     flag_d = flags['d']
     flag_c = flags['c']
@@ -180,7 +161,6 @@
                              quiet=True)
                 NO = float(grass.parse_command("r.univar", quiet=True, flags="g", map=tmpf0)['sum'])
                 NOV = 1 - (0.5 * NO)
-                grass.run_command("g.remove", quiet=True, flags="f", type="raster", name=tmpf0)
                 text_file.write("D," + nvar1 + "," + nvar2 + "," + str(NOV) + "\n")
                 grass.message("Niche overlap (D) of " + nvar1 + " and " + nvar2 + ": " + str(round(NOV, 3)))
 
@@ -202,7 +182,6 @@
                              quiet=True)
                 NE = float(grass.parse_command("r.univar", quiet=True, flags="g", map=tmpf1)['sum'])
                 NEQ = 1 - (0.5 * NE)
-                grass.run_command("g.remove", quiet=True, flags="f", type="raster", name=tmpf1)
                 text_file.write("I," + nvar1 + "," + nvar2 + "," + str(NEQ) + "\n")
                 grass.message("Niche overlap (I) of " + nvar1 + " and " + nvar2 + ": " + str(round(NEQ, 3)))
 



More information about the grass-commit mailing list