Пример #1
0
def interpret_bit_flags(bit_flags, flip_bits=None):
    """Converts input bit flags to a single integer value (bit mask) or `None`.

    Wraps `astropy.nddata.bitmask.interpret_bit_flags`, allowing the JWST
    bit mnemonics to be used in place of integers.

    Parameters
    ----------
    bit_flags : int, str, list, None
        See `astropy.nddate.bitmask.interpret_bit_flags`.
        Also allows strings using JWST mnemonics

    flip_bits : bool, None
        See `astropy.nddate.bitmask.interpret_bit_flags`.

    Returns
    -------
    bitmask : int or None
        Returns an integer bit mask formed from the input bit value or `None`
        if input ``bit_flags`` parameter is `None` or an empty string.
        If input string value was prepended with '~' (or ``flip_bits`` was set
        to `True`), then returned value will have its bits flipped
        (inverse mask).

    Examples
    --------
    Using JWST mnemonics:
    TBD
    """
    bit_flags_dm = bit_flags
    if isinstance(bit_flags, str):
        dm_flags = {key: str(val) for key, val in pixel.items()}
        bit_flags_dm = multiple_replace(bit_flags, dm_flags)

    return ap_interpret_bit_flags(bit_flags_dm, flip_bits=flip_bits)
Пример #2
0
def interpret_bit_flags(bit_flags, flip_bits=None, mnemonic_map=None):
    """Converts input bit flags to a single integer value (bit mask) or `None`.

    Wraps `astropy.nddate.bitmask.interpret_bit_flags`, allowing the
    bit mnemonics to be used in place of integers.

    Parameters
    ----------
    bit_flags : int, str, list, None
        See `astropy.nddate.bitmask.interpret_bit_flags`.
        Also allows strings using Roman mnemonics

    flip_bits : bool, None
        See `astropy.nddata.bitmask.interpret_bit_flags`.

    mnemonic_map : {str: int[,...]}
        Dictionary associating the mnemonic string to an integer value
        representing the set bit for that mnemonic.

    Returns
    -------
    bitmask : int or None
        Returns an integer bit mask formed from the input bit value or `None`
        if input ``bit_flags`` parameter is `None` or an empty string.
        If input string value was prepended with '~' (or ``flip_bits`` was set
        to `True`), then returned value will have its bits flipped
        (inverse mask).
    """
    if mnemonic_map is None:
        raise TypeError("`mnemonic_map` is a required argument")
    bit_flags_dm = bit_flags
    if isinstance(bit_flags, str):
        dm_flags = {key: str(val) for key, val in mnemonic_map.items()}
        bit_flags_dm = multiple_replace(bit_flags, dm_flags)

    return ap_interpret_bit_flags(bit_flags_dm, flip_bits=flip_bits)