Skip to content

Commit

Permalink
Add isfinite and finite_data to Surveys (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae authored Jun 27, 2024
1 parent 30ee051 commit 5ddafbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ latest
set the tolerance for the gradient often to a lower value, which saves
computation time.

- Survey

- New attributes ``isfinite`` and ``finite_data``. Former returns the indices
of the finite data, latter returns directly the finite data.

- Electrodes

- Fixed ``TxMagneticDipole``-representation and improved documentation of the
Expand Down
11 changes: 11 additions & 0 deletions emg3d/surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,17 @@ def _rec_types_coord(self, source):
indices = self._irec_types
return [tuple(self._rec_coord[source][ind].T) for ind in indices]

@property
def isfinite(self):
"""Return indices of the finite data."""
if not hasattr(self, '_isfinite'):
self._isfinite = np.isfinite(self.data.observed.data)
return self._isfinite

def finite_data(self, data='observed'):
"""Return finite elements of selected `data`."""
return self.data[data].data[self.isfinite]


def random_noise(standard_deviation, mean_noise=0.0, ntype='white_noise'):
r"""Return random noise for given inputs.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ 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')
Expand Down

0 comments on commit 5ddafbe

Please sign in to comment.