Class TimeSeries
public class TimeSeries
- Inheritance
-
TimeSeries
- Inherited Members
Constructors
TimeSeries()
Default Constructor
public TimeSeries()
TimeSeries(string)
Constructor
public TimeSeries(string title)
Parameters
title
stringTitle of the time series
Properties
Average
Returns the average value of the time series
public double Average { get; }
Property Value
Remarks
Simple average calculation without regard for time
DataSource
The original datasource of the time series
public TimeSeriesDataSource DataSource { get; set; }
Property Value
Dates
The time series' dates
public IList<DateTime> Dates { get; }
Property Value
DisplayOptions
Options for displaying the time series
public TimeSeriesDisplayOptions DisplayOptions { get; set; }
Property Value
EndDate
Returns the end date of the time series
public DateTime EndDate { get; }
Property Value
FirstValue
Returns the first value of the time series
public double FirstValue { get; }
Property Value
Id
Unique Id
public int Id { get; }
Property Value
Interpretation
The time series' interpretation
public TimeSeries.InterpretationEnum Interpretation { get; set; }
Property Value
LastValue
Returns the last value of the time series
public double LastValue { get; }
Property Value
Length
The time series' length (number of nodes)
public int Length { get; }
Property Value
Maximum
Returns the maximum value of the time series
public double Maximum { get; }
Property Value
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
Property Value
MaximumNode
Returns the node with the maximum value of the time series
public KeyValuePair<DateTime, double> MaximumNode { get; }
Property Value
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
Property Value
Metadata
The time series' metadata
public Metadata Metadata { get; set; }
Property Value
MetadataText
The time series' metadata formatted as a single string
public string MetadataText { get; }
Property Value
Remarks
Empty entries are omitted from the string
Minimum
Returns the minimum value of the time series
public double Minimum { get; }
Property Value
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
Property Value
NaNCount
The number of NaN nodes
public int NaNCount { get; }
Property Value
NaNPeriods
Returns the list of time periods (range, count) consisting of NaN nodes
public List<(DateRange range, int count)> NaNPeriods { get; }
Property Value
Nodes
The time series' nodes
public SortedList<DateTime, double> Nodes { get; }
Property Value
Nodes[DateTime]
Returns the value at timestamp t
public double Nodes[DateTime t] { get; }
Parameters
t
DateTime
Property Value
Nodes[DateTime, DateTime]
The time series' nodes within a defined time period (inclusively)
public SortedList<DateTime, double> Nodes[DateTime startdate, DateTime enddate] { get; }
Parameters
Property Value
NodesClean
The time series' nodes without NaN and Infinity values
public SortedList<DateTime, double> NodesClean { get; }
Property Value
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
Property Value
StartDate
Returns the start date of the time series
public DateTime StartDate { get; }
Property Value
Sum
Returns the sum of the time series' values
public double Sum { get; }
Property Value
Title
Title of the time series
public string Title { get; set; }
Property Value
Unit
The unit of the the time series' values
public string Unit { get; set; }
Property Value
Values
The time series' values
public IList<double> Values { get; }
Property Value
Volume
Returns the volume of the time series (values integrated over time)
public double Volume { get; }
Property Value
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
Methods
AddNode(DateTime, double)
Adds a node to the time series
public void AddNode(DateTime _date, double _value)
Parameters
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
DateTimeBase DateTime from which to offset
timesteptype
TimeSeries.TimeStepTypeEnumThe type of interval to offset
timestepinterval
intThe 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
TimeSeriesseries 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.TimeStepTypeEnumThe type of timestep interval
timestepinterval
intThe number of intervals that make up each timestep
startdate
DateTimeStart date for the new time series
outputInterpretation
TimeSeries.InterpretationEnumOptional 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
boolif True, the Id is preserved, otherwise a new unique Id is assigned (default)
Returns
Cut(TimeSeries)
Cut the time series to the timespan of another time series
public void Cut(TimeSeries series2)
Parameters
series2
TimeSeriesthe 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
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
DateTimeFirst timestamp
v1
doubleFirst value
t2
DateTimeSecond timestamp
v2
doubleSecond value
interpretation
TimeSeries.InterpretationEnumInterpretation to use
unitTimeStepType
TimeSeries.TimeStepTypeEnumTimeStepType 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
DateTimeFirst timestamp
v1
doubleFirst value
t2
DateTimeSecond timestamp
v2
doubleSecond value
t
DateTimeTimestamp at which to interpolate
interpretation
TimeSeries.InterpretationEnumInterpretation 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
intthe 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
TimeSeriesFirst timeseries
ts2
TimeSeriesSecond timeseries
ToString()
Returns the time series' title
public override string ToString()
Returns
UpdateNode(DateTime, double)
Updates the value of an existing node
public void UpdateNode(DateTime _date, double _value)
Parameters
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
stringMaxWert, 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
Returns
get_MaximumNode(DateTime, DateTime)
public KeyValuePair<DateTime, double> get_MaximumNode(DateTime startdate, DateTime enddate)
Parameters
Returns
get_Minimum(DateTime, DateTime)
public double get_Minimum(DateTime startdate, DateTime enddate)
Parameters
Returns
get_Nodes(DateTime)
public double get_Nodes(DateTime t)
Parameters
t
DateTime
Returns
get_Nodes(DateTime, DateTime)
public SortedList<DateTime, double> get_Nodes(DateTime startdate, DateTime enddate)
Parameters
Returns
get_NodesClean(DateTime, DateTime)
public SortedList<DateTime, double> get_NodesClean(DateTime startdate, DateTime enddate)
Parameters
Returns
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