From 132dce9726e71c10af554edf239515d575a70c75 Mon Sep 17 00:00:00 2001 From: Alexey Pechnikov Date: Sat, 6 Jul 2024 21:09:44 +0700 Subject: [PATCH] Rename some functions --- pygmtsar/pygmtsar/Stack_detrend.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pygmtsar/pygmtsar/Stack_detrend.py b/pygmtsar/pygmtsar/Stack_detrend.py index 94cac7f9..5a5a7c32 100644 --- a/pygmtsar/pygmtsar/Stack_detrend.py +++ b/pygmtsar/pygmtsar/Stack_detrend.py @@ -320,6 +320,10 @@ def regression_sgd(self, data, variables, weight=None, valid_pixels_threshold=10 max_iter=max_iter, tol=tol, alpha=alpha, l1_ratio=l1_ratio) def polyfit(self, data, weight=None, degree=0, days=None, count=None): + print ('NOTE: Function is deprecated. Use Stack.regression_pairs() instead.') + return self.regression_pairs(data=data, weight=weight, degree=degree, days=days, count=count) + + def regression_pairs(self, data, weight=None, degree=0, days=None, count=None): import xarray as xr import pandas as pd import numpy as np @@ -947,7 +951,11 @@ def velocity(self, data): # raise ValueError("The 'data' argument must include a 'date' or 'pair' dimension to detect trends.") # - def trend(self, data, dim='auto', deg=1): + def trend(self, data, dim='auto', degree=1): + print ('NOTE: Function is deprecated. Use Stack.regression1d() instead.') + return self.regression1d(data=data, dim=dim, degree=degree) + + def regression1d(self, data, dim='auto', degree=1): import xarray as xr import pandas as pd import numpy as np @@ -972,13 +980,13 @@ def trend(self, data, dim='auto', deg=1): else: dim_da = xr.DataArray(dim, dims=[stackdim]) data_dim = data.assign_coords(polyfit_coord=dim_da).swap_dims({'pair': 'polyfit_coord'}) - fit_coeff = data_dim.polyfit('polyfit_coord', deg).polyfit_coefficients.astype(np.float32) + fit_coeff = data_dim.polyfit('polyfit_coord', degree).polyfit_coefficients.astype(np.float32) fit = xr.polyval(data_dim['polyfit_coord'], fit_coeff)\ .swap_dims({'polyfit_coord': stackdim}).drop_vars('polyfit_coord').astype(np.float32).rename('trend') return xr.merge([fit, fit_coeff]).rename(polyfit_coefficients='coefficients') # fit existing coordinate values - fit_coeff = data.polyfit(dim, deg).polyfit_coefficients.astype(np.float32) + fit_coeff = data.polyfit(dim, degree).polyfit_coefficients.astype(np.float32) fit = xr.polyval(data[dim], fit_coeff).astype(np.float32).rename('trend') out = xr.merge([fit, fit_coeff]).rename(polyfit_coefficients='coefficients') if multi_index is not None: