Skip to content

Commit

Permalink
Merge pull request #80 from scipp/nxcansas-bin-centers
Browse files Browse the repository at this point in the history
Change SASdata to raise an error instead of writing invalid Q coord
  • Loading branch information
SimonHeybrock authored Nov 25, 2022
2 parents f49b047 + 52e4787 commit a61b417
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
13 changes: 13 additions & 0 deletions docs/about/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/scipp/scippnexus/pull/77>`_.

Contributors
~~~~~~~~~~~~

Simon Heybrock :sup:`a`

v0.4.1 (November 2022)
----------------------

Expand Down
2 changes: 1 addition & 1 deletion requirements-lowest/test-lowest.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
python-dateutil
scipp==0.12.4
scipp==0.13.1
scipy
h5py
pytest
17 changes: 8 additions & 9 deletions requirements-lowest/test-lowest.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/scippnexus/definitions/nxcansas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 15 additions & 4 deletions tests/application_definition_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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],
Expand All @@ -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):
Expand Down

0 comments on commit a61b417

Please sign in to comment.