TimeSeries

(Source code, png, hires.png, pdf)

../../_images/TimeSeries.png
class TimeSeries(*args)

Time series.

Available constructors:

TimeSeries(nSteps,dim)

TimeSeries(timeGrid, dim)

TimeSeries(timeGrid, sample)

TimeSeries(field)

Parameters:

nSteps : int

Enables to create a regular time grid on [0, nSteps] which time step is equal to 1.

timeGrid : RegularGrid

Regular time grid of the time series.

dim : int

Dimension of the values of the time series at each time stamp. By default, the values are equal to the null vector.

sample : 2-d sequence of float

Values assigned to each time stamp of the time series.

field : Field

Maps a field into a time series when the associated lesh cn be interpretated as a regular time grid.

Examples

Create a time series:

>>> import openturns as ot
>>> tmin = 0.0
>>> timeStep = 0.1
>>> n = 5
>>> myTimeGrid = ot.RegularGrid(tmin, timeStep, n)
>>> myValues = [[1.0], [2.0], [1.5], [4.5], [0.5]]
>>> myTimeSeries = ot.TimeSeries(myTimeGrid, myValues)

Draw the time series:

>>> graph = myTimeSeries.draw()

Methods

add(*args) Add a new value to the time series and extend the associated time grid.
asDeformedMesh() Get the mesh deformed according to the values of the field.
asSample()
draw() Draw the first marginal of the field if the spatial dimension is less than 2.
drawMarginal([index, interpolate]) Draw one marginal field if the spatial dimension is less than 2.
exportToVTKFile(fileName) Create the VTK format file of the field.
getClassName() Accessor to the object’s name.
getDescription() Get the description of the vertices and the values of the field.
getDimension() Get the dimension d of the values.
getId() Accessor to the object’s id.
getMarginal(*args)
getMesh() Get the mesh on which the field is defined.
getName() Accessor to the object’s name.
getSample() Get the values of the field.
getShadowedId() Accessor to the object’s shadowed id.
getSize() Get the number of values inside the field.
getSpatialDimension() Get the dimension of the domain \cD.
getSpatialMean() Get the spatial weighted mean of the values of the field.
getTemporalMean() Get the mean of the values of the field.
getTimeGrid() Get the mesh as a time grid if it is 1D and regular.
getValueAtIndex(index) Get the value of the field at the vertex of the given index.
getValueAtNearestPosition(position) Get the value of the field at the vertex of the mesh the nearest to the given point.
getValueAtNearestTime(timestamp)
getValues() Get the values of the field.
getVisibility() Accessor to the object’s visibility state.
hasName() Test if the object is named.
hasVisibleName() Test if the object has a distinguishable name.
setDescription(description) Set the description of the field..
setName(name) Accessor to the object’s name.
setShadowedId(id) Accessor to the object’s shadowed id.
setValueAtIndex(index, val) Assign the value of the field to the vertex at the given index.
setValueAtNearestPosition(position, val) Assign the value of the field to the vertex the nearest to a specified position.
setValueAtNearestTime(timestamp, val)
setValues(values) Assign values to a field.
setVisibility(visible) Accessor to the object’s visibility state.
__init__(*args)
add(*args)

Add a new value to the time series and extend the associated time grid.

Available usages:

add(sample)

add(timeSeries)

Parameters:

sample : 2-d sequence of float, of dimension the same as the dimension of the values of the time series.

timeSeries : TimeSeries, which time grid must match with the initial time grid (one follows the other).

Returns:

newTimeSeries: TimeSeries, which regular grid has been extended with a new time stamp or a second time grid, associated to the new values.

asDeformedMesh()

Get the mesh deformed according to the values of the field.

Returns:

deformedMesh : Mesh

The initial mesh is deformed as follows: each vertex of the mesh is replaced by the sum of the vertex and the value of the field at this vertex. Only works when d=n: the spatial dimension n: is equal to the dimension of the field d.

draw()

Draw the first marginal of the field if the spatial dimension is less than 2.

Returns:

graph : Graph

Calls drawMarginal(0, False).

See also

drawMarginal

drawMarginal(index=0, interpolate=True)

Draw one marginal field if the spatial dimension is less than 2.

Parameters:

index : int

The selected marginal.

interpolate : bool

Indicates whether the values at the vertices are linearly interpolated.

Returns:

graph : Graph

  • If the dimension of the mesh is n=1 and interpolate=True: it draws the graph of the piecewise linear function based on the selected marginal values of the field and the vertices coordinates (in \Rset).
  • If the dimension of the mesh is n=1 and interpolate=False: it draws the cloud of points which coordinates are (vertex, value of the marginal index).
  • If the dimension of the mesh is n=2 and interpolate=True: it draws several iso-values curves of the selected marginal, based on a piecewise linear interpolation within the simplices (triangles) of the mesh. You get an empty graph if the vertices are not connected through simplicies.
  • If the dimension of the mesh is n=2 and interpolate=False: if the vertices are connected through simplicies, each simplex is drawn with a color defined by the mean of the values of the vertices of the simplex. In the other case, it draws each vertex colored by its value.
