[GRASS-SVN] r66283 - grass-addons/grass7/raster/r.green/libgreen
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Sep 22 05:11:44 PDT 2015
Author: Giulia
Date: 2015-09-22 05:11:44 -0700 (Tue, 22 Sep 2015)
New Revision: 66283
Modified:
grass-addons/grass7/raster/r.green/libgreen/utils.py
Log:
r.green: temporary files as tmprgreen_PID
Modified: grass-addons/grass7/raster/r.green/libgreen/utils.py
===================================================================
--- grass-addons/grass7/raster/r.green/libgreen/utils.py 2015-09-22 12:06:38 UTC (rev 66282)
+++ grass-addons/grass7/raster/r.green/libgreen/utils.py 2015-09-22 12:11:44 UTC (rev 66283)
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import numpy as np
+import os
#import pdb
# import grass libraries
@@ -53,17 +54,26 @@
def check_overlay_rr(raster1, raster2):
"""
- check the overlay between a raster and a vector
+ check the overlay between rasters
:param raster1: grass raster name
:type raster: string
:param raster2: grass raster name
:type vector: string
"""
- formula = 'overlay = if( %s>0 && %s>0 , %s)' % (raster1, raster2, raster2)
+ pid = os.getpid()
+ tmp_diff = "tmprgreen_%i_diff" % pid
+ tmp_overlay = "tmprgreen_%i_overlay" % pid
+ formula = '%s = if( %s>0 && %s>0 , %s)' % (tmp_overlay, raster1,
+ raster2, raster2)
mapcalc(formula, overwrite=True)
- formula = 'diff = overlay - %s' % (raster2)
+ formula = "%s = if(isnull(%s), if(%s, 10), %s - %s)" % (tmp_diff,
+ tmp_overlay,
+ raster2,
+ tmp_overlay,
+ raster2)
+ formula = '%s = %s - %s' % (tmp_diff, tmp_overlay, raster2)
mapcalc(formula, overwrite=True)
- perc_0 = perc_of_overlay('diff', '0')
+ perc_0 = perc_of_overlay(tmp_diff, '0')
return perc_0
@@ -78,9 +88,9 @@
temp = 0
info = gcore.parse_command('r.report', flags='nh', map=raster, units='p')
for somestring in info.keys():
- if ((' %s|' % val) or ('|%s|' % val)) in somestring:
+ if ((' %s|' % val) in somestring) or (('|%s|' % val) in somestring):
temp = somestring.split('|')[-2]
- return temp
+ return temp
def raster2compressM(A):
@@ -117,7 +127,7 @@
"""
gcore.run_command("v.to.rast", overwrite=True, input=lakes,
output="lakes", use="val")
- stream, mset = stream.split('q') if '@' in stream else (stream, '')
+ stream, mset = stream.split('@') if '@' in stream else (stream, '')
del_lake = '%s=if(%s,if(isnull(lakes),%s,null()),null())' % (stream,
stream,
stream)
More information about the grass-commit
mailing list