Skip to content

Commit

Permalink
d.polar: fix launch module (py3) and write output EPS file
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Nov 20, 2020
1 parent 87bfc11 commit ef7f8cc
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions scripts/d.polar/d.polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def plot_xgraph():
p = gcore.Popen(['xgraph'], stdin=gcore.PIPE)
for point in sine_cosine_replic + newline + outercircle + newline + vector:
if isinstance(point, tuple):
p.stdin.write("%f %f\n" % point)
p.stdin.write(gcore.encode("%f %f\n" % point))
else:
p.stdin.write(point + '\n')
p.stdin.write(gcore.encode(point + '\n'))
p.stdin.close()
p.wait()

Expand Down Expand Up @@ -174,9 +174,9 @@ def plot_dgraph():
p = gcore.feed_command('d.graph', env=tenv)
for point in lines:
if isinstance(point, tuple):
p.stdin.write("%f %f\n" % point)
p.stdin.write(gcore.encode("%f %f\n" % point))
else:
p.stdin.write(point + '\n')
p.stdin.write(gcore.encode(point + '\n'))
p.stdin.close()
p.wait()

Expand Down Expand Up @@ -227,14 +227,14 @@ def plot_eps(psout):
averagedirectionlegendy = 1.85 * halfframe

##########
outf = file(psout, 'w')
outf = open(psout, 'w')

prolog = os.path.join(
os.environ['GISBASE'],
'etc',
'd.polar',
'ps_defs.eps')
inf = file(prolog)
inf = open(prolog)
shutil.copyfileobj(inf, outf)
inf.close()

Expand Down Expand Up @@ -428,11 +428,11 @@ def main():
#################################
# this file contains everything:
rawfile = tmp + "_raw"
rawf = file(rawfile, 'w')
rawf = open(rawfile, 'w')
gcore.run_command('r.stats', flags='1', input=map, stdout=rawf)
rawf.close()

rawf = file(rawfile)
rawf = open(rawfile)
totalnumber = 0
for line in rawf:
totalnumber += 1
Expand All @@ -444,7 +444,7 @@ def main():
# wipe out NULL data and undef data if defined by user
# - generate degree binned to integer, eliminate NO DATA (NULL):
# change 360 to 0 to close polar diagram:
rawf = file(rawfile)
rawf = open(rawfile)
nvals = 0
sumcos = 0
sumsin = 0
Expand Down Expand Up @@ -509,8 +509,21 @@ def main():
# Now output:

if eps:
psout = basename(eps, 'eps') + '.eps'
plot_eps(psout)
if not os.path.exists(os.path.dirname(eps)):
gcore.fatal(
_("EPS output file path <{}>, doesn't exists. "
"Set new output file path.".format(eps)
),
)
if not eps.endswith('.eps'):
eps += '.eps'
if os.path.exists(eps) and not os.getenv('GRASS_OVERWRITE'):
gcore.fatal(
_("option <output>: <{}> exists. To overwrite, "
"use the --overwrite flag.".format(eps)
),
)
plot_eps(eps)
elif xgraph:
plot_xgraph()
else:
Expand Down

0 comments on commit ef7f8cc

Please sign in to comment.