Miscellaneous Utilities¶
- class sacc.utils.Namespace(*strings)[source]¶
This helper class implements a very simple namespace object designed to store strings with the same name as their contents as a kind of simple string enum.
N = Namespace(‘a’, ‘b’, ‘c’)
assert N.a==’a’
assert N[‘a’]==’a’
assert N.index(‘b’)==1
Methods
index
- sacc.utils.hide_null_values(table)[source]¶
Replace None values in an astropy table with a null value, and change the column type to whatever suits the remaining data points
- Parameters:
- table: astropy table
Table to modify in-place
- sacc.utils.invert_spd_matrix(M, strict=True)[source]¶
Invert a symmetric positive definite matrix.
SPD matrices (for example, covariance matrices) have only positive eigenvalues.
- Parameters:
- M: 2d array
Matrix to invert
- strict: bool, default=True
If True, require that the matrix is SPD. If False, use a slower algorithm that will work on other matrices
- Returns:
- invM: 2d array
Inverse matrix
- sacc.utils.remove_dict_null_values(dictionary)[source]¶
Remove values in a dictionary that correspond to the null values above.
- Parameters:
- dictionary: dict
Dict (or subclass instance or other mapping) to modify in-place
- sacc.utils.unique_list(seq)[source]¶
Find the unique elements in a list or other sequence while maintaining the order. (i.e., remove any duplicated elements but otherwise leave it the same)
Method from: https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-whilst-preserving-order
- Parameters:
- seq: list or sequence
Any input object that can be iterated
- Returns:
- L: list
a new list of the unique objects