Table of Contents

Class TimeSeries

Namespace
BlueM.Wave
Assembly
Wave.dll
public class TimeSeries
Inheritance
TimeSeries
Inherited Members

Constructors

TimeSeries()

Default Constructor

public TimeSeries()

TimeSeries(string)

Constructor

public TimeSeries(string title)

Parameters

title string

Title of the time series

Properties

Average

Returns the average value of the time series

public double Average { get; }

Property Value

double

Remarks

Simple average calculation without regard for time

DataSource

The original datasource of the time series

public TimeSeriesDataSource DataSource { get; set; }

Property Value

TimeSeriesDataSource

Dates

The time series' dates

public IList<DateTime> Dates { get; }

Property Value

IList<DateTime>

DisplayOptions

Options for displaying the time series

public TimeSeriesDisplayOptions DisplayOptions { get; set; }

Property Value

TimeSeriesDisplayOptions

EndDate

Returns the end date of the time series

public DateTime EndDate { get; }

Property Value

DateTime

FirstValue

Returns the first value of the time series

public double FirstValue { get; }

Property Value

double

Id

Unique Id

public int Id { get; }

Property Value

int

Interpretation

The time series' interpretation

public TimeSeries.InterpretationEnum Interpretation { get; set; }

Property Value

TimeSeries.InterpretationEnum

LastValue

Returns the last value of the time series

public double LastValue { get; }

Property Value

double

Length

The time series' length (number of nodes)

public int Length { get; }

Property Value

int

Maximum

Returns the maximum value of the time series

public double Maximum { get; }

Property Value

double

Maximum[DateTime, DateTime]

Returns the maximum value of the time series within a defined time period (inclusively)

public double Maximum[DateTime startdate, DateTime enddate] { get; }

Parameters

startdate DateTime
enddate DateTime

Property Value

double

MaximumNode

Returns the node with the maximum value of the time series

public KeyValuePair<DateTime, double> MaximumNode { get; }

Property Value

KeyValuePair<DateTime, double>

MaximumNode[DateTime, DateTime]

Returns the node with the maximum value of the time series within a defined time period (inclusively)

public KeyValuePair<DateTime, double> MaximumNode[DateTime startdate, DateTime enddate] { get; }

Parameters

startdate DateTime
enddate DateTime

Property Value

KeyValuePair<DateTime, double>

Metadata

The time series' metadata

public Metadata Metadata { get; set; }

Property Value

Metadata

MetadataText

The time series' metadata formatted as a single string

public string MetadataText { get; }

Property Value

string

Remarks

Empty entries are omitted from the string

Minimum

Returns the minimum value of the time series

public double Minimum { get; }

Property Value

double

Minimum[DateTime, DateTime]

Returns the minimum value of the time series within a defined time period (inclusively)

public double Minimum[DateTime startdate, DateTime enddate] { get; }

Parameters

startdate DateTime
enddate DateTime

Property Value

double

NaNCount

The number of NaN nodes

public int NaNCount { get; }

Property Value

int

NaNPeriods

Returns the list of time periods (range, count) consisting of NaN nodes

public List<(DateRange range, int count)> NaNPeriods { get; }

Property Value

List<(DateRange range, int count)>

Nodes

The time series' nodes

public SortedList<DateTime, double> Nodes { get; }

Property Value

SortedList<DateTime, double>

Nodes[DateTime]

Returns the value at timestamp t

public double Nodes[DateTime t] { get; }

Parameters

t DateTime

Property Value

double

Nodes[DateTime, DateTime]

The time series' nodes within a defined time period (inclusively)

public SortedList<DateTime, double> Nodes[DateTime startdate, DateTime enddate] { get; }

Parameters

startdate DateTime
enddate DateTime

Property Value

SortedList<DateTime, double>

NodesClean

The time series' nodes without NaN and Infinity values

public SortedList<DateTime, double> NodesClean { get; }

Property Value

SortedList<DateTime, double>

Remarks

The cleaned nodes are cached and only created once per instance

NodesClean[DateTime, DateTime]

The time series' nodes without NaN and Infinity values within a defined time period (inclusively)

