Skip to content

Commit

Permalink
Merge pull request #119 from rayosborn/add-nxdata-functions
Browse files Browse the repository at this point in the history
Add NXData functions
  • Loading branch information
rayosborn authored Apr 13, 2020
2 parents 2841815 + 6656e9c commit 10215d7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/nexusformat/nexus/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6019,7 +6019,7 @@ def project(self, axes, limits=None, summed=True):
Using the default `limits=None` should be used with caution, since it
requires reading the entire data set into memory.
"""
signal_rank = self.nxsignal.ndim
signal_rank = self.ndim
if not is_iterable(axes):
axes = [axes]
if limits is None:
Expand Down Expand Up @@ -6270,6 +6270,24 @@ def implot(self, fmt='', xmin=None, xmax=None, ymin=None, ymax=None,
else:
raise NeXusError("Invalid shape for RGB(A) image")

@property
def ndim(self):
"""Rank of the NXdata signal."""
signal = self.nxsignal
if signal is not None:
return signal.ndim
else:
raise NeXusError("No signal defined for NXdata group")

@property
def shape(self):
"""Shape of the NXdata signal."""
signal = self.nxsignal
if signal is not None:
return signal.shape
else:
raise NeXusError("No signal defined for NXdata group")

@property
def nxsignal(self):
"""NXfield containing the signal data."""
Expand Down
2 changes: 2 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def test_data_creation():
assert "axes" in data.attrs
assert len(data.attrs["axes"]) == 3

assert data.ndim == 3
assert data.shape == (2, 5, 10)
assert data.nxsignal.nxname == "v"
assert data.nxsignal.ndim == 3
assert data.nxsignal.shape == (2, 5, 10)
Expand Down

0 comments on commit 10215d7

Please sign in to comment.