nexus2srs
Program to convert NeXus (.nxs) scan Files to the classic ASCII SRS .dat files.
By Dan Porter, Diamond Light Source Ltd. 2023-2025
Usage
From Terminal:
$ python -m nexus2srs '12345.nxs' '12345.dat' -tiff
In Python script:
from nexus2srs import nxs2dat
nxs2dat('12345.nxs', '/spool', write_tiff=False)
At Diamond Light Source:
$ module load nexus2srs
(python 3.12) $ cd /dls/i##/data/20##/mm####-1
(python 3.12) $ nexus2srs . spool/ -sync
In a Linux Terminal, this starts a continuous syncronisation process.
Requirements
python 3.10+, hdfmap, h5py, numpy, plus pillow for writing TIFF images
Installation
From PyPI:
$ python -m pip install nexus2srs
Methodology
The file conversion follows the following protocol:
- Open .nxs HDF file (using h5py) and create list of all datasets and groups using hdfmap
- Generate the top part of the header, either by looking for the 'scan_header' dataset or by populating with date, time and run number.
- Generate the list of metadata items in the header by selecting datasets with size <= 1, as available:
- Search for datasets with attribute @local_name, the name saved will be the last part of this name.
- If no @local_name datasets are found, take dataset names of all size <= 1 datasets in the file. Each dataset is saved as 'name' and 'group_name'.
- Build table of scanned data points by selecting datasets of equal shape with size >= 1, as available:
- Get names of fields from the dataset called 'scan_fields', find these datasets in the first NXdata group or group called 'measurement'
- Or, take all datasets in the default or first NXdata or group called 'measurement', with the same shape as the first dataset in this group
- Or, take all datasets in the file with shape equal to with the most common dataset shape in the file
- Search for dataset 'image_data', generate a template from the first contained TIFF image path and add to metadata
- Find 3D+ arrays in all NXdetector groups, generate and add TIFF image paths to metadata
For metadata and the table of scanned data, if the datasets contain the @decimals attribute, they will be rounded accordingly.
Once the conversion is complete, the components are joined into a single string including the header, metadata and table of scanned data. By default, a NeXus file at *'folder/file.nxs' will be saved as 'folder/file.dat'. If TIFF writing is enabled, detector image data from 3+D arrays in all NXdetector groups will be saved as TIFF images into a sub-folder like 'folder/RunNo_DetectorName_files/00001.tif'. Files will not be overwritten if they already exist.
Command line arguments
Usage (from terminal):
$ nexus2srs 12345.nxs 12345.dat
Include '-tiff' in arguments to save detector images as tif images.
Single synchronisation of files (batch job):
$ nexus2srs /path/to/nxs_files /path/to/dat_files
Continuous synchronisation of files (starts a continuous process):
$ nexus2srs /path/to/nxs_files /path/to/dat_files -sync
Arguments
| example | description |
|---|---|
| file.nxs | Convert file.nxs to file.dat |
| file.nxs newfile.dat | Convert file.nxs to newfile.dat |
| /folder | convert all folder/*.nxs files to folder/spool/*.dat |
| /folder /new | convert all folder/*.nxs files to new/*.dat |
| -tiff | Convert detector files to TIFF images |
| -sync | Continuously synchronise folders |
| -h, --help | Display documentation |
| --info | Set logging level to INFO |
| --debug | Set logging level to DEBUG |
| --quiet | Turn off logging (except errors) |
Testing (Jan 2023)
- Testing has been performed on several thousand old I16, I10 and I21 nexus files.
- No unexpected failures were found in these, however none of the files conform to the new, ideal nexus structure.
- Local files are converted in ~0.3s per file without image conversion.
- See Jupyter notebook nexus2srs_tests.ipynb for more information.
- Tested with nxs2dat jupyter processor on I16 15/12/2023, updated TIFF file writing.
Update September 2024
Significant re-factoring of code to include the hdfmap package. The HdfMap function takes care of creating the scannables table and the metadata, using current NeXus best practice. This allows for correct identification of metadata and uses "local_names" and "decimals" attributes.
Metadata
Release files for nexus2srs 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| nexus2srs-1.1.1.tar.gz | 21.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nexus2srs-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.4 kB
Release files / nexus2srs-1.1.1.tar.gz
| Download URL | nexus2srs-1.1.1.tar.gz |
|---|---|
| Size | 21.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42a0ab7414eedc3a7de093012a210d6e1117dfa51d32e36730dc7091e747440b
|
|
BLAKE2b-256 checksum How to use checksums |
6bc7bebb2840bf12f0492d48ddf5d1478f2fd29fa82e709c7cd5184f90d4f095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.
Transparency logRelease files / nexus2srs-1.1.1-py3-none-any.whl
| Download URL | nexus2srs-1.1.1-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e528e4f0989471baeb72b1ba96ec9ff8e514bbe18c711409905c854f3df33e9c
|
|
BLAKE2b-256 checksum How to use checksums |
612ff92d29e65f8e17ee9fdd8a2a53b9ade5999a16182e3e5ebb8bc8ceab0b64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.
Transparency logSecurity for nexus2srs 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for nexus2srs-1.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.