{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "52af59bb-083c-46c6-989a-bd4c65137a1a", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Import to be able to import python package from src\n", "import sys\n", "sys.path.insert(0, '../src')" ] }, { "cell_type": "code", "execution_count": null, "id": "d6fc731f-3f50-4e9a-a24c-b2ab01d4fa31", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import pandas as pd\n", "import ontime as on" ] }, { "cell_type": "markdown", "id": "670316b8-460c-4009-a5da-94278f4ac9a9", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "source": [ "# Time Series\n", "\n", "a `TimeSeries` is the basic object in onTime. It is basically an extended version of Darts TimeSeries. Therefore, it is multivariate by default and all Darts methods can be used." ] }, { "cell_type": "markdown", "id": "831f1944-599b-4761-a071-2a682346610a", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "source": [ "## Get some data\n", "\n", "Let's generate a random walk time series" ] }, { "cell_type": "code", "execution_count": 3, "id": "ef3e03e1-c247-4b5a-a27a-a13361e673b0", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "ts = on.generators.random_walk().generate(start=pd.Timestamp('2022-01-01'), end=pd.Timestamp('2022-12-31'))" ] }, { "cell_type": "markdown", "id": "52f41907-8b48-4427-8a44-5f45ab6196b0", "metadata": {}, "source": [ "The TimeSeries can be sliced and its data structure is an xarray." ] }, { "cell_type": "code", "execution_count": 4, "id": "01962643-33af-4adf-8bfa-7d0163e4e41c", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<TimeSeries (DataArray) (time: 5, component: 1, sample: 1)> Size: 40B\n",
       "array([[[ 0.49300558]],\n",
       "\n",
       "       [[ 0.07955401]],\n",
       "\n",
       "       [[ 0.0028518 ]],\n",
       "\n",
       "       [[ 0.26707493]],\n",
       "\n",
       "       [[-1.48484355]]])\n",
       "Coordinates:\n",
       "  * time       (time) datetime64[ns] 40B 2022-01-01 2022-01-02 ... 2022-01-05\n",
       "  * component  (component) object 8B 'random_walk'\n",
       "Dimensions without coordinates: sample\n",
       "Attributes:\n",
       "    static_covariates:  None\n",
       "    hierarchy:          None
" ], "text/plain": [ " Size: 40B\n", "array([[[ 0.49300558]],\n", "\n", " [[ 0.07955401]],\n", "\n", " [[ 0.0028518 ]],\n", "\n", " [[ 0.26707493]],\n", "\n", " [[-1.48484355]]])\n", "Coordinates:\n", " * time (time) datetime64[ns] 40B 2022-01-01 2022-01-02 ... 2022-01-05\n", " * component (component) object 8B 'random_walk'\n", "Dimensions without coordinates: sample\n", "Attributes:\n", " static_covariates: None\n", " hierarchy: None" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts[0:5]" ] }, { "cell_type": "markdown", "id": "0cbd8da5-81fd-4b2d-8b7d-8394ad87348b", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "source": [ "## Plot" ] }, { "cell_type": "markdown", "id": "0ec207a0-f270-4f1b-b362-0ad1c0584d2b", "metadata": {}, "source": [ "As expected, you can call the `plot()` method" ] }, { "cell_type": "code", "execution_count": 7, "id": "1cbbd4f4-035d-43fa-93a7-6801b944835f", "metadata": { "papermill": { "duration": null, "end_time": null, "exception": null, "start_time": null, "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts.plot()" ] } ], "metadata": { "kernelspec": { "display_name": "ontime-2OQVvbNf-py3.10", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" }, "papermill": { "default_parameters": {}, "duration": 60.248854, "end_time": "2024-01-31T17:51:31.161244", "environment_variables": {}, "exception": null, "input_path": "docs/user_guide/0_core/0.1-time-series-custom-class.ipynb", "output_path": "docs/user_guide/0_core/0.1-time-series-custom-class.ipynb", "parameters": {}, "start_time": "2024-01-31T17:50:30.912390", "version": "2.5.0" } }, "nbformat": 4, "nbformat_minor": 5 }