Skip to content
Snippets Groups Projects
AddTimeSeriesLog-v1.rst 2.07 KiB
Newer Older
.. relatedalgorithms::

.. properties::

Description
-----------

Creates/updates a time-series log entry on a chosen workspace. The given
timestamp & value are appended to the named log entry. If the named
entry does not exist then a new log is created. A time stamp must be
given in ISO8601 format, e.g. 2010-09-14T04:20:12.

By default, the given value is interpreted as a double and a double
series is either created or expected. However, if the "Type" is set to
"int" then the value is interpreted as an integer and an integer is
either created or expected.

Usage
-----

**Example**

.. testcode:: AddTimeSeriesLogEx

Peterson, Peter's avatar
Peterson, Peter committed
    import numpy as np
    ws = CreateSampleWorkspace("Event",BankPixelWidth=1)

Peterson, Peter's avatar
Peterson, Peter committed
    AddTimeSeriesLog(ws, Name="my_log", Time="2010-01-01T00:00:00", Value=100)
    AddTimeSeriesLog(ws, Name="my_log", Time="2010-01-01T00:30:00", Value=15)
    AddTimeSeriesLog(ws, Name="my_log", Time="2010-01-01T00:50:00", Value=100.2)

    log = ws.getRun().getLogData("my_log")
    print("my_log has {} entries".format(log.size()))
Peterson, Peter's avatar
Peterson, Peter committed
    for time, value in zip(log.times, log.value):
      ts = np.datetime_as_string(time.astype(np.dtype('M8[s]')), timezone='UTC')
      print("\t{}\t{:.6f}".format(ts, value))

    AddTimeSeriesLog(ws, Name="my_log", Time="2010-01-01T00:00:00", Value=12, Type="int", DeleteExisting=True)
    AddTimeSeriesLog(ws, Name="my_log", Time="2010-01-01T00:50:00", Value=34, Type="int")

    log = ws.getRun().getLogData("my_log")
    print("my_log now has {} entries".format(log.size()))
Peterson, Peter's avatar
Peterson, Peter committed
    for time, value in zip(log.times, log.value):
      ts = np.datetime_as_string(time.astype(np.dtype('M8[s]')), timezone='UTC')
      print("\t{}\t{:.6f}".format(ts, value))


Output:

.. testoutput:: AddTimeSeriesLogEx
    :options: +NORMALIZE_WHITESPACE

    my_log has 3 entries
        2010-01-01T00:00:00Z     100.000000
        2010-01-01T00:30:00Z     15.000000
        2010-01-01T00:50:00Z     100.200000
    my_log now has 2 entries
        2010-01-01T00:00:00Z     12.000000
        2010-01-01T00:50:00Z     34.000000