exportToVTKFile(fileName)

Create the VTK format file of the field.

Parameters:

myVTKFile : str

Name of the output file. No extension is append to the filename.

Notes

Creates the VTK format file that contains the mesh and the associated values that can be visualised with the open source software Paraview .

getClassName()

Accessor to the object’s name.

Returns:

class_name : str

The object class name (object.__class__.__name__).

getDescription()

Get the description of the vertices and the values of the field.

Returns:

description : Description

Description of the vertices and the values of the field.

getDimension()

Get the dimension d of the values.

Returns:

d : int

Dimension of the values: d.

getId()

Accessor to the object’s id.

Returns:

id : int

Internal unique identifier.

getMesh()

Get the mesh on which the field is defined.

Returns:

mesh : Mesh

Mesh over which the domain \cD is discretized.

getName()

Accessor to the object’s name.

Returns:

name : str

The name of the object.

getSample()

Get the values of the field.

Returns:

values : Sample

Values associated to the mesh. The size of the sample is the number of vertices of the mesh and the dimension is the dimension of the values (d).

getShadowedId()

Accessor to the object’s shadowed id.

Returns:

id : int

Internal unique identifier.

getSize()

Get the number of values inside the field.

Returns:

size : int

Number of values inside the field, which corresponds to the number of vertices of the mesh.

getSpatialDimension()

Get the dimension of the domain \cD.

Returns:

n : int

Dimension of the domain \cD: n.

getSpatialMean()

Get the spatial weighted mean of the values of the field.

Returns:

spatialMean : Point

Weighted mean of the values of the field, weighted by the volume of each simplex.

Notes

The spatial mean of the field is defined by:

\displaystyle \frac{1}{V} \sum_{S_i \in \cM} \left( \frac{1}{n+1}\sum_{k=0}^{n} \vect{x}_{i_k}\right) |S_i|

where S_i is the simplex of index i of the mesh, |S_i| its volume and (\vect{x}_{i_0}, \dots, \vect{x}_{i_n}) the values of the field associated to the vertices of S_i, and \displaystyle V=\sum_{S_i \in \cD} |S_i|.

getTemporalMean()

Get the mean of the values of the field.

Returns:

temporalMean : Point

Mean of the values of the field.

Notes

If we note (\vect{x}_0, \dots, \vect{x}_{N-1}) the values in \Rset^d of the field, then the temporal mean is defined by:

\displaystyle  \frac{1}{N} \sum_{i=0}^{N-1} \vect{x}_i

Only makes sense in the case of a regular grid.

getTimeGrid()

Get the mesh as a time grid if it is 1D and regular.

Returns:

timeGrid : RegularGrid

Mesh of the field when it can be interpreted as a RegularGrid. We check if the vertices of the mesh are scalar and are regularly spaced in \Rset but we don’t check if the connectivity of the mesh is conform to the one of a regular grid (without any hole and composed of ordered instants).

getValueAtIndex(index)

Get the value of the field at the vertex of the given index.

Parameters:

index : int

Vertex of the mesh of index index.

Returns:

value : Point

The value of the field associated to the selected vertex, in \Rset^d.

getValueAtNearestPosition(position)

Get the value of the field at the vertex of the mesh the nearest to the given point.

Parameters:

point : sequence of float in \Rset^n.

Returns:

value : Point in \Rset^d.

The value of the field associated to vertex the nearest of point with respect to the Euclidean norm.

getValues()

Get the values of the field.

Returns:

values : Sample

Values associated to the mesh. The size of the sample is the number of vertices of the mesh and the dimension is the dimension of the values (d). Identical to getSample().

getVisibility()

Accessor to the object’s visibility state.

Returns:

visible : bool

Visibility flag.

hasName()

Test if the object is named.

Returns:

hasName : bool

True if the name is not empty.

hasVisibleName()

Test if the object has a distinguishable name.

Returns:

hasVisibleName : bool

True if the name is not empty and not the default one.

setDescription(description)

Set the description of the field..

Parameters:

myDescription : Description

Description of the field. Must be of size n+d and give the description of the vertices and the values.

setName(name)

Accessor to the object’s name.

Parameters:

name : str

The name of the object.

setShadowedId(id)

Accessor to the object’s shadowed id.

Parameters:

id : int

Internal unique identifier.

setValueAtIndex(index, val)

Assign the value of the field to the vertex at the given index.

Parameters:

index : int

Index that characterizes one vertex of the mesh.

value : Point in \Rset^d.

New value assigned to the selected vertex.

setValueAtNearestPosition(position, val)

Assign the value of the field to the vertex the nearest to a specified position.

Parameters:

position : sequence of float in \Rset^n.

value : sequence of float in \Rset^d.

New value assigned to the vertex the nearest to position with respect to the Euclidean norm.

setValues(values)

Assign values to a field.

Parameters:

values : 2-d sequence of float

Values assigned to the mesh. The size of the values is the number of vertices of the mesh and the dimension is d.

setVisibility(visible)

Accessor to the object’s visibility state.

Parameters:

visible : bool

Visibility flag.