Commit fca04df5 authored by Rabotin Michael's avatar Rabotin Michael
Browse files

corrected errors in import module

parent aa93615e
......@@ -139,44 +139,4 @@ t-b resol: 1
rc.write('MAPSET: %s\n' % mapset)
def reclass(map_in, map_out, size):
p = grass_pipe_command('r.stats', flags='lnNc', input=map_in)
pReclass = grass_feed_command('r.reclass', overwrite=True, input=map_in, output=map_out, rules='-')
for l in p.stdout:
lSpl = decode(l).rstrip(os.linesep).split()
if int(lSpl[1]) <= int(size):
pReclass.stdin.write(encode('%s = %s\n' % (lSpl[0], lSpl[0])))
p.wait()
pReclass.stdin.close()
pReclass.wait()
def count_only(map_in, size):
statLines = decode(grass_read_command('r.stats', quiet=True, flags='lnNc', input=map_in)).rstrip(os.linesep).split(os.linesep)
c = 0
for l in statLines:
lSpl = l.split()
if int(lSpl[1]) <= int(size):
c += 1
return c
#return int(os.popen('r.stats --quiet -lnNc input=%s | awk %s' % (map_in, AWK_cmd_2(size))).readlines()[0])
def getAreasUpTo(map_in, size):
areas = []
statLists = []
statLines = decode(grass_read_command('r.stats', quiet=True, flags='lnNc', input=map_in)).rstrip(os.linesep).split(os.linesep)
for l in statLines:
statLists.append(l.strip().split())
# sort on second column
statLists = sorted(statLists, key=lambda x: int(x[1]))
# awk
intSize = int(size)
old = 0
for sl in statLists:
intSl1 = int(sl[1])
if old != intSl1 and intSl1 <= intSize:
areas.append(intSl1)
old = intSl1
return areas
......@@ -45,7 +45,7 @@ import multiprocessing
from multiprocessing import Pool, cpu_count
from utils import isint
from grassUtils import reclass, count_only, getAreasUpTo
......@@ -62,6 +62,50 @@ except ImportError:
MY_ABS_PATH=os.path.abspath(__file__)
MY_DIR=os.path.dirname(MY_ABS_PATH)
def reclass(map_in, map_out, size):
p = grass_pipe_command('r.stats', flags='lnNc', input=map_in)
pReclass = grass_feed_command('r.reclass', overwrite=True, input=map_in, output=map_out, rules='-')
for l in p.stdout:
lSpl = decode(l).rstrip(os.linesep).split()
if int(lSpl[1]) <= int(size):
pReclass.stdin.write(encode('%s = %s\n' % (lSpl[0], lSpl[0])))
p.wait()
pReclass.stdin.close()
pReclass.wait()
def count_only(map_in, size):
statLines = decode(grass_read_command('r.stats', quiet=True, flags='lnNc', input=map_in)).rstrip(os.linesep).split(os.linesep)
c = 0
for l in statLines:
lSpl = l.split()
if int(lSpl[1]) <= int(size):
c += 1
return c
#return int(os.popen('r.stats --quiet -lnNc input=%s | awk %s' % (map_in, AWK_cmd_2(size))).readlines()[0])
def getAreasUpTo(map_in, size):
areas = []
statLists = []
statLines = decode(grass_read_command('r.stats', quiet=True, flags='lnNc', input=map_in)).rstrip(os.linesep).split(os.linesep)
for l in statLines:
statLists.append(l.strip().split())
# sort on second column
statLists = sorted(statLists, key=lambda x: int(x[1]))
# awk
intSize = int(size)
old = 0
for sl in statLists:
intSl1 = int(sl[1])
if old != intSl1 and intSl1 <= intSize:
areas.append(intSl1)
old = intSl1
return areas
# function launched in parallel, yeyeah
def processSubbasin(params):
id, configFileDir, iRun, nbBasins, min_area, buffer_distance, tmpPath, generator, nbProc = params
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment