TidalPy.utilities.numpy_helper package

Submodules

TidalPy.utilities.numpy_helper.array_other module

TidalPy.utilities.numpy_helper.array_other.find_nearest(array: ndarray, value: NumericalType)[source]

Returns the index of the value closest to a provided value in a numpy array.

Parameters:
  • array (np.ndarray) – Numpy array to search in

  • value (NumericalType) – Value to search for within array

Returns:

index – Index of nearest value

Return type:

int

TidalPy.utilities.numpy_helper.array_other.neg_array_for_log_plot(array_with_negatives: ndarray)[source]

Converts one numpy array into two where both new arrays only have positive values. Useful for log-plotting.

Parameters:

array_with_negatives (np.ndarray) – Numpy array that may have negatives or zeros

Returns:

  • array_positive (np.ndarray) – Numpy array with original array’s positives

  • array_negative (np.ndarray) – Numpy array with original array’s negatives set to positive

TidalPy.utilities.numpy_helper.array_other.normalize_dict(dict_of_values: Dict[str, FloatArray], pass_negatives: bool = False, new_max: float = 1.0, new_min: float = 0.0)[source]

Normalizes values provided in a name separated dictionary to the specified range.

Parameters:
  • dict_of_values (Dict[str, FloatArray]) – Dictionary of reference keys pointing to the to-be-normalized values.

  • pass_negatives (bool = False) – If true then any values that are negative will be excluded from the normalization.

  • new_max (float = 1.0) – The upper-most of the post-normalized values

  • new_min (float = 0.0) – The lower-most of the post-normalized values

Returns:

dict_of_normalized_values – Dictionary of reference keys pointing to the post-normalized values.

Return type:

Dict[str, FloatArray]

TidalPy.utilities.numpy_helper.array_other.value_np_cleanup(value)[source]

TidalPy.utilities.numpy_helper.array_shape module

TidalPy.utilities.numpy_helper.array_shape.reshape_help(value: NumArray, comparison_shape: tuple, call_locale=None, force_into_new_shape: bool = False, force_ints_to_floats: bool = True) Tuple[Tuple[int, ...], ndarray][source]

Attempts to reshape value into an array that matches the shape of new_shape. Raises an error if it is unable to do so.

Parameters:
  • value (NumArray) – A number or array to be reshaped

  • comparison_shape (tuple) – New shape to try to force the value’s shape into

  • call_locale – class that will be used to generate an error message should it be needed.

  • force_into_new_shape (bool = False) – If True, the new value will be put into an array of new_shape instead of just a zero-dimensional array.

  • force_ints_to_floats (bool = True) – Even if value appears to be an integer, force it to be a float.

Returns:

  • new_shape (Tuple[int, …]) – Flag if the array appears to be a new shape.

  • new_array (np.ndarray) – New array based on value in the shape of new_shape.