[GRASS-user] help to use r.mapcalc with decimal/binary (modis data)

Dear All,

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 band.
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, null())”

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”).

Any guidance would be much appreciated.

kind regards

Andrew

sur_refl_qc_250m:

Bit Description
0-1 MODLAND QA bits;
00 – corrected product produced at ideal quality – all bands
01 – corrected product produced, less than ideal quality – some or all bands
10 – corrected product not produced due to cloud effects – all bands
11 – corrected product not produced for other reasons – some or all bands, may be fill value
[Note that a value of (11) overrides a value of (01)]
2-3 cloud state;
00 – clear
01 – cloudy
10 – mixed
11 – not set, assumed clear
4-7 band 1 data quality, four bit range;
0000 – highest quality
1000 – dead detector; data has been copied from adjacent detector
1001 – solar zenith >= 86 degrees
1010 – solar zenith >= 85 and < 86 degrees
1011 – missing input
1100 – internal constant used in place of climatological data for at least one atmospheric constant
1101 – correction out of bounds, pixel constrained to extreme allowable value
1110 – L1B data faulty
1111 – not processed due to deep ocean or clouds
8-11 band 2 data quality, four bit range;
(same values as above)
12 atmospheric correction performed;
0 – no
1 – yes
13 adjacency correction performed;
0 – no
1 – yes
14 different orbit from 500m;
0 – no
1 – yes
15 unused (spare)

This email and any files transmitted with it are confidential, may be legally privileged and are intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient, you are hereby notified that any use, distribution, or reproduction of the contents of this email is strictly prohibited and may be unlawful. If you are not the intended recipient, please notify the sender by return email and destroy all copies of the original message including any attachments thereto.
Thank you.

andrew.haywood@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
band.
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,
null())"

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").

Use

  r.mapcalc MASK="if(sur_refl_qc_250 & 3 == 0 , 1, null())"

For the

Given your description of the various bits, the coresponding masks are:

  Bits Mask
  0-1 0x0003
  2-3 0x000C
  4-7 0x00F0
  8-11 0x0F00
  12 0x1000
  13 0x2000
  14 0x4000
  15 0x8000

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
at:

  http://en.wikipedia.org/wiki/Binary_numeral_system

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