[GRASS-user] Computing histograms inline with mapcalc?

Glynn Clements glynn at gclements.plus.com
Sat Jul 14 09:06:29 EDT 2007


Shaun Walbridge wrote:

> We're looking at running a Monte Carlo simulation with our GRASS data, 
> and one step I'd like to simplify is making histograms.  Currently we 
> use R, but given that our input rasters have millions of cells, it's 
> time consuming.  I was thinking that we might be able to use GRASS 
> directly, since we're just doing many r.mapcalc calls.
> 
> I see histogram.c, and ideally I'd like to just roll a custom r.mapcalc 
> which adds its output to a histogram function, then write it out at the 
> end of the program. My C chops are poor, but I'm imagining something as 
> simple (in Python) as:
> 
> hist = {}
> values = [0.1, 0.1, 0.2, 3, 5, 3, 0.1, 0.2, 3, 0.1, 0.1]
> 
> for v in values:
>      if hist.has_key(v):
>          hist[v] += 1
>      else:
>          hist[v] = 1
> 
> What would be my best bet for creating this histogram?  Is hacking up my 
> own mapcalc function feasible?

If you call G_want_histogram(1) before opening the output map, a
histogram will be generated automatically for any integer maps.

Also, running r.support.stats will generate the histogram for the
specified map.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-user mailing list