{ "cells": [ { "cell_type": "markdown", "id": "59843784", "metadata": {}, "source": [ "# Light exposure analysis with pyActigraphy" ] }, { "cell_type": "markdown", "id": "796a75ef", "metadata": {}, "source": [ "![Light&Gears](img/daniele-levis-pelusi-Pp9qkEV_xPk-unsplash.jpg)" ] }, { "cell_type": "markdown", "id": "8c514efe", "metadata": {}, "source": [ "Photo by Daniele Levis Pelusi on Unsplash" ] }, { "cell_type": "markdown", "id": "3ea9684d", "metadata": {}, "source": [ "## Disclaimer\n", "\n", "The development of the pyActigraphy module for analysing light exposure data was led and financially supported by members of the Daylight Academy Project *The role of daylight for humans* (led by Mirjam Münch, Manuel Spitschan). The module is part of the Human Light Exposure Database. For more information about the project, please see\n", "https://daylight.academy/projects/state-of-light-in-humans/." ] }, { "cell_type": "markdown", "id": "804bc272", "metadata": {}, "source": [ "## Introduction\n", "\n", "Similarly to the analysis of locomotor activity via actigraphy, light exposure data analysis is difficult because of the lack of open-source analysis softwares that gives users access to a list of various analysis metrics.\n", "\n", "The light exposure data analysis module of *pyActigraphy* is meant to fix this issue." ] }, { "cell_type": "markdown", "id": "2684d70b", "metadata": {}, "source": [ "In this tutorial, we will review the light exposure analysis metrics currently available in pyActigraphy:\n", "\n", "* Exposure levels\n", "* Summary statistics\n", "* Time above threshold (TAT)\n", "* Mean light timing above threshold (MLit)\n", "* Extrema (min. and max.)\n", "* L5 and M10 (LMX)\n", "* IS and IV\n", "* Direct access to raw or thresholded data" ] }, { "cell_type": "markdown", "id": "e9a0910d", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "markdown", "id": "67b7bd15", "metadata": {}, "source": [ "As usual, first import the necessary packages:" ] }, { "cell_type": "code", "execution_count": 1, "id": "1676dbe8", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:48.122511Z", "start_time": "2023-01-30T15:49:46.488440Z" } }, "outputs": [], "source": [ "import pyActigraphy" ] }, { "cell_type": "code", "execution_count": 2, "id": "3adbe4a1", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:48.125417Z", "start_time": "2023-01-30T15:49:48.123781Z" } }, "outputs": [], "source": [ "import plotly.graph_objects as go" ] }, { "cell_type": "code", "execution_count": 3, "id": "2ac0fd6b", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:48.128840Z", "start_time": "2023-01-30T15:49:48.127099Z" } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 4, "id": "7921981b", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:48.131735Z", "start_time": "2023-01-30T15:49:48.130215Z" } }, "outputs": [], "source": [ "import os" ] }, { "cell_type": "markdown", "id": "f35e8e90", "metadata": {}, "source": [ "## Log-transformation of light data" ] }, { "cell_type": "markdown", "id": "4dee9a8b", "metadata": {}, "source": [ "Light data are (log10+1)-transformed in *pyActigraphy*. Therefore, when threshold values are meant to applied to the light levels, the corresponding value on the (log10+1) scale should be applied.\n", "\n", "**NB**: an offset of 1 is added to the light data before log10 transformation in order to avoid a divergence of the log10 function when the light data values are zero: $\\log_{10}(0) = -\\infty $.\n", "\n", "So, on a (log10+1) scale:\n", "\n", "* 10 lux threshold correspond to a value of log(10+1)~1\n", "* 100 lux threshold correspond to a value of log(100+1)~2\n", "* 1000 lux threshold correspond to a value of log(1000+1)~3\n", "* ...\n", "\n", "To simply get the exact value, use the `np.log10` function of the *numpy* package we imported earlier:" ] }, { "cell_type": "code", "execution_count": 5, "id": "1fc4382d", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:48.137178Z", "start_time": "2023-01-30T15:49:48.132605Z" } }, "outputs": [ { "data": { "text/plain": [ "(1.0413926851582251, 2.0043213737826426, 3.000434077479319)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.log10(10+1), np.log10(100+1), np.log10(1000+1)" ] }, { "cell_type": "markdown", "id": "a1aa7fde", "metadata": {}, "source": [ "## Input data" ] }, { "cell_type": "markdown", "id": "ff1ef61e", "metadata": {}, "source": [ "Set up a path to your favorite data file. Here, we use a recording made with a Actiwatch Spectrum Pro from Respironic:" ] }, { "cell_type": "code", "execution_count": 6, "id": "0de4f34b", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:48.140684Z", "start_time": "2023-01-30T15:49:48.138239Z" } }, "outputs": [], "source": [ "fpath = os.path.join(\n", " os.path.dirname(pyActigraphy.__file__),\n", " 'tests','data', 'test_sample_rpx_ger_with_light.csv'\n", ")" ] }, { "cell_type": "markdown", "id": "d05d42ff", "metadata": {}, "source": [ "To read such a file, use the corresponding reader function:" ] }, { "cell_type": "code", "execution_count": 7, "id": "d55209af", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.345245Z", "start_time": "2023-01-30T15:49:48.141775Z" } }, "outputs": [], "source": [ "raw = pyActigraphy.io.read_raw_rpx(\n", " fpath,\n", " language='GER',\n", " delimiter=',',\n", " decimal=','\n", ")" ] }, { "cell_type": "markdown", "id": "76efcaba", "metadata": {}, "source": [ "Now, let's verify which light channels are available for this recording:" ] }, { "cell_type": "code", "execution_count": 8, "id": "369afd25", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.348997Z", "start_time": "2023-01-30T15:49:49.346410Z" } }, "outputs": [ { "data": { "text/plain": [ "Index(['Grünes Licht', 'Blaues Licht', 'Rotes Licht', 'Weißes Licht'], dtype='object')" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.get_channel_list()" ] }, { "cell_type": "markdown", "id": "863dbcdc", "metadata": {}, "source": [ "As expected, this device records light exposure data in 4 different channels (White light + RBG).\n", "\n", "In the following, we will learn how to analyse these different channels." ] }, { "cell_type": "markdown", "id": "f2b27773", "metadata": {}, "source": [ "## Light exposure metrics" ] }, { "cell_type": "markdown", "id": "c91231aa", "metadata": {}, "source": [ "### Exposure level" ] }, { "cell_type": "markdown", "id": "fd896a99", "metadata": {}, "source": [ "This function returns coarse statistics (mean, median, sum, etc) about the light exposure level. It is possible to define the daily time window during which these statistics are calculated." ] }, { "cell_type": "code", "execution_count": 9, "id": "fca5c988", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.353630Z", "start_time": "2023-01-30T15:49:49.351380Z" }, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method light_exposure_level in module pyActigraphy.light.light_metrics:\n", "\n", "light_exposure_level(threshold=None, start_time=None, stop_time=None, agg='mean') method of pyActigraphy.light.light.LightRecording instance\n", " Light exposure level\n", " \n", " Calculate the aggregated (mean, median, etc) light exposure level\n", " per epoch.\n", " \n", " Parameters\n", " ----------\n", " threshold: float, optional\n", " If not set to None, discard data below threshold before computing\n", " exposure levels.\n", " Default is None.\n", " start_time: str, optional\n", " If not set to None, discard data before start time,\n", " on a daily basis.\n", " Supported time string: 'HH:MM:SS'\n", " Default is None.\n", " stop_time: str, optional\n", " If not set to None, discard data after stop time, on a daily basis.\n", " Supported time string: 'HH:MM:SS'\n", " Default is None.\n", " agg: str, optional\n", " Aggregating function used to summarize exposure levels.\n", " Available functions: 'mean', 'median', 'std', etc.\n", " Default is 'mean'.\n", " \n", " Returns\n", " -------\n", " levels : pd.Series\n", " A pandas Series with aggreagted light exposure levels per channel\n", "\n" ] } ], "source": [ "help(raw.light.light_exposure_level)" ] }, { "cell_type": "markdown", "id": "ce6eebb3", "metadata": {}, "source": [ "Default settings: mean exposure level per acquisition epoch" ] }, { "cell_type": "code", "execution_count": 10, "id": "abba6512", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.359931Z", "start_time": "2023-01-30T15:49:49.355452Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 0.980005\n", "Blaues Licht 0.917368\n", "Rotes Licht 1.092138\n", "Weißes Licht 0.826787\n", "dtype: float64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.light_exposure_level()" ] }, { "cell_type": "markdown", "id": "65a351ff", "metadata": {}, "source": [ "Median exposure level:" ] }, { "cell_type": "code", "execution_count": 11, "id": "c94048d6", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.366669Z", "start_time": "2023-01-30T15:49:49.360987Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 0.795185\n", "Blaues Licht 0.674861\n", "Rotes Licht 1.002166\n", "Weißes Licht 0.000000\n", "dtype: float64" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.light_exposure_level(agg='median')" ] }, { "cell_type": "markdown", "id": "deb5ee02", "metadata": {}, "source": [ "Restricting the time window to '08:00'-'16:00' on a daily basis:" ] }, { "cell_type": "code", "execution_count": 12, "id": "fec94552", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.374167Z", "start_time": "2023-01-30T15:49:49.367737Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 1.855412\n", "Blaues Licht 1.743363\n", "Rotes Licht 2.036617\n", "Weißes Licht 1.749981\n", "dtype: float64" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.light_exposure_level(\n", " start_time='08:00:00',\n", " stop_time='16:00:00',\n", ")" ] }, { "cell_type": "markdown", "id": "aceb6075", "metadata": {}, "source": [ "It is also possible to only consider light exposure data above a certain threshold. For example, to compute the mean light exposure level above 10 lux, between '12:00' and '18:00':" ] }, { "cell_type": "code", "execution_count": 13, "id": "9bf25322", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.383176Z", "start_time": "2023-01-30T15:49:49.375889Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 2.069842\n", "Blaues Licht 1.991611\n", "Rotes Licht 2.216590\n", "Weißes Licht 2.108550\n", "dtype: float64" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.light_exposure_level(\n", " threshold=1, # on a log10 scale\n", " start_time='12:00',\n", " stop_time='18:00'\n", ")" ] }, { "cell_type": "markdown", "id": "f96455b1", "metadata": {}, "source": [ "### Summary statistics (mean, median, s.d., max., min., sum)" ] }, { "cell_type": "markdown", "id": "caa3eecd", "metadata": {}, "source": [ "This function returns various summary statistics about the data aggregated into time bins. The length of these time bins, but also their start and stop times, are configurable." ] }, { "cell_type": "code", "execution_count": 14, "id": "795fa45f", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.387902Z", "start_time": "2023-01-30T15:49:49.384952Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method summary_statistics_per_time_bin in module pyActigraphy.light.light_metrics:\n", "\n", "summary_statistics_per_time_bin(bins='24h', agg_func=['mean', 'median', 'sum', 'std', 'min', 'max']) method of pyActigraphy.light.light.LightRecording instance\n", " Summary statistics.\n", " \n", " Calculate summary statistics (ex: mean, median, etc) according to a\n", " user-defined (regular or arbitrary) binning.\n", " \n", " Parameters\n", " ----------\n", " bins: str or list of tuples, optional\n", " If set to a string, bins is used to define a regular binning where\n", " every bin is of length \"bins\". Ex: \"2h\".\n", " Otherwise, the list of 2-tuples is used to define an arbitrary\n", " binning. Ex: \\[('2000-01-01 00:00:00','2000-01-01 11:59:00')\\].\n", " Default is '24h'.\n", " agg_func: list, optional\n", " List of aggregation functions to be used on every bin.\n", " Default is \\['mean', 'median', 'sum', 'std', 'min', 'max'\\].\n", " \n", " Returns\n", " -------\n", " ss : pd.DataFrame\n", " A pandas DataFrame with summary statistics per channel.\n", "\n" ] } ], "source": [ "help(raw.light.summary_statistics_per_time_bin)" ] }, { "cell_type": "markdown", "id": "86ab2125", "metadata": {}, "source": [ "By default, this function returns the mean, median, sum, standard deviation, as well as the min and max, of data aggregated into consecutive 24h bins, for all light channels separately:" ] }, { "cell_type": "code", "execution_count": 15, "id": "73f66f2c", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.440825Z", "start_time": "2023-01-30T15:49:49.389294Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Grünes LichtBlaues Licht...Rotes LichtWeißes Licht
meanmediansumstdminmaxmeanmediansumstd...sumstdminmaxmeanmediansumstdminmax
Date_Time
2019-09-191.1733151.0773641407.9784320.9965100.03.7931621.0788630.9484131294.6360310.975758...1701.5134091.0163350.04.7634351.1547361.0013011385.6836061.0169600.04.500635
2019-09-201.1060910.9804583034.0068331.0695930.04.5865991.0362300.9079492842.3791121.017715...3421.4503891.1320330.04.9025521.0791860.8139132956.9709701.0948770.04.064586
2019-09-210.9924910.1914072858.3741301.1823520.04.0569430.9367340.2467452697.7947281.129741...3165.1569401.2672070.04.9576120.9601500.0000002764.2726621.2103510.04.067003
2019-09-220.7209140.2273722076.2326410.9049470.03.5290450.6630840.1202451909.6815750.866469...2424.7990810.9823950.03.6425630.5770170.0000001661.8083710.9055020.03.591937
2019-09-230.8745320.9790932475.8014610.7823790.02.8555190.8200530.8779472321.5703220.748673...2749.6703290.8515620.03.0216030.5943510.0000001682.0133560.8318290.04.727014
2019-09-241.0538361.1172713035.0482970.9871290.04.1931520.9901571.0310042850.6609030.934035...3317.1405801.0609610.04.7958870.8347240.0000002403.1696191.0369070.05.157700
2019-09-251.0677381.2161643075.0860770.9932490.04.3944691.0027011.1414472887.7801010.945765...3319.4300311.0541340.04.9600000.8205920.0000002363.3047181.0259480.04.383197
2019-09-260.9594140.0000001599.3437821.1284360.03.5186460.9035120.0000001506.1537511.061862...1696.6437861.1721890.03.4067100.7686330.0000001281.3110231.0516660.03.442743
\n", "

8 rows × 24 columns

\n", "
" ], "text/plain": [ " Grünes Licht \\\n", " mean median sum std min max \n", "Date_Time \n", "2019-09-19 1.173315 1.077364 1407.978432 0.996510 0.0 3.793162 \n", "2019-09-20 1.106091 0.980458 3034.006833 1.069593 0.0 4.586599 \n", "2019-09-21 0.992491 0.191407 2858.374130 1.182352 0.0 4.056943 \n", "2019-09-22 0.720914 0.227372 2076.232641 0.904947 0.0 3.529045 \n", "2019-09-23 0.874532 0.979093 2475.801461 0.782379 0.0 2.855519 \n", "2019-09-24 1.053836 1.117271 3035.048297 0.987129 0.0 4.193152 \n", "2019-09-25 1.067738 1.216164 3075.086077 0.993249 0.0 4.394469 \n", "2019-09-26 0.959414 0.000000 1599.343782 1.128436 0.0 3.518646 \n", "\n", " Blaues Licht ... Rotes Licht \\\n", " mean median sum std ... sum \n", "Date_Time ... \n", "2019-09-19 1.078863 0.948413 1294.636031 0.975758 ... 1701.513409 \n", "2019-09-20 1.036230 0.907949 2842.379112 1.017715 ... 3421.450389 \n", "2019-09-21 0.936734 0.246745 2697.794728 1.129741 ... 3165.156940 \n", "2019-09-22 0.663084 0.120245 1909.681575 0.866469 ... 2424.799081 \n", "2019-09-23 0.820053 0.877947 2321.570322 0.748673 ... 2749.670329 \n", "2019-09-24 0.990157 1.031004 2850.660903 0.934035 ... 3317.140580 \n", "2019-09-25 1.002701 1.141447 2887.780101 0.945765 ... 3319.430031 \n", "2019-09-26 0.903512 0.000000 1506.153751 1.061862 ... 1696.643786 \n", "\n", " Weißes Licht \\\n", " std min max mean median sum \n", "Date_Time \n", "2019-09-19 1.016335 0.0 4.763435 1.154736 1.001301 1385.683606 \n", "2019-09-20 1.132033 0.0 4.902552 1.079186 0.813913 2956.970970 \n", "2019-09-21 1.267207 0.0 4.957612 0.960150 0.000000 2764.272662 \n", "2019-09-22 0.982395 0.0 3.642563 0.577017 0.000000 1661.808371 \n", "2019-09-23 0.851562 0.0 3.021603 0.594351 0.000000 1682.013356 \n", "2019-09-24 1.060961 0.0 4.795887 0.834724 0.000000 2403.169619 \n", "2019-09-25 1.054134 0.0 4.960000 0.820592 0.000000 2363.304718 \n", "2019-09-26 1.172189 0.0 3.406710 0.768633 0.000000 1281.311023 \n", "\n", " \n", " std min max \n", "Date_Time \n", "2019-09-19 1.016960 0.0 4.500635 \n", "2019-09-20 1.094877 0.0 4.064586 \n", "2019-09-21 1.210351 0.0 4.067003 \n", "2019-09-22 0.905502 0.0 3.591937 \n", "2019-09-23 0.831829 0.0 4.727014 \n", "2019-09-24 1.036907 0.0 5.157700 \n", "2019-09-25 1.025948 0.0 4.383197 \n", "2019-09-26 1.051666 0.0 3.442743 \n", "\n", "[8 rows x 24 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.summary_statistics_per_time_bin()" ] }, { "cell_type": "markdown", "id": "af0892d5", "metadata": {}, "source": [ "To change the size of the time bins, now focusing on the mean light level, computed every 12h for instance:" ] }, { "cell_type": "code", "execution_count": 16, "id": "c47abda5", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.465257Z", "start_time": "2023-01-30T15:49:49.443380Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Grünes LichtBlaues LichtRotes LichtWeißes Licht
meanmeanmeanmean
Date_Time
2019-09-19 12:00:001.1733151.0788631.4179281.154736
2019-09-20 00:00:000.8156240.7742310.8790380.793869
2019-09-20 12:00:001.4270981.3257761.6563871.393846
2019-09-21 00:00:000.6725850.6265420.7356610.650413
2019-09-21 12:00:001.3123971.2469271.4633811.270103
2019-09-22 00:00:000.1242030.0929700.2070930.111713
2019-09-22 12:00:001.3176251.2331971.4767951.042321
2019-09-23 00:00:000.4857320.4561160.5368740.406213
2019-09-23 12:00:001.2770291.1968111.4209720.788981
2019-09-24 00:00:000.7639320.7005900.8070240.769530
2019-09-24 12:00:001.3437401.2795221.4965460.899872
2019-09-25 00:00:000.5591630.5197930.5952880.525671
2019-09-25 12:00:001.5763131.4856101.7098711.115513
2019-09-26 00:00:000.8387030.7892600.8837270.617451
2019-09-26 12:00:001.6771441.5828341.8148581.667534
\n", "
" ], "text/plain": [ " Grünes Licht Blaues Licht Rotes Licht Weißes Licht\n", " mean mean mean mean\n", "Date_Time \n", "2019-09-19 12:00:00 1.173315 1.078863 1.417928 1.154736\n", "2019-09-20 00:00:00 0.815624 0.774231 0.879038 0.793869\n", "2019-09-20 12:00:00 1.427098 1.325776 1.656387 1.393846\n", "2019-09-21 00:00:00 0.672585 0.626542 0.735661 0.650413\n", "2019-09-21 12:00:00 1.312397 1.246927 1.463381 1.270103\n", "2019-09-22 00:00:00 0.124203 0.092970 0.207093 0.111713\n", "2019-09-22 12:00:00 1.317625 1.233197 1.476795 1.042321\n", "2019-09-23 00:00:00 0.485732 0.456116 0.536874 0.406213\n", "2019-09-23 12:00:00 1.277029 1.196811 1.420972 0.788981\n", "2019-09-24 00:00:00 0.763932 0.700590 0.807024 0.769530\n", "2019-09-24 12:00:00 1.343740 1.279522 1.496546 0.899872\n", "2019-09-25 00:00:00 0.559163 0.519793 0.595288 0.525671\n", "2019-09-25 12:00:00 1.576313 1.485610 1.709871 1.115513\n", "2019-09-26 00:00:00 0.838703 0.789260 0.883727 0.617451\n", "2019-09-26 12:00:00 1.677144 1.582834 1.814858 1.667534" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.summary_statistics_per_time_bin(bins='12h', agg_func=['mean'])" ] }, { "cell_type": "markdown", "id": "80c68993", "metadata": {}, "source": [ "Finally, arbitrary start and stop times can be used to define the time bins;" ] }, { "cell_type": "code", "execution_count": 17, "id": "647ed039", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.502008Z", "start_time": "2023-01-30T15:49:49.467522Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Blaues LichtGrünes LichtRotes LichtWeißes Licht
meanstdmeanstdmeanstdmeanstd
01.5898730.9101441.6938520.9190211.8983400.9269441.6621870.968826
11.1976720.5864411.2779480.6064331.4219940.6392780.7895490.782999
\n", "
" ], "text/plain": [ " Blaues Licht Grünes Licht Rotes Licht \\\n", " mean std mean std mean std \n", "0 1.589873 0.910144 1.693852 0.919021 1.898340 0.926944 \n", "1 1.197672 0.586441 1.277948 0.606433 1.421994 0.639278 \n", "\n", " Weißes Licht \n", " mean std \n", "0 1.662187 0.968826 \n", "1 0.789549 0.782999 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.summary_statistics_per_time_bin(\n", " bins=[\n", " ['2019-09-19 12:00:00','2019-09-19 19:59:00'],\n", " ['2019-09-23 12:00:00','2019-09-23 23:59:00']\n", " ],\n", " agg_func=['mean','std']\n", ")" ] }, { "cell_type": "markdown", "id": "92d8a8f1", "metadata": {}, "source": [ "### Time above threshold (TAT)" ] }, { "cell_type": "markdown", "id": "28979a02", "metadata": {}, "source": [ "This function computes the total time spent with a light exposure level above a certain threshold. Similarly to the light exposure level function, it is possible to configure the daily time window during which this metric is calculated. Various time output format are available." ] }, { "cell_type": "code", "execution_count": 18, "id": "16257818", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.505884Z", "start_time": "2023-01-30T15:49:49.503252Z" }, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method TAT in module pyActigraphy.light.light_metrics:\n", "\n", "TAT(threshold=None, start_time=None, stop_time=None, oformat=None) method of pyActigraphy.light.light.LightRecording instance\n", " Time above light threshold.\n", " \n", " Calculate the total light exposure time above the threshold.\n", " \n", " Parameters\n", " ----------\n", " threshold: float, optional\n", " If not set to None, discard data below threshold before computing\n", " exposure levels.\n", " Default is None.\n", " start_time: str, optional\n", " If not set to None, discard data before start time,\n", " on a daily basis.\n", " Supported time string: 'HH:MM:SS'\n", " Default is None.\n", " stop_time: str, optional\n", " If not set to None, discard data after stop time, on a daily basis.\n", " Supported time string: 'HH:MM:SS'\n", " Default is None.\n", " oformat: str, optional\n", " Output format. Available formats: 'minute' or 'timedelta'.\n", " If set to 'minute', the result is in number of minutes.\n", " If set to 'timedelta', the result is a pd.Timedelta.\n", " If set to None, the result is in number of epochs.\n", " Default is None.\n", " \n", " Returns\n", " -------\n", " tat : pd.Series\n", " A pandas Series with aggreagted light exposure levels per channel\n", "\n" ] } ], "source": [ "help(raw.light.TAT)" ] }, { "cell_type": "markdown", "id": "076d493c", "metadata": {}, "source": [ "With the default settings (no threshold, no time window restriction):" ] }, { "cell_type": "code", "execution_count": 19, "id": "0ad7ccd3", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.513704Z", "start_time": "2023-01-30T15:49:49.507193Z" }, "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 19961\n", "Blaues Licht 19960\n", "Rotes Licht 19957\n", "Weißes Licht 19955\n", "dtype: int64" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.TAT()" ] }, { "cell_type": "markdown", "id": "c2bec589", "metadata": {}, "source": [ "the results are identical to the total number of epochs in the recording." ] }, { "cell_type": "markdown", "id": "d2712672", "metadata": {}, "source": [ "To calculate the number of epochs spent above a threshold of 10 lux:" ] }, { "cell_type": "code", "execution_count": 20, "id": "ef68ce45", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.522587Z", "start_time": "2023-01-30T15:49:49.516260Z" }, "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 9351\n", "Blaues Licht 9000\n", "Rotes Licht 9983\n", "Weißes Licht 7479\n", "dtype: int64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.TAT(threshold=1)" ] }, { "cell_type": "markdown", "id": "f15500ed", "metadata": {}, "source": [ "The parameter `oformat` defines the output format. Available formats:\n", "* 'minute':" ] }, { "cell_type": "code", "execution_count": 21, "id": "e4cb3e5d", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.529587Z", "start_time": "2023-01-30T15:49:49.523550Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 4675.5\n", "Blaues Licht 4500.0\n", "Rotes Licht 4991.5\n", "Weißes Licht 3739.5\n", "dtype: float64" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.TAT(threshold=1, oformat='minute')" ] }, { "cell_type": "markdown", "id": "fb0e1cfd", "metadata": {}, "source": [ "* 'timedelta': " ] }, { "cell_type": "code", "execution_count": 22, "id": "6f12e663", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.539064Z", "start_time": "2023-01-30T15:49:49.530630Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 3 days 05:55:30\n", "Blaues Licht 3 days 03:00:00\n", "Rotes Licht 3 days 11:11:30\n", "Weißes Licht 2 days 14:19:30\n", "dtype: timedelta64[ns]" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.TAT(threshold=1, oformat='timedelta')" ] }, { "cell_type": "markdown", "id": "050e57e9", "metadata": {}, "source": [ "Time spent above threshold at specific time periods:" ] }, { "cell_type": "code", "execution_count": 23, "id": "122cb1d8", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.550435Z", "start_time": "2023-01-30T15:49:49.540151Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 2 days 16:38:00\n", "Blaues Licht 2 days 14:24:00\n", "Rotes Licht 2 days 20:01:30\n", "Weißes Licht 2 days 11:09:30\n", "dtype: timedelta64[ns]" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.TAT(\n", " threshold=1, start_time='08:00:00', stop_time='20:00:00', oformat='timedelta'\n", ")" ] }, { "cell_type": "markdown", "id": "6fd5fd2f", "metadata": {}, "source": [ "### Time above threshold per period (TATp)" ] }, { "cell_type": "markdown", "id": "cee9eed3", "metadata": {}, "source": [ "Sometimes, it could be useful to compute the TAT on consecutive periods of time in order to assess the evolution of such metric through time or before and after a specific intervention. While it is always to possible to read the same file multiple times and restrict its start and stop time to different periods each time, *pyActigraphy* allows users to directly compute the TAT on a daily basis." ] }, { "cell_type": "markdown", "id": "2c41aa71", "metadata": {}, "source": [ "This function has the same input parameters as the TAT function:" ] }, { "cell_type": "code", "execution_count": 24, "id": "79c124f7", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.554843Z", "start_time": "2023-01-30T15:49:49.551705Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method TATp in module pyActigraphy.light.light_metrics:\n", "\n", "TATp(threshold=None, start_time=None, stop_time=None, oformat=None) method of pyActigraphy.light.light.LightRecording instance\n", " Time above light threshold (per day).\n", " \n", " Calculate the total light exposure time above the threshold,\n", " per calendar day.\n", " \n", " Parameters\n", " ----------\n", " threshold: float, optional\n", " If not set to None, discard data below threshold before computing\n", " exposure levels.\n", " Default is None.\n", " start_time: str, optional\n", " If not set to None, discard data before start time,\n", " on a daily basis.\n", " Supported time string: 'HH:MM:SS'\n", " Default is None.\n", " stop_time: str, optional\n", " If not set to None, discard data after stop time, on a daily basis.\n", " Supported time string: 'HH:MM:SS'\n", " Default is None.\n", " oformat: str, optional\n", " Output format. Available formats: 'minute' or 'timedelta'.\n", " If set to 'minute', the result is in number of minutes.\n", " If set to 'timedelta', the result is a pd.Timedelta.\n", " If set to None, the result is in number of epochs.\n", " Default is None.\n", " \n", " Returns\n", " -------\n", " tatp : pd.DataFrame\n", " A pandas DataFrame with aggreagted light exposure levels\n", " per channel and per day.\n", "\n" ] } ], "source": [ "help(raw.light.TATp)" ] }, { "cell_type": "code", "execution_count": 25, "id": "d5dbdcc2", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.574896Z", "start_time": "2023-01-30T15:49:49.556910Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Grünes LichtBlaues LichtRotes LichtWeißes Licht
2019-09-19138.5111.5174.0141.5
2019-09-20374.5318.0433.0377.0
2019-09-21408.0366.5440.5428.5
2019-09-22163.0122.0205.5179.0
2019-09-2387.543.5194.586.5
2019-09-24305.5236.5417.0277.5
2019-09-25237.5202.5316.5243.0
2019-09-26183.5159.0236.0150.5
\n", "
" ], "text/plain": [ " Grünes Licht Blaues Licht Rotes Licht Weißes Licht\n", "2019-09-19 138.5 111.5 174.0 141.5\n", "2019-09-20 374.5 318.0 433.0 377.0\n", "2019-09-21 408.0 366.5 440.5 428.5\n", "2019-09-22 163.0 122.0 205.5 179.0\n", "2019-09-23 87.5 43.5 194.5 86.5\n", "2019-09-24 305.5 236.5 417.0 277.5\n", "2019-09-25 237.5 202.5 316.5 243.0\n", "2019-09-26 183.5 159.0 236.0 150.5" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.TATp(threshold=2, oformat='minute')" ] }, { "cell_type": "markdown", "id": "162f8f9d", "metadata": {}, "source": [ "### Mean light timing (MLit)" ] }, { "cell_type": "markdown", "id": "fea6e9df", "metadata": {}, "source": [ "This function calculates the mean light timing above threshold ($\\mathrm{MLit}^{XXX}$), defined in [Reid et al. (2014)](https://doi.org/10.1371/journal.pone.0092251) as the average clock time of all aggregated data points above XXX lux. In the original paper, a threshold of 500 lux was chosen but in this function, the threshold is configurable.\n", "\n", "The results are expressed in number of minutes since midnight, irrespective of the sampling period." ] }, { "cell_type": "code", "execution_count": 26, "id": "7d1b6d4b", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.580417Z", "start_time": "2023-01-30T15:49:49.576162Z" }, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method MLiT in module pyActigraphy.light.light_metrics:\n", "\n", "MLiT(threshold) method of pyActigraphy.light.light.LightRecording instance\n", " Mean light timing.\n", " \n", " Mean light timing above threshold, MLiT^C.\n", " \n", " \n", " Parameters\n", " ----------\n", " threshold: float\n", " Threshold value.\n", " \n", " Returns\n", " -------\n", " MLiT : pd.DataFrame\n", " A pandas DataFrame with MLiT^C per channel.\n", " \n", " Notes\n", " -----\n", " \n", " The MLiT variable is defined in ref [1]_:\n", " \n", " .. math::\n", " \n", " MLiT^C = \\frac{\\sum_{j}^{m}\\sum_{k}^{n} j\\times I^{C}_{jk}}{\n", " \\sum_{j}^{m}\\sum_{k}^{n} I^{C}_{jk}}\n", " \n", " where :math:`I^{C}_{jk}` is equal to 1 if the light level is higher\n", " than the threshold C, m is the total number of epochs per day and n is\n", " the number of days covered by the data.\n", " \n", " References\n", " ----------\n", " \n", " .. [1] Reid K.J., Santostasi G., Baron K.G., Wilson J., Kang J.,\n", " Zee P.C., Timing and Intensity of Light Correlate with Body\n", " Weight in Adults. PLoS ONE 9(4): e92251.\n", " https://doi.org/10.1371/journal.pone.0092251\n", "\n" ] } ], "source": [ "help(raw.light.MLiT)" ] }, { "cell_type": "markdown", "id": "b3fe723d", "metadata": {}, "source": [ "To compute the $\\mathrm{MLit}^{500}$:" ] }, { "cell_type": "code", "execution_count": 27, "id": "1d4f423e", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.618072Z", "start_time": "2023-01-30T15:49:49.588228Z" } }, "outputs": [ { "data": { "text/plain": [ "Grünes Licht 800.190773\n", "Blaues Licht 812.883784\n", "Rotes Licht 813.205830\n", "Weißes Licht 791.039116\n", "dtype: float64" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Do not forget that the light exposure data are converted to log10+1.\n", "raw.light.MLiT(threshold=np.log10(500+1))" ] }, { "cell_type": "code", "execution_count": 28, "id": "08fc1c67", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.623458Z", "start_time": "2023-01-30T15:49:49.620460Z" }, "scrolled": true }, "outputs": [ { "data": { "text/plain": [ "(13.0, 11.039116000000035)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# To convert this number of minutes into a time of day, simply divide it by the number of minutes per hour:\n", "divmod(791.039116,60)" ] }, { "cell_type": "markdown", "id": "f177d7d8", "metadata": {}, "source": [ "The mean light timing for white light exposure above 500 lux is around 13h11 for this recording." ] }, { "cell_type": "markdown", "id": "8215c82f", "metadata": {}, "source": [ "Just like for the TAT, it might be interesting to compute the $\\mathrm{MLit}^{XXX}$ variable on a daily basis. Again, *pyActigraphy* makes that operation easy:" ] }, { "cell_type": "code", "execution_count": 29, "id": "05486564", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.666492Z", "start_time": "2023-01-30T15:49:49.625233Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Grünes LichtBlaues LichtRotes LichtWeißes Licht
2019-09-19871.489247872.392857884.867742878.613402
2019-09-20774.283981764.430464787.884106716.108051
2019-09-21870.485294884.329167866.842282870.277961
2019-09-22871.580189874.472222870.177515881.189815
2019-09-23770.000000889.000000779.000000618.491228
2019-09-24829.362832861.191011829.003185792.220430
2019-09-25782.959239779.517606782.586000778.137143
2019-09-26637.688172656.558594643.789189671.674528
\n", "
" ], "text/plain": [ " Grünes Licht Blaues Licht Rotes Licht Weißes Licht\n", "2019-09-19 871.489247 872.392857 884.867742 878.613402\n", "2019-09-20 774.283981 764.430464 787.884106 716.108051\n", "2019-09-21 870.485294 884.329167 866.842282 870.277961\n", "2019-09-22 871.580189 874.472222 870.177515 881.189815\n", "2019-09-23 770.000000 889.000000 779.000000 618.491228\n", "2019-09-24 829.362832 861.191011 829.003185 792.220430\n", "2019-09-25 782.959239 779.517606 782.586000 778.137143\n", "2019-09-26 637.688172 656.558594 643.789189 671.674528" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.MLiTp(threshold=np.log10(500+1))" ] }, { "cell_type": "markdown", "id": "e2713198", "metadata": {}, "source": [ "### Extrema" ] }, { "cell_type": "markdown", "id": "e3182c70", "metadata": {}, "source": [ "This function simply returns information (timing and value) about the minimal or maximal light exposure data value." ] }, { "cell_type": "code", "execution_count": 30, "id": "6017cc08", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.670741Z", "start_time": "2023-01-30T15:49:49.667892Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method get_light_extremum in module pyActigraphy.light.light_metrics:\n", "\n", "get_light_extremum(extremum) method of pyActigraphy.light.light.LightRecording instance\n", " Light extremum.\n", " \n", " Return the index and the value of the requested extremum (min or max).\n", " \n", " Parameters\n", " ----------\n", " extremum: str\n", " Name of the extremum.\n", " Available: 'min' or 'max'.\n", " \n", " Returns\n", " -------\n", " ext : pd.DataFrame\n", " A pandas DataFrame with extremum info per channel.\n", "\n" ] } ], "source": [ "help(raw.light.get_light_extremum)" ] }, { "cell_type": "code", "execution_count": 31, "id": "092647fd", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.681280Z", "start_time": "2023-01-30T15:49:49.671819Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelindexvalue
0Grünes Licht2019-09-20 09:06:304.586599
1Blaues Licht2019-09-24 10:17:304.033464
2Rotes Licht2019-09-25 14:07:304.96
3Weißes Licht2019-09-24 15:06:305.1577
\n", "
" ], "text/plain": [ " channel index value\n", "0 Grünes Licht 2019-09-20 09:06:30 4.586599\n", "1 Blaues Licht 2019-09-24 10:17:30 4.033464\n", "2 Rotes Licht 2019-09-25 14:07:30 4.96\n", "3 Weißes Licht 2019-09-24 15:06:30 5.1577" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.get_light_extremum(extremum='max')" ] }, { "cell_type": "code", "execution_count": 32, "id": "5155495b", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.691561Z", "start_time": "2023-01-30T15:49:49.682455Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelindexvalue
0Grünes Licht2019-09-19 14:35:000.0
1Blaues Licht2019-09-19 15:43:300.0
2Rotes Licht2019-09-19 15:43:300.0
3Weißes Licht2019-09-19 15:43:300.0
\n", "
" ], "text/plain": [ " channel index value\n", "0 Grünes Licht 2019-09-19 14:35:00 0.0\n", "1 Blaues Licht 2019-09-19 15:43:30 0.0\n", "2 Rotes Licht 2019-09-19 15:43:30 0.0\n", "3 Weißes Licht 2019-09-19 15:43:30 0.0" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.get_light_extremum(extremum='min')" ] }, { "cell_type": "markdown", "id": "7a7efbf6", "metadata": {}, "source": [ "### L5 and M10 (values and timing)" ] }, { "cell_type": "markdown", "id": "b3f419dc", "metadata": {}, "source": [ "The L5 (M10) variable refers to the 5(10)h-period of daily light exposure profile with the lowest(highest) light exposure levels. In this function, the length of this period can be configured. Information about the timing and the mean hourly light exposure levels are returned." ] }, { "cell_type": "code", "execution_count": 33, "id": "de5a5803", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.696681Z", "start_time": "2023-01-30T15:49:49.692716Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method LMX in module pyActigraphy.light.light_metrics:\n", "\n", "LMX(length='5h', lowest=True) method of pyActigraphy.light.light.LightRecording instance\n", " Least or Most light period of length X\n", " \n", " Onset and mean hourly light exposure levels during the X least or most\n", " bright hours of the day.\n", " \n", " Parameters\n", " ----------\n", " length: str, optional\n", " Period length.\n", " Default is '5h'.\n", " lowest: bool, optional\n", " If lowest is set to True, the period of least light exposure is\n", " considered. Otherwise, consider the period of most light exposure.\n", " Default is True.\n", " \n", " Returns\n", " -------\n", " lmx_t, lmx: (pd.Timedelta, float)\n", " Onset and mean hourly light exposure level.\n", " \n", " Notes\n", " -----\n", " \n", " The LMX variable is derived from the L5 and M10 defined in [1]_ as the\n", " mean hourly activity levels during the 5/10 least/most active hours.\n", " \n", " References\n", " ----------\n", " \n", " .. [1] Van Someren, E.J.W., Lijzenga, C., Mirmiran, M., Swaab, D.F.\n", " (1997). Long-Term Fitness Training Improves the Circadian\n", " Rest-Activity Rhythm in Healthy Elderly Males.\n", " Journal of Biological Rhythms, 12(2), 146–156.\n", " http://doi.org/10.1177/074873049701200206\n", "\n" ] } ], "source": [ "help(raw.light.LMX)" ] }, { "cell_type": "code", "execution_count": 34, "id": "b00c92e6", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.730853Z", "start_time": "2023-01-30T15:49:49.698353Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelindexvalue
0Grünes Licht0 days 08:21:00222.124699
1Blaues Licht0 days 08:21:00208.756896
2Rotes Licht0 days 08:21:00243.791392
3Weißes Licht0 days 08:20:30210.89479
\n", "
" ], "text/plain": [ " channel index value\n", "0 Grünes Licht 0 days 08:21:00 222.124699\n", "1 Blaues Licht 0 days 08:21:00 208.756896\n", "2 Rotes Licht 0 days 08:21:00 243.791392\n", "3 Weißes Licht 0 days 08:20:30 210.89479" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.LMX(length='10h',lowest=False)" ] }, { "cell_type": "markdown", "id": "085e6a5c", "metadata": {}, "source": [ "It seems that the 10h long period with the highest light exposure levels starts at 8h21." ] }, { "cell_type": "code", "execution_count": 35, "id": "f4981ce9", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.763157Z", "start_time": "2023-01-30T15:49:49.732132Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelindexvalue
0Grünes Licht0 days 23:55:000.122553
1Blaues Licht0 days 00:00:000.11122
2Rotes Licht0 days 00:00:000.122716
3Weißes Licht0 days 00:00:000.0
\n", "
" ], "text/plain": [ " channel index value\n", "0 Grünes Licht 0 days 23:55:00 0.122553\n", "1 Blaues Licht 0 days 00:00:00 0.11122\n", "2 Rotes Licht 0 days 00:00:00 0.122716\n", "3 Weißes Licht 0 days 00:00:00 0.0" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.LMX(length='5h',lowest=True)" ] }, { "cell_type": "markdown", "id": "388735c7", "metadata": {}, "source": [ "It seems that the 5h long period with the lowest light exposure levels starts at 00h00." ] }, { "cell_type": "markdown", "id": "3b78bfb8", "metadata": {}, "source": [ "It is easy to visually check if these results are correct by computing the average daily profile of light exposure:" ] }, { "cell_type": "code", "execution_count": 36, "id": "149e4f85", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.811324Z", "start_time": "2023-01-30T15:49:49.764251Z" } }, "outputs": [], "source": [ "dlp = raw.light.average_daily_profile(\n", " rsfreq='60min', cyclic=False, channel='Weißes Licht'\n", ")" ] }, { "cell_type": "code", "execution_count": 37, "id": "ef323ca5", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.834015Z", "start_time": "2023-01-30T15:49:49.812446Z" }, "scrolled": false }, "outputs": [], "source": [ "dlp_fig = go.Figure(go.Scatter(x=dlp.index.astype(str),y=dlp))" ] }, { "cell_type": "code", "execution_count": 38, "id": "b79d9214", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.938820Z", "start_time": "2023-01-30T15:49:49.835194Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/vnd.plotly.v1+json": { "config": { "plotlyServerURL": "https://plot.ly" }, "data": [ { "type": "scatter", "x": [ "0 days 00:00:00", "0 days 01:00:00", "0 days 02:00:00", "0 days 03:00:00", "0 days 04:00:00", "0 days 05:00:00", "0 days 06:00:00", "0 days 07:00:00", "0 days 08:00:00", "0 days 09:00:00", "0 days 10:00:00", "0 days 11:00:00", "0 days 12:00:00", "0 days 13:00:00", "0 days 14:00:00", "0 days 15:00:00", "0 days 16:00:00", "0 days 17:00:00", "0 days 18:00:00", "0 days 19:00:00", "0 days 20:00:00", "0 days 21:00:00", "0 days 22:00:00", "0 days 23:00:00" ], "y": [ 0, 0, 0, 0, 0, 0, 0.0004112372889273725, 0.5765675803414322, 1.1330971884319505, 1.4910248724235557, 1.5038337935387143, 1.8124956988091185, 1.938802659056979, 1.7981270544805368, 2.1274445886074216, 2.0825446479836183, 1.8799956444654153, 1.5023714541650137, 1.1276249410036132, 0.4029766095580972, 0.25665617696985293, 0.21071622997600217, 0.09427088924817652, 0.008417746893065004 ] } ], "layout": { "template": { "data": { "bar": [ { "error_x": { "color": "#2a3f5f" }, "error_y": { "color": "#2a3f5f" }, "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "bar" } ], "barpolar": [ { "marker": { "line": { "color": "#E5ECF6", "width": 0.5 }, "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "barpolar" } ], "carpet": [ { "aaxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "baxis": { "endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f" }, "type": "carpet" } ], "choropleth": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "choropleth" } ], "contour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "contour" } ], "contourcarpet": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "contourcarpet" } ], "heatmap": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmap" } ], "heatmapgl": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "heatmapgl" } ], "histogram": [ { "marker": { "pattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 } }, "type": "histogram" } ], "histogram2d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2d" } ], "histogram2dcontour": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "histogram2dcontour" } ], "mesh3d": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "type": "mesh3d" } ], "parcoords": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "parcoords" } ], "pie": [ { "automargin": true, "type": "pie" } ], "scatter": [ { "fillpattern": { "fillmode": "overlay", "size": 10, "solidity": 0.2 }, "type": "scatter" } ], "scatter3d": [ { "line": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatter3d" } ], "scattercarpet": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattercarpet" } ], "scattergeo": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergeo" } ], "scattergl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattergl" } ], "scattermapbox": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scattermapbox" } ], "scatterpolar": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolar" } ], "scatterpolargl": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterpolargl" } ], "scatterternary": [ { "marker": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "type": "scatterternary" } ], "surface": [ { "colorbar": { "outlinewidth": 0, "ticks": "" }, "colorscale": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "type": "surface" } ], "table": [ { "cells": { "fill": { "color": "#EBF0F8" }, "line": { "color": "white" } }, "header": { "fill": { "color": "#C8D4E3" }, "line": { "color": "white" } }, "type": "table" } ] }, "layout": { "annotationdefaults": { "arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1 }, "autotypenumbers": "strict", "coloraxis": { "colorbar": { "outlinewidth": 0, "ticks": "" } }, "colorscale": { "diverging": [ [ 0, "#8e0152" ], [ 0.1, "#c51b7d" ], [ 0.2, "#de77ae" ], [ 0.3, "#f1b6da" ], [ 0.4, "#fde0ef" ], [ 0.5, "#f7f7f7" ], [ 0.6, "#e6f5d0" ], [ 0.7, "#b8e186" ], [ 0.8, "#7fbc41" ], [ 0.9, "#4d9221" ], [ 1, "#276419" ] ], "sequential": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ], "sequentialminus": [ [ 0, "#0d0887" ], [ 0.1111111111111111, "#46039f" ], [ 0.2222222222222222, "#7201a8" ], [ 0.3333333333333333, "#9c179e" ], [ 0.4444444444444444, "#bd3786" ], [ 0.5555555555555556, "#d8576b" ], [ 0.6666666666666666, "#ed7953" ], [ 0.7777777777777778, "#fb9f3a" ], [ 0.8888888888888888, "#fdca26" ], [ 1, "#f0f921" ] ] }, "colorway": [ "#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52" ], "font": { "color": "#2a3f5f" }, "geo": { "bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white" }, "hoverlabel": { "align": "left" }, "hovermode": "closest", "mapbox": { "style": "light" }, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": { "angularaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "radialaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "scene": { "xaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "yaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" }, "zaxis": { "backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white" } }, "shapedefaults": { "line": { "color": "#2a3f5f" } }, "ternary": { "aaxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "baxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" }, "bgcolor": "#E5ECF6", "caxis": { "gridcolor": "white", "linecolor": "white", "ticks": "" } }, "title": { "x": 0.05 }, "xaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 }, "yaxis": { "automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": { "standoff": 15 }, "zerolinecolor": "white", "zerolinewidth": 2 } } } } }, "text/html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dlp_fig.show()" ] }, { "cell_type": "markdown", "id": "cffa6da2", "metadata": {}, "source": [ "### IS & IV" ] }, { "cell_type": "markdown", "id": "ebf5fec5", "metadata": {}, "source": [ "The interdaily stability (IS) and intradaily variability (IV) were first defined in the context of the locomotor activity analysis, to quantify the stability of the circadian activity pattern and the fragmentation of this daily pattern, respectively.\n", "\n", "Now, within the pyActigraphy module for light analysis, these metrics can be computed using the light exposure levels as inputs.\n", "\n", "**NB**: the default parameter values for these functions are different from the values used by default for the IS/IV functions for activity data, directly accessible via `raw.IS()` or `raw.IV()`." ] }, { "cell_type": "code", "execution_count": 39, "id": "34b9aae5", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.942108Z", "start_time": "2023-01-30T15:49:49.939877Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method IS in module pyActigraphy.light.light_metrics:\n", "\n", "IS(binarize=False, threshold=0) method of pyActigraphy.light.light.LightRecording instance\n", " Interdaily stability\n", " \n", " The Interdaily stability (IS) quantifies the repeatibilty of the\n", " daily light exposure pattern over each day contained in the activity\n", " recording.\n", " \n", " Parameters\n", " ----------\n", " binarize: bool, optional\n", " If set to True, the data are binarized.\n", " Default is False.\n", " threshold: int, optional\n", " If binarize is set to True, data above this threshold are set to 1\n", " and to 0 otherwise.\n", " Default is 0.\n", " \n", " Returns\n", " -------\n", " is : pd.DataFrame\n", " A pandas DataFrame with IS per channel.\n", " \n", " \n", " Notes\n", " -----\n", " \n", " This variable is derived from the original IS variable defined in\n", " ref [1]_ as:\n", " \n", " .. math::\n", " \n", " IS = \\frac{d^{24h}}{d^{1h}}\n", " \n", " with:\n", " \n", " .. math::\n", " \n", " d^{1h} = \\sum_{i}^{n}\\frac{\\left(x_{i}-\\bar{x}\\right)^{2}}{n}\n", " \n", " where :math:`x_{i}` is the number of active (counts higher than a\n", " predefined threshold) minutes during the :math:`i^{th}` period,\n", " :math:`\\bar{x}` is the mean of all data and :math:`n` is the number of\n", " periods covered by the actigraphy data and with:\n", " \n", " .. math::\n", " \n", " d^{24h} = \\sum_{i}^{p} \\frac{\n", " \\left( \\bar{x}_{h,i} - \\bar{x} \\right)^{2}\n", " }{p}\n", " \n", " where :math:`\\bar{x}^{h,i}` is the average number of active minutes\n", " over the :math:`i^{th}` period and :math:`p` is the number of periods\n", " per day. The average runs over all the days.\n", " \n", " For the record, this is the 24h value from the chi-square periodogram\n", " (Sokolove and Bushel, 1978).\n", " \n", " References\n", " ----------\n", " \n", " .. [1] Witting W., Kwa I.H., Eikelenboom P., Mirmiran M., Swaab D.F.\n", " Alterations in the circadian rest–activity rhythm in aging and\n", " Alzheimer׳s disease. Biol Psychiatry. 1990;27:563–572.\n", "\n" ] } ], "source": [ "help(raw.light.IS)" ] }, { "cell_type": "markdown", "id": "069efd78", "metadata": {}, "source": [ "By default, light exposure data are not binarized before computing the IS:" ] }, { "cell_type": "code", "execution_count": 40, "id": "46b682d0", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.966637Z", "start_time": "2023-01-30T15:49:49.943301Z" }, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelIS
0Grünes Licht0.685174
1Blaues Licht0.673244
2Rotes Licht0.718167
3Weißes Licht0.667941
\n", "
" ], "text/plain": [ " channel IS\n", "0 Grünes Licht 0.685174\n", "1 Blaues Licht 0.673244\n", "2 Rotes Licht 0.718167\n", "3 Weißes Licht 0.667941" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.IS()" ] }, { "cell_type": "markdown", "id": "33016794", "metadata": {}, "source": [ "However, it remains possible to do so by applying a threshold (at 100 lux for example):" ] }, { "cell_type": "code", "execution_count": 41, "id": "792db3c9", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:49.996793Z", "start_time": "2023-01-30T15:49:49.967723Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelIS
0Grünes Licht0.413717
1Blaues Licht0.381848
2Rotes Licht0.443128
3Weißes Licht0.41415
\n", "
" ], "text/plain": [ " channel IS\n", "0 Grünes Licht 0.413717\n", "1 Blaues Licht 0.381848\n", "2 Rotes Licht 0.443128\n", "3 Weißes Licht 0.41415" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.IS(binarize=True, threshold=2)" ] }, { "cell_type": "code", "execution_count": 42, "id": "3f97740a", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:50.000018Z", "start_time": "2023-01-30T15:49:49.997755Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method IV in module pyActigraphy.light.light_metrics:\n", "\n", "IV(binarize=False, threshold=0) method of pyActigraphy.light.light.LightRecording instance\n", " Intradaily variability\n", " \n", " The Intradaily Variability (IV) quantifies the variability of the\n", " light exposure pattern.\n", " \n", " Parameters\n", " ----------\n", " binarize: bool, optional\n", " If set to True, the data are binarized.\n", " Default is False.\n", " threshold: int, optional\n", " If binarize is set to True, data above this threshold are set to 1\n", " and to 0 otherwise.\n", " Default is 4.\n", " \n", " Returns\n", " -------\n", " iv: pd.DataFrame\n", " A pandas DataFrame with IV per channel.\n", " \n", " Notes\n", " -----\n", " \n", " It is defined in ref [1]_:\n", " \n", " .. math::\n", " \n", " IV = \\frac{c^{1h}}{d^{1h}}\n", " \n", " with:\n", " \n", " .. math::\n", " \n", " d^{1h} = \\sum_{i}^{n}\\frac{\\left(x_{i}-\\bar{x}\\right)^{2}}{n}\n", " \n", " where :math:`x_{i}` is the number of active (counts higher than a\n", " predefined threshold) minutes during the :math:`i^{th}` period,\n", " :math:`\\bar{x}` is the mean of all data and :math:`n` is the number of\n", " periods covered by the actigraphy data,\n", " \n", " and with:\n", " \n", " .. math::\n", " \n", " c^{1h} = \\sum_{i}^{n-1} \\frac{\n", " \\left( x_{i+1} - x_{i} \\right)^{2}\n", " }{n-1}\n", " \n", " References\n", " ----------\n", " \n", " .. [1] Witting W., Kwa I.H., Eikelenboom P., Mirmiran M., Swaab D.F.\n", " Alterations in the circadian rest–activity rhythm in aging and\n", " Alzheimer׳s disease. Biol Psychiatry. 1990;27:563–572.\n", "\n" ] } ], "source": [ "help(raw.light.IV)" ] }, { "cell_type": "markdown", "id": "3cf7ae49", "metadata": {}, "source": [ "By default, no data binarization is applied:" ] }, { "cell_type": "code", "execution_count": 43, "id": "5ab0cceb", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:50.008766Z", "start_time": "2023-01-30T15:49:50.000982Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelIV
0Grünes Licht0.076118
1Blaues Licht0.071945
2Rotes Licht0.057085
3Weißes Licht0.157271
\n", "
" ], "text/plain": [ " channel IV\n", "0 Grünes Licht 0.076118\n", "1 Blaues Licht 0.071945\n", "2 Rotes Licht 0.057085\n", "3 Weißes Licht 0.157271" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.IV()" ] }, { "cell_type": "markdown", "id": "eac267cf", "metadata": {}, "source": [ "But, again, data binarization can easily be performed:" ] }, { "cell_type": "code", "execution_count": 44, "id": "22be461c", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:50.021972Z", "start_time": "2023-01-30T15:49:50.009767Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
channelIV
0Grünes Licht0.16142
1Blaues Licht0.163378
2Rotes Licht0.125533
3Weißes Licht0.212527
\n", "
" ], "text/plain": [ " channel IV\n", "0 Grünes Licht 0.16142\n", "1 Blaues Licht 0.163378\n", "2 Rotes Licht 0.125533\n", "3 Weißes Licht 0.212527" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.IV(binarize=True, threshold=1)" ] }, { "cell_type": "markdown", "id": "2274771f", "metadata": {}, "source": [ "### Access to raw and thresholded data" ] }, { "cell_type": "markdown", "id": "bd3bf622", "metadata": {}, "source": [ "Most of the analyses on light exposure can be performed using the various metrics available in the *pyActigraphy* light module. However, for the most fearless users that require full access to the light exposure time series, it is possible to directly access the raw data or simply the thresholded data:" ] }, { "cell_type": "code", "execution_count": 45, "id": "8982eff8", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:50.024911Z", "start_time": "2023-01-30T15:49:50.022938Z" }, "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method VAT in module pyActigraphy.light.light_metrics:\n", "\n", "VAT(threshold=None) method of pyActigraphy.light.light.LightRecording instance\n", " Values above light threshold.\n", " \n", " Returns the light exposure values above the threshold.\n", " \n", " Parameters\n", " ----------\n", " threshold: float, optional\n", " If not set to None, discard data below threshold before computing\n", " exposure levels.\n", " Default is None.\n", " \n", " Returns\n", " -------\n", " vat : pd.Series\n", " A pandas Series with light exposure levels per channel\n", "\n" ] } ], "source": [ "help(raw.light.VAT)" ] }, { "cell_type": "markdown", "id": "b6e33371", "metadata": {}, "source": [ "Inspect the first 5 epochs of raw light data:" ] }, { "cell_type": "code", "execution_count": 46, "id": "977f76a9", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:50.036454Z", "start_time": "2023-01-30T15:49:50.027414Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Grünes LichtBlaues LichtRotes LichtWeißes Licht
Date_Time
2019-09-19 14:00:002.3873902.2201082.3729122.267477
2019-09-19 14:00:302.3873902.2201082.3729122.267477
2019-09-19 14:01:003.7931623.7068034.0294243.786615
2019-09-19 14:01:303.1646503.1075493.4844423.152298
2019-09-19 14:02:002.8475732.7958803.1646502.847351
\n", "
" ], "text/plain": [ " Grünes Licht Blaues Licht Rotes Licht Weißes Licht\n", "Date_Time \n", "2019-09-19 14:00:00 2.387390 2.220108 2.372912 2.267477\n", "2019-09-19 14:00:30 2.387390 2.220108 2.372912 2.267477\n", "2019-09-19 14:01:00 3.793162 3.706803 4.029424 3.786615\n", "2019-09-19 14:01:30 3.164650 3.107549 3.484442 3.152298\n", "2019-09-19 14:02:00 2.847573 2.795880 3.164650 2.847351" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.data.head(5)" ] }, { "cell_type": "markdown", "id": "0e78a9df", "metadata": {}, "source": [ "Or access the raw data thresholded at 100 lux:" ] }, { "cell_type": "code", "execution_count": 47, "id": "1303c80a", "metadata": { "ExecuteTime": { "end_time": "2023-01-30T15:49:50.051961Z", "start_time": "2023-01-30T15:49:50.038552Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Grünes LichtBlaues LichtRotes LichtWeißes Licht
Date_Time
2019-09-19 14:00:002.3873902.2201082.3729122.267477
2019-09-19 14:00:302.3873902.2201082.3729122.267477
2019-09-19 14:01:003.7931623.7068034.0294243.786615
2019-09-19 14:01:303.1646503.1075493.4844423.152298
2019-09-19 14:02:002.8475732.7958803.1646502.847351
...............
2019-09-26 13:57:30NaNNaNNaNNaN
2019-09-26 13:58:00NaNNaNNaNNaN
2019-09-26 13:58:30NaNNaNNaNNaN
2019-09-26 13:59:00NaNNaNNaNNaN
2019-09-26 13:59:30NaNNaNNaNNaN
\n", "

20160 rows × 4 columns

\n", "
" ], "text/plain": [ " Grünes Licht Blaues Licht Rotes Licht Weißes Licht\n", "Date_Time \n", "2019-09-19 14:00:00 2.387390 2.220108 2.372912 2.267477\n", "2019-09-19 14:00:30 2.387390 2.220108 2.372912 2.267477\n", "2019-09-19 14:01:00 3.793162 3.706803 4.029424 3.786615\n", "2019-09-19 14:01:30 3.164650 3.107549 3.484442 3.152298\n", "2019-09-19 14:02:00 2.847573 2.795880 3.164650 2.847351\n", "... ... ... ... ...\n", "2019-09-26 13:57:30 NaN NaN NaN NaN\n", "2019-09-26 13:58:00 NaN NaN NaN NaN\n", "2019-09-26 13:58:30 NaN NaN NaN NaN\n", "2019-09-26 13:59:00 NaN NaN NaN NaN\n", "2019-09-26 13:59:30 NaN NaN NaN NaN\n", "\n", "[20160 rows x 4 columns]" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw.light.VAT(2)" ] }, { "cell_type": "markdown", "id": "c4aecb10", "metadata": {}, "source": [ "Et voilà! For now..." ] } ], "metadata": { "kernelspec": { "display_name": "pyActi37", "language": "python", "name": "pyacti37" }, "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.7.12" } }, "nbformat": 4, "nbformat_minor": 5 }