public SortedList<DateTime, double> NodesClean[DateTime startdate, DateTime enddate] { get; }

Parameters

startdate DateTime
enddate DateTime

Property Value

SortedList<DateTime, double>

StartDate

Returns the start date of the time series

public DateTime StartDate { get; }

Property Value

DateTime

Sum

Returns the sum of the time series' values

public double Sum { get; }

Property Value

double

Title

Title of the time series

public string Title { get; set; }

Property Value

string

Unit

The unit of the the time series' values

public string Unit { get; set; }

Property Value

string

Values

The time series' values

public IList<double> Values { get; }

Property Value

IList<double>

Volume

Returns the volume of the time series (values integrated over time)

public double Volume { get; }

Property Value

double

Remarks

Only works for time-based units that end with "/s", "/min", "/h" or "/d" and interpretations Instantaneous, BlockLeft and BlockRight. Otherwise returns NaN.

getUniqueID

Returns a new unique ID

public static int getUniqueID { get; }

Property Value

int

Methods

AddNode(DateTime, double)

Adds a node to the time series

public void AddNode(DateTime _date, double _value)

Parameters

_date DateTime

Date

_value double

Value

Remarks

If the given date already exists, the new node is discarded and a warning is written to the log

AddTimeInterval(DateTime, TimeStepTypeEnum, int)

Returns a new DateTime offset from the given base DateTime by the specified interval

public static DateTime AddTimeInterval(DateTime t, TimeSeries.TimeStepTypeEnum timesteptype, int timestepinterval)

Parameters

t DateTime

Base DateTime from which to offset

timesteptype TimeSeries.TimeStepTypeEnum

The type of interval to offset

timestepinterval int

The number of intervals to offset (can be negative in order to subract)

Returns

DateTime

The offset DateTime

Append(TimeSeries)

Appends a time series

public void Append(TimeSeries series2)

Parameters

series2 TimeSeries

series to be appended

Remarks

in the case of an overlap between the two series, the nodes of the appended series within the overlap are discarded

ChangeTimestep(TimeStepTypeEnum, int, DateTime, InterpretationEnum)

Returns a new, equidistant time series with the specified timestep

public TimeSeries ChangeTimestep(TimeSeries.TimeStepTypeEnum timesteptype, int timestepinterval, DateTime startdate, TimeSeries.InterpretationEnum outputInterpretation = InterpretationEnum.Undefined)

Parameters

timesteptype TimeSeries.TimeStepTypeEnum

The type of timestep interval

timestepinterval int

The number of intervals that make up each timestep

startdate DateTime

Start date for the new time series

outputInterpretation TimeSeries.InterpretationEnum

Optional interpretation to use for the output timeseries. If not defined, the original interpretation is preserved, if possible

Returns

TimeSeries

The new time series

Remarks

Output interpretation Instantaneous is not implemented, because it would require considering a time interval 0.5 * dt to the left and right of the output timestamps which causes issues with timestep intervals of type Month (and also headaches). Time steps that are not fully within the time series are not included in the result time series. Time steps within which at least one node contain NaN values also get the value NaN.

TODO: Support more interpretations Allow handling NaN values (e.g. as 0)?

Clone(bool)

Clones a time series

public TimeSeries Clone(bool preserveId = false)

Parameters

preserveId bool

if True, the Id is preserved, otherwise a new unique Id is assigned (default)

Returns

TimeSeries

Cut(TimeSeries)

Cut the time series to the timespan of another time series

public void Cut(TimeSeries series2)

Parameters

series2 TimeSeries

the time series to whose timespan the time series should be cut

Cut(DateTime, DateTime)

Cut a time series using start and end dates

public void Cut(DateTime _start, DateTime _end)

Parameters

_start DateTime

start date

_end DateTime

end date

Remarks

Removes all nodes before the start date and after the end date. If there is no node with the exact start date, the closest node before the start date is also kept. If there is no node with the exact end date, the closest node after the end date is also kept.

IntegrateVolume(DateTime, double, DateTime, double, InterpretationEnum, TimeStepTypeEnum)

Integrates the volume between two nodes while respecting interpretation and unit

