Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Português


synchronize

synchronize several timeseries on the same time basis

Syntax

tsout = synchronize(tsin1, ..., tsinN)

tsout = synchronize(tsin1, ..., tsinN, howtosynchronize)
tsout = synchronize(tsin1, ..., tsinN, howtosynchronize, method)

tsout = synchronize(tsin1, ..., tsinN, newTimeStep)
tsout = synchronize(tsin1, ..., tsinN, newTimeStep, method)

tsout = synchronize(tsin1, ..., tsinN, newTimes)
tsout = synchronize(tsin1, ..., tsinN, newTimes, method)

tsout = synchronize(tsin1, ..., tsinN, "regular", "TimeStep", timeStep)
tsout = synchronize(tsin1, ..., tsinN, "regular", "SampleRate", sampleRate)
tsout = synchronize(tsin1, ..., tsinN, "regular", method, "TimeStep", timeStep)
tsout = synchronize(tsin1, ..., tsinN, "regular", method, "SampleRate", sampleRate)

tsout = synchronize(..., Name, Value)

[tsout1, ..., tsoutN] = synchronize(tsin1, ..., tsinN, ....)

Arguments

tsin1, ..., tsinN

timeseries object in input

howtosynchronize

method to create the new row times of tsout:'union', 'intersection'

newTimeStep

time step defined by 'yearly', 'monthly', 'daily', 'hourly', 'minutely', 'secondly'

newTimes

new time, duration or datetime column vector.

timeStep

time step, duration or calendarDuration value

sampleRate

number of samples per second (Hz), double value

method

method used to fill the missing values or to compute informations for each new row time

methods available to fill the missing value: 'default', 'fillwithmissing', 'fillwihconstant', 'linear', 'spline'

computation methods available: 'count', 'firstvalue', 'lastvalue', 'mode', Scilab function, user function

Name, Value

'Constant': option available only with fillwihconstant method

'IncludedEdge': 'left' or 'right' value. This option is only available with 'count', 'firstvalue', 'lastvalue', 'mode', Scilab function, user function methods.

tsout1, ..., tsoutN

new timeseries.

Description

The synchronize function synchronizes the variables (columns) of all timeseries on the same time basis. tsout will contain all variables of all tsin. If several timeseries have the same variable name, then a "_var" + an integer is added to the variable name.

tsout = synchronize(tsin1, ..., tsinN) returns a timeseries with the variables of each tsin1, ..., tsinN synchronized on the same time basis. This new time basis of tsout is the union of all the tsin times sorted by increasing order. Each time in tsout is unique, i.e. for a duplicate time in multiple tsins, variables column are joined under this time in tsout. The time basis of the tsins are often different, by synchronizing them, NaN, "" or NaT (default values when a data is missing) are added when there is no data corresponding to thus time in its initial time basis.

tsout = synchronize(tsin1, ..., tsinN, howtosynchronize) synchronizes all the input timeseries to the same time basis built with howtosynchronize. This variable can be

  • 'union': groups all times of timeseries to form a single one.

  • 'intersection': create the new time basis only with the times that are common to all timeseries.

tsout = synchronize(tsin1, ..., tsinN, howtosynchronize, method) creates a new timeseries from the input timeseries by synchronizing all variables to the same time basis. howtosynchronize specifies the content of the time vector. The method variable specifies the method used to fill in variables that have no data for this time. It can be used to aggregate data by using a Scilab or an user function:

  • 'default': either fillwithmissing or use method defined in VariableContinuity property.

  • 'fillwithmissing': for the times of tsout not matching to the times of tsin, the rows of tsout are filled with the default values for each type (NaN for doubles, "" for strings, NaT for datetimes, ...).

  • 'fillwithconstant': this method uses to 'Constant' keyword. 'Constant' is a cell of the same number of columns than tsin without the Time column. The cell content must concord with the column of tsin1, ..., tsinN.

  • 'linear': linear interpolation. tsin1, ..., tsinN must be sorted by time and contains unique values in the time column.

  • 'spline': cubique spline interpolation. tsin1, ..., tsinN must be sorted by time and contains unique values in the time column.

  • 'count': counts the number of values of tsin1, ..., tsinN contained in each new time step defined for tsout.

  • 'firstvalue': takes the first value contained in tsin1, ..., tsinN for each time step defined for tsout.

  • 'lastvalue': takes the last value contained in tsin1, ..., tsinN for each time step defined for tsout.

  • 'mode': computes the mode of the values of tsin1, ..., tsinN contained in each new time step defined for tsout.

  • Scilab or user function: function used to compute values of tsout (for example: mean, sum, ...).

