From 2dbc29e0696fe25bc3f55afb6cee1bea7bb9d9f1 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Mon, 21 Feb 2022 15:28:13 +1100 Subject: [PATCH] fix: minor fix to variogram saving wavelength guess as attribute can access wavelength guess after model has been built for debugging --- .../interpolators/_discrete_fold_interpolator.py | 2 +- LoopStructural/modelling/fold/svariogram.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/LoopStructural/interpolators/_discrete_fold_interpolator.py b/LoopStructural/interpolators/_discrete_fold_interpolator.py index 6d2df9005..16f0972dd 100644 --- a/LoopStructural/interpolators/_discrete_fold_interpolator.py +++ b/LoopStructural/interpolators/_discrete_fold_interpolator.py @@ -250,5 +250,5 @@ def add_fold_constraints( B = np.zeros(A.shape[0]) idc = np.array(idc[:ncons, :]) self.add_constraints_to_least_squares( - A, B, fold_regularisation[1], idc, name="fold regularisation 3" + A, B, fold_regularisation[2], idc, name="fold regularisation 3" ) diff --git a/LoopStructural/modelling/fold/svariogram.py b/LoopStructural/modelling/fold/svariogram.py index 592802b91..64aca1450 100644 --- a/LoopStructural/modelling/fold/svariogram.py +++ b/LoopStructural/modelling/fold/svariogram.py @@ -60,7 +60,7 @@ def __init__(self, xdata, ydata): self.variance_matrix = (self.ydata[:, None] - self.ydata[None, :]) ** 2 self.lags = None self.variogram = None - + self.wavelength_guess = [None, None] def calc_semivariogram(self, lag=None, nlag=None, lags=None): """ Calculate a semi-variogram for the x and y data for this object. @@ -113,6 +113,11 @@ def calc_semivariogram(self, lag=None, nlag=None, lags=None): step = np.nanmean(np.nanmin(d, axis=1)) * 4.0 # find number of steps to cover range in data nstep = int(np.ceil((np.nanmax(self.xdata) - np.nanmin(self.xdata)) / step)) + if nstep > 200: + logger.warning(f'Variogram has too many steps: {nstep}, using 200') + maximum = step*nstep + nstep = 200 + step = maximum/nstep self.lags = np.arange(step / 2.0, nstep * step, step) logger.info( f"Using average minimum nearest neighbour distance as lag distance size {step} and using {nstep} lags" @@ -176,8 +181,11 @@ def find_wavelengths(self, **kwargs): if wl2 > 0.0 and wl2 > wl1 * 2 and wl1py < py2[i]: break if wl1 == 0.0 and wl2 == 0.0: - return 2 * (np.max(self.xdata) - np.min(self.xdata)), 0.0 + self.wavelength_guess = [2 * (np.max(self.xdata) - np.min(self.xdata)), 0.0] + return self.wavelength_guess if np.isclose(wl1, 0.0): - return np.array([wl2 * 2.0, wl1 * 2.0]) + self.wavelength_guess = np.array([wl2 * 2.0, wl1 * 2.0]) + return self.wavelength_guess # wavelength is 2x the peak on the curve - return np.array([wl1 * 2.0, wl2 * 2.0]) + self.wavelength_guess = np.array([wl1 * 2.0, wl2 * 2.0]) + return self.wavelength_guess \ No newline at end of file