Skip to content

Commit

Permalink
Warn if links are dead
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHeybrock committed Nov 8, 2023
1 parent e5c1d2a commit 9ce7743
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/scippnexus/nxtransformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# @author Simon Heybrock
from __future__ import annotations

import warnings
from typing import Dict, List, Optional, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -381,8 +382,10 @@ def _with_positions(
out[store_position] = transform * sc.vector([0, 0, 0], unit='m')
if store_transform is not None:
out[store_transform] = transform
except TransformationChainResolver.ChainError:
pass
except TransformationChainResolver.ChainError as e:
warnings.warn(
UserWarning(f'depends_on chain references missing node:\n{e}')
)
for name, value in dg.items():
if isinstance(value, sc.DataGroup):
value = _with_positions(
Expand Down
11 changes: 11 additions & 0 deletions tests/nxtransformations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ def test_compute_positions_with_rotation(h5root):
)


@pytest.mark.filterwarnings("ignore:depends_on chain references missing node")
def test_compute_positions_skips_for_path_beyond_root(h5root):
instrument = snx.create_class(h5root, 'instrument', snx.NXinstrument)
value = sc.scalar(6.5, unit='m')
Expand Down Expand Up @@ -712,3 +713,13 @@ def test_compute_positions_does_not_apply_time_dependent_transform_to_pixel_offs
assert 'position' not in result['detector_0']['data'].coords
result = snx.compute_positions(loaded, store_transform='transform')
assert_identical(result['detector_0']['transform'], t * offset)


def test_compute_positions_warns_if_depends_on_is_dead_link(h5root):
instrument = snx.create_class(h5root, 'instrument', snx.NXinstrument)
detector = create_detector(instrument)
snx.create_field(detector, 'depends_on', sc.scalar('transform'))
root = make_group(h5root)
loaded = root[()]
with pytest.warns(UserWarning, match='depends_on chain references missing node'):
snx.compute_positions(loaded)

0 comments on commit 9ce7743

Please sign in to comment.