@@ -752,8 +752,8 @@ def Crespo(
752752 Returns
753753 -------
754754 crespo : pandas.core.Series
755- Time series containing the estimated periods of rest (0 ) and
756- activity (1 ).
755+ Time series containing the estimated periods of rest (1 ) and
756+ activity (0 ).
757757
758758 References
759759 ----------
@@ -907,6 +907,9 @@ def Crespo(
907907 crespo .iloc [0 ] = 1
908908 crespo .iloc [- 1 ] = 1
909909
910+ # Invert labelling (make classification output consistent with other algorithms)
911+ crespo = np .where (crespo == 1 , 0 , 1 )
912+
910913 if plot :
911914 # Specify the layout of the figure to be generated
912915 layout = go .Layout (title = "Rest/Activity detection" , xaxis = dict (title = "Date time" ),
@@ -1117,6 +1120,7 @@ def Roenneberg(
11171120 # Return the scoring series
11181121 return rbg
11191122
1123+
11201124def Roenneberg_AoT (
11211125 data ,
11221126 trend_period = '24h' ,
@@ -1618,7 +1622,7 @@ def main_sleep_bouts(data, report='major'):
16181622 return minor_sleep , mean
16191623
16201624
1621- def waso (data , algo = 'Cole-Kripke' , ** kwargs ):
1625+ def waso (data , frequency , algo = 'Cole-Kripke' , ** kwargs ):
16221626 """
16231627 Calculate Wake After Sleep Onset (WASO)
16241628
@@ -1628,6 +1632,8 @@ def waso(data, algo='Cole-Kripke', **kwargs):
16281632 Input data series with a DatetimeIndex, where the index specifies the time points and
16291633 the values represent the input variable (e.g., activity, light). Time and value arrays
16301634 are extracted from this series.
1635+ frequency : pd.Timedelta
1636+ Sampling frequency of the activity trace in data.
16311637 algo
16321638 Sleep detection algorithm to use to detect sleep fragments during a consolidated sleep
16331639 period (as determined by the Roenneberg algorithm). It can be either 'Cole-Kripke',
@@ -1639,15 +1645,12 @@ def waso(data, algo='Cole-Kripke', **kwargs):
16391645 * "10sec_max_non_overlap": maximum 10-second non-overlapping epoch per minute
16401646 * "30sec_max_non_overlap": maximum 30-second non-overlapping epoch per minute
16411647
1642-
16431648 Returns
16441649 -------
16451650 pd.Series
16461651 A series containing WASO values per day
16471652 np.float64
16481653 Mean WASO value
1649-
1650-
16511654 """
16521655 # Calculate main consolidated sleep episodes using the Roenneberg algorithm
16531656 main_sleep_df = main_sleep_bouts (data )[0 ]
@@ -1685,7 +1688,11 @@ def waso(data, algo='Cole-Kripke', **kwargs):
16851688
16861689 # Count minutes in which individual is awake during the consolidated sleep window
16871690 # (0: sleep, 1: wake)
1688- waso_minutes = ((1 - sleep_window ).sum ())
1691+ # Adjust waso_minutes by the sampling rate (how many minutes per sample)
1692+ minutes_per_sample = pd .Timedelta ('1min' )/ frequency
1693+
1694+ # Calculate adjusted waso_minutes
1695+ waso_minutes = ((1 - sleep_window ).sum ()) * minutes_per_sample
16891696
16901697 # Append the result to the waso_values list
16911698 waso_values [date ] = waso_minutes
0 commit comments