3

I've been using Julia as a data analysis tool, and I recently discovered the TimeSeries.jl package, which has many interesting features for time series analysis.

However, as a Physicist, my time series aren't usually indexed by a date and a clock time (such as 01/01 12:30:00) but by the number of time units gone by (eg. a time series would go from t=0s to t=200s). The conversion from seconds to minutes isn't desired in this case. Not only that, but sometimes there is no conversion to be made, when using an abstract time unit instead of seconds, for example.

So is there a way to index the rows of a time series object with simple numbers (ints and floats) instead of with Date or DateType objects? Or maybe is there some other Package that can do it?

The documentation of TimeSeries.jl doesn't seem to show a way.

2 Answers 2

2

As defined here TimeArray requires its D parameter to be TimeType, so in practice it is Date, Time or DateTime.

You could implement your custom subtype of TimeType, but probably there are easier options. In general there are several packages in Julia ecosystem that allow you to index by arbitrary indices, e.g. AxisArrays.jl or NamedArrays.jl. It seems to me that the example described here should exactly suit your needs.

Sign up to request clarification or add additional context in comments.

2 Comments

AxisArray.jl is a good way to index the series by its time, but I am not sure if I can use it together with TimeSeries.jl in a way to take advantage of the features of the latter package. But I was able to create a subtype of TimeType that holds only an Int, and also implement the basic functions for it. It seems to work well enough for utilizing TimeSeries.jl functions, though I wasn't able to achive some more complex behavior such as plotting. Still, I guess that will make do. Thank you!
Agreed - if you use AxisArray.jl then you get only what AxisArray.jl provides :(.
0

Assuming your time units are stored as integers that are implicitly understood to be integral seconds, stored in the vector elapsed_seconds, you can convert the seconds before creating the time series. Note that elapsed_seconds must be strictly increasing. With the time-measured data as a vector of integer or floating point values named observations:

using TimeSeries, Dates

elapsed_seconds = [15,30];
observations = [1.5, 5.125];

secs = Time.(Second.(elapsed_seconds));
ta = TimeArray(secs, observations)

# 2×1 TimeArray{Float64,1,Time,Array{Float64,1}} 00:00:15 to 00:00:30
# │          │ A     │
# ├──────────┼───────┤
# │ 00:00:15 │ 1.5   │
# │ 00:00:30 │ 5.125 │

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.