From c84e954efc12137c6b5ade4fae920d60a15d4875 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 1 Sep 2021 12:54:12 -0400 Subject: [PATCH] Fixed bug with unevenly spaced input Changed exact equality check for measurement frequencies being the same as pnps frequencies to approximate equality, and changed the MeshGrid.interpolate() function so that it updates the axes as well as the data, like one would expect. --- pypret/mesh_data.py | 2 ++ pypret/retrieval/retriever.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pypret/mesh_data.py b/pypret/mesh_data.py index 71efdd7..61530d2 100644 --- a/pypret/mesh_data.py +++ b/pypret/mesh_data.py @@ -161,6 +161,8 @@ def interpolate(self, axis1=None, axis2=None, degree=2, sorted=False): uncertainty = np.take(uncertainty, idx, axis=i) dataf = RegularGridInterpolator(tuple(orig_axes), data, bounds_error=False, fill_value=0.0) + # Resample the axes to be evenly spaced + axes = [np.linspace(axis[0],axis[-1],len(axis),endpoint=True) for axis in axes] grid = lib.build_coords(*axes) self.data = dataf(grid) self.axes = axes diff --git a/pypret/retrieval/retriever.py b/pypret/retrieval/retriever.py index 701e975..d486804 100644 --- a/pypret/retrieval/retriever.py +++ b/pypret/retrieval/retriever.py @@ -7,6 +7,7 @@ from ..pulse_error import pulse_error from .. import lib from ..pnps import BasePNPS +from math import isclose # global dictionary that contains all PNPS classes _RETRIEVER_CLASSES = {} @@ -106,7 +107,7 @@ def retrieve(self, measurement, initial_guess, weights=None, def _retrieve_begin(self, measurement, initial_guess, weights): pnps = self.pnps - if not np.all(pnps.process_w == measurement.axes[1]): + if not np.allclose(pnps.process_w, measurement.axes[1], rtol=1e-6): raise ValueError("Measurement has to lie on simulation grid!") # Store measurement self.measurement = measurement