geetools.bitreader#

Bit Reader module.

Module Contents#

Classes#

BitReader

Bit Reader.

class geetools.bitreader.BitReader(options, bit_length=None)[source]#

Bases: object

Bit Reader.

Initializes with parameter options, which must be a dictionary with the following format:

keys must be a str with the bits places, example: ‘0-1’ means bit 0 and bit 1

values must be a dictionary with the bit value as the key and the category (str) as value. Categories must be unique.

  • Encode: given a category/categories return a list of possible values

  • Decode: given a value return a list of categories

Example

MOD09 (http://modis-sr.ltdri.org/guide/MOD09_UserGuide_v1_3.pdf) (page 28, state1km, 16 bits):

``` options = {

‘0-1’: {0:’clear’, 1:’cloud’, 2:’mix’}, ‘2-2’: {1:’shadow’}, ‘8-9’: {1:’small_cirrus’, 2:’average_cirrus’, 3:’high_cirrus’} }

reader = BitReader(options, 16)

print(reader.decode(204)) ` >>['shadow', 'clear'] ` print(reader.match(204, ‘cloud’) ``` >>False

TODO missing docstring.

decode(value)[source]#

given a value return a list with all categories.

decodeImage(image, qa_band)[source]#

Get an Image with one band per category in the Bit Reader.

Parameters:
  • bit_reader (BitReader) – the bit reader

  • qa_band (str) – name of the band that holds the bit information

Returns:

the image with the decode bands added

static decodeKey(key)[source]#

decodes an option’s key into a list.

encode(cat)[source]#

Given a category, return the encoded value (only).

encodeAnd(*args)[source]#

Decodes a combination of the given categories. returns a list of.

possible values .

encodeBand(category, mask, name=None)[source]#

Make an image in which all pixels have the value for the given.

category.

Parameters:
  • category (str) – the category to encode

  • mask (ee.Image) – the mask that indicates which pixels encode

  • name (str) – name of the resulting band. If None it’ll be the same as ‘mask’

Returns:

A one band image

Return type:

ee.Image

encodeNot(*args)[source]#

Given a set of categories return a list of values that DO NOT.

match with any .

encodeOne(cat)[source]#

Given a category, return a list of values that match it.

encodeOr(*args)[source]#

Decodes a combination of the given categories. returns a list of.

possible values .

static getBin(bit, nbits=None, shift=0)[source]#

from https://stackoverflow.com/questions/699866/python-int-to-binary.

match(value, category)[source]#

given a value and a category return True if the value includes.

that category, else False .