Skip to content

Commit

Permalink
Merge pull request #101 from scipp/filter-nan
Browse files Browse the repository at this point in the history
fix: remove non-finite values
  • Loading branch information
jokasimr authored Oct 24, 2024
2 parents 0c9dbb4 + 0cf0c30 commit 2921d40
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/ess/amor/orso.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ def build_orso_iofq_dataset(
r = sc.values(iofq.data)
sr = sc.stddevs(iofq.data)
sqz = sigma_q.to(unit="1/angstrom", copy=False)
data = (qz, r, sr, sqz)

return OrsoIofQDataset(
OrsoDataset(header, np.column_stack([_extract_values_array(d) for d in data]))
)
data = np.column_stack(tuple(map(_extract_values_array, (qz, r, sr, sqz))))
data = data[np.isfinite(data).all(axis=-1)]
return OrsoIofQDataset(OrsoDataset(header, data))


def _extract_values_array(var: sc.Variable) -> np.ndarray:
Expand Down
6 changes: 6 additions & 0 deletions tests/amor/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ def test_run_data_pipeline(amor_pipeline: sciline.Pipeline):
@pytest.mark.filterwarnings("ignore:Invalid transformation, missing attribute")
def test_run_full_pipeline(amor_pipeline: sciline.Pipeline):
amor_pipeline[SampleRotation[SampleRun]] = sc.scalar(0.85, unit="deg")
# Make the Q range cover a larger interval than the experiment is sensitive to.
# This let's us test the non-covered regions are filtered from the ORSO data.
amor_pipeline[QBins] = sc.geomspace(
dim="Q", start=0.005, stop=0.15, num=391, unit="1/angstrom"
)
amor_pipeline[Filename[SampleRun]] = amor.data.amor_sample_run(608)
res = amor_pipeline.compute(orso.OrsoIofQDataset)
assert res.info.data_source.experiment.instrument == "Amor"
assert res.info.reduction.software.name == "ess.reflectometry"
assert res.data.ndim == 2
assert res.data.shape[1] == 4
assert np.all(res.data[:, 1] >= 0)
assert np.isfinite(res.data).all()


@pytest.mark.filterwarnings("ignore:Failed to convert .* into a transformation")
Expand Down

0 comments on commit 2921d40

Please sign in to comment.