\(\renewcommand\AA{\unicode{x212B}}\)

ChangeTimeZero v1

Summary

The algorithm adjusts the zero time of a workspace.

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

An input workspace.

RelativeTimeOffset

Input

number

0

A relative time offset in seconds.

AbsoluteTimeOffset

Input

string

An absolute time offset as an ISO8601 string (YYYY-MM-DDTHH:MM::SS, eg 2013-10-25T13:58:03).

OutputWorkspace

Output

MatrixWorkspace

Mandatory

An output workspace.

Description

The algorithm modifies the time signatures of a MatrixWorkspace. The new time signature alters the logs and in case of an EventWorkspace the neutron times as well.

The time offset can be specified in one of the two following ways:

  • A time offset in seconds: In this case all time stamps in the workspace are shifted by the specified amount. A positive entry creates a shift into the future and a negative one creates a shift into the past relative to the original time.

  • An ISO8601 time stamp (YYYY-MM-DDTHH:MM:SS, eg 2003-11-30T03:23:54). The logs need to contain a proton_charge time series property for this shift to work. The first time entry of the proton_charge time series is used as a reference time stamp and all times will be shifted according to the difference between this time stamp and the newly specified value.

Only one of the two ways of shifting the time can be specified.

Usage

Note

To run these usage examples please first download the usage data, and add these to your path. In Mantid this is done using Manage User Directories.

Example - Relative Time Shift for an EventWorkspace:

# Load an event workspace
original_ws = Load('CNCS_7860_event.nxs')

# Specify the time shift
time_shift = 10000.5

# Change the zero time
shifted_ws = ChangeTimeZero(InputWorkspace = original_ws , RelativeTimeOffset = time_shift)

# Check some logs
original_proton_charge = original_ws.getRun()['proton_charge']
shifted_proton_charge = shifted_ws .getRun()['proton_charge']

# Check some events
original_pulse_times = original_ws.getSpectrum(7).getPulseTimes()
shifted_pulse_times = shifted_ws.getSpectrum(7).getPulseTimes()

print("Original proton_charge time:  {} ,  {} , ...".format(original_proton_charge.nthTime(0), original_proton_charge.nthTime(1)))
print("Shifted proton_charge time:  {} ,  {} , ...".format(shifted_proton_charge.nthTime(0), shifted_proton_charge.nthTime(1)))

print("Original pulse times:  {} ,  {} , ...".format(original_pulse_times[0], original_pulse_times[1]))
print("Shifted pulse times:  {} ,  {} , ...".format(shifted_pulse_times[0], shifted_pulse_times[1]))

Output:

Original proton_charge time:  2010-03-25T16:08:37  ,  2010-03-25T16:08:37.016667999  , ...
Shifted proton_charge time:  2010-03-25T18:55:17.500000000  ,  2010-03-25T18:55:17.516667999  , ...
Original pulse times:  2010-03-25T16:09:57.474029541  ,  2010-03-25T16:10:33.529106140  , ...
Shifted pulse times:  2010-03-25T18:56:37.974029541  ,  2010-03-25T18:57:14.029106140  , ...

Example - Absolute Time Shift for an EventWorkspace:

# Load an event workspace
original_ws = Load('CNCS_7860_event.nxs')

# Specify the time shift
time_shift = '2002-07-13T14:00:01'

# Change the zero time
shifted_ws = ChangeTimeZero(InputWorkspace = original_ws , AbsoluteTimeOffset = time_shift)

# Check some logs
original_proton_charge = original_ws.getRun()['proton_charge']
shifted_proton_charge = shifted_ws .getRun()['proton_charge']

# Check some events
original_pulse_times = original_ws.getSpectrum(7).getPulseTimes()
shifted_pulse_times = shifted_ws.getSpectrum(7).getPulseTimes()

print("Original proton_charge time:  {} ,  {} , ...".format(original_proton_charge.nthTime(0), original_proton_charge.nthTime(1)))
print("Shifted proton_charge time:  {} ,  {} , ...".format(shifted_proton_charge.nthTime(0), shifted_proton_charge.nthTime(1)))

print("Original pulse times:  {} ,  {} , ...".format(original_pulse_times[0], original_pulse_times[1]))
print("Shifted pulse times:  {} ,  {} , ...".format(shifted_pulse_times[0], shifted_pulse_times[1]))

Output:

Original proton_charge time:  2010-03-25T16:08:37  ,  2010-03-25T16:08:37.016667999  , ...
Shifted proton_charge time:  2002-07-13T14:00:01  ,  2002-07-13T14:00:01.016667999  , ...
Original pulse times:  2010-03-25T16:09:57.474029541  ,  2010-03-25T16:10:33.529106140  , ...
Shifted pulse times:  2002-07-13T14:01:21.474029541  ,  2002-07-13T14:01:57.529106140  , ...

Categories: AlgorithmIndex | Utility\Workspaces

Source

C++ header: ChangeTimeZero.h

C++ source: ChangeTimeZero.cpp