Skip to content

Commit

Permalink
d.polar: fix launch module (py3) and write output EPS file (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi authored Nov 22, 2020
1 parent 1515813 commit c7ec0a8
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 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 @@ -418,6 +418,18 @@ def main():
if eps and xgraph:
gcore.fatal(_("Please select only one output method"))

if eps:
if os.sep in eps and not os.path.exists(os.path.dirname(eps)):
gcore.fatal(_("EPS output file path <{}>, doesn't exists. "
"Set new output file path.".format(eps)))
else:
eps = basename(eps, 'eps') + '.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)))

# check if we have xgraph (if no EPS output requested)
if xgraph and not gcore.find_program('xgraph'):
gcore.fatal(
Expand All @@ -428,11 +440,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 +456,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 +521,7 @@ def main():
# Now output:

if eps:
psout = basename(eps, 'eps') + '.eps'
plot_eps(psout)
plot_eps(psout=eps)
elif xgraph:
plot_xgraph()
else:
Expand Down

0 comments on commit c7ec0a8

Please sign in to comment.