tsout = synchronize(tsin1, ..., tsinN, newTimeStep) or tsout = synchronize(tsin1, ..., tsinN, newTimeStep, method) synchronizes tsin1, ..., tsinN on the new time basis generated by newTimeStep: 'yearly', 'monthly' 'daily', 'hourly', 'minutely' ou 'secondly'.

tsout = synchronize(tsin1, ..., tsinN, newTimes) or tsout = synchronize(tsin1, ..., tsinN, newTimes, method) creates a new timeseries based on the newTimes, duration or datetime vector.

tsout = synchronize(tsin1, ..., tsinN, "regular", "TimeStep", timeStep) or tsout = synchronize(tsin1, ..., tsinN, "TimeStep", timeStep, method): time vector, contained in tsout, is created from the time step timeStep, duration or calendarDuration scalar.

tsout = synchronize(tsin1, ..., tsinN, "regular", "SampleRate", sampleRate) or tsout = synchronize(tsin1, ..., tsinN, "SampleRate", sampleRate, method): generates a timeseries with regular time step defined by sampleRate.

tsout = synchronize(..., method, "IncludedEdge", "right"|"left"). When IncludedEdge is equal to 'left', the computed time base (newrowTimes) will be truncated to newrowTimes(1:$-1) unless newrowTimes($) is present in the initial time basis of tsin1, .., tsinN. If IncludedEdge is equal to "right", then newrowTimes will be truncated to newrowTimes(2:$) unless newrowTimes(1) is present in the initial time basis of tsin1, .., tsinN.

[tsout1, .., tsoutN] = synchronize(tsin1, .., tsinN [, ...]) returns N output timeseries if there is N input timeseries. Each ouptut timeseries will be on the same time basis.

Examples

synchronize two timeseries

T = datetime(["2022-12-01 08:35:00"; "2022-12-01 08:37:00"; "2022-12-01 08:39:00"; ...
"2022-12-01 08:45:17"; "2022-12-01 08:47:00"]);
AmbientTemperature = [18; 18.5; 20; 20.2; 20.5];
FlowRate = [50; 52; 53; 55; 60];
ts1 = timeseries(T, AmbientTemperature, FlowRate, "VariableNames", ["Time", "AmbientTemp", "FlowRate"])

T = datetime(["2022-12-01 08:27:00"; "2022-12-01 08:40:00"; "2022-12-01 08:43:00"]);
OutdoorTemperature = [-1; 1; 1.3];
IndoorTemperature = [19; 19; 19];
ts2 = timeseries(T, OutdoorTemperature, IndoorTemperature, "VariableNames", ["Time", "OutdoorTemp", "IndoorTemp"])

ts = synchronize(ts1, ts2)

synchronize two timeseries with linear method + newTimeStep = "minutely"

T = datetime(["2022-12-01 08:35:00"; "2022-12-01 08:37:00"; "2022-12-01 08:39:00"; ...
"2022-12-01 08:45:17"; "2022-12-01 08:47:00"]);
AmbientTemperature = [18; 18.5; 20; 20.2; 20.5];
FlowRate = [50; 52; 53; 55; 60];
ts1 = timeseries(T, AmbientTemperature, FlowRate, "VariableNames", ["Time", "AmbientTemp", "FlowRate"])

