Dear statistics experts,
how can we compute the median of a floating point cover raster map, over
a base map (using the conventional terminology as in r.stats.zonal)?
It appears that there is no module to get the median out of floating
point raster maps, using a base map as in r.stats.zonal or r.statistics
(which does not support floating point figures).
Is there an alternative to r.median for GRASS 7.x?
A work around with r.statistics, is to use r.reclass and get the
floating point numbers (reported via r.stats -n1) as category labels of the
cover map. Yet, r.reclass rounds up floats before assigning a category.
At the moment the shortest path seems to be v.rast.stats. This would
require some conversions back and forth from raster to vector for the
base map though.
Thank you for any hints, Nikos
On Fri, 26 Jan 2018, Nikos Alexandris wrote:
how can we compute the median of a floating point cover raster map, over a
base map (using the conventional terminology as in r.stats.zonal)?
Nikos,
By definition the median value has as many observations/measurements less
than this value as greater than this value. Because floating point numbers
are not represented exactly in computers (unless you extend them out to
several dozen digits to the right of the decimal point), I suggest you
create a map with integer values that will work for your application.
You can find cells with values greater than some number, and less than
some number but you'll have a difficult time finding that number and getting
grass (or any application) to recognize it.
HTH,
Rich
* Rich Shepard <rshepard@appl-ecosys.com> [2018-01-26 11:12:14 -0800]:
On Fri, 26 Jan 2018, Nikos Alexandris wrote:
how can we compute the median of a floating point cover raster map, over a
base map (using the conventional terminology as in r.stats.zonal)?
Nikos,
By definition the median value has as many observations/measurements less
than this value as greater than this value. Because floating point numbers
are not represented exactly in computers (unless you extend them out to
several dozen digits to the right of the decimal point), I suggest you
create a map with integer values that will work for your application.
Something like multiply by * 1000, find the median, then divide by 1000
(as suggested in the past for other modules that don't treat fp
numbers).
You can find cells with values greater than some number, and less than
some number but you'll have a difficult time finding that number and getting
grass (or any application) to recognize it.
HTH,
Yes it helps.
As for the last comment: do you mean it's going to be computationally
"difficult", as in running time? There are algorithms that handle
this as I read on the net. If floating point numbers of the cover map
that fall inside an area (as per the base map), are treated as a vector,
then sorting the figures will give an answer. Even in case of even
number of numbers, the median can be, practically, the average of the
two middle-placed figures, or select the highest number of the lower
part.
Thank you, Nikos
On Fri, 26 Jan 2018, Nikos Alexandris wrote:
As for the last comment: do you mean it's going to be computationally
"difficult", as in running time?
Nikos,
No, not running time. It was long ago when GRASS was still limited to
interger numbers, and I used postgres for attribute data storage. I was
frustrated trying to find a row in a table that had a floating point number
using a SQL select statement until I realized I needed to select using the
integer of that number rounded down. Because of the imprecision of storing a
floating point number there was no way to select a value equal to it.
However, selecting for a value less than the number did the trick.
Rich
Hi Nikos,
Did you consider using r.univar (with a zones map, like v.rast.stats does: https://trac.osgeo.org/grass/browser/grass/branches/releasebranch_7_2/scripts/v.rast.stats/v.rast.stats.py#L238, just with colon as separator) and using the resulting table as input to r.recode (https://grass.osgeo.org/grass74/manuals/r.recode.html) for example?
Cheers,
Stefan
-----Original Message-----
From: grass-user [mailto:grass-user-bounces@lists.osgeo.org] On Behalf Of Nikos Alexandris
Sent: fredag 26. januar 2018 19.52
To: GRASS-GIS user mailing list <grass-user@lists.osgeo.org>
Subject: [GRASS-user] Alternative to r.median for GRASS 7.x?
Dear statistics experts,
how can we compute the median of a floating point cover raster map, over a base map (using the conventional terminology as in r.stats.zonal)?
It appears that there is no module to get the median out of floating point raster maps, using a base map as in r.stats.zonal or r.statistics (which does not support floating point figures).
Is there an alternative to r.median for GRASS 7.x?
A work around with r.statistics, is to use r.reclass and get the floating point numbers (reported via r.stats -n1) as category labels of the cover map. Yet, r.reclass rounds up floats before assigning a category.
At the moment the shortest path seems to be v.rast.stats. This would require some conversions back and forth from raster to vector for the base map though.
Thank you for any hints, Nikos
r.stats.quantile should work:
https://grass.osgeo.org/grass72/manuals/r.stats.quantile.html
···
On Jan 26, 2018 4:44 PM, “Stefan Blumentrath” <Stefan.Blumentrath@nina.no> wrote:
Hi Nikos,
Did you consider using r.univar (with a zones map, like v.rast.stats does: https://trac.osgeo.org/grass/browser/grass/branches/releasebranch_7_2/scripts/v.rast.stats/v.rast.stats.py#L238, just with colon as separator) and using the resulting table as input to r.recode (https://grass.osgeo.org/grass74/manuals/r.recode.html) for example?
Cheers,
Stefan
-----Original Message-----
From: grass-user [mailto:grass-user-bounces@lists.osgeo.org] On Behalf Of Nikos Alexandris
Sent: fredag 26. januar 2018 19.52
To: GRASS-GIS user mailing list <grass-user@lists.osgeo.org>
Subject: [GRASS-user] Alternative to r.median for GRASS 7.x?
Dear statistics experts,
how can we compute the median of a floating point cover raster map, over a base map (using the conventional terminology as in r.stats.zonal)?
It appears that there is no module to get the median out of floating point raster maps, using a base map as in r.stats.zonal or r.statistics (which does not support floating point figures).
Is there an alternative to r.median for GRASS 7.x?
A work around with r.statistics, is to use r.reclass and get the floating point numbers (reported via r.stats -n1) as category labels of the cover map. Yet, r.reclass rounds up floats before assigning a category.
At the moment the shortest path seems to be v.rast.stats. This would require some conversions back and forth from raster to vector for the base map though.
Thank you for any hints, Nikos
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user
Hi,
No! Honestly, I did not see the "zones" parameter 
Reads as something worth trying. As Anna indicated `r.stats.quantiles`,
however, looks there is a kind-of direct option.
Thank you!
* Stefan Blumentrath <Stefan.Blumentrath@nina.no> [2018-01-26 21:43:49 +0000]:
Hi Nikos,
Did you consider using r.univar (with a zones map, like v.rast.stats does: https://trac.osgeo.org/grass/browser/grass/branches/releasebranch_7_2/scripts/v.rast.stats/v.rast.stats.py#L238, just with colon as separator) and using the resulting table as input to r.recode (https://grass.osgeo.org/grass74/manuals/r.recode.html) for example?
Cheers,
Stefan
-----Original Message-----
From: grass-user [mailto:grass-user-bounces@lists.osgeo.org] On Behalf Of Nikos Alexandris
Sent: fredag 26. januar 2018 19.52
To: GRASS-GIS user mailing list <grass-user@lists.osgeo.org>
Subject: [GRASS-user] Alternative to r.median for GRASS 7.x?
Dear statistics experts,
how can we compute the median of a floating point cover raster map, over a base map (using the conventional terminology as in r.stats.zonal)?
It appears that there is no module to get the median out of floating point raster maps, using a base map as in r.stats.zonal or r.statistics (which does not support floating point figures).
Is there an alternative to r.median for GRASS 7.x?
A work around with r.statistics, is to use r.reclass and get the floating point numbers (reported via r.stats -n1) as category labels of the cover map. Yet, r.reclass rounds up floats before assigning a category.
At the moment the shortest path seems to be v.rast.stats. This would require some conversions back and forth from raster to vector for the base map though.
Thank you for any hints, Nikos
--
Nikos Alexandris | Remote Sensing & Geomatics
GPG Key Fingerprint 6F9D4506F3CA28380974D31A9053534B693C4FB3
Thanks!
A somewhat longer example to get percentiles 1, 99 and the median:
for MAP in `t.rast.list -u aggregates_median column=name` ;do for P in 1 50 99 ;do r.stats.quantile cover=$MAP base=landcover percentile=${P} output=landcover_${MAP}_percentile_${P}_categories -r ;done ;done
for MAP in `t.rast.list -u aggregates_median column=name` ;do for P in 1 50 99 ;do r.stats.quantile cover=$MAP base=landcover percentile=${P} output=landcover_${MAP}_percentile_${P} ;done ;done
Nikos
* Anna Petrášová <kratochanna@gmail.com> [2018-01-26 17:53:36 -0500]:
r.stats.quantile should work:
https://grass.osgeo.org/grass72/manuals/r.stats.quantile.html