[GRASS-user] help to use r.mapcalc with decimal/binary (modis
glynn at gclements.plus.com
Thu May 24 20:01:43 EDT 2007
andrew.haywood at poyry.com wrote:
> i am having some issues with analysing MOD09 modis data in grass. I
> would like to mask out the cloud pixels using the below quality control
> when i import this band the unsigned 16bit integer is converted in decimal
> and I am unsure how to use r.mapcalc to create a mask based on the
> different bits.
> I am unsure how I should go about this (see *** section below). I would
> like to try different selections to see which would make the best mask but
> i am unsure how to do this against a binary field
> eg. r.mapcalc MASK="if(sur_refl_qc_250 == **** clear state **** , 1,
> how do I select out the different bits to create the mask?
> At this stage i am thinking of trying to convert the decimal back to
> binary (not sure how to do this ) and then subselect columns (bits) eg 0-1
> or 2-3 and the placing an if statement (eg. if column01 == "00" or if
> column23 = "00").
r.mapcalc MASK="if(sur_refl_qc_250 & 3 == 0 , 1, null())"
Given your description of the various bits, the coresponding masks are:
The value to compare will need to be shifted into the correct range,
e.g. for "band 1 quality = missing input":
r.mapcalc MASK="if(sur_refl_qc_250 & 0x00F0 == 0x00B0 , 1, null())"
If you're unfamiliar with binary arithmetic, there's some information
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user