FlaggedData

class sofia_redux.scan.flags.flagged_data.FlaggedData[source]

Bases: ABC

Initialize a FlaggedData object.

The FlaggedData object contains a set of associated flags and original data indices and allows operations that include those attributes.

Attributes Summary

default_field_types

Return the default values for FlaggedData attributes.

fields

Return the available attributes of the FlaggedData object.

fixed_index

Return the fixed index.

flag

Return the associated data flags.

internal_attributes

Returns attribute names that are internal to the data for get actions.

is_singular

Return whether the data contains only a single scalar measurement.

referenced_attributes

Returns attribute names that should be referenced during a copy.

shape

Return the shape of the FlaggedData.

size

Return the size of the FlaggedData.

special_fields

Return fields that do not comply with the shape of other data.

Methods Summary

copy()

Return a copy of the data.

delete_indices(indices_or_mask)

Completely deletes data elements.

discard_flag(flag[, criterion])

Remove all data flagged with the given flag.

find_fixed_indices(fixed_indices[, cull])

Returns the actual indices given fixed indices.

get_attribute_indices(internal, attribute, ...)

Return selected indices of a given value.

get_flagged_indices([keep_flag, ...])

Return flagged indices based on a number of criteria.

get_index_size([indices])

Get indices and the size of indices covered.

get_indices(indices)

Return selected data for given indices.

insert_blanks(insert_indices)

Inserts blank frame data.

is_flagged([flag, indices])

Find flagged data indices.

is_unflagged([flag, indices])

Find data indices that are not flagged.

merge(data)

Add additional data onto the end of this data.

set_default_values()

Populate data fields with default values.

set_flags(flag[, indices])

Flag data with the supplied flag.

to_indices(indices_or_mask[, discard])

Convert an array of indices, or an array mask to the correct format.

unflag([flag, indices])

Remove data flags.

Attributes Documentation

default_field_types

Return the default values for FlaggedData attributes.

Returns:
dict

Keys contain the name of the attribute and values contain the value.

fields

Return the available attributes of the FlaggedData object.

Returns:
set (str)
fixed_index

Return the fixed index.

The fixed indices are designed to be constant irrespective of any operations, deletions, etc and provide a reverse lookup onto the original data set.

Returns:
fixed_indexnumpy.ndarray (int)
flag

Return the associated data flags.

Returns:
flagsnumpy.ndarray (int)
internal_attributes

Returns attribute names that are internal to the data for get actions.

These attributes should always be returned as-is regardless of indexing.

Returns:
set (str)
is_singular

Return whether the data contains only a single scalar measurement.

Returns:
singularbool
referenced_attributes

Returns attribute names that should be referenced during a copy.

Returns:
set (str)
shape

Return the shape of the FlaggedData.

This is only 1-D.

Returns:
tuple (int)
size

Return the size of the FlaggedData.

Returns:
int
special_fields

Return fields that do not comply with the shape of other data.

This is of particular importance for delete_indices. Although all arrays must have shape[0] = self.size, special handling may be required in certain cases.

Returns:
fieldsset (str)

Methods Documentation

copy()[source]

Return a copy of the data.

Returns:
FlaggedData
delete_indices(indices_or_mask)[source]

Completely deletes data elements.

Actual indices should be passed in. To delete based on fixed index values, please convert first using find_fixed_indices.

Parameters:
indices_or_masknumpy.ndarray of (bool or int)

The indices to delete, or a boolean mask where True marks an element for deletion.

Returns:
None
discard_flag(flag, criterion=None)[source]

Remove all data flagged with the given flag.

Parameters:
flagint or str or ChannelFlagTypes

The flag to discard_flag.

criterionstr, optional

One of {‘DISCARD_ANY’, ‘DISCARD_ALL’, ‘DISCARD_MATCH’, ‘KEEP_ANY’, ‘KEEP_ALL’, ‘KEEP_MATCH’}. *_ANY refers to any flag that is not zero (unflagged). *_ALL refers to any flag that contains flag, and *_MATCH refers to any flag that exactly matches flag. The default (None), uses DISCARD_ANY if flag is None, and DISCARD_ALL otherwise.

Returns:
None
find_fixed_indices(fixed_indices, cull=True)[source]

Returns the actual indices given fixed indices.

The fixed indices are those that are initially loaded. Returned indices are their locations in the data arrays.

Parameters:
fixed_indicesint or np.ndarray (int)

The fixed indices.

