bitmask module

The bitmask module provides routines for working with bitmasks, and defines a PixelBitMask.

A bitmask is an integer (for pyvista Data objects, a 32-bit integer), where each bit can be used to flag a particular condition, so instead of just having a boolean mask (good or bad), it can be more nuanced. It is possible that one might have bits in a bitmask that flag a condition that should be recogized, but does not necessarily imply that the data are bad. To accomodate that, a defined bitmask identifies conditions for each bit, and also include a flag to denote whether that conidition is sufficient to deem a pixel as bad.

The pyvista PixelBitMask include bits for bad pixels, pixels identified as cosmic rays, saturated pixels, etc. Definitions for a complete set are still in progress.

One uses a bitmask by instantiating an object, e.g.,

from pyvista import bitmask
pixmask = bitmask.PixelBitMask()

This then has methods for associating a bit with a name (getname() and getval()) and for checking whether a given bitmask value denotes that the pixel is bad. For example,

satpix = np.where(bitmaskarray & pixmask.getval('SATPIX'))

can be used to identify pixels flagged as saturated.

badpix = np.where(bitmaskarray & pixmask.badval())

can be used to identify pixels flagged as bad (any of the bad bits set).

To see the PixelBitMask definitions, you can instantite a bitmask object and use the print() method, e.g.:

pixmask.print()

bitmask functions

class pyvista.bitmask.BitMask[source]

Base class for bitmasks, define common methods

At a minimum, a BitMask will have a set of name, level, descrip

BitMask provides 3 methods:
getname(val,level=level)returns name(s) of all set bits

(optionally, of requested level)

getval(name) : returns value of bit with input name badval() : returns value of all bits that are marked bad (level=1) warnval() : returns value of all bits that are marked warn (level=2)

getname(val, level=0, strip=True)[source]

Given input value, returns names of all set bits, optionally of a given level

getval(name)[source]

Get the numerical bit value of a given character name(s)

badval()[source]

Return bitmask value of all bits that indicate BAD in input bitmask

warnval()[source]

Return bitmask value of all bits that indicate BAD in input bitmask

print(fmt='txt', fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Formatted output of bit definitions

class pyvista.bitmask.PixelBitMask[source]

BitMask class for APOGEE pixel bitmask (APOGEE_PIXMASK)