Wolfram Language

Time Series Processing

Combine Asynchronous Measurements

A liquid flows from two tanks and is combined into a single flow. The individual flows from each tank are calculated via the measurement of liquid levels in each tank and given as times series. Compute the combined flow from both tanks.

In[1]:=
Click for copyable input
h1 = TemporalData[TimeSeries, {{ StructuredArray[QuantityArray, {101}, StructuredArray`StructuredData[QuantityArray, CompressedData[" 1:eJwBNQPK/CFib1JlAQAAAGUAAADe5APaz4oAQCSFr48qYgBAQzBMKDxTAEDX ymqz2x8AQNOLnrenpP8/Kmwvk1Ia/z8huN4wvNb+P4rfuUg5z/4/mdIrXD7C /j/Uwimro3P+PxLt/Jvz4/0/qjRGTexP/T+BerQGpvj8P89ndGK45/w/uSuU QGrm/D/3+kpQAbD8P6MLVq3yMPw/4lTjuNuY+z9wTWvQuS77P9Lv9rulD/s/ //pavhEU+z8YLJKVKfT6P+YyAQjbifo/QKWO0djz+T/A5FSVYHn5P9wGcJO5 SPk/s14mlqhM+T8WL8Ql9T/5PzZrds4O7fg/5iLiH0xf+D+CvLZMftj3P+3W qeZulPc/BmCaoeOR9z+FMpKnwpP3P7+KpFA/Wfc/735hFG3Z9j++3QIdd0v2 P87+0M7j8/U/oJ8LlpTl9T+KFYiNavD1P1yaFoaDzfU/ddD7xmhg9T/9saxT N9H0P7+BjKTCZ/Q/jidTHYdJ9D9A+nBKMlf0P9b8SZ1xSfQ/3ZNSCoXy8z/B 8GpwT2jzPxZGDC848PI/HzcSGFq/8j/6I6RCr8nyPx+uXV8fzfI/Mvnt4kWO 8j+lcOh1DA/yP1yDkX7qjPE/7W3IZGBI8T+9GiYLqEnxP152KqElWfE/9Zck XIky8T8wIG3wnMPwP04gUh4EPfA/WedE9gjL7z/8E27037HvPxCrWcsl3e8/ 4hlDFD+97z9nOo3taQjvP+h16WqI/u0/J0/Rkm8u7T+urSnBhPLsP8WXTrap He0/bRLmuLQk7T9tTK7IZp7sP2u9NqEupOs/J3WK3Mq66j8bzo9SOljqP3/m Tig4d+o/OWJ4ihuc6j8Upnb4hkbqP08bxY1wZ+k/QrxSy/Zu6D8Tx6a6S+Xn PwYq0SZz7ec/ndGUjRUl6D+4gEpd7f7nP2Kb8eanROc/FZ293t1I5j+9YnNA IJvlP6EruLryg+U/LLUSnx7C5T+Q8wcHr8blP4TvD3hdOOU/Wl/dx6lF5D+Z /JtJH3rjP4Nyzev7PeM/ZcZaRVl24z93vVHo6Z3jPwwN4rqOP+M/aTuqJv5h 4j9XG7Zkp4HhP0VTVME+HuE/9dGrFA== "], "Meters", {{1}}]]}, { TemporalData`DateSpecification[{2016, 2, 3, 17, 0, 0.}, {2016, 2, 7, 21, 0, 0}, {1, "Hour"}]}, 1, {"Continuous", 1}, {"Discrete", 1}, 1, {ResamplingMethod -> { "Interpolation", InterpolationOrder -> 1}}}, True, 314.1]; h2 = TemporalData[TimeSeries, {{ StructuredArray[QuantityArray, {101}, StructuredArray`StructuredData[QuantityArray, CompressedData[" 1:eJwBNQPK/CFib1JlAQAAAGUAAADe5APaz4oAQCOFr48qYgBAWwPf4N9MAEBS Om4VdZn+PwngPIFrVfw/w0NCHNWZ+z9a09uBZsf8Pxe3P5fCfv4/ss8cEKDm /j9YFSmc6l39P5tC/AfYC/s/AuMHBPbM+T+AxXXML336P+AErK6XMfw/oeO4 kWwU/T+VJkksOBX8P32SqPG33/k/lmsozcI5+D/2xRoL6mD4PyP1dj3D6fk/ Ez6I2lQn+z9rGrkfDLf6P6iE3q7kw/g/DtWOrkXa9j9h6QGSL3n2P1fJJ+hT tPc/mXtDXuwm+T8KWSKioj75P/bpYbSxq/c/KZ3c+IGl9T8gGf0U2sj0PyaB IA5KnfU/Z4uDEF4d9z8a3WXPFav3P6Hb1msJjPY/eG3sElyQ9D9aBVrA4E7z P+VlDz+PrvM/Ot4sO24W9T8yXSYgSf/1P5XHmyBiXPU/5XIOMrWO8z+C/ifc mQbyP4FPhVQb7/E/goxHzU4e8z/yOQXGjkH0P5HPQ+F1F/Q/8hzXvYuU8j+R H7wjQOjwPz7fXelsYvA/ZeCYyYBA8T/t50aD6nryP+dNdqScu/I/ZyQA5B+X 8T/DSwWmlNPvP0LAfkiUEO4/1MyQlYgN7z+Ad8BdLbbwP3USRUfmSvE/SgME ROiN8D+S13+SyP/tP81vGU/Jues/EBlSmGjw6z87i6MVxv3tP3gbv1aYle8/ 9Ca3+aTm7j9ga3NGEj7sP5Wwax17suk/LYTLxm8x6T+9Mlb+gsDqP5sdtOk9 h+w/OLwD2HeK7D9YKMteHXnqP/PR9gS95+c/ogVVcVPR5j94zJwiUcjnP0b7 k3+Mf+k/yzWCkxAK6j9p8Rw1DZ/oP6BooC9NQ+Y/058TsNzJ5D+x4cno0iTl PwgutSnBleY/kbmhed9u5z+9Gd9kjKLmPzSKhEg+reQ/ojbXlLsO4z+zPmb0 IOHiP9R0w+wu4uM/pCGvgmbH5D9reNbsHnrkP/Ko3Wy9DOM/RtvVUBGQ4T+k hbaMlgbhP/MowdSsfuE/XFEVpd8i4j/yDMcEJRjiPxyQlJ3qROE/fqHOrPZG 4D/MgGaimHDfP3Bp5/unEN8/l3mlKQ== "], "Meters", {{1}}]]}, { TemporalData`DateSpecification[{2016, 2, 3, 17, 30, 0.}, {2016, 2, 7, 21, 30, 0}, {1, "Hour"}]}, 1, {"Continuous", 1}, { "Discrete", 1}, 1, { ResamplingMethod -> {"Interpolation", InterpolationOrder -> 1}}}, True, 314.1];

Plot the liquid levels.

In[2]:=
Click for copyable input
DateListPlot[{h1, h2}, FrameLabel -> Automatic, Joined -> False, Filling -> Axis]
Out[2]=

The measurements are not simultaneousthe time series have different time stamps.

In[3]:=
Click for copyable input
SameQ[h1["Dates"], h2["Dates"]]
Out[3]=

The net flow from each tank depends on the common discharge coefficient , the area of the cross sections of an outlet, and the liquid level, and is given as the following function.

In[4]:=
Click for copyable input
flowFun[c_, a_, height_] := Evaluate[c*a* Sqrt[2*UnitConvert[Entity["Planet", "Earth"]["Gravity"]]]* Sqrt[height ]]

Compute the flow from each tank by applying the formula to each time series.

In[5]:=
Click for copyable input
flow1 = flowFun[.7, Quantity[\[Pi] 0.25^2, "Meters Squared"], h1];
In[6]:=
Click for copyable input
flow2 = flowFun[.7, Quantity[\[Pi] 0.26^2, "Meters squared"], h2];

Calculate the total flow.

In[7]:=
Click for copyable input
TotalFlow = flow1 + flow2;

The time stamps of the sum are the union of the time stamps from both time series over a common time range.

In[8]:=
Click for copyable input
newtimes = Union[Complement[flow1["Dates"], {flow1["FirstDate"]}], Complement[flow2["Dates"], {flow2["LastDate"]}]];
In[9]:=
Click for copyable input
SameQ[newtimes, TotalFlow["Dates"]]
Out[9]=

Plot the flows.

show complete Wolfram Language input
In[10]:=
Click for copyable input
DateListPlot[{flow1, flow2, TotalFlow}, FrameLabel -> Automatic, Filling -> Axis, Joined -> False, PlotStyle -> PointSize[.01], PlotLegends -> SwatchLegend[{"flow1", "flow2", "TotalFlow"}]]
Out[10]=

Related Examples

de fr pt-br ru zh