Table of Contents

Class TimeSeriesDataSet

Namespace
TimeSeriesAnalysis
Assembly
TimeSeriesAnalysis.dll

A class that holds time-series data for any number of tags, and with built in support for serializing/deserializing to a csv-file.

Time is either treated by giving a timeBase in seconds and a starting time, or by specifying a vector of timestamps.

public class TimeSeriesDataSet
Inheritance
TimeSeriesDataSet
Inherited Members

Constructors

TimeSeriesDataSet()

Default constructor

[JsonConstructor]
public TimeSeriesDataSet()

TimeSeriesDataSet(string, char, string)

Constructor that builds a dataset object from a csv-file, by loading LoadFromCsv(). If file does not exist, it is created

public TimeSeriesDataSet(string csvFileName, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")

Parameters

csvFileName string

name of csv-file

separator char

the separator in the csv-file

dateTimeFormat string

the format of date-time strings in the csv-file

TimeSeriesDataSet(TimeSeriesDataSet)

Constructor that copies another dataset into the returned object

public TimeSeriesDataSet(TimeSeriesDataSet inputDataSet)

Parameters

inputDataSet TimeSeriesDataSet

TimeSeriesDataSet(TimeSeriesDataSet, List<int>)

Constructor that copies another dataset into the returned object, but only the values and times for the indices given

public TimeSeriesDataSet(TimeSeriesDataSet inputDataSet, List<int> indicesToNotCopy)

Parameters

inputDataSet TimeSeriesDataSet
indicesToNotCopy List<int>

TimeSeriesDataSet(CsvContent, char, string)

Constructor that builds a dataset object from a csv-file, by loading LoadFromCsv() This version of the constructor is useful when receiving the csv-data across an API.

public TimeSeriesDataSet(CsvContent csvContent, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")

Parameters

csvContent CsvContent

the csv data loaded into a CsvContent object

separator char

the separator in the csv-file

dateTimeFormat string

the format of date-time strings in the csv-file

Properties

BadDataID

Some systems for storing data do not support "NaN", but instead some other magic value is reserved for indicating that a value is bad or missing.

public double BadDataID { get; set; }

Property Value

double

Methods

Add(string, double[])

Add an entire time-series to the dataset

public bool Add(string signalName, double[] values)

Parameters

signalName string
values double[]

Returns

bool

AddConstant(string, double)

Add a constant value to the time-series to the dataset

public bool AddConstant(string signalName, double value)

Parameters

signalName string
value double

Returns

bool

AddDataPoint(string, int, double)

Add a single data point

public bool AddDataPoint(string signalID, int idx, double value)

Parameters

signalID string
idx int
value double

Returns

bool

returns false if signal does not already exist or if index is beyond dataset size

AddNoiseToSignal(string, double, int)

Adds noise to a given signal in the dataset. (This is mainly intended for testing identification algorithms against simulated data.)

public bool AddNoiseToSignal(string signalName, double noiseAmplitude, int seed)

Parameters

signalName string

name of signal to have noise added to it

noiseAmplitude double

the amplutide of noise, the noise will be [-noiseAmplitude, noiseAmplitude]

seed int

a integer seed number is

Returns

bool

AddSet(TimeSeriesDataSet)

Adds all signals in a given set to this set

public bool AddSet(TimeSeriesDataSet inputDataSet)

Parameters

inputDataSet TimeSeriesDataSet

Returns

bool

AppendDataPoint(string, double)

Append a single value to a given signal.The signal is added if the signal name does not exist. This method is useful for logging values in a for-loop. Combine with AppendTimeStamp to ensure there is a time-stamp. If this variable does not exist, then previous values are padded.

public void AppendDataPoint(string signalName, double value)

Parameters

signalName string

name of signal

value double

value of signal

AppendTimeStamp(DateTime)

Used in conjunction with AppendDataPoint when appending data to the data set. Appends a time stamp, and updates the number of data points N, if the timestamp does not already exist and is newer than the newest time stamp in the current dataset.

public bool AppendTimeStamp(DateTime timestamp)

Parameters

timestamp DateTime

Returns

bool

true if able to append, otherwise false

Combine(TimeSeriesDataSet)

Combine this data set with the inputDataset into a new set

public TimeSeriesDataSet Combine(TimeSeriesDataSet inputDataSet)

Parameters

inputDataSet TimeSeriesDataSet

Returns

TimeSeriesDataSet

the newly created dataset

ContainsSignal(string)

Determine if a specific signal is in the dataset

public bool ContainsSignal(string signalID)

Parameters

signalID string

Returns

bool

CreateDownsampledCopy(int, int)

Returns a copy of the dataset that is downsampled by the given factor.

public TimeSeriesDataSet CreateDownsampledCopy(int downsampleFactor, int keyIndex = 0)

Parameters

downsampleFactor int

value greater than 1 indicating that every Floor(n*factor) value of the original data will be transferred.

keyIndex int

optional index around which to perform the downsampling.

Returns

TimeSeriesDataSet

CreateOversampledCopy(double)

Returns a copy of the dataset that is oversampled by the given factor.

public TimeSeriesDataSet CreateOversampledCopy(double timeBaseOversampled)

Parameters

timeBaseOversampled double

desired time base

Returns

TimeSeriesDataSet

a downsampled copy, or null if operation failed. (Method will return null if no timestamps are given.)

CreateTimestamps(double, int, DateTime?)

Creates internal timestamps from a given start time and time-base, must be called after filling the values

public void CreateTimestamps(double timeBase_s, int N = 0, DateTime? t0 = null)

Parameters

timeBase_s double

the time between samples in the dataset, in total seconds

N int

number of datapoints

t0 DateTime?

start time, can be null, which can be useful for testing

GetAsMatrix(List<int>)

Get all signals in the dataset as a matrix

public (double[,], string[]) GetAsMatrix(List<int> indicesToIgnore = null)

Parameters

indicesToIgnore List<int>

Returns

(double[,], string[])

the signals as a 2d-matrix, and the an array of strings with corresponding signal names

GetData(string[], int)

Get Data for multiple signals at a specific time index

public double[] GetData(string[] signalNames, int timeIdx)

Parameters

signalNames string[]
timeIdx int

Returns

double[]

May return null if an error occurred

GetDescription()

Gets the description of the dataset

public string GetDescription()

Returns

string

GetIndicesToIgnore()

Get a list of the indices in the dataset that are flagged to be ignored in identification

public List<int> GetIndicesToIgnore()

Returns

List<int>

empty list if no indices, otherwise a list of indices (never returns null)

GetLength()

Get the length in samples of the data set

The length of the dataset is determined by the number of timestamps.

public int? GetLength()

Returns

int?

an integer indicating the length of the dataset

GetNumDataPoints()

Returns the number of data points in the dataset

public int GetNumDataPoints()

Returns

int

GetNumSimulatorRestarts()

Get the number of time the simulator was restarted due to periods of bad data(only applicable for simulated datasets)

public int GetNumSimulatorRestarts()

Returns

int

GetSignalNames()

Get the names of all the signals, whether constant or varying

public string[] GetSignalNames()

Returns

string[]

GetTimeBase()

Get the time-base, the average time between two samples in the dataset

public double GetTimeBase()

Returns

double

The time-base in seconds

GetTimeDiff_s(int, int)

Returns the time difference in seconds between two indices (in seconds)

public double GetTimeDiff_s(int newerIndex, int olderIndex)

Parameters

newerIndex int
olderIndex int

Returns

double

GetTimeStamps()

Get a vector of the timestamps of the data-set, or null if no timestamps

public DateTime[] GetTimeStamps()

Returns

DateTime[]

GetValue(string, int)

Get Data for multiple signals at a specific time index

public double? GetValue(string signalName, int timeIdx)

Parameters

signalName string
timeIdx int

Returns

double?

May return null if an error occurred

GetValues(string)

Get the values of a specific signal

public double[] GetValues(string signalName)

Parameters

signalName string

Returns

double[]

null if signal not found

GetValues(string, SignalType, int)

Get the values of a specific signal

public double[] GetValues(string processID, SignalType signalType, int index = 0)

Parameters

processID string
signalType SignalType
index int

Returns

double[]

GetValuesAtTime(string[], int)

Get one or more signals from the dataset at a given time

public double[] GetValuesAtTime(string[] signalIds, int timeIndex)

Parameters

signalIds string[]
timeIndex int

Returns

double[]

InitNewSignal(string, double, int, double)

Define a new signal, specifying only its initial value

public void InitNewSignal(string signalName, double initialValue, int N, double nonYetSimulatedValue = NaN)

Parameters

signalName string
initialValue double

the value of time zero

N int

number of time stamps

nonYetSimulatedValue double

what value to fill in for future undefined times, default:nan

IsIndicesToIgnoreSet()

Determine if internal IndicesToIgnore is "null" i.e. has not been specified

public bool IsIndicesToIgnoreSet()

Returns

bool

true if IndicesToIgnore is not null, or false it is null

LoadFromCsv(string, char, string)

Reads data form a csv-file (such as that created by ToCSV())

public bool LoadFromCsv(string csvFileName, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")

Parameters

csvFileName string

csv file name

separator char

default separator

dateTimeFormat string

format string of the time-series vector to be read

Returns

bool

LoadFromCsv(CsvContent, char, string)

Loads the CsvContent(which can be read from a file) into a TimeSeriesDataSet object

public bool LoadFromCsv(CsvContent csvContent, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")

Parameters

csvContent CsvContent
separator char
dateTimeFormat string

Returns

bool

Remove(string)

Removes a signal from the dataset

public bool Remove(string signalName)

Parameters

signalName string

Returns

bool

ReplaceValues(string, double[], int)

Replaces the values of a specific signal

public void ReplaceValues(string signalName, double[] newValues, int index = 0)

Parameters

signalName string
newValues double[]
index int

ReplaceValues(string, SignalType, double[], int)

Replaces the values of a specific signal

public void ReplaceValues(string processID, SignalType signalType, double[] newValues, int index = 0)

Parameters

processID string
signalType SignalType
newValues double[]
index int

SetDescription(string, bool)

Set the description of the dataset

public void SetDescription(string description, bool doAppend = false)

Parameters

description string
doAppend bool

is set to true, the text is appended to previous text

SetIndicesToIgnore(List<int>)

The given indices will be skipped in any subsequent simulation of the dataset

public void SetIndicesToIgnore(List<int> indicesToIgnore)

Parameters

indicesToIgnore List<int>

SetNumSimulatorRestarts(int)

Save the number of simulator restarts that has been performed for a simulated dataset (not applicable for measured datasets)

public void SetNumSimulatorRestarts(int numSimulatorRestarts)

Parameters

numSimulatorRestarts int

SetTimeStamps(List<DateTime>)

Explicitly sets the timestamps of the time-series (possibly overriding any timeBase_s that was given during init) If times is null, then the method creates timestamps based on timeBase_s and t0.

public void SetTimeStamps(List<DateTime> times)

Parameters

times List<DateTime>

SubSetPrc(double, double)

Create a copy of the data set that is a "subset", given using start and end percentages of the original data span.

public TimeSeriesDataSet SubSetPrc(double startPrc, double endPrc)

Parameters

startPrc double
endPrc double

Returns

TimeSeriesDataSet

SubsetInd(int, int)

Create a copy of the data set that is a "subset", given using start and end indices of the original data span.

public TimeSeriesDataSet SubsetInd(int startInd, int endInd)

Parameters

startInd int
endInd int

Returns

TimeSeriesDataSet

ToCsv(string, string, int)

Exports the time-series data set to a csv-file

Times are encoded as "yyyy-MM-dd HH:mm:ss" and be loaded with CSV.LoadFromFile() afterwards

public bool ToCsv(string fileName, string csvSeparator = ";", int nSignificantDigits = 5)

Parameters

fileName string

The CSV-file name

csvSeparator string

the separator to use in the csv-file(despite the name, the most common is perhaps ";" which Excel will recognize automatically)

nSignificantDigits int

the number of significant digits to include for each variable

Returns

bool

true if successful, otherwise false

ToCsvText(string, int)

Create a comma-separated-variable(CSV) string of the dataset

public string ToCsvText(string csvSeparator = ";", int nSignificantDigits = 5)

Parameters

csvSeparator string

symbol used to separate columns in the string

nSignificantDigits int

number of significant digits per value

Returns

string

The CSV-string

ToDict()

Create a dictionary of all dataset values. Constants are padded out to be of N length.

public Dictionary<string, double[]> ToDict()

Returns

Dictionary<string, double[]>

Returns the dataset as a dictionary

ToString()

Summaize dataset in string

public override string ToString()

Returns

string

UpdateCsv()

When a dataset has been loaded from csv-file and changed, this method writes said changes back to the csv-file.

public bool UpdateCsv()

Returns

bool

true if successful, otherwise false