T = datetime(["2022-12-01 08:27:00"; "2022-12-01 08:40:00"; "2022-12-01 08:43:00"]);
OutdoorTemperature = [-1; 1; 1.3];
IndoorTemperature = [19; 19; 19];
ts2 = timeseries(T, OutdoorTemperature, IndoorTemperature, "VariableNames", ["Time", "OutdoorTemp", "IndoorTemp"])

ts = synchronize(ts1, ts2, "minutely", "linear")

synchronize two timeseries with newTimes vector

T = datetime(["2022-12-01 08:35:00"; "2022-12-01 08:37:00"; "2022-12-01 08:39:00"; ...
"2022-12-01 08:45:17"; "2022-12-01 08:47:00"]);
AmbientTemperature = [18; 18.5; 20; 20.2; 20.5];
FlowRate = [50; 52; 53; 55; 60];
ts1 = timeseries(T, AmbientTemperature, FlowRate, "VariableNames", ["Time", "AmbientTemp", "FlowRate"])

T = datetime(["2022-12-01 08:27:00"; "2022-12-01 08:40:00"; "2022-12-01 08:43:00"]);
OutdoorTemperature = [-1; 1; 1.3];
IndoorTemperature = [19; 19; 19];
ts2 = timeseries(T, OutdoorTemperature, IndoorTemperature, "VariableNames", ["Time", "OutdoorTemp", "IndoorTemp"])

newTimes = datetime("2022-12-01 08:27:00"):minutes(2):datetime("2022-12-01 08:47:00");
ts = synchronize(ts1, ts2, newTimes', "linear")

synchronize two timeseries with intersection

T = datetime(["2022-12-01 00:00:00"; "2022-12-01 06:00:00"; "2022-12-01 12:00:00"; ...
"2022-12-01 18:00:00"; "2022-12-02 00:00:00"]);
WindDir = ["NW"; "NW"; "W"; "W"; "NW"];
WindSpeed = [8; 10; 7; 9.5; 10.2];
ts1 = timeseries(T, WindDir, WindSpeed, "VariableNames", ["Time", "WindDirection", "WindSpeed"])

T = datetime(["2022-12-01 00:00:00"; "2022-12-01 12:00:00"; "2022-12-02 00:00:00"]);
OutdoorTemperature = [-1; 1; -3];
CurrentWeather = ["Snow"; "Sun"; "Snow"];
ts2 = timeseries(T, OutdoorTemperature, CurrentWeather, "VariableNames", ["Time", "OutdoorTemp", "Weather"])

ts = synchronize(ts1, ts2, "intersection")

synchronize two timeseries with union

T = [datetime("2022-12-01"):hours(3):datetime("2022-12-03")]';
TemperatureParis = floor(rand(size(T, "*"), 1) * 5 - 1);
ts1 = timeseries(T, TemperatureParis, "VariableNames", ["Time", "Paris_Temp"])

T = [datetime("2022-12-01"):hours(6):datetime("2022-12-03")]';
TemperatureMadrid = floor(rand(size(T, "*"), 1) * 6 + 10);
ts2 = timeseries(T, TemperatureMadrid, "VariableNames", ["Time", "Madrid_Temp"])

[tsout1, tsout2] = synchronize(ts1, ts2, "union")

synchronize two timeseries on each day using mean function

T = [datetime("2022-12-01"):hours(3):datetime("2022-12-03")]';
TemperatureParis = floor(rand(size(T, "*"), 1) * 5 - 1);
ts1 = timeseries(T, TemperatureParis, "VariableNames", ["Time", "Paris_Temp"])

T = [datetime("2022-12-01"):hours(6):datetime("2022-12-03")]';
TemperatureMadrid = floor(rand(size(T, "*"), 1) * 6 + 10);
ts2 = timeseries(T, TemperatureMadrid, "VariableNames", ["Time", "Madrid_Temp"])

ts = synchronize(ts1, ts2, "daily", mean)

See also

  • timeseries — create a timeseries - table with time as index
  • retime — create a new timeserie on a new time basis
  • isregular — check if the time vector is regular

History

VersãoDescrição
2024.0.0 Introduction in Scilab.
Report an issue
<< struct2table Timeseries/Table table >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:53:29 CEST 2024