From 10281d7cddbbca8cfb52de95fc13a85500067403 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Fri, 25 Nov 2022 08:42:33 +0100 Subject: [PATCH 1/2] Change SASdata to raise an error instead of writing invalid Q coord --- docs/about/release-notes.rst | 13 +++++++++++++ src/scippnexus/definitions/nxcansas.py | 4 ++++ tests/application_definition_test.py | 19 +++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/docs/about/release-notes.rst b/docs/about/release-notes.rst index 2e138f42..e8047de0 100644 --- a/docs/about/release-notes.rst +++ b/docs/about/release-notes.rst @@ -28,6 +28,19 @@ Release Notes Neil Vaytet :sup:`a`\ , and Jan-Lukas Wynen :sup:`a` +v0.4.2 (November 2022) +---------------------- + +Bugfixes +~~~~~~~~ + +* Fix SASdata to raise an exception when given Q-edges, which is not valid for SASdata `#77 `_. + +Contributors +~~~~~~~~~~~~ + +Simon Heybrock :sup:`a` + v0.4.1 (November 2022) ---------------------- diff --git a/src/scippnexus/definitions/nxcansas.py b/src/scippnexus/definitions/nxcansas.py index b4dd7fed..82f6104a 100644 --- a/src/scippnexus/definitions/nxcansas.py +++ b/src/scippnexus/definitions/nxcansas.py @@ -59,6 +59,10 @@ def __write_to_nexus_group__(self, group: NXobject): if da.variances is not None: signal.attrs['uncertainties'] = 'I_errors' group.create_field('I_errors', sc.stddevs(da.data)) + if da.coords.is_edges('Q'): + raise ValueError( + "Q is given as bin-edges, but NXcanSAS requires Q points (such as " + "bin centers).") coord = group.create_field('Q', da.coords['Q']) if da.coords['Q'].variances is not None: if self._variances is None: diff --git a/tests/application_definition_test.py b/tests/application_definition_test.py index 079a3d0d..afab891b 100644 --- a/tests/application_definition_test.py +++ b/tests/application_definition_test.py @@ -6,7 +6,7 @@ @pytest.fixture() -def nxroot(request): +def nxroot(): """Yield NXroot containing a single NXentry named 'entry'""" with h5py.File('dummy.nxs', mode='w', driver="core", backing_store=False) as f: root = NXroot(f) @@ -23,7 +23,8 @@ def test_setitem_SASentry(nxroot): assert entry['run'][()] == 12345 -def test_setitem_SASdata(nxroot): +@pytest.fixture() +def I_of_Q(): data = sc.array( dims=['Q'], values=[0.1, 0.2, 0.1, 0.4], @@ -32,10 +33,20 @@ def test_setitem_SASdata(nxroot): da = sc.DataArray(data=data) da.coords['Q'] = sc.linspace('Q', 0, 1, num=5, unit='1/angstrom') da.coords['Q'].variances = sc.array(dims=['Q'], values=[1, 1, 4, 4, 1]).values - nxroot['sasdata'] = SASdata(da, Q_variances='resolutions') + return da + + +def test_setitem_SASdata_raises_ValueError_when_given_bin_edges(nxroot, I_of_Q): + with pytest.raises(ValueError): + nxroot['sasdata'] = SASdata(I_of_Q, Q_variances='resolutions') + + +def test_setitem_SASdata(nxroot, I_of_Q): + I_of_Q.coords['Q'] = I_of_Q.coords['Q'][1:] + nxroot['sasdata'] = SASdata(I_of_Q, Q_variances='resolutions') nxroot._definition = NXcanSAS data = nxroot['sasdata'] - assert sc.identical(data[...], da) + assert sc.identical(data[...], I_of_Q) def test_setitem_SASdata_raises_if_interpretation_of_variances_not_specified(nxroot): From 52e4787981f7ff566a0bbe3612e64a1bf0f447b9 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Fri, 25 Nov 2022 08:47:30 +0100 Subject: [PATCH 2/2] Update lowest scipp --- requirements-lowest/test-lowest.in | 2 +- requirements-lowest/test-lowest.txt | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/requirements-lowest/test-lowest.in b/requirements-lowest/test-lowest.in index 9394449e..10f62a3d 100644 --- a/requirements-lowest/test-lowest.in +++ b/requirements-lowest/test-lowest.in @@ -1,5 +1,5 @@ python-dateutil -scipp==0.12.4 +scipp==0.13.1 scipy h5py pytest diff --git a/requirements-lowest/test-lowest.txt b/requirements-lowest/test-lowest.txt index 4e571c5e..58c08469 100644 --- a/requirements-lowest/test-lowest.txt +++ b/requirements-lowest/test-lowest.txt @@ -1,9 +1,8 @@ -# SHA1:f2d0f341978c4e9d11ba22dedb60abe2d5d75ded # -# This file is autogenerated by pip-compile-multi +# This file is autogenerated by pip-compile with python 3.8 # To update, run: # -# pip-compile-multi +# pip-compile test-lowest.in # attrs==22.1.0 # via pytest @@ -14,7 +13,7 @@ exceptiongroup==1.0.0rc9 graphlib-backport==1.0.3 # via scipp h5py==3.7.0 - # via -r requirements/test-lowest.in + # via -r test-lowest.in iniconfig==1.1.1 # via pytest numpy==1.23.4 @@ -29,15 +28,15 @@ pluggy==1.0.0 pyparsing==3.0.9 # via packaging pytest==7.2.0 - # via -r requirements/test-lowest.in + # via -r test-lowest.in python-dateutil==2.8.2 - # via -r requirements/test-lowest.in + # via -r test-lowest.in pyyaml==6.0 # via confuse -scipp==0.12.4 - # via -r requirements/test-lowest.in +scipp==0.13.1 + # via -r test-lowest.in scipy==1.9.3 - # via -r requirements/test-lowest.in + # via -r test-lowest.in six==1.16.0 # via python-dateutil tomli==2.0.1