lezargus.library.sanitize module

lezargus.library.sanitize module#

Collection of a wide variety of data and input sanitization methods.

Data and input sanitization is important to make sure it matches the program expectations and to make sure that processes do not encounter garbage in to have garbage out.

Specific internal sanitization methods may be stored in the same module as the internal subject instead of this one.

lezargus.library.sanitize.clean_finite_arrays(*arrays: hint.NDArray) tuple[hint.NDArray][source]#

Return parallel arrays with any non-finite number removed from them.

We remove all parallel-aligned values (aligned with each other) which are not a finite number, such as NaN and infinity. Because we remove data, the shape of the output arrays will likely be very different to the input.

Parameters:

*arrays (ndarray) – The arrays, which are all parallel, to remove the non-finite numbers from.

Returns:

clean_arrays – The cleaned arrays, arranged in a tuple, in the exact order they were input in as arrays.

Return type:

tuple

lezargus.library.sanitize.fix_fits_header_value(input_data: object) str | int | float | bool | hint.Undefined[source]#

Fix any input into something FITS headers allow.

Per the FITS standard, the allowable data types which values entered in FITS headers is a subset of what Python can do. As such, this function converts any type of reasonable input into something the FITS headers would allow. Note, we mostly do basic checking and conversions. If the object is too exotic, it may cause issues down the line.

In general, only strings, integers, floating point, boolean, and blank values are allowed. Astropy usually will handle further conversion from the basic Python types so we only convert up to there.

Parameters:

input_data (object) – The input to convert into an allowable FITS header keyword.

Returns:

header_output – The output after conversion. Note the None is not actually a None type itself, but Astropy’s header None/Undefined type.

Return type:

str, int, float, bool, or None

lezargus.library.sanitize.verify_broadcastability(reference_array: hint.NDArray, test_array: hint.NDArray) tuple[bool, hint.NDArray | None][source]#

Verify if a test array is broadcastable with the reference array.

This function serves to see if two arrays are compatible in shape. If the “test” array is just a single number, we allow it to broadcast, and return it if needed.

Parameters:
  • reference_array (ndarray) – The reference array which we are testing against.

  • test_array (ndarray) – The test array that we are testing to.

Returns:

  • verify (bool) – The verification.

  • broadcast (ndarray) – The broadcasted array, may be trashed if not needed,