2.0.0b10
catchment modelling framework
Loading...
Searching...
No Matches
timeseries Class Reference

A timeseries is a list of values, equally distributed over time. More...

Detailed Description

A timeseries is a list of values, equally distributed over time.

To create one, one have to provide as start date and a step size. The end time is calculated from the number of values. Values queried for times before the start time are returned as the first item, values after the end time equal the last item. A timeseries with only one item reacts like a scalar value.

Creating a time series

import cmf
# Start date is the January 5th 2001 at 2:30 pm
start=cmf.Time(5,1,2001,14,30)
# time step of the timeseries is 20 minutes
step=cmf.min*20
# Type of interpolation between values
# 0 - Nearest neighbor,
# 1 - Linear,
# 2 - Squared,
# 3 - Cubic, etc.
interpolation=1
# Create timeseries
timeseries=cmf.timeseries(begin=start,step=step,interpolation=interpolation)
# add data
timeseries.add(0.1) # Value at 2001/5/1 2:30pm is 0.1
timeseries.add(0.2) # Value at 2001/5/1 2:50pm is 0.2
timeseries.add(0.1) # Value at 2001/5/1 3:10pm is 0.1

With this technique it is simple to read files or databases to fill timeseries.

<b> Using a timeseries</b>
Query every minute between 2:15 and 3:14 pm
for t in cmf.timerange(start,start+cmf.h,cmf.min):
print "Time:",t.AsDate(),"Value:",timeseries[t]
Query a specific position of the timeseries
print timeseries[2]
A timeseries is a list of values, equally distributed over time.
Definition timeseries.h:66
The main namespace of the model framework. Contains the other namespaces and the project class.
Definition __init__.py:1

Public Member Functions

 timeseries (cmf::math::Time begin=cmf::math::Time(), cmf::math::Time step=cmf::math::day, int interpolationmethod=1, size_t count=0)
 Constructor of a time series.
 
void add (double Value)
 Appends a measurement.
 
cmf::math::Time begin () const
 First date of measurement.
 
size_t count_values () const
 Number of valid values (=size - # of NaN's)
 
cmf::math::Time end () const
 Last date of measurements.
 
int interpolationpower () const
 Method for the interpolation (0 - Nearest neighbor, 1- linear, 2 - cubic spline (not implemented yet)
 
bool is_empty () const
 returns true if no values are added to the timeseries
 
double operator[] (cmf::math::Time t) const
 Returns an interpolated value at time t.
 
double & operator[] (ptrdiff_t i)
 Returns a reference to the value at position i.
 
size_t size () const
 Number of items in the timeseries.
 
cmf::math::Time step () const
 Time between the measurements.
 
Operators

Binary operators defined as free operators:

x = {+,-,*,/}

Defined for (x is one of the operators above):

  • timeseries = timeseries x timeseries
  • timeseries = double x timeseries
  • timeseries = timeseries x double
timeseriesoperator+= (cmf::math::timeseries)
 add timeseries to this
 
timeseriesoperator+= (double)
 add scalar to this
 
timeseriesoperator-= (cmf::math::timeseries)
 Subtract timeseries from this.
 
timeseriesoperator-= (double)
 Subtract scalar from this.
 
timeseriesoperator*= (cmf::math::timeseries)
 Multiply each element of timeseries with each element of this.
 
timeseriesoperator*= (double)
 Multiply each element of timeseries with scalar.
 
timeseriesoperator/= (cmf::math::timeseries)
 Divide each element of this by each element of timeseries.
 
timeseriesoperator/= (double)
 Divide each element of this by scalar.
 
timeseries reduce_min (cmf::math::Time begin, cmf::math::Time step) const
 Creates a timeseries with a bigger timestep, containing the minimum.
 
timeseries reduce_max (cmf::math::Time begin, cmf::math::Time step) const
 Creates a timeseries with a bigger timestep, containing the maximum.
 
timeseries reduce_sum (cmf::math::Time begin, cmf::math::Time step) const
 Creates a timeseries with a bigger timestep, containing the sum.
 
timeseries reduce_avg (cmf::math::Time begin, cmf::math::Time step) const
 Creates a timeseries with a bigger timestep, containing the average.
 

Constructor & Destructor Documentation

◆ timeseries()

timeseries ( cmf::math::Time begin = cmf::math::Time(),
cmf::math::Time step = cmf::math::day,
int interpolationmethod = 1,
size_t count = 0 )

Constructor of a time series.

Parameters
beginFirst date of measurement
stepTime between measurements
interpolationmethodMethod for the interpolation (0 - Nearest neighbor, 1- linear, 2 - cubic spline (not implemented yet)
countInitial number of items. Items are filled with 0.0