r.mapcalc, median and NULL

3 messages Options
Embed this post
Permalink
Agustin Lobo-2

r.mapcalc, median and NULL

Reply Threaded More More options
Print post
Permalink
Hi!
The grass doc is very clear on the behavior of r.mpacalc regarding NULL:
"NULL-values in function arguments should result in NULL"

I have to calculate the median of a set of 12 monthly layers, i.e.
mean(l1,l2,l3,...l12)

the problem is that some layers have some NULL values. I can
replace NULL by, for example, 0, but this will be having a large effect
in the value of the mean. Is not there any way of setting something
like the na.rm=T of R?

Alternatively, could I calculate (in GRASS) a raster of the number of
months with NULL value present
for each i, j position? In that way I could replace NULL by 0 but then add up
the layers and divide by a raster that would be 12 in most cells, 11 in those
having 1 NULL, 10 in those having 2 NULL etc

Not sure if I explain myself clearly. Would be easily done in R, but
the raster layers are large. Perhaps a problem for the R raster
package?

Agus


--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
e-mail [hidden email]
http://www.ija.csic.es/gt/obster
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
Joel Pitt

Re: r.mapcalc, median and NULL

Reply Threaded More More options
Print post
Permalink
I think what you want is r.series

On Fri, Feb 13, 2009 at 6:58 AM, Agustin Lobo <[hidden email]> wrote:

> Hi!
> The grass doc is very clear on the behavior of r.mpacalc regarding NULL:
> "NULL-values in function arguments should result in NULL"
>
> I have to calculate the median of a set of 12 monthly layers, i.e.
> mean(l1,l2,l3,...l12)
>
> the problem is that some layers have some NULL values. I can
> replace NULL by, for example, 0, but this will be having a large effect
> in the value of the mean. Is not there any way of setting something
> like the na.rm=T of R?
>
> Alternatively, could I calculate (in GRASS) a raster of the number of
> months with NULL value present
> for each i, j position? In that way I could replace NULL by 0 but then add up
> the layers and divide by a raster that would be 12 in most cells, 11 in those
> having 1 NULL, 10 in those having 2 NULL etc
>
> Not sure if I explain myself clearly. Would be easily done in R, but
> the raster layers are large. Perhaps a problem for the R raster
> package?
>
> Agus
>
>
> --
> Dr. Agustin Lobo
> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
> Lluis Sole Sabaris s/n
> 08028 Barcelona
> Spain
> Tel. 34 934095410
> Fax. 34 934110012
> e-mail [hidden email]
> http://www.ija.csic.es/gt/obster
> _______________________________________________
> grass-stats mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/grass-stats
>
_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats
hamish-2

Re: r.mapcalc, median and NULL

Reply Threaded More More options
Print post
Permalink
In reply to this post by Agustin Lobo-2

Agustin Lobo wrote:

> The grass doc is very clear on the behavior of r.mpacalc regarding NULL:
> "NULL-values in function arguments should result in NULL"
>
> I have to calculate the median of a set of 12 monthly layers, i.e.
> mean(l1,l2,l3,...l12)
>
> the problem is that some layers have some NULL values. I can
> replace NULL by, for example, 0, but this will be having a large effect
> in the value of the mean. Is not there any way of setting something
> like the na.rm=T of R?

in matlab this is called nanmean(). they (& grass) don't let the default
mean() do nice tricks like that automatically because it lets you silently
fool yourself*. If "n" is not consistent across the mean-map the result
is somewhat suspect. at minimum you'd also want a std dev map.
* (but excel does let you do that ;)

An idea from a smart friend of mine to fill in those gaps: if data is
multi-year you can make a null-filled average for each month without
introducing the temporal bias, then take a propagating-null average
for the full year from those filled-monthly maps.

see also the sea surface temperature hole-filling and 28-day rolling
composite ideas here:
  http://grass.osgeo.org/wiki/MODIS#Removing_holes


> Alternatively, could I calculate (in GRASS) a raster of the number of
> months with NULL value present for each i, j position?

sure, you could do that with r.mapcalc's if( isnull() ).

> In that way I could replace NULL by 0 but then add up the layers and
> divide by a raster that would be 12 in most cells, 11 in those having
> 1 NULL, 10 in those having 2 NULL etc

yeah, but consider why those cells are NULL. Maybe this is from satellite
surface temperature data and an area is often cloudy some time of year
(eg monsoon) so satellite can't see the ground and no data. e.g. if winter
months are often cloudy you get lots of NULLs in your winter month maps,
and by skipping those you are biasing the end result to be warmer than it
should be.


Hamish



     

_______________________________________________
grass-stats mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-stats