Class TimeSeriesDataSet
A class that holds time-series data for any number of tags, and with built in support for serlalizing/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.
Inherited Members
Namespace: TimeSeriesAnalysis
Assembly: TimeSeriesAnalysis.dll
Syntax
public class TimeSeriesDataSet
Constructors
| Edit this page View SourceTimeSeriesDataSet()
Default constructor
Declaration
[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
Declaration
public TimeSeriesDataSet(string csvFileName, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
Parameters
Type | Name | Description |
---|---|---|
string | csvFileName | name of csv-file |
char | separator | the separator in the csv-file |
string | dateTimeFormat | the format of date-time strings in the csv-file |
TimeSeriesDataSet(TimeSeriesDataSet)
Constructor that copies another dataset into the returned object
Declaration
public TimeSeriesDataSet(TimeSeriesDataSet inputDataSet)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputDataSet |
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.
Declaration
public TimeSeriesDataSet(CsvContent csvContent, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
Parameters
Type | Name | Description |
---|---|---|
CsvContent | csvContent | the csv data loaded into a CsvContent object |
char | separator | the separator in the csv-file |
string | dateTimeFormat | the format of date-time strings in the csv-file |
Methods
| Edit this page View SourceAdd(string, double[])
Add an entire time-series to the dataset
Declaration
public bool Add(string signalName, double[] values)
Parameters
Type | Name | Description |
---|---|---|
string | signalName | |
double[] | values |
Returns
Type | Description |
---|---|
bool |
AddConstant(string, double)
Add a constant value to the time-series to the dataset
Declaration
public bool AddConstant(string signalName, double value)
Parameters
Type | Name | Description |
---|---|---|
string | signalName | |
double | value |
Returns
Type | Description |
---|---|
bool |
AddDataPoint(string, int, double)
Add a single data point
Declaration
public bool AddDataPoint(string signalID, int idx, double value)
Parameters
Type | Name | Description |
---|---|---|
string | signalID | |
int | idx | |
double | value |
Returns
Type | Description |
---|---|
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 datset. (This is mainly intended for testing identification algorithms against simulated data.)
Declaration
public bool AddNoiseToSignal(string signalName, double noiseAmplitude, int seed)
Parameters
Type | Name | Description |
---|---|---|
string | signalName | name of signal to have noise added to it |
double | noiseAmplitude | the amplutide of noise, the noise will be [-noiseAmplitude, noiseAmplitude] |
int | seed | a integer seed number is |
Returns
Type | Description |
---|---|
bool |
AddSet(TimeSeriesDataSet)
Adds all signals in a given set to this set
Declaration
public bool AddSet(TimeSeriesDataSet inputDataSet)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputDataSet |
Returns
Type | Description |
---|---|
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.
Declaration
public void AppendDataPoint(string signalName, double value)
Parameters
Type | Name | Description |
---|---|---|
string | signalName | name of signal |
double | value | 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 stampe in the curent dataset.
Declaration
public bool AppendTimeStamp(DateTime timestamp)
Parameters
Type | Name | Description |
---|---|---|
DateTime | timestamp |
Returns
Type | Description |
---|---|
bool | true if able to append, otherwise false |
Combine(TimeSeriesDataSet)
Combine this data set with the inputDataset into a new set
Declaration
public TimeSeriesDataSet Combine(TimeSeriesDataSet inputDataSet)
Parameters
Type | Name | Description |
---|---|---|
TimeSeriesDataSet | inputDataSet |
Returns
Type | Description |
---|---|
TimeSeriesDataSet | the newly created dataset |
ContainsSignal(string)
Determine if a specific signal is in the dataset
Declaration
public bool ContainsSignal(string signalID)
Parameters
Type | Name | Description |
---|---|---|
string | signalID |
Returns
Type | Description |
---|---|
bool |
CreateDownsampledCopy(int)
Returns a copy of the dataset that is downsampled by the given factor
Declaration
public TimeSeriesDataSet CreateDownsampledCopy(int downsampleFactor)
Parameters
Type | Name | Description |
---|---|---|
int | downsampleFactor | value greater than 1 indicating that every nth value of the orignal data will be transferred |
Returns
Type | Description |
---|---|
TimeSeriesDataSet |
CreateTimestamps(double, int, DateTime?)
Creates internal timestamps from a given start time and timebase, must be called after filling the values
Declaration
public void CreateTimestamps(double timeBase_s, int N = 0, DateTime? t0 = null)
Parameters
Type | Name | Description |
---|---|---|
double | timeBase_s | the time between samples in the dataset, in total seconds |
int | N | |
DateTime? | t0 | start time, can be null, which can be usedful for testing |
GetAsMatrix(List<int>)
Get all signals in the dataset as a matrix
Declaration
public (double[,], string[]) GetAsMatrix(List<int> indicesToIgnore = null)
Parameters
Type | Name | Description |
---|---|---|
List<int> | indicesToIgnore |
Returns
Type | Description |
---|---|
(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
Declaration
public double[] GetData(string[] signalNames, int timeIdx)
Parameters
Type | Name | Description |
---|---|---|
string[] | signalNames | |
int | timeIdx |
Returns
Type | Description |
---|---|
double[] | May return null if an error occured |
GetIndicesToIgnore()
Get a list of the indices in the dataset that are flagged to be ignored in identification
Declaration
public List<int> GetIndicesToIgnore()
Returns
Type | Description |
---|---|
List<int> |
GetLength()
Get the length in samples of the data set
The length of the dataset is determined by the number of timestamps.
Declaration
public int? GetLength()
Returns
Type | Description |
---|---|
int? | an integer indicating the length of the dataset |
GetNumDataPoints()
Returns the number of data points in the dataset
Declaration
public int GetNumDataPoints()
Returns
Type | Description |
---|---|
int |
GetSignalNames()
Get the names of all the singals, wheter constant or varying
Declaration
public string[] GetSignalNames()
Returns
Type | Description |
---|---|
string[] |
GetTimeBase()
Get the timebase, the time between two samples in the dataset
Declaration
public double GetTimeBase()
Returns
Type | Description |
---|---|
double | The timebase in seconds |
GetTimeStamps()
Get a vector of the timestamps of the data-set, or null if no timestamps
Declaration
public DateTime[] GetTimeStamps()
Returns
Type | Description |
---|---|
DateTime[] |
GetValue(string, int)
Get Data for multiple signals at a specific time index
Declaration
public double? GetValue(string signalName, int timeIdx)
Parameters
Type | Name | Description |
---|---|---|
string | signalName | |
int | timeIdx |
Returns
Type | Description |
---|---|
double? | May return null if an error occured |
GetValues(string)
Get the values of a specific signal
Declaration
public double[] GetValues(string signalName)
Parameters
Type | Name | Description |
---|---|---|
string | signalName |
Returns
Type | Description |
---|---|
double[] | null if signal not found |
GetValues(string, SignalType, int)
Get the values of a specific signal
Declaration
public double[] GetValues(string processID, SignalType signalType, int index = 0)
Parameters
Type | Name | Description |
---|---|---|
string | processID | |
SignalType | signalType | |
int | index |
Returns
Type | Description |
---|---|
double[] |
GetValuesAtTime(string[], int)
Get one or more signals from the dataset at a given time
Declaration
public double[] GetValuesAtTime(string[] signalIds, int timeIndex)
Parameters
Type | Name | Description |
---|---|---|
string[] | signalIds | |
int | timeIndex |
Returns
Type | Description |
---|---|
double[] |
InitNewSignal(string, double, int, double)
Define a new signal, specifying only its inital value
Declaration
public void InitNewSignal(string signalName, double initalValue, int N, double nonYetSimulatedValue = NaN)
Parameters
Type | Name | Description |
---|---|---|
string | signalName | |
double | initalValue | the value of time zero |
int | N | number of time stamps |
double | nonYetSimulatedValue | what value to fill in for future undefined times, default:nan |
LoadFromCsv(string, char, string)
Reads data form a csv-file (such as that created by ToCSV())
Declaration
public bool LoadFromCsv(string csvFileName, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
Parameters
Type | Name | Description |
---|---|---|
string | csvFileName | csv file name |
char | separator | default separator |
string | dateTimeFormat | format string of the time-series vector to be read |
Returns
Type | Description |
---|---|
bool |
LoadFromCsv(CsvContent, char, string)
Loads the CsvContent(which can be read from a file) into a TimeSeriesDataSet object
Declaration
public bool LoadFromCsv(CsvContent csvContent, char separator = ';', string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
Parameters
Type | Name | Description |
---|---|---|
CsvContent | csvContent | |
char | separator | |
string | dateTimeFormat |
Returns
Type | Description |
---|---|
bool |
Remove(string)
Removes a signal from the dataset
Declaration
public bool Remove(string signalName)
Parameters
Type | Name | Description |
---|---|---|
string | signalName |
Returns
Type | Description |
---|---|
bool |
SetIndicesToIgnore(List<int>)
The given indices will be skipped in any subsequent simulation of the dataset
Declaration
public void SetIndicesToIgnore(List<int> indicesToIgnore)
Parameters
Type | Name | Description |
---|---|---|
List<int> | indicesToIgnore |
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.
Declaration
public void SetTimeStamps(List<DateTime> times)
Parameters
Type | Name | Description |
---|---|---|
List<DateTime> | times |
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.
Declaration
public TimeSeriesDataSet SubSetPrc(double startPrc, double endPrc)
Parameters
Type | Name | Description |
---|---|---|
double | startPrc | |
double | endPrc |
Returns
Type | Description |
---|---|
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.
Declaration
public TimeSeriesDataSet SubsetInd(int startInd, int endInd)
Parameters
Type | Name | Description |
---|---|---|
int | startInd | |
int | endInd |
Returns
Type | Description |
---|---|
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
Declaration
public bool ToCsv(string fileName, string csvSeparator = ";", int nSignificantDigits = 5)
Parameters
Type | Name | Description |
---|---|---|
string | fileName | The CSV-file name |
string | csvSeparator | the separator to use in the csv-file(despite the name, the most common is perhaps ";" which Excel will recognize automatically) |
int | nSignificantDigits | the number of singificant digits to include for each variable |
Returns
Type | Description |
---|---|
bool | true if successful, otherwise false |
ToCsvText(string, int)
Create a comma-separated-variable(CSV) string of the dataset
Declaration
public string ToCsvText(string csvSeparator = ";", int nSignificantDigits = 5)
Parameters
Type | Name | Description |
---|---|---|
string | csvSeparator | symbol used to separate columns in the string |
int | nSignificantDigits | number of significant digits per value |
Returns
Type | Description |
---|---|
string | The CSV-string |
ToDict()
Create a dictionary of all dataset values. Constants are padded out to be of N length.
Declaration
public Dictionary<string, double[]> ToDict()
Returns
Type | Description |
---|---|
Dictionary<string, double[]> | Returns the dataset as a dictionary |
UpdateCsv()
When a dataset has been loaded from csv-file and changed, this method writes said changes back to the csv-file.
Declaration
public bool UpdateCsv()
Returns
Type | Description |
---|---|
bool | true if succesful, otherwise false |