[GRASS-user] MAP Calculator mean of eight neighbors to interpolate 0 value in raster map

if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
[0,-1],[1,-1])/8))

I want to use mapcalc to do the above. I am missing a syntax step.
if a value is zero take the average of the eight nearest neighbors and
replace the value with this. Otherwise, keep the value unchanged

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis

r.mapcalc "newmap = if ( yourmap==0 , ( sum( yourmap[-1,1] ,
yourmap[0,1] , ...)/8 ) , yourmap)"

is that what you mean?

stephen sefick schrieb:

if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
[0,-1],[1,-1])/8))

I want to use mapcalc to do the above. I am missing a syntax step.
if a value is zero take the average of the eight nearest neighbors and
replace the value with this. Otherwise, keep the value unchanged

I think so- let me try it

On Fri, Aug 28, 2009 at 12:04 PM, achim<ak7@jupiter.uni-freiburg.de> wrote:

r.mapcalc "newmap = if ( yourmap==0 , ( sum( yourmap[-1,1] ,
yourmap[0,1] , ...)/8 ) , yourmap)"

is that what you mean?

stephen sefick schrieb:

if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
[0,-1],[1,-1])/8))

I want to use mapcalc to do the above. I am missing a syntax step.
if a value is zero take the average of the eight nearest neighbors and
replace the value with this. Otherwise, keep the value unchanged

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis

May be something like:
(please, check several values!)

r.mapcalc “B=if(A==0, sum(A[-1,-1], A[0, -1], A[1,-1], A[-1,0], A[1,0], A[-1,1], A[0, 1], A[1,1])/8, A”)

cheers

milton

2009/8/28 stephen sefick <ssefick@gmail.com>

if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
[0,-1],[1,-1])/8))

I want to use mapcalc to do the above. I am missing a syntax step.
if a value is zero take the average of the eight nearest neighbors and
replace the value with this. Otherwise, keep the value unchanged


Stephen Sefick

Let’s not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis


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

Hi stephen,

just to remember not include yourmap[0,0]

bests
milton

2009/8/28 stephen sefick <ssefick@gmail.com>

I think so- let me try it

On Fri, Aug 28, 2009 at 12:04 PM, achim<ak7@jupiter.uni-freiburg.de> wrote:

r.mapcalc “newmap = if ( yourmap==0 , ( sum( yourmap[-1,1] ,
yourmap[0,1] , …)/8 ) , yourmap)”

is that what you mean?

stephen sefick schrieb:

if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
[0,-1],[1,-1])/8))

I want to use mapcalc to do the above. I am missing a syntax step.
if a value is zero take the average of the eight nearest neighbors and
replace the value with this. Otherwise, keep the value unchanged


Stephen Sefick

Let’s not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis


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

This does not quite work for my purposes. The problem is the the 0
values are in a 2 or 3 grid wide seam in between patched raster maps,
so the value is lower than it should be using

r.mapcalc "benning_dem=if(patch_benning==0,
(patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
patch_benning)"

any thoughts,

Stephen Sefick

On Fri, Aug 28, 2009 at 12:08 PM, Milton Cezar
Ribeiro<miltinho.astronauta@gmail.com> wrote:

Hi stephen,

just to remember not include yourmap[0,0]
bests
milton
2009/8/28 stephen sefick <ssefick@gmail.com>

I think so- let me try it

On Fri, Aug 28, 2009 at 12:04 PM, achim<ak7@jupiter.uni-freiburg.de>
wrote:
> r.mapcalc "newmap = if ( yourmap==0 , ( sum( yourmap[-1,1] ,
> yourmap[0,1] , ...)/8 ) , yourmap)"
>
> is that what you mean?
>
> stephen sefick schrieb:
>> if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
>> [0,-1],[1,-1])/8))
>>
>> I want to use mapcalc to do the above. I am missing a syntax step.
>> if a value is zero take the average of the eight nearest neighbors and
>> replace the value with this. Otherwise, keep the value unchanged
>>
>

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                                                           \-K\. Mullis

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

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis

