{ "cells": [ { "cell_type": "markdown", "id": "41296cc6-9d84-47c5-8a92-2d292f6f3c4a", "metadata": { "papermill": { "duration": 0.011316, "end_time": "2024-01-31T17:50:21.685261", "exception": false, "start_time": "2024-01-31T17:50:21.673945", "status": "completed" }, "tags": [] }, "source": [ "# Processing" ] }, { "cell_type": "code", "execution_count": 1, "id": "9286e0b8-3c78-4b0f-943c-d219e9840dfe", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:48.022312300Z", "start_time": "2023-11-20T17:50:47.944632100Z" }, "papermill": { "duration": 0.015118, "end_time": "2024-01-31T17:50:21.706301", "exception": false, "start_time": "2024-01-31T17:50:21.691183", "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": 2, "id": "2028eed7-b1c3-4c9e-b6a0-00433caa7d0f", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:56.596807200Z", "start_time": "2023-11-20T17:50:47.951738100Z" }, "papermill": { "duration": 2.555444, "end_time": "2024-01-31T17:50:24.265958", "exception": false, "start_time": "2024-01-31T17:50:21.710514", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import ontime as on\n", "from ontime.core.plotting._marks.area import area" ] }, { "cell_type": "markdown", "id": "e24da8ab-6a83-4c2f-9ff0-c633d4693a91", "metadata": { "papermill": { "duration": 0.00259, "end_time": "2024-01-31T17:50:24.271298", "exception": false, "start_time": "2024-01-31T17:50:24.268708", "status": "completed" }, "tags": [] }, "source": [ "---\n", "## Generation of random time series" ] }, { "cell_type": "code", "execution_count": 3, "id": "0fcb01c4-3990-4c8e-aec4-41bcc7221635", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:56.618382400Z", "start_time": "2023-11-20T17:50:56.599352900Z" }, "papermill": { "duration": 0.008077, "end_time": "2024-01-31T17:50:24.281886", "exception": false, "start_time": "2024-01-31T17:50:24.273809", "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": "5af625dd-ba6b-4f3b-9f42-462fe8918c5a", "metadata": { "papermill": { "duration": 0.002987, "end_time": "2024-01-31T17:50:24.287343", "exception": false, "start_time": "2024-01-31T17:50:24.284356", "status": "completed" }, "tags": [] }, "source": [ "---\n", "## Apply function on the whole time series" ] }, { "cell_type": "markdown", "id": "d097ae05-fe76-40b7-bdbe-709150040cbf", "metadata": { "papermill": { "duration": 0.002526, "end_time": "2024-01-31T17:50:24.292325", "exception": false, "start_time": "2024-01-31T17:50:24.289799", "status": "completed" }, "tags": [] }, "source": [ "with Lambda function" ] }, { "cell_type": "code", "execution_count": 4, "id": "186f2463-c1f5-4563-bb70-4f671a3a56d1", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:56.671509300Z", "start_time": "2023-11-20T17:50:56.617335800Z" }, "papermill": { "duration": 0.014626, "end_time": "2024-01-31T17:50:24.309396", "exception": false, "start_time": "2024-01-31T17:50:24.294770", "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([[[2.]],\n",
       "\n",
       "       [[2.]],\n",
       "\n",
       "       [[2.]],\n",
       "\n",
       "       [[2.]],\n",
       "\n",
       "       [[2.]]])\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([[[2.]],\n", "\n", " [[2.]],\n", "\n", " [[2.]],\n", "\n", " [[2.]],\n", "\n", " [[2.]]])\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": [ "add_two = on.processors.mapper(lambda x : x + 2)\n", "new_ts = add_two.process(ts)\n", "(new_ts - ts).head()" ] }, { "cell_type": "markdown", "id": "4b558654-2243-46a4-87cf-a63c7e9a703c", "metadata": { "papermill": { "duration": 0.005172, "end_time": "2024-01-31T17:50:24.317900", "exception": false, "start_time": "2024-01-31T17:50:24.312728", "status": "completed" }, "tags": [] }, "source": [ "with normal function" ] }, { "cell_type": "code", "execution_count": 5, "id": "629580cf-a70a-4ad9-ab9e-acfcf3c10a81", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:56.720374700Z", "start_time": "2023-11-20T17:50:56.671509300Z" }, "papermill": { "duration": 0.012946, "end_time": "2024-01-31T17:50:24.333791", "exception": false, "start_time": "2024-01-31T17:50:24.320845", "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([[[2.]],\n",
       "\n",
       "       [[2.]],\n",
       "\n",
       "       [[2.]],\n",
       "\n",
       "       [[2.]],\n",
       "\n",
       "       [[2.]]])\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([[[2.]],\n", "\n", " [[2.]],\n", "\n", " [[2.]],\n", "\n", " [[2.]],\n", "\n", " [[2.]]])\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": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def add_2(x):\n", " return x + 2\n", "\n", "add_two = on.processors.mapper(add_2)\n", "new_ts = add_two.process(ts)\n", "(new_ts - ts).head()" ] }, { "cell_type": "markdown", "id": "ffbed9d6-d331-4708-8d50-25882c85e60d", "metadata": { "papermill": { "duration": 0.003824, "end_time": "2024-01-31T17:50:24.341012", "exception": false, "start_time": "2024-01-31T17:50:24.337188", "status": "completed" }, "tags": [] }, "source": [ "---\n", "## Apply Function on Windows of the Time Series" ] }, { "cell_type": "code", "execution_count": 6, "id": "4889d3c1-21e3-4983-ab90-8f5c597286dc", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:56.728483200Z", "start_time": "2023-11-20T17:50:56.704212500Z" }, "papermill": { "duration": 0.006431, "end_time": "2024-01-31T17:50:24.350778", "exception": false, "start_time": "2024-01-31T17:50:24.344347", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "mean = on.processors.windower({\n", " 'function': 'mean',\n", " 'mode': 'rolling',\n", " 'window': 10\n", "})" ] }, { "cell_type": "code", "execution_count": 7, "id": "9bd8cc70-d177-4a05-b153-4f3030c87fad", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:56.797720400Z", "start_time": "2023-11-20T17:50:56.718376800Z" }, "papermill": { "duration": 0.008789, "end_time": "2024-01-31T17:50:24.362889", "exception": false, "start_time": "2024-01-31T17:50:24.354100", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "new_ts = on.TimeSeries.from_darts(mean.process(ts))" ] }, { "cell_type": "code", "execution_count": 8, "id": "6334dc30-13e5-4050-b74a-1334f7a30217", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:57.170751300Z", "start_time": "2023-11-20T17:50:56.749590200Z" }, "papermill": { "duration": 0.189607, "end_time": "2024-01-31T17:50:24.555853", "exception": false, "start_time": "2024-01-31T17:50:24.366246", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts.plot(height=50)" ] }, { "cell_type": "code", "execution_count": 9, "id": "68c344c5-62d4-4157-8cf0-6bb114095487", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:57.823373Z", "start_time": "2023-11-20T17:50:57.170751300Z" }, "papermill": { "duration": 0.204988, "end_time": "2024-01-31T17:50:24.771365", "exception": false, "start_time": "2024-01-31T17:50:24.566377", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "new_ts.plot(height=50)" ] }, { "cell_type": "markdown", "id": "222fb321-085e-4f95-80f7-6a22b6326fb9", "metadata": { "papermill": { "duration": 0.003641, "end_time": "2024-01-31T17:50:24.778923", "exception": false, "start_time": "2024-01-31T17:50:24.775282", "status": "completed" }, "tags": [] }, "source": [ "---\n", "## Split Time Series in defined durations of e.g. day, week, month, year" ] }, { "cell_type": "code", "execution_count": 10, "id": "9802955b-6791-43bb-80d4-74ccb4119d70", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:57.893400Z", "start_time": "2023-11-20T17:50:57.823373Z" }, "papermill": { "duration": 0.008428, "end_time": "2024-01-31T17:50:24.790855", "exception": false, "start_time": "2024-01-31T17:50:24.782427", "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": "code", "execution_count": 11, "id": "de2ab66c-2832-4007-91d0-f54c427a08e0", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.191262500Z", "start_time": "2023-11-20T17:50:57.846406600Z" }, "papermill": { "duration": 0.137594, "end_time": "2024-01-31T17:50:24.932047", "exception": false, "start_time": "2024-01-31T17:50:24.794453", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts.plot(height=50, width=600)" ] }, { "cell_type": "markdown", "id": "b4248fb8-1711-4610-9f3a-a139295af3f2", "metadata": { "papermill": { "duration": 0.003872, "end_time": "2024-01-31T17:50:24.939991", "exception": false, "start_time": "2024-01-31T17:50:24.936119", "status": "completed" }, "tags": [] }, "source": [ "### Split by month" ] }, { "cell_type": "markdown", "id": "130ba09a-7fba-4348-9110-64683722f2d8", "metadata": { "papermill": { "duration": 0.003693, "end_time": "2024-01-31T17:50:24.947330", "exception": false, "start_time": "2024-01-31T17:50:24.943637", "status": "completed" }, "tags": [] }, "source": [ "All offset aliases can be used to make different split length (https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases)" ] }, { "cell_type": "code", "execution_count": 12, "id": "7fb009b3-9619-4f68-b04b-4456f915e677", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.272813800Z", "start_time": "2023-11-20T17:50:58.193380500Z" }, "papermill": { "duration": 0.016386, "end_time": "2024-01-31T17:50:24.967309", "exception": false, "start_time": "2024-01-31T17:50:24.950923", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/fred.montet/src/vast-ch/ontime/src/ontime/core/time_series/time_series.py:57: FutureWarning: 'M' is deprecated and will be removed in a future version, please use 'ME' instead.\n", " splits_df = [g for n, g in df.groupby(pd.Grouper(freq=period))]\n" ] } ], "source": [ "seq = ts.split_by_period('M')" ] }, { "cell_type": "code", "execution_count": 13, "id": "196aaa0b-ec20-4117-91d2-c0e74387c7e8", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.272813800Z", "start_time": "2023-11-20T17:50:58.241177400Z" }, "papermill": { "duration": 0.007314, "end_time": "2024-01-31T17:50:24.978758", "exception": false, "start_time": "2024-01-31T17:50:24.971444", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(seq)" ] }, { "cell_type": "markdown", "id": "8e5dd4a7-f524-4206-8c58-778ddde56d44", "metadata": { "papermill": { "duration": 0.003837, "end_time": "2024-01-31T17:50:24.986337", "exception": false, "start_time": "2024-01-31T17:50:24.982500", "status": "completed" }, "tags": [] }, "source": [ "### Group the splits" ] }, { "cell_type": "code", "execution_count": 14, "id": "f475c77b-bd6a-44e2-bd85-c5d765722667", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.352137200Z", "start_time": "2023-11-20T17:50:58.245972300Z" }, "papermill": { "duration": 0.024337, "end_time": "2024-01-31T17:50:25.014397", "exception": false, "start_time": "2024-01-31T17:50:24.990060", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "ts_g = ts.group_splits(seq)" ] }, { "cell_type": "code", "execution_count": 15, "id": "2fd2369b-df3e-4f59-b940-a034216474f4", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.368465600Z", "start_time": "2023-11-20T17:50:58.336395200Z" }, "papermill": { "duration": 0.014682, "end_time": "2024-01-31T17:50:25.033070", "exception": false, "start_time": "2024-01-31T17:50:25.018388", "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.10963182]],\n",
       "\n",
       "       [[0.21330887]],\n",
       "\n",
       "       [[1.29061992]],\n",
       "\n",
       "       [[0.42607427]],\n",
       "\n",
       "       [[1.33176918]]])\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.10963182]],\n", "\n", " [[0.21330887]],\n", "\n", " [[1.29061992]],\n", "\n", " [[0.42607427]],\n", "\n", " [[1.33176918]]])\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": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts_g.head()" ] }, { "cell_type": "markdown", "id": "8e6e5a8b-6375-4023-9c45-e86e070b76ed", "metadata": { "papermill": { "duration": 0.004058, "end_time": "2024-01-31T17:50:25.041262", "exception": false, "start_time": "2024-01-31T17:50:25.037204", "status": "completed" }, "tags": [] }, "source": [ "---\n", "## Compute Correlation Through Time" ] }, { "cell_type": "markdown", "id": "5cfff298-3e1d-4118-b4cd-6592acc3d164", "metadata": { "papermill": { "duration": 0.004075, "end_time": "2024-01-31T17:50:25.049539", "exception": false, "start_time": "2024-01-31T17:50:25.045464", "status": "completed" }, "tags": [] }, "source": [ "Load some data from the Energy dataset in Darts" ] }, { "cell_type": "code", "execution_count": 16, "id": "1ab88c7f-b09c-4ff3-9537-82d4c185c9f1", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.615819900Z", "start_time": "2023-11-20T17:50:58.367300900Z" }, "papermill": { "duration": 0.072589, "end_time": "2024-01-31T17:50:25.126120", "exception": false, "start_time": "2024-01-31T17:50:25.053531", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "from darts.datasets import EnergyDataset\n", "ts = EnergyDataset().load()" ] }, { "cell_type": "markdown", "id": "6c17e3a4-59ff-458b-b523-ce9f9f9b6e80", "metadata": { "papermill": { "duration": 0.004061, "end_time": "2024-01-31T17:50:25.134567", "exception": false, "start_time": "2024-01-31T17:50:25.130506", "status": "completed" }, "tags": [] }, "source": [ "Get a few columns and samples" ] }, { "cell_type": "code", "execution_count": 17, "id": "f5244eb1-4811-4c6d-baf3-33c52da1c824", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.634302200Z", "start_time": "2023-11-20T17:50:58.618142700Z" }, "papermill": { "duration": 0.0093, "end_time": "2024-01-31T17:50:25.147712", "exception": false, "start_time": "2024-01-31T17:50:25.138412", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "cols = ['generation biomass', 'generation solar', 'generation nuclear']\n", "ts = ts[cols][0:1000]" ] }, { "cell_type": "markdown", "id": "446bea0e-2094-42e0-b40b-7c817db7ac7e", "metadata": { "papermill": { "duration": 0.003945, "end_time": "2024-01-31T17:50:25.155597", "exception": false, "start_time": "2024-01-31T17:50:25.151652", "status": "completed" }, "tags": [] }, "source": [ "Compute correlations within a daily window" ] }, { "cell_type": "code", "execution_count": 18, "id": "99fa151a-1fe4-4aea-95c0-8a6029e34c51", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:58.666856100Z", "start_time": "2023-11-20T17:50:58.636923700Z" }, "papermill": { "duration": 0.006829, "end_time": "2024-01-31T17:50:25.166246", "exception": false, "start_time": "2024-01-31T17:50:25.159417", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "correlation = on.processors.correlation('1D')" ] }, { "cell_type": "code", "execution_count": 19, "id": "943287fb-a54d-4c3c-a797-ce44057241da", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:59.062222700Z", "start_time": "2023-11-20T17:50:58.662713900Z" }, "papermill": { "duration": 0.111481, "end_time": "2024-01-31T17:50:25.281786", "exception": false, "start_time": "2024-01-31T17:50:25.170305", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "ts_corr = correlation.process(ts)" ] }, { "cell_type": "code", "execution_count": 20, "id": "dea59b2d-2ce0-4916-a7a6-b6778bdbedfd", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:59.521493200Z", "start_time": "2023-11-20T17:50:59.062222700Z" }, "papermill": { "duration": 0.160868, "end_time": "2024-01-31T17:50:25.446797", "exception": false, "start_time": "2024-01-31T17:50:25.285929", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ts_corr[0:100].plot(height=50, width=600)" ] }, { "cell_type": "markdown", "id": "b3bfce59-fc26-4ae0-9596-27d987d1efa6", "metadata": { "ExecuteTime": { "end_time": "2023-11-20T17:50:59.521493200Z", "start_time": "2023-11-20T17:50:59.520654800Z" }, "papermill": { "duration": 0.004722, "end_time": "2024-01-31T17:50:25.456209", "exception": false, "start_time": "2024-01-31T17:50:25.451487", "status": "completed" }, "tags": [] }, "source": [ "---" ] }, { "cell_type": "markdown", "id": "a27988b7-46cf-40c6-8131-4d12cd4d45f7", "metadata": {}, "source": [ "## Compute the Density of a TimeSeries" ] }, { "cell_type": "markdown", "id": "4792b182-04ec-4a9e-ab1c-c6aaaf459dc0", "metadata": {}, "source": [ "Create a BinaryTimeSeries with anomalies and detect them" ] }, { "cell_type": "code", "execution_count": 21, "id": "e4418c9c-7a8c-447b-aaa9-a3686bf3f72f", "metadata": {}, "outputs": [], "source": [ "from darts.datasets import EnergyDataset\n", "ts = EnergyDataset().load()\n", "ts = ts['generation biomass']" ] }, { "cell_type": "code", "execution_count": 22, "id": "47eecf9c-f035-4533-bf15-7f61702ef332", "metadata": {}, "outputs": [], "source": [ "def add_point_anomalies(ts, n, value):\n", " df = ts.pd_dataframe()\n", " random_indices = np.random.choice(df.index, size=n, replace=False)\n", " df.loc[random_indices] = value\n", " return on.TimeSeries.from_dataframe(df)" ] }, { "cell_type": "code", "execution_count": 23, "id": "3ec90894-64cb-4025-8da4-f2dd1b571d11", "metadata": {}, "outputs": [], "source": [ "ts_w_ano = add_point_anomalies(ts, 100, 10000)" ] }, { "cell_type": "code", "execution_count": 24, "id": "d2ab08e7-529f-41aa-8b74-29685dc323f7", "metadata": {}, "outputs": [], "source": [ "td_point = on.detectors.threshold(high_threshold=800)\n", "ts_ano_point = td_point.detect(ts_w_ano)" ] }, { "cell_type": "markdown", "id": "a495098b-85dc-4320-af0f-7871ea76e2e0", "metadata": {}, "source": [ "Compute the density of anomalies" ] }, { "cell_type": "code", "execution_count": 25, "id": "6a2fcc8c-d715-4fee-8cc7-81efe2ff61f6", "metadata": {}, "outputs": [], "source": [ "ts_ano_density = on.processors.density(\n", " window_length=round(len(ts_ano_point)/16), \n", " mode='absolute'\n", ").process(ts_ano_point)" ] }, { "cell_type": "code", "execution_count": 26, "id": "7eb1e15a-da24-4ac7-9ca5-f9cc3846d740", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(\n", " on.Plot(ts_ano_density)\n", " .add(area)\n", " .properties(height=40, width=600)\n", " .show()\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "14382cf5-8ddf-434b-91d4-ae57ffdb817a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10" }, "papermill": { "default_parameters": {}, "duration": 4.997488, "end_time": "2024-01-31T17:50:26.082072", "environment_variables": {}, "exception": null, "input_path": "docs/user_guide/0_core/0.3-processing.ipynb", "output_path": "docs/user_guide/0_core/0.3-processing.ipynb", "parameters": {}, "start_time": "2024-01-31T17:50:21.084584", "version": "2.5.0" } }, "nbformat": 4, "nbformat_minor": 5 }