[GRASS5] d.polar using d.graph

Markus wrote:

The d.polar is waiting for a volunteer to change the xgraph
dependency to GRASS' d.graph. Maybe done in a few minutes for someone
who knows the syntax of d.graph input... The xgraph input
is just a title and coordinate pairs to draw the polar
diagram.

well, here's a proof of concept; messy, but it does plot something--

`cat` and $FOO in d.graph's stdin is the required magic..

I've done it after-the-fact, but factoring x,y to 0-100% could be done
right in the "sin()*r, cos()*r" step to save time & space.

notes:
my 1000x1000 aspect grid made 50mb temp files!

I got weird output when trying from r.slope.aspect (elev from
r.surf.contour). Spikes every 45degree. I thought I had my awk
wrong.. [d.histogram of it attached]. Probably an artifact of blocky
r.surf.contour output? That histogram is interesting.. smaller peaks
22.5deg out of phase with the 45deg spikes..? odd.

Is 0deg north-up or does it have to be rotated? angle_n_up = 90-theta

The script could use lots of optimization.. move $2*$3/$4 stuff into one
coefficient before running awk, etc., e.g.
  echo "\"All Data incl. NULL" > ${TMP}_outercircle
  RADIUS_COEFF=`echo "$TOTALNUMBER $TOTALVALIDNUMBER $MAXRADIUS" | \
     awk '{printf "%.8f", $1/$2 * $3}'`
  for i in `seq 0 360` ; do
    echo "$i $RADIUS_COEFF" | awk ...

The following doesn't honour the undef= option, is it on purpose?
# unit vector on raw data converted to radians without no data:
cat ${TMP}_raw | grep -v '^*'| awk 'BEGIN {sum = 0.0}

d.polar code follows (insert at end of script before cleanup)
---------------------

RING=0.95 # percent of frame to use
cat ${TMP}_sine_cosine_replic | tail +2 | awk -v RING=$RING -v MAX=$MAXRADIUS \
    '{printf "%f %f\n", (($1 / MAX * RING) +1)*50, (($2 / MAX * RING)+1)*50}' \
       > ${TMP}_sine_cosine_replic_normalized

VECT=`cat ${TMP}_vector | tail -n 1 | awk -v RING=$RING -v MAX=$MAXRADIUS \
    '{printf "%f %f\n", (($1 / MAX * RING) +1)*50, (($2 / MAX * RING)+1)*50}'`

#d.erase
d.graph << EOF
  # draw the goods
  color red
  polygon
   `cat ${TMP}_sine_cosine_replic_normalized`

  # draw axes
  color black
  width 0
  move 0 50
  draw 100 50
  move 50 0
  draw 50 100

  # draw circle
  # mandatory! as drawing is proportional to non-square frame

  # draw vector
  color green
  width 2
  move 50 50
  draw $VECT

  # draw compass text
  color black
  width 2
  move 50.5 95
  text N
# move 50.5 1
# text S
# move 1 50.5
# text W
# move 95 50.5
# text E
EOF

Hamish

(attachments)

aspect_spike.png

Hamish,

On Fri, Mar 17, 2006 at 02:21:29AM +1300, Hamish wrote:

Markus wrote:
> The d.polar is waiting for a volunteer to change the xgraph
> dependency to GRASS' d.graph. Maybe done in a few minutes for someone
> who knows the syntax of d.graph input... The xgraph input
> is just a title and coordinate pairs to draw the polar
> diagram.

well, here's a proof of concept; messy, but it does plot something--

`cat` and $FOO in d.graph's stdin is the required magic..

I've done it after-the-fact, but factoring x,y to 0-100% could be done
right in the "sin()*r, cos()*r" step to save time & space.

I wouldn't mind if someone improves the script.

notes:
my 1000x1000 aspect grid made 50mb temp files!

I got weird output when trying from r.slope.aspect (elev from
r.surf.contour). Spikes every 45degree. I thought I had my awk
wrong.. [d.histogram of it attached]. Probably an artifact of blocky
r.surf.contour output? That histogram is interesting.. smaller peaks
22.5deg out of phase with the 45deg spikes..? odd.

Check if you produced an integer DEM. If so, then it is no
surprise (see comments in r.slope.aspect manual).

Is 0deg north-up or does it have to be rotated? angle_n_up = 90-theta

0deg is East as common notion in GRASS (except for r.param.scale).
But north is up in the diagram (I think).

The script could use lots of optimization.. move $2*$3/$4 stuff into one
coefficient before running awk, etc., e.g.
  echo "\"All Data incl. NULL" > ${TMP}_outercircle
  RADIUS_COEFF=`echo "$TOTALNUMBER $TOTALVALIDNUMBER $MAXRADIUS" | \
     awk '{printf "%.8f", $1/$2 * $3}'`
  for i in `seq 0 360` ; do
    echo "$i $RADIUS_COEFF" | awk ...

You are kindly invited to take a look.

The following doesn't honour the undef= option, is it on purpose?
# unit vector on raw data converted to radians without no data:
cat ${TMP}_raw | grep -v '^*'| awk 'BEGIN {sum = 0.0}

No, fixed.

d.polar code follows (insert at end of script before cleanup)
---------------------

...

This looks promising.
Maybe some power user picks it up and also adds the ring and
the directional indicator.

thanks for the proof of concept,

Markus

Markus wrote:
> The d.polar is waiting for a volunteer to change the xgraph
> dependency to GRASS' d.graph. Maybe done in a few minutes for
> someone who knows the syntax of d.graph input... The xgraph input
> is just a title and coordinate pairs to draw the polar
> diagram.

well, here's a proof of concept; messy, but it does plot something--

idea - add a switch to d.polar to make a scatter plot (many dots)
diagram with the angle again from the aspect map but the radius taken
from a slope map, not the frequency of occurance count. Together with the
freq rose plot, I think this would be very useful for terrain
classification. The 90deg as max radius means that the scaling to the
edge of the screen is mostly done for you already..

Hamish