Hi Stephen, may be you can share some picture?

bests

milton

2009/8/28 stephen sefick <ssefick@gmail.com>

This does not quite work for my purposes. The problem is the the 0
values are in a 2 or 3 grid wide seam in between patched raster maps,
so the value is lower than it should be using

r.mapcalc “benning_dem=if(patch_benning==0,
(patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
patch_benning)”

any thoughts,

Stephen Sefick

On Fri, Aug 28, 2009 at 12:08 PM, Milton Cezar
Ribeiro<miltinho.astronauta@gmail.com> wrote:

Hi stephen,

just to remember not include yourmap[0,0]
bests
milton
2009/8/28 stephen sefick <ssefick@gmail.com>

I think so- let me try it

On Fri, Aug 28, 2009 at 12:04 PM, achim<ak7@jupiter.uni-freiburg.de>
wrote:

r.mapcalc “newmap = if ( yourmap==0 , ( sum( yourmap[-1,1] ,
yourmap[0,1] , …)/8 ) , yourmap)”

is that what you mean?

stephen sefick schrieb:

if(0, (sum([-1,1], [0, 1], [1,1], [-1,0], [0,0], [1,0],[-1,-1],
[0,-1],[1,-1])/8))

I want to use mapcalc to do the above. I am missing a syntax step.
if a value is zero take the average of the eight nearest neighbors and
replace the value with this. Otherwise, keep the value unchanged


Stephen Sefick

Let’s not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis


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

Stephen Sefick

Let’s not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

stephen sefick wrote:

This does not quite work for my purposes. The problem is the the 0
values are in a 2 or 3 grid wide seam in between patched raster maps,
so the value is lower than it should be using

r.mapcalc "benning_dem=if(patch_benning==0,
(patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
patch_benning)"

any thoughts,

Do you want the average of all of the surrounding values, or only the
non-zero values?

If you replace the zeros with nulls, you can use r.neighbors and
r.patch.

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

only the no zero values. I could probably do something like if
patch_benning[-1,-1]>0 etc., but I don not know how to code the number
of non-zero numbers in the divisor to get and average. Thanks for all
of the help.

Stephen Sefick

On Fri, Aug 28, 2009 at 1:44 PM, Glynn Clements<glynn@gclements.plus.com> wrote:

stephen sefick wrote:

This does not quite work for my purposes. The problem is the the 0
values are in a 2 or 3 grid wide seam in between patched raster maps,
so the value is lower than it should be using

r.mapcalc "benning_dem=if(patch_benning==0,
(patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
patch_benning)"

any thoughts,

Do you want the average of all of the surrounding values, or only the
non-zero values?

If you replace the zeros with nulls, you can use r.neighbors and
r.patch.

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

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis

what about setting all zero-values to NULL
(r.mapcalc "nullmap=(if (map==0,null(),map)")
and then running r.fillnulls?
(http://grass.itc.it/grass64/manuals/html64_user/r.fillnulls.html)

A.

stephen sefick schrieb:

only the no zero values. I could probably do something like if
patch_benning[-1,-1]>0 etc., but I don not know how to code the number
of non-zero numbers in the divisor to get and average. Thanks for all
of the help.

Stephen Sefick

On Fri, Aug 28, 2009 at 1:44 PM, Glynn Clements<glynn@gclements.plus.com> wrote:

stephen sefick wrote:

This does not quite work for my purposes. The problem is the the 0
values are in a 2 or 3 grid wide seam in between patched raster maps,
so the value is lower than it should be using

r.mapcalc "benning_dem=if(patch_benning==0,
(patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
patch_benning)"

any thoughts,

Do you want the average of all of the surrounding values, or only the
non-zero values?

If you replace the zeros with nulls, you can use r.neighbors and
r.patch.

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

I tried this and it gave unsatisfactory results. I used the default
settings. I don't remember exactly why the results were
unsatisfactory, but I will check when I get home. This will be in
about thirty minutes.
regards,

Stephen Sefick

On Fri, Aug 28, 2009 at 4:33 PM, achim<ak7@jupiter.uni-freiburg.de> wrote:

what about setting all zero-values to NULL
(r.mapcalc "nullmap=(if (map==0,null(),map)")
and then running r.fillnulls?
(http://grass.itc.it/grass64/manuals/html64_user/r.fillnulls.html)

A.

stephen sefick schrieb:

only the no zero values. I could probably do something like if
patch_benning[-1,-1]>0 etc., but I don not know how to code the number
of non-zero numbers in the divisor to get and average. Thanks for all
of the help.

Stephen Sefick

On Fri, Aug 28, 2009 at 1:44 PM, Glynn Clements<glynn@gclements.plus.com> wrote:

stephen sefick wrote:

This does not quite work for my purposes. The problem is the the 0
values are in a 2 or 3 grid wide seam in between patched raster maps,
so the value is lower than it should be using

r.mapcalc "benning_dem=if(patch_benning==0,
(patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
patch_benning)"

any thoughts,

Do you want the average of all of the surrounding values, or only the
non-zero values?

If you replace the zeros with nulls, you can use r.neighbors and
r.patch.

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

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis

stephen sefick wrote:

>> This does not quite work for my purposes. The problem is the the 0
>> values are in a 2 or 3 grid wide seam in between patched raster maps,
>> so the value is lower than it should be using
>>
>> r.mapcalc "benning_dem=if(patch_benning==0,
>> (patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
>> patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
>> patch_benning)"
>>
>> any thoughts,
>
> Do you want the average of all of the surrounding values, or only the
> non-zero values?

only the no zero values. I could probably do something like if
patch_benning[-1,-1]>0 etc., but I don not know how to code the number
of non-zero numbers in the divisor to get and average.

r.mapcalc "benning_dem = eval( \
  m = patch_benning, \
  numer = m[-1,-1]+ m[-1,0]+ m[-1,1]+ m[0,-1]+ m[0,1]+ m[1,-1]+ m[1,0]+ m[1,1], \
  denom = !m[-1,-1]+!m[-1,0]+!m[-1,1]+!m[0,-1]+!m[0,1]+!m[1,-1]+!m[1,0]+!m[1,1], \
  if(m,m,numer/denom))

The "!" (logical "not") operator returns 1 if its operand is zero and
0 otherwise.

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

I must have made a miss-step because turning the 0 to null and then
used r.fillnulls. Thanks everybody for there very helpful responses.
I did get to learn about mapcalc in the process.
kind regards,

Stephen Sefick

On Fri, Aug 28, 2009 at 5:21 PM, Glynn Clements<glynn@gclements.plus.com> wrote:

stephen sefick wrote:

>> This does not quite work for my purposes. The problem is the the 0
>> values are in a 2 or 3 grid wide seam in between patched raster maps,
>> so the value is lower than it should be using
>>
>> r.mapcalc "benning_dem=if(patch_benning==0,
>> (patch_benning[-1,-1]+patch_benning[1,-1]+patch_benning[-1,0]+
>> patch_benning[1,0]+patch_benning[-1,1]+patch_benning[1,1])/6,
>> patch_benning)"
>>
>> any thoughts,
>
> Do you want the average of all of the surrounding values, or only the
> non-zero values?

only the no zero values. I could probably do something like if
patch_benning[-1,-1]>0 etc., but I don not know how to code the number
of non-zero numbers in the divisor to get and average.

r.mapcalc "benning_dem = eval( \
m = patch_benning, \
numer = m[-1,-1]+ m[-1,0]+ m[-1,1]+ m[0,-1]+ m[0,1]+ m[1,-1]+ m[1,0]+ m[1,1], \
denom = !m[-1,-1]+!m[-1,0]+!m[-1,1]+!m[0,-1]+!m[0,1]+!m[1,-1]+!m[1,0]+!m[1,1], \
if(m,m,numer/denom))

The "!" (logical "not") operator returns 1 if its operand is zero and
0 otherwise.

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

--
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

                -K. Mullis