Flags

class sofia_redux.scan.flags.flags.Flags[source]

Bases: ABC

The Flags class contains methods to manipulate flagging.

Attributes Summary

descriptions

flags

letters

Methods Summary

all_excluding(flag)

Return all available flags with the exception of the one given here.

all_flags()

Return the flag containing all flags.

and_operation(values, flag)

Return the result of an "and" operation with a given flag.

convert_flag(flag)

Convert a flag in various forms to a standard enum format.

discard_indices(flag_array[, flag, criterion])

Return indices to discard for a given criterion/flag.

discard_mask(flag_array[, flag, criterion])

Return a mask indicating which flags do not match certain conditions.

edit_header(header[, prefix])

Add the flags to a FITS header.

flag_mask(flag_array[, flag, criterion])

Return a mask indicating which flags that meet certain conditions.

flag_to_description(flag)

Return a description of a given flag.

flag_to_letter(flag)

Return a letter representation of a given flag.

flagged_indices(flag_array[, flag, criterion])

Return indices to for a given criterion/flag.

is_flagged(thing[, flag, indices, exact])

Return whether a given argument is flagged.

is_unflagged(thing[, flag, indices, exact])

Return whether a given argument is flagged.

letter_to_flag(letter)

Return the associated flag for a given string letter identifier.

or_operation(values, flag)

Return the result of an "or" operation with a given flag.

parse_string(text)

Return the flag for a string of letter identifiers.

to_letters(flag)

Convert a flag or flags to a string representation.

unflag(flag, remove_flag)

Return the result of unflagging one flag by another.

Attributes Documentation

descriptions = {}
flags = None
letters = {}

Methods Documentation

classmethod all_excluding(flag)[source]

Return all available flags with the exception of the one given here.

Parameters:
flagstr or int or enum.Enum

The flag to not include.

Returns:
flagenum.Enum
classmethod all_flags()[source]

Return the flag containing all flags.

Returns:
all_flagsenum.Enum
classmethod and_operation(values, flag)[source]

Return the result of an “and” operation with a given flag.

Parameters:
valuesint or str or enum.Enum or numpy.ndarray (int)

The values to “and”.

flagint or str or enum.Enum

The flag to “and” with.

Returns:
and_resultint or numpy.ndarray (int)
classmethod convert_flag(flag)[source]

Convert a flag in various forms to a standard enum format.

Parameters:
flagenum.Enum or None or int or str

None will return flag(0). str values will look for that given flag name and may also use the ‘|’ character to provide a combination of flags.

Returns:
enum.Enum
classmethod discard_indices(flag_array, flag=None, criterion=None)[source]

Return indices to discard for a given criterion/flag.

Parameters:
flag_arraynumpy.ndarray (int)

An array of integer flags to check.

flagint or str or enum.Enum, optional

The flag to check against. If not supplied and non-zero flag is considered fair game in the relevant criterion schema.

criterionstr, optional

May be one of {‘DISCARD_ANY’, ‘DISCARD_ALL’, ‘DISCARD_MATCH’, ‘KEEP_ANY’, ‘KEEP_ALL’, ‘KEEP_MATCH’}. If not supplied, ‘DISCARD_ANY’ will be used if a flag is not supplied, and ‘DISCARD_ALL’ will be used if a flag is supplied. The ‘_ANY’ suffix means flag is irrelevant and any non-zero value will be considered “flagged”. ‘_ALL’ means that flagged values will contain ‘flag’, and ‘_MATCH’ means that flagged values will exactly equal ‘flag’. ‘KEEP_’ inverts the True/False meaning of the output.

Returns:
indicesnumpy.ndarray (int) or tuple (int)

The indices to discard. If flag_array has multiple dimensions, the result will be a tuple of integer arrays as would be returned by np.nonzero(). Otherwise a 1-D integer array will be returned.

classmethod discard_mask(flag_array, flag=None, criterion=None)[source]

Return a mask indicating which flags do not match certain conditions.

Parameters:
flag_arraynumpy.ndarray (int)

An array of integer flags to check.

flagint or str or enum.Enum, optional

The flag to check against. If not supplied and non-zero flag is considered fair game in the relevant criterion schema.

criterionstr, optional

May be one of {‘DISCARD_ANY’, ‘DISCARD_ALL’, ‘DISCARD_MATCH’, ‘KEEP_ANY’, ‘KEEP_ALL’, ‘KEEP_MATCH’}. If not supplied, ‘DISCARD_ANY’ will be used if a flag is not supplied, and ‘DISCARD_ALL’ will be used if a flag is supplied. The ‘_ANY’ suffix means flag is irrelevant and any non-zero value will be considered “flagged”. ‘_ALL’ means that flagged values will contain ‘flag’, and ‘_MATCH’ means that flagged values will exactly equal ‘flag’. ‘KEEP_’ inverts the True/False meaning of the output.

Returns:
masknumpy.ndarray (bool)

An array the same shape as flag_array where True indicated that element met the given criterion.

classmethod edit_header(header, prefix='')[source]

Add the flags to a FITS header.

Parameters:
headerastropy.io.fits.header.Header

The FITS header to edit.

prefixstr, optional

An optional prefix to add to the header key name.

Returns:
None
classmethod flag_mask(flag_array, flag=None, criterion=None)[source]

Return a mask indicating which flags that meet certain conditions.

This is basically the same as discard_mask, but the meanings of KEEP and DISCARD are swapped.

Parameters:
flag_arraynumpy.ndarray (int)

An array of integer flags to check.

flagint or str or enum.Enum, optional