cullbool, optional

If True, do not include fixed indices not found in the result. If False, missing indices will be replaced by -1.

Returns:
indicesnumpy.ndarray (int)

The indices of fixed_indices in the data arrays. A tuple will be returned, in the case where we are examining more than one dimension.

static get_attribute_indices(internal, attribute, value, indices)[source]

Return selected indices of a given value.

Parameters:
internalset (str)

If attribute is found in this set, the original value will be returned, as internal attributes should remain constant regardless of indexing.

attributestr

The name of the attribute in the FlaggedData to which value belongs.

valuenumpy.ndarray or Coordinate or object or csr_matrix

The value for which to retrieve indices.

indicesnumpy.ndarray (bool or int) or slice or tuple (int)

The indices to select and return from value.

Returns:
selected_valuesnumpy.ndarray or Coordinate or object or csr_matrix

In most cases the result will be value[indices].

get_flagged_indices(keep_flag=None, discard_flag=None, match_flag=None, indices=True)[source]

Return flagged indices based on a number of criteria.

Parameters:
keep_flagint or str or Flags.flags

Keep flags that contain this/these flags.

discard_flagint or str or Flags.flags

Discard any flags that contain this/these flags.

match_flagint or str or Flags.flags

Keep only those flags that exactly match this/these flags. Overrides all other criteria.

indicesbool, optional

If True, return an array of integer indices. Otherwise, return a boolean mask where True indicates flagged data.

Returns:
indicesnumpy.ndarray (int or bool)

The indices or mask matching the flag criteria(s).

get_index_size(indices=None)[source]

Get indices and the size of indices covered.

Parameters:
indicesint or numpy.ndarray (int) or slice
Returns:
indices, sizeslice or int or numpy.ndarray (int), int
get_indices(indices)[source]

Return selected data for given indices.

Parameters:
indiceslist or int or numpy.ndarray (int)

The indices to extract.

Returns:
FlaggedData
insert_blanks(insert_indices)[source]

Inserts blank frame data.

Actual indices should be passed in. To delete based on fixed index values, please convert first using find_fixed_indices.

Blank data are set to 0 in whatever unit is applicable.

Parameters:
insert_indicesnumpy.ndarray of (int)

The index locations to insert.

Returns:
None
is_flagged(flag=None, indices=False)[source]

Find flagged data indices.

Parameters:
flagint or str or Flag.flags, optional

The flag to check. If not supplied, returns any indices that have non-zero flags.

indicesbool, optional

If False the return value will be a boolean mask. If True, the actual indices will be returned.

Returns:
flaggednumpy.ndarray (bool or int)

A boolean mask if indices is False or channel indices otherwise.

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

Find data indices that are not flagged.

Parameters:
flagint or str or Flags.flags, optional

The flag to check. If not supplied, returns any indices that have zero flags.

indicesbool, optional

If False the return value will be a boolean mask. If True, the actual indices will be returned.

Returns:
unflaggednumpy.ndarray (bool or int)

A boolean mask if indices is False or indices otherwise.

merge(data)[source]

Add additional data onto the end of this data.

Parameters:
dataFlaggedData
Returns:
None
set_default_values()[source]

Populate data fields with default values.

The default values are loaded from the default_field_types property which returns a dictionary of the form {field_name: value}. If the value is a type, the default values will be empty numpy arrays. Other valid values can be astropy quantities or standard python types such as int, float, str, etc. All fields will be set to numpy arrays of the same type and filled with the same value.

Returns:
None
set_flags(flag, indices=None)[source]

Flag data with the supplied flag.

Parameters:
flagint or str or Flags.flags

The flag to set.

indicesnumpy.ndarray (int), optional

The indices to flag. If not supplied, all data are flagged.

Returns:
None
to_indices(indices_or_mask, discard=False)[source]

Convert an array of indices, or an array mask to the correct format.

Parameters:
indices_or_masknumpy.ndarray (bool or int) or slice

An array of indices or an array mask where each True element indicates an index that should be included.

discardbool, optional

If True, return all indices that are not included in the indices, or the indices of False values in a mask.

Returns:
indicesnumpy.ndarray (int)
unflag(flag=None, indices=None)[source]

Remove data flags.

Parameters:
flagint or str or Flags.flags

The flag to remove. If not supplied, all data are unflagged.

indicesnumpy.ndarray (int), optional

The indices to flag. If not supplied, all data are flagged.

Returns:
None