From 1f3f430d4fb3c1bdaa3abda7966a9162dc599347 Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Sun, 9 Jul 2017 16:18:44 +0200 Subject: [PATCH] Replaced similar code with a function --- wafo/transform/models.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/wafo/transform/models.py b/wafo/transform/models.py index 462b578..063e542 100644 --- a/wafo/transform/models.py +++ b/wafo/transform/models.py @@ -549,21 +549,23 @@ class TrOchi(TrCommon2): return (y2 - mean2) / sigma2 def _dat2gauss(self, x, *xi): - if len(xi) > 0: - raise ValueError('Transforming derivatives is not implemented!') - - xn = (atleast_1d(x) - self.mean) / self.sigma - shape0 = xn.shape - yn = np.reshape(self._forward(xn.ravel()), shape0) - return yn * self.ysigma + self.ymean + return self._transformgauss(self._forward, + self.ymean, self.ysigma, + self.mean, self.sigma, x, *xi) def _gauss2dat(self, y, *yi): + return self._transformgauss(self._backward, + self.mean, self.sigma, + self.ymean, self.ysigma, y, *yi) + + @staticmethod + def _transformgauss(trfun, mean, sigma, ymean, ysigma, y, *yi): if len(yi) > 0: raise ValueError('Transforming derivatives is not implemented!') - yn = (atleast_1d(y) - self.ymean) / self.ysigma + yn = (atleast_1d(y) - ymean) / ysigma shape0 = yn.shape - xn = np.reshape(self._backward(yn.ravel()), shape0) - return xn * self.sigma + self.mean + xn = np.reshape(trfun(yn.ravel()), shape0) + return xn * sigma + mean def main():