[GRASS-user] Probabilistic neighborhood analysis

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo

Hello Bernardo,

I haven’t tested myself, but have you tried r.neighbors with the different weight-related options?

Vero

El mié, 14 dic 2022 a las 10:38, Bernardo Santos via grass-user (<grass-user@lists.osgeo.org>) escribió:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

What about using the fuzzy logic modules?

-k.

Please excuse brevity. Sent from tiny pocket computer with non-haptic feedback keyboard.

On Wed, Dec 14, 2022, 13:38 Bernardo Santos via grass-user <grass-user@lists.osgeo.org> wrote:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Hi Vero,

Thanks for the suggestion.
I tried it, but it only gives different weights to the values within the neighborhood according to a distance decay function. However, the values are still determined “deterministically”.

What I could do is to use the function terra::focal() in R, since within it I can define a function to be computed for the neighborhood and use sample() to make this operation probabilistic. It seems to work, but it quite time consuming though.

Best
Bernardo

Em segunda-feira, 26 de dezembro de 2022 16:13:02 GMT+1, Veronica Andreo veroandreo@gmail.com escreveu:

Hello Bernardo,

I haven’t tested myself, but have you tried r.neighbors with the different weight-related options?

Vero

El mié, 14 dic 2022 a las 10:38, Bernardo Santos via grass-user (<grass-user@lists.osgeo.org>) escribió:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Hi Ken,

The fuzzy logic tools seem interesting! But I am new to the concept so I did not really think about how could I set functions/rules that increase with the frequency of a land cover class…
Do you know any example in this context?

I thought that people working with satellite imagery classification and cloud cover would have experience with that, since sometimes it is necessary to somehow interpolate and fill values cover by clouds…

Best
B

Em segunda-feira, 26 de dezembro de 2022 16:50:42 GMT+1, Ken Mankoff mankoff@gmail.com escreveu:

What about using the fuzzy logic modules?

-k.

Please excuse brevity. Sent from tiny pocket computer with non-haptic feedback keyboard.

On Wed, Dec 14, 2022, 13:38 Bernardo Santos via grass-user <grass-user@lists.osgeo.org> wrote:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Hello Bernardo,
although a solution with r.mapcalc random could be made to work, I'd
say creating a new dedicated module is the way to go. Just an idea –
create neighbour count raster (how many cells with centre class are in
a sliding window), in second pass unroll classes based on their count
and then choose random class from obtained list.

I don't think it is so common to infill (inpaint) categorical values
in classification results of remote sensing.
Māris.

pirmd., 2023. g. 9. janv., plkst. 13:18 — lietotājs Bernardo Santos
via grass-user (<grass-user@lists.osgeo.org>) rakstīja:

Hi Ken,

The fuzzy logic tools seem interesting! But I am new to the concept so I did not really think about how could I set functions/rules that increase with the frequency of a land cover class...
Do you know any example in this context?

I thought that people working with satellite imagery classification and cloud cover would have experience with that, since sometimes it is necessary to somehow interpolate and fill values cover by clouds...

Best
B

Em segunda-feira, 26 de dezembro de 2022 16:50:42 GMT+1, Ken Mankoff <mankoff@gmail.com> escreveu:

What about using the fuzzy logic modules?

  -k.

Please excuse brevity. Sent from tiny pocket computer with non-haptic feedback keyboard.

On Wed, Dec 14, 2022, 13:38 Bernardo Santos via grass-user <grass-user@lists.osgeo.org> wrote:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a "probabilistic" neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

10 janv. 2023 08:46:42 Maris Nartiss <maris.gis@gmail.com>:

Hello Bernardo,
although a solution with r.mapcalc random could be made to work, I'd
say creating a new dedicated module is the way to go. Just an idea –
create neighbour count raster (how many cells with centre class are in
a sliding window), in second pass unroll classes based on their count
and then choose random class from obtained list.

I don't think it is so common to infill (inpaint) categorical values
in classification results of remote sensing.

I think this is quite common. However, it is generally done using majority rules or similar. I don't think I have seen much use of randomization in that context.

Moritz

Hi Bernardo,

Not sure if this helps but there is also this function in r.mapcalc:

https://grass.osgeo.org/grass78/manuals/r.mapcalc.html

graph(x,x1,y1[x2,y2..]) convert the x to a y based on points
in a graph F
graph2(x,x1[,x2,..],y1[,y2..]) alternative form of graph()

The graph() function allows users to specify a x-y conversion using
pairs of x,y coordinates. In some situations a transformation from one
value to another is not easily established mathematically, but can be
represented by a 2-D graph and then linearly interpolated. The graph()
function provides the opportunity to accomplish this. An x-axis value
is provided to the graph function along with the associated graph
represented by a series of x,y pairs. The x values must be
monotonically increasing (each larger than or equal to the previous).
The graph function linearly interpolates between pairs. Any x value
lower the lowest x value (i.e. first) will have the associated y value
returned. Any x value higher than the last will similarly have the
associated y value returned.
[...]

Perhaps a dynamic (set of) graphs could be constructed?

Best,
Markus

On Wed, Dec 14, 2022 at 2:37 PM Bernardo Santos via grass-user
<grass-user@lists.osgeo.org> wrote:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.
However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a "probabilistic" neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?
If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!
Best
Bernardo
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

--
Markus Neteler, PhD
https://www.mundialis.de - free data with free software
https://grass.osgeo.org
https://courses.neteler.org/blog

