[GRASS-SVN] r74157 - grass-addons/grass7/raster/r.width.funct
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Mar 5 07:44:30 PST 2019
Author: madi
Date: 2019-03-05 07:44:30 -0800 (Tue, 05 Mar 2019)
New Revision: 74157
Modified:
grass-addons/grass7/raster/r.width.funct/r.width.funct.py
Log:
fix error reported in ML - IndexError: invalid index to scalar variable
Modified: grass-addons/grass7/raster/r.width.funct/r.width.funct.py
===================================================================
--- grass-addons/grass7/raster/r.width.funct/r.width.funct.py 2019-03-05 14:45:13 UTC (rev 74156)
+++ grass-addons/grass7/raster/r.width.funct/r.width.funct.py 2019-03-05 15:44:30 UTC (rev 74157)
@@ -47,10 +47,13 @@
import matplotlib.pyplot as plt
import grass.script as grass
import numpy as np
-from operator import itemgetter
def main():
- stats = grass.read_command('r.stats', input = options['map'], sep = 'space', nv = '*', nsteps = '255', flags = 'Anc').split('\n')[:-1]
+ stats = grass.read_command('r.stats', input = options['map'], \
+ sep = 'space', \
+ nv = '*', \
+ nsteps = '255', \
+ flags = 'Anc').split('\n')[:-1]
# res = cellsize
res = grass.region()['nsres']
@@ -61,20 +64,20 @@
for i in range(len(stats)):
if i == 0:
- zn[i,0], zn[i,1] = list(map(float, stats[i].split(' ')))
+ zn[i,0], zn[i,1] = map(float, stats[i].split(' '))
zn[i,1] = zn[i,1]
zn[i,2] = zn[i,1] * res
if i != 0:
- zn[i,0], zn[i,1] = list(map(float, stats[i].split(' ')))
+ zn[i,0], zn[i,1] = map(float, stats[i].split(' '))
zn[i,2] = zn[i,1] + zn[i-1,2]
zn[i,3] = zn[i,1] * (res**2)
totcell = sum(zn[:,1])
- print("Tot. cells", totcell)
+ print("Tot. cells %s" %(totcell))
totarea = totcell * (res**2)
- print("Tot. area", totarea)
+ print("Tot. area %s" %(totarea))
maxdist = max(zn[:,0])
- print("Max distance", maxdist)
+ print("Max distance %s" %(maxdist))
for i in range(len(stats)):
kl[i,0] = zn[i,0]
@@ -97,15 +100,15 @@
print("===========================")
print("Width Function | quantiles")
print("===========================")
- print('%.0f' %findint(kl,0.05) , "|", 0.05)
- print('%.0f' %findint(kl,0.15) , "|", 0.15)
- print('%.0f' %findint(kl,0.3) , "|", 0.3)
- print('%.0f' %findint(kl,0.4) , "|", 0.4)
- print('%.0f' %findint(kl,0.5) , "|", 0.5)
- print('%.0f' %findint(kl,0.6) , "|", 0.6)
- print('%.0f' %findint(kl,0.7) , "|", 0.7)
- print('%.0f' %findint(kl,0.85) , "|", 0.85)
- print('%.0f' %findint(kl,0.95) , "|", 0.95)
+ print('%.0f | %s') %(findint(kl,0.05), 0.05)
+ print('%.0f | %s') %(findint(kl,0.15), 0.15)
+ print('%.0f | %s') %(findint(kl,0.3), 0.3)
+ print('%.0f | %s') %(findint(kl,0.4), 0.4)
+ print('%.0f | %s') %(findint(kl,0.5), 0.5)
+ print('%.0f | %s') %(findint(kl,0.6), 0.6)
+ print('%.0f | %s') %(findint(kl,0.7), 0.7)
+ print('%.0f | %s') %(findint(kl,0.85), 0.85)
+ print('%.0f | %s') %(findint(kl,0.95), 0.95)
print('\n')
print('Done!')
@@ -121,10 +124,7 @@
plt.close('all')
def findint(kl,f):
- Xf = np.abs(kl-f);
- Xf = np.where(Xf==Xf.min())
- item = itemgetter(0)(Xf)
- Xf = item[0]
+ Xf = np.abs(kl-f); Xf = np.where(Xf==Xf.min())
z1, z2, f1, f2 = kl[int(Xf[0])][0], kl[int(Xf[0]-1)][0], kl[int(Xf[0])][1], kl[int(Xf[0]-1)][1]
z = z1 + ((z2 - z1) / (f2 - f1)) * (f - f1)
return z
More information about the grass-commit
mailing list