interpret_bit_flags#
- astropy.nddata.interpret_bit_flags(bit_flags, flip_bits=None, flag_name_map=None)[source]#
Converts input bit flags to a single integer value (bit mask) or
None
.When input is a list of flags (either a Python list of integer flags or a string of comma-,
'|'
-, or'+'
-separated list of flags), the returned bit mask is obtained by summing input flags.Note
In order to flip the bits of the returned bit mask, for input of
str
type, prepend ‘~’ to the input string. ‘~’ must be prepended to the entire string and not to each bit flag! For input that is already a bit mask or a Python list of bit flags, setflip_bits
forTrue
in order to flip the bits of the returned bit mask.- Parameters:
- bit_flags
int
,str
,list
,None
An integer bit mask or flag,
None
, a string of comma-,'|'
- or'+'
-separated list of integer bit flags or mnemonic flag names, or a Python list of integer bit flags. Ifbit_flags
is astr
and if it is prepended with ‘~’, then the output bit mask will have its bits flipped (compared to simple sum of input flags). For inputbit_flags
that is already a bit mask or a Python list of bit flags, bit-flipping can be controlled throughflip_bits
parameter.Note
When
bit_flags
is a list of flag names, theflag_name_map
parameter must be provided.Note
Only one flag separator is supported at a time.
bit_flags
string should not mix','
,'+'
, and'|'
separators.- flip_bitsbool,
None
Indicates whether or not to flip the bits of the returned bit mask obtained from input bit flags. This parameter must be set to
None
when inputbit_flags
is eitherNone
or a Python list of flags.- flag_name_map
BitFlagNameMap
A
BitFlagNameMap
object that provides mapping from mnemonic bit flag names to integer bit values in order to translate mnemonic flags to numeric values whenbit_flags
that are comma- or ‘+’-separated list of menmonic bit flag names.
- bit_flags
- Returns:
Examples
>>> from astropy.nddata.bitmask import interpret_bit_flags, extend_bit_flag_map >>> ST_DQ = extend_bit_flag_map('ST_DQ', CR=1, CLOUDY=4, RAINY=8, HOT=16, DEAD=32) >>> "{0:016b}".format(0xFFFF & interpret_bit_flags(28)) '0000000000011100' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags('4,8,16')) '0000000000011100' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags('CLOUDY,RAINY,HOT', flag_name_map=ST_DQ)) '0000000000011100' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags('~4,8,16')) '1111111111100011' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags('~(4+8+16)')) '1111111111100011' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags('~(CLOUDY+RAINY+HOT)', ... flag_name_map=ST_DQ)) '1111111111100011' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags([4, 8, 16])) '0000000000011100' >>> "{0:016b}".format(0xFFFF & interpret_bit_flags([4, 8, 16], flip_bits=True)) '1111111111100011'