Hi Makus,

Nice suggestion, I did not know about this function within r.mapcalc (it is quite hidden!)
I still do not know how to operationalize it, though.
For now, the solution with R worked, but it could be useful to have something like that in GRASS in the future.
Should I open an issue with a suggestion?
(I do not have time to do it right now)

Best
Bernardo

Em quarta-feira, 11 de janeiro de 2023 09:39:17 GMT+1, Markus Neteler neteler@osgeo.org escreveu:

Hi Bernardo,

Not sure if this helps but there is also this function in r.mapcalc:

https://grass.osgeo.org/grass78/manuals/r.mapcalc.html

graph(x,x1,y1[x2,y2…]) convert the x to a y based on points

in a graph F

graph2(x,x1[,x2,…],y1[,y2…]) alternative form of graph()

The graph() function allows users to specify a x-y conversion using

pairs of x,y coordinates. In some situations a transformation from one

value to another is not easily established mathematically, but can be

represented by a 2-D graph and then linearly interpolated. The graph()

function provides the opportunity to accomplish this. An x-axis value

is provided to the graph function along with the associated graph

represented by a series of x,y pairs. The x values must be

monotonically increasing (each larger than or equal to the previous).

The graph function linearly interpolates between pairs. Any x value

lower the lowest x value (i.e. first) will have the associated y value

returned. Any x value higher than the last will similarly have the

associated y value returned.

[…]

Perhaps a dynamic (set of) graphs could be constructed?

Best,

Markus

On Wed, Dec 14, 2022 at 2:37 PM Bernardo Santos via grass-user

<grass-user@lists.osgeo.org> wrote:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.

However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?

If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!

Best

Bernardo


grass-user mailing list

grass-user@lists.osgeo.org

https://lists.osgeo.org/mailman/listinfo/grass-user

Markus Neteler, PhD

https://www.mundialis.de - free data with free software

https://grass.osgeo.org

https://courses.neteler.org/blog

Hi Bernardo,

Yes, feel free to open a feature request issue. You can assign it to yourself if you think you may tackle it afterwards.

Cheers,
Vero

El lun, 16 ene 2023 a las 19:20, Bernardo Santos via grass-user (<grass-user@lists.osgeo.org>) escribió:

Hi Makus,

Nice suggestion, I did not know about this function within r.mapcalc (it is quite hidden!)
I still do not know how to operationalize it, though.
For now, the solution with R worked, but it could be useful to have something like that in GRASS in the future.
Should I open an issue with a suggestion?
(I do not have time to do it right now)

Best
Bernardo

Em quarta-feira, 11 de janeiro de 2023 09:39:17 GMT+1, Markus Neteler <neteler@osgeo.org> escreveu:

Hi Bernardo,

Not sure if this helps but there is also this function in r.mapcalc:

https://grass.osgeo.org/grass78/manuals/r.mapcalc.html

graph(x,x1,y1[x2,y2…]) convert the x to a y based on points

in a graph F

graph2(x,x1[,x2,…],y1[,y2…]) alternative form of graph()

The graph() function allows users to specify a x-y conversion using

pairs of x,y coordinates. In some situations a transformation from one

value to another is not easily established mathematically, but can be

represented by a 2-D graph and then linearly interpolated. The graph()

function provides the opportunity to accomplish this. An x-axis value

is provided to the graph function along with the associated graph

represented by a series of x,y pairs. The x values must be

monotonically increasing (each larger than or equal to the previous).

The graph function linearly interpolates between pairs. Any x value

lower the lowest x value (i.e. first) will have the associated y value

returned. Any x value higher than the last will similarly have the

associated y value returned.

[…]

Perhaps a dynamic (set of) graphs could be constructed?

Best,

Markus

On Wed, Dec 14, 2022 at 2:37 PM Bernardo Santos via grass-user

<grass-user@lists.osgeo.org> wrote:

Hi,

I am trying to produce scenarios of past land cover, before hydropower reservoirs were built. To do so, I need to fill empty pixels from a raster in the locations where the reservoirs are currently present, using as input the actual land cover map. I tried doing that with r.neighbors (taking method=mode) with neighborhoods of increasing size, to replace null pixels with the most common land cover class in the neighborhood. I also tried that with r.fill.stats which is basically the same thing.

However, the results gets very homogeneous, since the interpolated null cells always get the value of the most common land cover class.

Do anyway know of a method in GRASS to perform a “probabilistic” neirighborhood analysis, where cells in a neighborhood are given weights (possibly related to the distance to the central cell and to their frequency) and these weights are used to stocastically sample a value to fill the central cell?

If not in GRASS, does anyway know of such a method in a different platform, i.e. R?

Thanks!

Best

Bernardo


grass-user mailing list

grass-user@lists.osgeo.org

https://lists.osgeo.org/mailman/listinfo/grass-user

Markus Neteler, PhD

https://www.mundialis.de - free data with free software

https://grass.osgeo.org

https://courses.neteler.org/blog


grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Hi Bernardo,

On Mon, Jan 16, 2023 at 11:19 PM Bernardo Santos
<bernardo_brandaum@yahoo.com.br> wrote:

Hi Makus,

Nice suggestion, I did not know about this function within r.mapcalc (it is quite hidden!)

Do you (or anyone else) have a suggestion how to make it more visible?
Ideas welcome.

thanks,
Markus