SaveNexusMuon v1#

Summary#

Saves a muon workspace to a Muon NeXus V2 file that can be loaded by LoadMuonNexus and the Muon Analysis interface.

See Also#

LoadMuonNexusV2, LoadMuonNexus

Properties#

Name

Direction

Type

Default

Description

InputWorkspace

Input

Workspace

Mandatory

The single-period muon workspace to save. The counts must be whole numbers, as they are when loaded from a muon file, and all spectra must have the same time bins.

Filename

Input

string

Mandatory

The name of the Muon NeXus file to write, as a full or relative path. Allowed extensions: [‘.nxs’]

TimeZero

Input

number

Optional

Time zero in microseconds, written to the file. Use the TimeZero output of Load.

TimeZeroCorrected

Input

boolean

True

Whether TimeZero has already been subtracted from the time axis of the workspace, as Load does when CorrectTime is set. If so, TimeZero is added back before saving.

FirstGoodData

Input

number

Optional

First good data in microseconds, which must not be before time zero. GoodDataRelativeToTimeZero sets whether it is measured from time zero or from the start of the raw time axis. If not set, it is taken from the FirstGoodData log.

LastGoodData

Input

number

Optional

Last good data in microseconds, which must be after FirstGoodData and not after the end of the time axis. GoodDataRelativeToTimeZero sets whether it is measured from time zero or from the start of the raw time axis. If not set, the data is good up to the end of the time axis.

GoodDataRelativeToTimeZero

Input

boolean

True

Whether FirstGoodData and LastGoodData are measured from time zero, as shown in Muon Analysis, rather than from the start of the raw time axis, as given by the FirstGoodData and LastGoodData outputs of Load.

MainFieldDirection

Input

string

The main field direction. If not set, it is taken from the main_field_direction log. If neither is available, it is not written and loading assumes Longitudinal. Allowed values: [‘’, ‘Longitudinal’, ‘Transverse’]

DeadTimeTable

Input

TableWorkspace

A table of detector dead times, with columns of spectrum (int) and dead-time (double), as given by the DeadTimeTable output of Load. Detectors not in the table, or all detectors if it is not set, are given a dead time of zero.

DetectorGroupingTable

Input

TableWorkspace

A table of detector groups, with a single column of detector lists (vector_int), as given by the DetectorGroupingTable output of Load. If not set, loading uses the default grouping of the instrument.

Description#

Saves a muon workspace to a NeXus file in the ISIS Muon NeXus V2 (HDF5) format. The saved file can be loaded again with Load, which uses LoadMuonNexusV2, and opened in the Muon Analysis and Frequency Domain Analysis interfaces.

The usual way to use the algorithm is to save a workspace loaded from a muon file, after any changes such as removing bad counts or editing sample logs. Pass the TimeZero, DeadTimeTable and DetectorGroupingTable outputs of Load to the matching properties so they are kept in the saved file.

Time zero and good data range#

By default Load subtracts time zero from the time axis (CorrectTime=True) and stores the FirstGoodData sample log relative to time zero. TimeZero must always be set. If TimeZeroCorrected is true, which is the default, TimeZero is added back to the time axis and to the FirstGoodData log before saving. If the workspace was loaded with CorrectTime=False, set TimeZeroCorrected to false.

FirstGoodData can also be given directly. By default it is measured from time zero, as shown in the Muon Analysis interface. To give it from the start of the raw time axis instead, as returned by the FirstGoodData output of Load, set GoodDataRelativeToTimeZero to false. For example, if time zero is 0.213 microseconds and first good data is 0.107 microseconds after it, give FirstGoodData=0.107, or FirstGoodData=0.32 with GoodDataRelativeToTimeZero=False. First good data before time zero is rejected.

Workspaces do not record the last good data, so to keep it, pass the LastGoodData output of Load with GoodDataRelativeToTimeZero=False, or give it measured from time zero. It must be after the first good data and not after the end of the time axis. If it is not given, the data is good up to the end of the time axis, as in ISIS muon files.

The file stores first and last good data as bin numbers, in units of the resolution, which is the width of the first time bin. The values saved are rounded to the nearest whole bin, but the first good bin is never before time zero and the last good bin is never after the end of the time axis. The last good bin must be at least one bin after the first good bin.

What is saved#

Field in the file

Source

counts

The counts of each spectrum. Errors are not saved: they are recalculated as the square root of the counts on loading.

raw_time

The time bin edges, with TimeZero added back if TimeZeroCorrected is true.

resolution

The width of the first time bin.

time_zero

The TimeZero property.

first_good_bin

The FirstGoodData property, or the FirstGoodData sample log.

last_good_bin

The LastGoodData property, or the end of the time axis.

dead_time

The DeadTimeTable property. Detectors not in the table, or all detectors if no table is given, have a dead time of zero.

grouping

The DetectorGroupingTable property. If no table is given, grouping is not saved and loading uses the default grouping of the instrument.

orientation

The MainFieldDirection property, or the main_field_direction sample log.

sample/temperature,

The sample_temp and sample_magn_field sample logs.

sample/magnetic_field

good_frames, run_number,

The goodfrm, run_number, run_start and run_end sample logs.

start_time, end_time

periods

The period_* sample logs, or the values for a single period. The total counts are calculated from the saved counts.

runlog

Every time series sample log of floating-point numbers, 32-bit integers or text. Logs that loading creates itself, such as running and periods, are not saved.

The proton charge, raw frames and experiment identifier are taken from the gd_prtn_chrg, tot_prtn_chrg, rawfrm and rb_proposal sample logs. Workspaces loaded from older muon files do not have these logs, so they are saved as zero or blank. Muon analysis does not use them.

Restrictions on the input workspace#

  • Only single-period data can be saved. To save multi-period data, load and save each period separately using the EntryNumber property of Load.

  • The workspace must contain histogram data whose time bins are the same for every spectrum, in microseconds.

  • The counts must be non-negative whole numbers, as in raw muon data. Data that has been dead time corrected, normalised or rebinned to fractional counts cannot be saved.

  • Each spectrum must contain a single detector whose ID equals its spectrum number.

  • The workspace must have an instrument and the run_number, run_start, run_end, goodfrm, sample_temp and sample_magn_field sample logs, which are needed to load the file.

Usage#

Example - Save a muon run and load it again

import os

loaded = Load("EMU00102347.nxs_v2", DeadTimeTable="dead_times", DetectorGroupingTable="grouping")
file_path = os.path.join(config["defaultsave.directory"], "EMU00102347_saved.nxs")
SaveNexusMuon(InputWorkspace=loaded.OutputWorkspace, Filename=file_path, TimeZero=loaded.TimeZero,
              DeadTimeTable="dead_times", DetectorGroupingTable="grouping")

reloaded = Load(file_path, DeadTimeTable="saved_dead_times", DetectorGroupingTable="saved_grouping")
print("The saved file has {} spectra".format(reloaded.OutputWorkspace.getNumberHistograms()))
print("Time zero is {:.2f} microseconds".format(reloaded.TimeZero))
print("First good data is {:.3f} microseconds".format(reloaded.FirstGoodData))

Output:

The saved file has 96 spectra
Time zero is 0.16 microseconds
First good data is 0.384 microseconds

Categories: AlgorithmIndex | DataHandling\Nexus | Muon\DataHandling

Source#

C++ header: SaveNexusMuon.h

C++ source: SaveNexusMuon.cpp