Skip to content

Commit

Permalink
fixes #43
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Feb 1, 2016
1 parent b04e0a5 commit 3bb6228
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ Change History
Production
**********

:2016.0131.0: support new NeXus method for default/signal/axes/_indices,
`issue #43 <https://github.com/prjemian/spec2nexus/issues/43>`_
:2016.0130.0: fixed `issue #44 <https://github.com/prjemian/spec2nexus/issues/44>`_
:2015.1221.1: added versioneer support (`issue #40 <https://github.com/prjemian/spec2nexus/issues/40>`_)
:2015.1221.0: read scans with repeated scan numbers (`issue #39 <https://github.com/prjemian/spec2nexus/issues/39>`_)
:2015.1221.0: read scans with repeated scan numbers
(`issue #39 <https://github.com/prjemian/spec2nexus/issues/39>`_)
:2015.0822.0: extractSpecScan: add option to report scan heading data, such as positioners and Q
:2015.0214.0: h5toText: handle HDF5 'O' data type (variable length strings)
:2015.0127.0: spec: ignore bad data lines
Expand Down
2 changes: 1 addition & 1 deletion src/spec2nexus/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def getScan(self, scan_number=0):
'''return the scan number indicated, None if not found'''
if int(float(scan_number)) < 1:
# relative list index (integer only), convert to actual scan number
keylist = sorted(self.scans.keys())
keylist = sorted(self.getScanNumbers())
key = len(keylist) + int(scan_number)
if 0 <= key < len(keylist):
scan_number = keylist[key]
Expand Down
28 changes: 22 additions & 6 deletions src/spec2nexus/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ def save(self, hdf_file, scan_list=[]):
In general, the tree structure of the NeXus HDF5 file is::
hdf5_file: NXroot
@entry="S1"
@default="S1"
# attributes
S1:NXentry
@data="data"
@default="data"
# attributes and metadata fields
data:NXdata
@signal=<name of signal field>
@axes=<name(s) of axes of signal>
@<axis>_indices=<list of indices in "axis1">
<signal_is_the_last_column>:NX_NUMBER[number of points] = ... data ...
@signal=1
@axes='<axis_is_name_of_first_column>'
@<axis>_indices=<list of indices in "axis1" used as dimension scales of the "signal">
<axis_is_name_of_first_column>:NX_NUMBER[number of points] = ... data ...
# other columns from the scan
Expand All @@ -78,7 +80,7 @@ def save(self, hdf_file, scan_list=[]):
self.save_scan(nxentry, self.spec.getScan(key))
if pick_first_entry:
pick_first_entry = False
eznx.addAttributes(root, entry='S'+str(key))
eznx.addAttributes(root, default='S'+str(key))
root.close() # be CERTAIN to close the file

def root_attributes(self):
Expand All @@ -104,7 +106,7 @@ def root_attributes(self):
def save_scan(self, nxentry, scan):
'''*internal*: save the data from each SPEC scan to its own NXentry group'''
scan.interpret() # ensure interpretation is complete
eznx.addAttributes(nxentry, data="data")
eznx.addAttributes(nxentry, default="data")
eznx.write_dataset(nxentry, "title", str(scan))
eznx.write_dataset(nxentry, "scan_number", scan.scanNum)
eznx.write_dataset(nxentry, "command", scan.scanCmd)
Expand Down Expand Up @@ -141,8 +143,22 @@ def save_data(self, nxdata, scan):
# these locations suggested to NIAC, easier to parse than attached to dataset!
if len(signal) == 0:
pass

# Syntax of axes attribute (http://wiki.nexusformat.org/2014_axes_and_uncertainties):
# @axes="H:K" INCOREECT
# @axes="H", "K" CORRECT
if axes.find(':') >= 0:
axes = axes.split(':')
eznx.addAttributes(nxdata, signal=signal, axes=axes)
eznx.addAttributes(nxdata[signal], signal=1, axes=axes)
#eznx.addAttributes(nxdata[signal], signal=1, axes=axes) # deprecated now
# assume here that "axis_name" has rank=1
# TODO: test that scan.data[axis_name] has rank=1
indices = [0,] # 0-based reference
if isinstance(axes, str):
eznx.addAttributes(nxdata, **{axes+'_indices': indices})
else:
for axis_name in axes:
eznx.addAttributes(nxdata, **{axis_name+'_indices': indices})

def oneD(self, nxdata, scan):
'''*internal*: generic data parser for 1-D column data, returns signal and axis'''
Expand All @@ -151,7 +167,7 @@ def oneD(self, nxdata, scan):

signal = utils.clean_name(scan.column_last) # primary Y axis
axis = utils.clean_name(scan.column_first) # primary X axis
self.mca_spectra(nxdata, scan, axis) # records any MCA data
self.mca_spectra(nxdata, scan, axis) # records any MCA data
return signal, axis

def mca_spectra(self, nxdata, scan, primary_axis_label):
Expand Down

0 comments on commit 3bb6228

Please sign in to comment.