The flag to check against. If not supplied and non-zero flag is considered fair game in the relevant criterion schema.

criterionstr, optional

May be one of {‘DISCARD_ANY’, ‘DISCARD_ALL’, ‘DISCARD_MATCH’, ‘KEEP_ANY’, ‘KEEP_ALL’, ‘KEEP_MATCH’}. If not supplied, ‘KEEP_ANY’ will be used if a flag is not supplied, and ‘KEEP_ALL’ will be used if a flag is supplied. The ‘_ANY’ suffix means flag is irrelevant and any non-zero value will be considered “flagged”. ‘_ALL’ means that flagged values will contain ‘flag’, and ‘_MATCH’ means that flagged values will exactly equal ‘flag’. ‘KEEP_’ inverts the True/False meaning of the output.

Returns:
masknumpy.ndarray (bool)

An array the same shape as flag_array where True indicated that element met the given criterion.

classmethod flag_to_description(flag)[source]

Return a description of a given flag.

Parameters:
flagenum.Enum or None or int or str

None will return flag(0). str values will look for that given flag name and may also use the ‘|’ character to provide a combination of flags.

Returns:
str
classmethod flag_to_letter(flag)[source]

Return a letter representation of a given flag.

Parameters:
flagenum.Enum or None or int or str

None will return flag(0). str values will look for that given flag name and may also use the ‘|’ character to provide a combination of flags.

Returns:
str
classmethod flagged_indices(flag_array, flag=None, criterion=None)[source]

Return indices to for a given criterion/flag.

This is the same as discard_indices with switched meanings of ‘DISCARD’ and ‘KEEP’.

Parameters:
flag_arraynumpy.ndarray (int)

An array of integer flags to check.

flagint or str or enum.Enum, optional

The flag to check against. If not supplied and non-zero flag is considered fair game in the relevant criterion schema.

criterionstr, optional

May be one of {‘DISCARD_ANY’, ‘DISCARD_ALL’, ‘DISCARD_MATCH’, ‘KEEP_ANY’, ‘KEEP_ALL’, ‘KEEP_MATCH’}. If not supplied, ‘KEEP_ANY’ will be used if a flag is not supplied, and ‘KEEP_ALL’ will be used if a flag is supplied. The ‘_ANY’ suffix means flag is irrelevant and any non-zero value will be considered “flagged”. ‘_ALL’ means that flagged values will contain ‘flag’, and ‘_MATCH’ means that flagged values will exactly equal ‘flag’. ‘KEEP_’ inverts the True/False meaning of the output.

Returns:
indicesnumpy.ndarray (int) or tuple (int)

The indices to discard. If flag_array has multiple dimensions, the result will be a tuple of integer arrays as would be returned by np.nonzero(). Otherwise a 1-D integer array will be returned.

classmethod is_flagged(thing, flag=None, indices=False, exact=False)[source]

Return whether a given argument is flagged.

Parameters:
thingnumpy.ndarray (int) or str or enum.Enum or int

An array of flags or a flag identifier.

flagenum.Enum or int or str, optional

The flag to check.

indicesbool, optional

If True return an array of integer indices as returned by np.nonzero(). Otherwise, return a boolean mask.

exactbool, optional

If True, a value will only be considered flagged if it matches the given flag exactly.

Returns:
flaggednumpy.ndarray (int or bool) or bool or tuple (int)

If indices is True (only applicable when thing is an array), returns a numpy array of ints if the number of dimensions is 1. For N-D arrays the output will be similar to np.nonzero(). If thing is an array and indices is False, a boolean mask will be returned. If thing contains a single value then True or False will be returned.

classmethod is_unflagged(thing, flag=None, indices=False, exact=False)[source]

Return whether a given argument is flagged.

Parameters:
thingnumpy.ndarray (int) or str or enum.Enum or int

An array of flags or a flag identifier.

flagenum.Enum or int or str, optional

The flag to check.

indicesbool, optional

If True return an array of integer indices as returned by np.nonzero(). Otherwise, return a boolean mask.

exactbool, optional

If True, a value will only be considered unflagged if it is not exactly equal to the given flag.

Returns:
flaggednumpy.ndarray (int or bool) or bool or tuple (int)

If indices is True (only applicable when thing is an array), returns a numpy array of ints if the number of dimensions is 1. For N-D arrays the output will be similar to np.nonzero(). If thing is an array and indices is False, a boolean mask will be returned. If thing contains a single value then True or False will be returned.

classmethod letter_to_flag(letter)[source]

Return the associated flag for a given string letter identifier.

Parameters:
letterstr

A length 1 string.

Returns:
flagenum.Enum
classmethod or_operation(values, flag)[source]

Return the result of an “or” operation with a given flag.

Parameters:
valuesint or str or enum.Enum or numpy.ndarray (int)

The values to “or”.

flagint or str or enum.Enum

The flag to “or” with.

Returns:
or_resultint or numpy.ndarray (int)
classmethod parse_string(text)[source]

Return the flag for a string of letter identifiers.

Parameters:
textstr

A string containing single letter flag identifiers.

Returns:
flagenum.Enum
classmethod to_letters(flag)[source]

Convert a flag or flags to a string representation.

Parameters:
flagstr or int or enum.Enum or iterable

The flag(s) to convert.

Returns:
str or numpy.ndarray (str)
classmethod unflag(flag, remove_flag)[source]

Return the result of unflagging one flag by another.

Parameters:
flagint or str or enum.Enum

The base flag.

remove_flagint or str or enum.Enum

The flag to remove.

Returns:
enum.Enum