makeLifeSimpler

Author: Wilfried Mercier - IRAP

A set of useful functions to make life simpler when analysing data.

Warning

Some functions have not been updated or used in months and may not behave as would be expected.

makeLifeSimpler.applyMask(listOfArrays: List[numpy.ndarray], mask: numpy.ndarray) List[numpy.ndarray][source]

Apply the same mask to a list of arrays and return the new arrays.

Parameters
  • listOfArrays (list[ndarray]) – list of arrays the mask is applied to

  • mask (ndarray) – mask to apply

Returns

list of arrays with the mask applied. If len(listOfArrays) is 1, it returns only an array instead of a list of arrays with one object.

Return type

list[ndarray] if len(listOfArrays) != 1 else ndarray

makeLifeSimpler.checkDupplicates(master: List[numpy.ndarray], names: Optional[List[str]] = None) None[source]

Check if galaxies are found multiple times in an array by looking for duplicates of (RA, DEC) pairs.

Parameters
  • master (list of structured ndarrays (with 'RA' and 'DEC' fields)) – list of structured arrays to check

  • names (list[str]) – (Optional) names of the arrays

Returns

None

makeLifeSimpler.convertCoords(coordinates: Union[List, List[Dict]], inSize: Tuple[int] = (200, 200), outSize: Tuple[int] = (31, 31), conversionFactor: float = 1.0) List[Dict][source]

Transforms the coordinates of a/many point(s) from one image to another

Parameters
  • coordinates (dict or list of dict) – coordinates of the points to convert from one image to another

  • inSize (2-tuple[int] or list[int]) – (Optional) size of the image the points are from

  • outSize (2-tuple[int] or list[int]) – (Optional) size of the image whereto we want to convert the positions of the points

  • conversionFactor (float) – (Optional) numerical factor to convert the position from pixel to another relavant unit

Returns

a list of dictionnaries with transformed coordinates

Return type

list[dict]

makeLifeSimpler.findWhereIsValue(listOfArrays: List[numpy.ndarray], val: Optional[Union[int, float]] = None) List[bool][source]

Find and print the first position where a value is found within a list of arrays.

Parameters
  • listOfArrays (list[ndarray]) – list from which the value val is searched

  • val (int or float or None) – (Optional) value to look for. If None, it looks for nan values.

Returns

list of booleans with the same length as listOfArrays, with True when the value was found in the array and False otherwise.

Return type

list[bool]

makeLifeSimpler.inferError(function: Callable, parameters: List, err_params: List, minBounds: Optional[List] = None, maxBounds: Optional[List] = None, num: int = 1000, centralValue: Optional[Union[int, float]] = None, **kwargs) float[source]

Infer the 1 sigma error on the output of a function by estimating its standard deviation when perturbating its parameters according to their errors. Errors are assumed to be Gaussian.

Parameters
  • function (func) – function to infer the output error

  • parameters (list) – parameters to pass to the function. Order must be identical as in the function declaration.

  • err_params (list) – 1 sigma errors of the parameters. If the parameter is fixed or perfectly known, provide None instead to bypass the pertubation part.

  • minBounds (list) – (Optional) minimum limit allowed for the parameters when perturbating them. All perturbed parameters beyond these thresholds will be set to these values.

  • maxBounds (list) – (Optional) maximum limit allowed for the parameters when perturbating them. All perturbed parameters beyond these thresholds will be set to these values.

  • centralValue (int or float) – (Optional) value used to compute the standard deviation (usually median or mean). If no value is provided, the median value of the perturbed iterations is used.

  • num (int) – (Optional) number of iterations to perform

  • kwargs (dict) – additional parameters to pass onto the function at the end

Returns

1 sigma error of the function around the median value

Return type

float

Raises

TypeError – if

  • num is not an int

  • parameters is not a list

  • err_params is not a list

  • minBounds is not a list

  • maxBounds is not a list

  • centralValue is neither int nor float

makeLifeSimpler.logicalAndFromList(lst: List[numpy.ndarray]) numpy.ndarray[source]

Compute the intersection of all the subarrays in the main array

Parameters

lst (list[ndarray]) – list of arrays containing True or False values

Returns

np.logical_and applied on all the subarrays

Return type

ndarray

makeLifeSimpler.maskToRemoveVal(listOfArrays: List[numpy.ndarray], val: Optional[Union[int, float]] = None, keep: bool = True, astroTableMask: bool = False) numpy.ndarray[source]

Computes a mask by finding occurences in a list of arrays.

Parameters
  • listOfArrays (list[ndarray]) – list of arrays from which the mask is built

  • val (int or float or None) – (Optional) value to find. If None, it looks for nan values.

  • keep (bool) – (Optional) if True, it builds a mask with True everywhere the value val is encountered. If False, it does the opposite.

  • astroTableMask (bool) – (Optional) if True returns a mask from the astropy table column instead of looking for some value/nans with False values everywhere the data is masked.

Returns

a mask

Return type

ndarray

Raises

ValueError – if the arrays do not have the same shape

makeLifeSimpler.transpose(lists: List[Union[List, Tuple]]) List[Union[List, Tuple]][source]

Take the transpose of a list of lists/tuples.

All the inner lists are assumed to be of equal length, otherwise the transpose will not work correctly.

Parameters

lists (list[list] or lists[tuple]) – list of all the lists or tuples to perform the transpose onto

Returns

the transposed list

Return type

list