utils.py#

Utility functions related to processing SBS instrument data.

class seabirdscientific.utils.WarnAllMembersMeta(cls, bases, classdict, **kwds)#
seabirdscientific.utils.close_enough(test_values: ndarray, expected_values: ndarray, rounding_order: int, absolute_tolerance: float) bool#

Compares ndarrays, ignoring differences due to rounding or truncating the least significant digit. This is only for comparing data to legacy software

Occasionally a float will be accurate to some decimal, but the next lower decimal may toggle it over or under 5, causing it to round differently if it’s rounded or truncated. This function adds and subtracts half of the least significant digit, then compares values of a given tolerance to either result

Parameters:
  • test_values – values derived by this library

  • expected_values – values derived by SeaSoft

  • rounding_order – The order that CNV values were rounded to

  • absolute_tolerance – values must be at least this close after adding or subtracting the rounding error

Returns:

pass or fail aggregate

seabirdscientific.utils.get_tolerance(data: ndarray, flag_value=-9.99e-29)#

Checks the first 10 values of an array, gets the longest decimal length to the right of the decimal, and returns 1/10^length. Used for unit tests so results can be compared with a variable tolerance

Parameters:

data – a numpy array of numbers

Returns:

the number of significant digits to the right of the decimal

seabirdscientific.utils.percent_match(x1: ndarray, x2: ndarray) str#

Calculates the extent that two arrays match.

Parameters:
  • x1 – first array to be compared

  • x2 – second array to be compared

Returns:

a message with the percentage of matching elements

seabirdscientific.utils.plot(**kwargs: ndarray)#

Plots a dictionary of ndarrays

Parameters:

kwargs – the dictionary to plot

seabirdscientific.utils.profile(fun)#

Decorator for profiling long running functions during development. Add @profile above the function to be measured, then call the function in a script to get a line by line report printed to the console. Remove the decorator when done

Parameters:

fun – This is implicitly the function below the decorator