From e64358bebdfe066fde72a74016115eab3b9164a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dieter=20Werthm=C3=BCller?= Date: Fri, 30 Aug 2024 10:03:17 +0200 Subject: [PATCH] Don't set _finite if no data (#342) --- docs/manual/references.rst | 8 ++++++-- emg3d/surveys.py | 10 ++++++++-- tests/test_surveys.py | 11 ++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/manual/references.rst b/docs/manual/references.rst index 97c7ef2b..80eaf2d1 100644 --- a/docs/manual/references.rst +++ b/docs/manual/references.rst @@ -19,8 +19,12 @@ References .. [JoOM06] Jönsthövel, T. B., C. W. Oosterlee, and W. A. Mulder, 2006, Improving multigrid for 3-D electro-magnetic diffusion on stretched grids: European Conference on Computational Fluid Dynamics; UUID: - `df65da5c-e43f-47ab-b80d-2f8ee7f35464 - `_. + `632b503b-149a-47c1-a6b2-2f98f8703b48 + `_. + + .. + df65da5c-e43f-47ab-b80d-2f8ee7f35464 # Old uuid + .. [Hack85] Hackbusch, W., 1985, Multi-grid methods and applications: Springer, Berlin, Heidelberg, Volume 4 of Springer Series in Computational Mathematics; DOI: `10.1007/978- 3-662-02427-0 0: + self._isfinite = finite + else: + finite = self._isfinite + return finite def finite_data(self, data='observed'): """Return finite elements of selected `data`.""" diff --git a/tests/test_surveys.py b/tests/test_surveys.py index f4046926..cb7049c2 100644 --- a/tests/test_surveys.py +++ b/tests/test_surveys.py @@ -266,16 +266,23 @@ def test_add_noise(self): ) data = np.logspace(0, -20, offs.size)+1j*np.logspace(0, -20, offs.size) + data = data[None, :, None] survey = surveys.Survey( sources=emg3d.electrodes.TxElectricDipole((0, 0, 0, 0, 0)), receivers=rec, frequencies=1.0, - data=data, relative_error=0.01, noise_floor=1e-15 ) + assert survey.isfinite.sum() == 0 + assert not hasattr(survey, '_isfinite') + survey.data['observed'] = survey.data.observed.copy(data=data) + assert survey.isfinite.sum() == 21 + assert hasattr(survey, '_isfinite') + assert survey.finite_data().shape == (21,) + # Defined cutting survey.add_noise(min_offset=1000, min_amplitude=1e-19, add_to='test1') # Ensure short offsets are NaN @@ -284,8 +291,6 @@ def test_add_noise(self): assert np.all(np.isnan(survey.data.test1.data[:, -1:, :])) # Ensure no others are none assert np.sum(np.isnan(survey.data.test1.data)) == 3 - assert survey.isfinite.sum() == 21 - assert survey.finite_data().shape == (21,) # No cutting survey.add_noise(min_offset=0, min_amplitude=10e-50, add_to='test2')