watex.utils.funcutils.make_arr_consistent#

watex.utils.funcutils.make_arr_consistent(refarr, arr, fill_value=nan, return_index=False, method='naive')[source]#

Make arr to be consistent with the reference array refarr. Fill the missing value with param fill_value.

Note that it does care of the position of the value in the array. Use Numpy digitize to compute the bins. The array caveat here is the bins must be monotonically decreasing or increasing.

If the values in arr are present in refarr, the position of arr in new consistent array should be located decreasing or increasing order.

Parameters:
  • arr (array-like 1d,) – Array to extended with fill value. It should be shorter than the refarr.

  • refarr (array-like- the reference array. It should have a greater) – length than the array arr.

  • fill_value (float,) – Value to fill the arr to match the length of the refarr.

  • return_index (bool or str, default=True) –

    index of the position of the elements in refarr.

    Default is False. If mask should return the

    mask of existing element in reference array

  • method (str, default="naive") –

    Is the method used to find the right position of items in arr based on the reference array. - naive, considers the length of arr must fit the number of

    items that should be visible in the consistent array. This method erases the remaining bins values out of length of arr.

    • ``strict` did the same but rather than considering the length,

      it considers the maximum values in the arr. It assumes that arr is sorted in ascending order. This methods is usefull for plotting a specific stations since the station loactions are sorted in ascending order.

Returns:

index: indices of the position of arr items in refarr. mask: bool of the position arr items in refarr t: new consistent array with the same length as refarr

Return type:

non_zero_index , mask or t

Examples

>>> import numpy as np
>>> from watex.utils.funcutils import make_arr_consistent
>>> refarr = np.arange (12)
>>> arr = np.arange (7, 10)
>>> make_arr_consistent (refarr, arr )
Out[84]: array([nan, nan, nan, nan, nan, nan, nan,  7.,  8.,  9., nan, nan])
>>> make_arr_consistent (refarr, arr , return_index =True )
Out[104]: array([7, 8, 9], dtype=int64)
>>> make_arr_consistent (refarr, arr , return_index ="mask" )
Out[105]:
array([False, False, False, False, False, False, False,  True,  True,
        True, False, False])
>>> a = np.arange ( 12 ); b = np.linspace (7, 10 , 7)
>>> make_arr_consistent (a, b )
Out[112]: array([nan, nan, nan, nan, nan, nan, nan,  7.,  8.,  9., 10., 11.])
>>> make_arr_consistent (a, b ,method='strict')
Out[114]: array([nan, nan, nan, nan, nan, nan, nan,  7.,  8.,  9., 10., nan])