Time series data is stored in the time series database whenever a Time Series is run. You can also insert data directly into the time series database. This allows you to bring your own historical or forecasted time series data into the Myst Platform. Currently, users who wish to insert their own time series data into the Myst Platform must do so through the Myst Platform client library. To add data at regular intervals, users will need to run the insert client library code on a schedule.
Myst Platform Client Library
To insert data into a Time Series you will need to use the Myst Platform client library. You can find the Python package as well as detailed instructions for how to install it here.
Navigate to the Project Create space of the project that contains the Time Series that you want to insert data into. Click on the Time Series of interest and copy the UUID of the Time Series from the right side-panel. The project UUID will be in the project URL.
After authenticating yourself in the client library, you can go ahead and retrieve your Time Series.
import myst myst.authenticate() # Retrieve the project you want to use. project = myst.Project.get(uuid="<uuid>") # Retrieve the time series you want to insert data into. time_series = myst.TimeSeries.get(project=..., uuid="<uuid>")
Next, create a Time Array with your data and insert it into the Time Series. Note that Time Arrays require data that is localized in the UTC time zone. You can also use
myst.TimeArray.from_pandas_series(...) to create a Time Array from a Pandas Series, which supports native functionality to convert between time zones.
import numpy as np # Create a time array containing your data. time_array = myst.TimeArray( sample_period=myst.TimeDelta("PT1H"), start_time=myst.Time("2022-01-01T00:00:00Z"), end_time=myst.Time("2022-02-01T00:00:00Z"), as_of_time=myst.Time("2022-02-14T00:00:00Z"), values=np.random.random(31 * 24), ) # Insert the time array into your time series. time_series.insert_time_array(time_array=time_array)
Your data will now be stored in the time series database, along with data from results that were generated by a Time Series Run Policy. Note that the Natural Times and the As Of Time all need to be aligned with the Sample Period of the Time Series. For inserting historical data the As Of Time should be larger than the Natural Times. We recommend using an As Of Time that is the current UTC time floored to the Sample Period.
Note that data that you insert will always take precedence over data from policy-driven results. See the Query Time Series Data section to learn how to query your time series data.
Updated over 1 year ago