[GRASS-dev] strange mapcalc result

This is from GRASS 7 compiled from svn trunk yesterday.

I'm simply trying to assign null values in an SRTM using r.mapcalc. I do the following statement...

r.mapcalc expression='SRTM_ffB03_p199r033=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

The entire map turns to null.

Any idea what I'm doing wrong?

Michael

____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University

voice: 480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu

Michael Barton wrote:

This is from GRASS 7 compiled from svn trunk yesterday.

I'm simply trying to assign null values in an SRTM using r.mapcalc. I do the following statement...

r.mapcalc expression='SRTM_ffB03_p199r033=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

The entire map turns to null.

Any idea what I'm doing wrong?

Using the same map for input and output results in undefined
behaviour. If you want to change a value to null "in place", use
r.null.

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

In the even that this might be the case, I also tried creating a new map

r.mapcalc expression='SRTM_ffB03_p199r033_2=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)'

...and got the same result with the new map.

r.null does work of course.

Michael
____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University

voice: 480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu

On Jul 11, 2011, at 8:54 PM, Glynn Clements wrote:

Michael Barton wrote:

This is from GRASS 7 compiled from svn trunk yesterday.

I'm simply trying to assign null values in an SRTM using r.mapcalc. I do the following statement...

r.mapcalc expression='SRTM_ffB03_p199r033=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

The entire map turns to null.

Any idea what I'm doing wrong?

Using the same map for input and output results in undefined
behaviour. If you want to change a value to null "in place", use
r.null.

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

Michael Barton wrote:

In the even that this might be the case, I also tried creating a new map

r.mapcalc expression='SRTM_ffB03_p199r033_2=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)'

...and got the same result with the new map.

No idea. r.mapcalc hasn't had any changes in months.

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

Well, maybe a fluke. I'll check again and report anything weird.

Michael
______________________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University
Tempe, AZ 85287-2402
USA

voice: 480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax: 480-965-7671(SHESC), 480-727-0709 (CSDC)
www: http://csdc.asu.edu, http://shesc.asu.edu
    http://www.public.asu.edu/~cmbarton

On Jul 13, 2011, at 1:05 AM, Glynn Clements wrote:

Michael Barton wrote:

In the even that this might be the case, I also tried creating a new map

r.mapcalc expression='SRTM_ffB03_p199r033_2=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)'

...and got the same result with the new map.

No idea. r.mapcalc hasn't had any changes in months.

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

On Mon, Jul 11, 2011 at 7:36 PM, Michael Barton <Michael.Barton@asu.edu> wrote:

This is from GRASS 7 compiled from svn trunk yesterday.

I'm simply trying to assign null values in an SRTM using r.mapcalc. I do the following statement...

r.mapcalc expression='SRTM_ffB03_p199r033=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

The entire map turns to null.

Any idea what I'm doing wrong?

Try this:

r.mapcalc expression='SRTM_ffB03_p199r033 =
if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

(note the white spaces around "=", which is required in GRASS7 - a bit
unfortunate...)

Markus

Should this be documented on wiki for grass7 new features,
so that there is one place people where can go to when updating
their scripts, workflows, edu material etc. to grass7?
http://trac.osgeo.org/grass/wiki/Grass7/NewFeatures
There is a change for r.mapcalc noted like this:
r.mapcalc: use pthreads for parsing
but it is not clear from this that every r.mapcalc expression that people have
will need to be modified to run in grass7
(if I understand the changes correctly - I haven't tried it enough yet).

Or we could just say - read the manual page for everything
when updating to grass7, it may be easier than trying to track all the changes

Helena

On Jul 17, 2011, at 12:47 PM, Markus Neteler wrote:

On Mon, Jul 11, 2011 at 7:36 PM, Michael Barton <Michael.Barton@asu.edu> wrote:

This is from GRASS 7 compiled from svn trunk yesterday.

I'm simply trying to assign null values in an SRTM using r.mapcalc. I do the following statement...

r.mapcalc expression='SRTM_ffB03_p199r033=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

The entire map turns to null.

Any idea what I'm doing wrong?

Try this:

r.mapcalc expression='SRTM_ffB03_p199r033 =
if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

(note the white spaces around "=", which is required in GRASS7 - a bit
unfortunate...)

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

I just ran this again and it works fine, with and without the spaces--and even copying over the original file. That is, it all works as originally expected it to work. I don't know why this did not work the other day. I tried it several times. The command I sent to the list was copied from my terminal produced all nulls. Now it produces the expected values.

Weird

Michael
____________________
C. Michael Barton
Director, Center for Social Dynamics & Complexity
Professor of Anthropology, School of Human Evolution & Social Change
Arizona State University

voice: 480-965-6262 (SHESC), 480-727-9746 (CSDC)
fax: 480-965-7671 (SHESC), 480-727-0709 (CSDC)
www: http://www.public.asu.edu/~cmbarton, http://csdc.asu.edu

On Jul 17, 2011, at 9:47 AM, Markus Neteler wrote:

On Mon, Jul 11, 2011 at 7:36 PM, Michael Barton <Michael.Barton@asu.edu> wrote:

This is from GRASS 7 compiled from svn trunk yesterday.

I'm simply trying to assign null values in an SRTM using r.mapcalc. I do the following statement...

r.mapcalc expression='SRTM_ffB03_p199r033=if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

The entire map turns to null.

Any idea what I'm doing wrong?

Try this:

r.mapcalc expression='SRTM_ffB03_p199r033 =
if(SRTM_ffB03_p199r033==-32768,null(),SRTM_ffB03_p199r033)' --o

(note the white spaces around "=", which is required in GRASS7 - a bit
unfortunate...)

Markus

Michael:
in general it's a bad idea to read and write to the same map in a single step from any module.
doing this task with r.null may be easier.
I'm not sure if you complied with pthreads, but if so that may change
read/write behavior vs. grass6 ?

Helena:
that r.mapcalc is now a normal module using G_parser() and so requires
special care with '=' (as described by Markus) should definitely be
mentioned in any changes from grass6 list. fwiw over the last year I've
slowly been going around updating all grass6 scripts and help examples
I've come across to add the spaces to make them forward compatible.

pthreads doesn't parse, it breaks up the processing into multiple threads
internally for a performance gain.

Hamish

Markus Neteler wrote:

(note the white spaces around "=", which is required in GRASS7 - a bit
unfortunate...)

It shouldn't be required if you explictly specify the "expression=".
It should only be required if "expression=" is omitted, to ensure that
the parser treats it as a "default option" argument and not an
option=value argument.

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