eebit.bitmask#

Bitmask module.

Classes#

Bit

Initialize a Bit.

BitGroup

Initialize a bit group.

BitMask

Initialize a bitmask.

Module Contents#

class eebit.bitmask.Bit(position, positive, negative=None)[source]#

Initialize a Bit.

Parameters:
  • position (int | str) – position of the bit.

  • positive (str) – positive bit description.

  • negative (str | None) – negative bit description. If None, it uses “no {positive}”.

is_negative(value)[source]#

Check if a value is negative for this bit.

Parameters:

value (int) – the value to check.

Returns:

True if the value is negative for this bit, False otherwise.

Return type:

bool

is_positive(value)[source]#

Check if a value is positive for this bit.

Parameters:

value (int) – the value to check.

Returns:

True if the value is positive for this bit, False otherwise.

Return type:

bool

negative_values(n_bits=None)[source]#

Get the negative values of the bit.

Parameters:

n_bits (int | None) – number of bits to consider. If None, it uses the bit position + 1.

Return type:

list

positive_values(n_bits=None)[source]#

Get the positive values of the bit.

Parameters:

n_bits (int | None) – number of bits to consider. If None, it uses the bit position + 1.

Return type:

list

to_bit_group(description)[source]#

Convert a Bit to a BitGroup.

Parameters:

description (str) – description of the bit group.

Returns:

A BitGroup object.

Return type:

BitGroup

property max_value: int[source]#

Get the maximum value of the bit.

Return type:

int

property min_value: int[source]#

Get the minimum value of the bit.

Return type:

int

negative = 'no Uninferable'[source]#
positive[source]#
property value_map: dict[Literal['0', '1'], str][source]#

Get the value map of the bit.

Return type:

dict[Literal[‘0’, ‘1’], str]

class eebit.bitmask.BitGroup(description, min_position, max_position, value_map)[source]#

Initialize a bit group.

Parameters:
  • min_position (int) – minimum position of the bit group.

  • max_position (int) – maximum position of the bit group.

  • value_map (dict) – a dict with the bit positions as keys and the bit descriptions as values. {bit-key: bit-value}

  • description (str) – description of the bit group. Different from each bit descriptions in the value_map.

_get_key_for_bit_value(value)[source]#

Get the key for a given bit value.

Parameters:

value (str) – the bit value to get the key for.

Return type:

int

_get_value_for_bit_key(key)[source]#

Get the bit value for a given bit key.

Parameters:

key (int)

Return type:

str

decode_to_columns(table, column)[source]#

Decode a column in a FeatureCollection into multiple columns.

Parameters:
  • table (ee.FeatureCollection) – the FeatureCollection to decode.

  • column (str) – the column to decode.

Returns:

A new FeatureCollection with one column per bit value in the group.

Return type:

ee.FeatureCollection

decode_value(value)[source]#

Decode a value into its description.

Parameters:

value (int) – the value to decode.

Returns:

The description of the value, or None if not found.

Return type:

str | None

classmethod from_dict(bit_info)[source]#

Create a BitGroup from a dict.

Parameters:

bit_info (dict) – a dict with the bit positions as keys and the bit descriptions as values.

Returns:

A BitGroup object.

Return type:

BitGroup

get_mask_by_bit_value(image, value)[source]#

Get a mask for a given bit value in the group.

Parameters:
  • image (ee.Image) – the image to get the mask from.

  • value (str) – the bit value to get the mask for.

Returns:

A binary image with 1 for pixels that have the description, and 0 otherwise.

Return type:

ee.Image

get_mask_by_position(image, position)[source]#

Get a mask for a given bit position in the group.

Parameters:
  • image (ee.Image) – the image to get the mask from.

  • position (int | str) – the position of the bit in the group.

Returns:

A binary image with 1 for pixels that have the bit set, and 0 otherwise.

Return type:

ee.Image

get_masks(image)[source]#

Get masks for all bit values in the group.

Parameters:

image (ee.Image) – the image to get the masks from.

Returns:

An image with one band per bit value in the group.

Return type:

ee.Image

is_positive(value, key=None, description=None)[source]#

Check if a value is positive for this bit group.

Parameters:
  • value (int) – the value to check.

  • key (int | str | None) – the key to check.

  • description (str | None) – the description to check.

Returns:

True if the value is positive for the passed key or description, False otherwise.

Return type:

bool

is_positive_by_description(value, description)[source]#

Check if a value is positive for this description.

Parameters:
  • value (int) – the value to check.

  • description (str) – the description to check.

Returns:

True if the value is positive for the passed description, False otherwise.

Return type:

bool

is_positive_by_description_gee(value, description)[source]#

Check if a value is positive for this description using GEE.

Parameters:
  • value (ee.Number) – the value to check.

  • description (str) – the description to check.

Returns:

True if the value is positive for the passed description, False otherwise.

Return type:

bool

is_positive_by_key(value, key)[source]#

Check if a value is positive for this key.

Parameters:
  • value (int) – the value to check.

  • key (int | str) – the key to check.

Returns:

True if the value is positive for the passed key, False otherwise.

Return type:

bool

is_positive_by_key_gee(value, key)[source]#

Check if a value is positive for this key using GEE.

Parameters:
  • value (ee.Number) – the value to check.

  • key (int | str) – the key to check.

Returns:

True if the value is positive for the passed key, False otherwise.

Return type:

bool

is_positive_gee(value, key=None, description=None)[source]#

Check if a value is positive for this bit group using GEE.

Parameters:
  • value (ee.Number) – the value to check.

  • key (int | str | None) – the key to check.

  • description (str | None) – the description to check.

Returns:

True if the value is positive for the passed key or description, False otherwise.

Return type:

bool

to_dict()[source]#

Convert a bit group to a dict.

Return type:

dict

BAND_NAME_PATTERN = '{description} - {value}'[source]#
_reverse_value_map[source]#
property bit_values: list[str][source]#

Get the list of bit values in the value map.

Return type:

list[str]

description[source]#
property group_mask: int[source]#

Get the mask for the entire group.

Return type:

int

max_position[source]#
min_position[source]#
n_values[source]#
value_map[source]#
class eebit.bitmask.BitMask(bits, total=None)[source]#

Initialize a bitmask.

Parameters:
  • bits (list[BitGroup]) – a list of BitGroup.

  • total (int | None) – total number of bits. If None, it uses the maximum position of the last group + 1.

bit_values()[source]#

Get the list of bit values in the bitmask.

Return type:

list[str]

decode_to_columns(table, column)[source]#

Decode a column in a FeatureCollection into multiple columns.

Parameters:
  • table (ee.FeatureCollection) – the FeatureCollection to decode.

  • column (str) – the column to decode.

Returns:

A new FeatureCollection with one column per bit value in the bitmask.

Return type:

ee.FeatureCollection

decode_value(value)[source]#

Decode a value into its descriptions.

Parameters:

value (int) – the value to decode.

Returns:

A dict with the descriptions of the value, or None if not found.

Return type:

dict[str, str | None]

classmethod from_dict(bits_info)[source]#

Create a BitMask from a dict.

Parameters:

bits_info (dict)

Return type:

BitMask

get_group_by_description(description)[source]#

Get the BitGroup that match a given description.

Parameters:

description (str) – the description to search for.

Returns:

The BitGroup that match the given description.

Return type:

BitGroup

get_masks(image)[source]#

Get masks for all bit values in the bitmask.

Returns:

An image with one band per bit value in the bitmask.

Parameters:

image (ee.Image)

Return type:

ee.Image

to_dict()[source]#

Convert a Bitmask into a dict.

Return type:

dict

bits = [][source]#
total[source]#