This is an internal library of the spec2nexus software. It is not expected that users of this package will need to call the writer module directly.

source code documentation

(internal library) Parses SPEC data using spec2nexus.eznx API (only requires h5py)

class spec2nexus.writer.Writer(spec_data)[source]

writes out scans from SPEC data file to NeXus HDF5 file

Parameters:spec_data (obj) – instance of SpecDataFile
mca_spectra(nxdata, scan, primary_axis_label)[source]

internal: parse for optional 2-D MCA spectra

mesh(nxdata, scan)[source]

internal: data parser for 2-D mesh and hklmesh

oneD(nxdata, scan)[source]

internal: generic data parser for 1-D column data, returns signal and axis


internal: returns the attributes to be written to the root element as a dict

save(hdf_file, scan_list=None)[source]

save the information in this SPEC data file to a NeXus HDF5 file

Each scan in scan_list will be converted to a NXentry group. Scan data will be placed in a NXdata group where the attribute signal=1 is the last column and the corresponding attribute axes=<name of the first column>. There are variations on this for 2-D and higher dimensionality data, such as mesh scans.

In general, the tree structure of the NeXus HDF5 file is:

hdf5_file: NXroot
    # attributes
        # attributes and metadata fields
            @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 ...
                @<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
  • hdf_file (str) – name of NeXus/HDF5 file to be written
  • scanlist ([int]) – list of scan numbers to be read
save_data(nxdata, scan)[source]

internal: store the scan data

save_dict(group, data)[source]

internal: store a dictionary

save_scan(nxentry, scan)[source]

internal: save the data from each SPEC scan to its own NXentry group

write_ds(group, label, data, **attr)[source]

internal: writes a dataset to the HDF5 file, records the SPEC name as an attribute