watex.utils.scalePosition#
- watex.utils.scalePosition(ydata, xdata=None, func=None, c_order=0, show=False, **kws)[source]#
Correct data location or position and return new corrected location
- Parameters:
ydata (array_like, series or dataframe) – The dependent data, a length M array - nominally
f(xdata, ...).xdata (array_like or object) – The independent variable where the data is measured. Should usually be an M-length sequence or an (k,M)-shaped array for functions with k predictors, but can actually be any object. If
None, xdata is generated by default using the length of the given ydata.func (callable) – The model function,
f(x, ...). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments. The default func islinearfunction i.e forf(x)= ax +b. where a is slope and b is the intercept value. Setting your own function for better fitting is recommended.c_order (int or str) – The index or the column name if
ydatais given as a dataframe to select the right column for scaling.show (bool) – Quick visualization of data distribution.
kws (dict) – Additional keyword argument from scipy.optimize_curvefit parameters. Refer to scipy.optimize.curve_fit.
- Returns:
- ydata - array -like - Data scaled
- popt - array-like Optimal values for the parameters so that the sum of
the squared residuals of
f(xdata, \*popt) - ydatais minimized.- pcov - array like The estimated covariance of popt. The diagonals provide
the variance of the parameter estimate. To compute one standard deviation
errors on the parameters use
perr = np.sqrt(np.diag(pcov)). How thesigma parameter affects the estimated covariance depends on absolute_sigma
argument, as described above. If the Jacobian matrix at the solution
doesn’t have a full rank, then ‘lm’ method returns a matrix filled with
np.inf, on the other hand ‘trf’ and ‘dogbox’ methods use Moore-Penrose
pseudoinverse to compute the covariance matrix.
Examples
>>> from watex.utils import erpSelector, scalePosition >>> df = erpSelector('data/erp/l10_gbalo.xlsx') >>> df.columns ... Index(['station', 'resistivity', 'longitude', 'latitude', 'easting', 'northing'], dtype='object') >>> # correcting northing coordinates from easting data >>> northing_corrected, popt, pcov = scalePosition(ydata =df.northing , xdata = df.easting, show=True) >>> len(df.northing.values) , len(northing_corrected) ... (20, 20) >>> popt # by default popt =(slope:a ,intercept: b) ... array([1.01151734e+00, 2.93731377e+05]) >>> # corrected easting coordinates using the default x. >>> easting_corrected, *_= scalePosition(ydata =df.easting , show=True) >>> df.easting.values ... array([790284, 790281, 790277, 790270, 790265, 790260, 790254, 790248, ... 790243, 790237, 790231, 790224, 790218, 790211, 790206, 790200, ... 790194, 790187, 790181, 790175], dtype=int64) >>> easting_corrected ... array([790288.18571705, 790282.30300999, 790276.42030293, 790270.53759587, ... 790264.6548888 , 790258.77218174, 790252.88947468, 790247.00676762, ... 790241.12406056, 790235.2413535 , 790229.35864644, 790223.47593938, ... 790217.59323232, 790211.71052526, 790205.8278182 , 790199.94511114, ... 790194.06240407, 790188.17969701, 790182.29698995, 790176.41428289]) .. _Bagoue region: https://en.wikipedia.org/wiki/Bagou%C3%A9
. _Cote d’Ivoire: https://en.wikipedia.org/wiki/Ivory_Coast