public static double IntegrateVolume(DateTime t1, double v1, DateTime t2, double v2, TimeSeries.InterpretationEnum interpretation, TimeSeries.TimeStepTypeEnum unitTimeStepType = TimeStepTypeEnum.Second)

Parameters

t1 DateTime

First timestamp

v1 double

First value

t2 DateTime

Second timestamp

v2 double

Second value

interpretation TimeSeries.InterpretationEnum

Interpretation to use

unitTimeStepType TimeSeries.TimeStepTypeEnum

TimeStepType of the unit, default is per second

Returns

double

The volume

InterpolateValue(DateTime, double, DateTime, double, DateTime, InterpretationEnum)

Interpolates a value between two nodes while respecting the interpretation

public static double InterpolateValue(DateTime t1, double v1, DateTime t2, double v2, DateTime t, TimeSeries.InterpretationEnum interpretation)

Parameters

t1 DateTime

First timestamp

v1 double

First value

t2 DateTime

Second timestamp

v2 double

Second value

t DateTime

Timestamp at which to interpolate

interpretation TimeSeries.InterpretationEnum

Interpretation to use

Returns

double

The interpolated value

SplitHydroYears(int)

Splits a time series into individual series for each hydrological year

public Dictionary<int, TimeSeries> SplitHydroYears(int startMonth = 11)

Parameters

startMonth int

the month with which the hydrological year starts. Default = 11 (November)

Returns

Dictionary<int, TimeSeries>

A dictionary of time series, the key represents the calendar year in which each hydrological year starts

Synchronize(ref TimeSeries, ref TimeSeries)

Synchronizes two timeseries in-place by only keeping the common timestamps

public static void Synchronize(ref TimeSeries ts1, ref TimeSeries ts2)

Parameters

ts1 TimeSeries

First timeseries

ts2 TimeSeries

Second timeseries

ToString()

Returns the time series' title

public override string ToString()

Returns

string

UpdateNode(DateTime, double)

Updates the value of an existing node

public void UpdateNode(DateTime _date, double _value)

Parameters

_date DateTime

Date

_value double

Value

convertErrorValues(params double[])

Creates a copy of the time series in which all nodes with specified error values are converted to NaN

public TimeSeries convertErrorValues(params double[] errorvalues)

Parameters

errorvalues double[]

array of error values to ignore

Returns

TimeSeries

the cleaned time series

Remarks

a tolerance of 0.0001 is used to compare series values to errorvalues

getWert(string)

Calculate a metric from the time series' values

public double getWert(string WertTyp)

Parameters

WertTyp string

MaxWert, MinWert, Average, AnfWert, EndWert, Summe

Returns

double

the calculated metric

Remarks

Obsolete, kept for backwards compatibility with BlueM.Opt

get_Maximum(DateTime, DateTime)

public double get_Maximum(DateTime startdate, DateTime enddate)

Parameters

startdate DateTime
enddate DateTime

Returns

double

get_MaximumNode(DateTime, DateTime)

public KeyValuePair<DateTime, double> get_MaximumNode(DateTime startdate, DateTime enddate)

Parameters

startdate DateTime
enddate DateTime

Returns

KeyValuePair<DateTime, double>

get_Minimum(DateTime, DateTime)

public double get_Minimum(DateTime startdate, DateTime enddate)

Parameters

startdate DateTime
enddate DateTime

Returns

double

get_Nodes(DateTime)

public double get_Nodes(DateTime t)

Parameters

t DateTime

Returns

double

get_Nodes(DateTime, DateTime)

public SortedList<DateTime, double> get_Nodes(DateTime startdate, DateTime enddate)

Parameters

startdate DateTime
enddate DateTime

Returns

SortedList<DateTime, double>

get_NodesClean(DateTime, DateTime)

public SortedList<DateTime, double> get_NodesClean(DateTime startdate, DateTime enddate)

Parameters

startdate DateTime
enddate DateTime

Returns

SortedList<DateTime, double>

removeNaNValues()

Returns a copy of the time series without the nodes having NaN and Infinity values

public TimeSeries removeNaNValues()

Returns

TimeSeries

the cleaned time series