SaveNexusProcessed v1

../_images/SaveNexusProcessed-v1_dlg.png

SaveNexusProcessed dialog.

Summary

The SaveNexusProcessed algorithm will write the given Mantid workspace to a Nexus file. SaveNexusProcessed may be invoked by SaveNexus.

Properties

Name Direction Type Default Description
InputWorkspace Input Workspace Mandatory Name of the workspace to be saved
Filename Input string Mandatory The name of the Nexus file to write, as a full or relative path. Allowed extensions: [‘.nxs’, ‘.nx5’, ‘.xml’]
Title Input string   A title to describe the saved workspace
WorkspaceIndexMin Input number 0 Index number of first spectrum to write, only for single period data.
WorkspaceIndexMax Input number Optional Index of last spectrum to write, only for single period data.
WorkspaceIndexList Input int list   List of spectrum numbers to read, only for single period data.
Append Input boolean False Determines whether .nxs file needs to be over written or appended
PreserveEvents Input boolean True For EventWorkspaces, preserve the events when saving (default). If false, will save the 2D histogram version of the workspace with the current binning parameters.
CompressNexus Input boolean False For EventWorkspaces, compress the Nexus data field (default False). This will make smaller files but takes much longer.

Description

The algorithm SaveNexusProcessed will write a Nexus data file from the named workspace. This can later be loaded using LoadNexusProcessed v2.

The file name can be an absolute or relative path and should have the extension .nxs, .nx5 or .xml. Warning - using XML format can be extremely slow for large data sets and generate very large files. Both the extensions nxs and nx5 will generate HDF5 files.

The optional parameters can be used to control which spectra are saved into the file. If WorkspaceIndexMin and WorkspaceIndexMax are given, then only that range to data will be loaded.

A Mantid Nexus file may contain several workspace entries each labelled with an integer starting at 1. If the file already contains n workspaces, the new one will be labelled n+1.

Time series data

TimeSeriesProperty data within the workspace will be saved as NXlog sections in the Nexus file. Only floating point logs are stored and loaded at present.

EventWorkspaces

This algorithm will save EventWorkspaces with full event data, unless you uncheck PreserveEvents, in which case the histogram version of the workspace is saved.

Optionally, you can check CompressNexus, which will compress the event data. Warning! This can be very slow, and only gives approx. 40% compression because event data is typically denser than histogram data. CompressNexus is off by default.

Usage

Example - a basic example using SaveNexusProcessed.

import os

ws = CreateSampleWorkspace()
file_name = "myworkspace.nxs"
path = os.path.join(os.path.expanduser("~"), file_name)
SaveNexusProcessed(ws, path)

print(os.path.isfile(path))

Output:

True

Example - an example using SaveNexusProcessed with additional options.

import os

ws = CreateSampleWorkspace()
file_name = "myworkspace.nxs"
path = os.path.join(os.path.expanduser("~"), file_name)
SaveNexusProcessed(ws, path, Title="MyWorkspace", WorkspaceIndexMin=0, WorkspaceIndexMax=9)

print(os.path.isfile(path))

ws = Load(path)
print("Saved workspace has {} spectra".format(ws.getNumberHistograms()))

Output:

True
Saved workspace has 10 spectra

Example - an example using SaveNexusProcessed to save an Event workspace.

import os

ws = CreateSampleWorkspace("Event")
file_name = "myworkspace.nxs"
path = os.path.join(os.path.expanduser("~"), file_name)
SaveNexusProcessed(ws, path, CompressNexus=True, PreserveEvents=True)

print(os.path.isfile(path))

ws = Load(path)
print("Saved workspace has {} spectra".format(ws.getNumberHistograms()))

Output:

True
Saved workspace has 200 spectra

Categories: AlgorithmIndex | DataHandling\Nexus

Source

C++ source: SaveNexusProcessed.cpp (last modified: 2019-09-10)

C++ header: SaveNexusProcessed.h (last modified: 2019-09-04)