Skip to content

Commit b7dcc71

Browse files
committed
Implement sleep_efficiency and sleep_onset_latency in sleep diaries
1 parent 1321d04 commit b7dcc71

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

circStudio/analysis/sleep/diary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def sleep_efficiency(self, data):
242242
Returns
243243
-------
244244
float
245-
Sleep efficiency.
245+
Sleep efficiency (decimal)
246246
247247
"""
248248
# Calculate average total sleep time (within the main sleep bout)

circStudio/analysis/sleep/sleep.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,15 +1564,18 @@ def main_sleep_bouts(data, report='major'):
15641564
minor_sleep = sleep_events.drop(main_sleep.index)
15651565

15661566
if report == 'major':
1567-
# Calculate mean duration (in minutes) of the main sleep episode
1568-
mean = main_sleep['duration'].mean().total_seconds() / 60
1567+
# Calculate mean duration of the main sleep episode
1568+
#mean = main_sleep['duration'].mean().total_seconds() / 60
1569+
mean = np.mean(main_sleep['duration'])
15691570

15701571
# Return dataframe with major sleep events and summary stats
15711572
return main_sleep, mean
15721573

15731574
elif report == 'minor':
1574-
# Calculate mean duration (in minutes) of the main sleep episode
1575-
mean = minor_sleep['duration'].mean().total_seconds() / 60
1575+
# Calculate mean duration of the main sleep episode
1576+
#mean = minor_sleep['duration'].mean().total_seconds() / 60
1577+
mean = np.mean(minor_sleep['duration'])
1578+
15761579

15771580
# Return dataframe with major sleep events and summary stats
15781581
return minor_sleep, mean

docs/source/tutorial_3.ipynb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
{
3636
"cell_type": "code",
37-
"execution_count": 1,
37+
"execution_count": 98,
3838
"id": "ba14333118837a04",
3939
"metadata": {
4040
"ExecuteTime": {
@@ -59,7 +59,7 @@
5959
},
6060
{
6161
"cell_type": "code",
62-
"execution_count": 2,
62+
"execution_count": 99,
6363
"id": "8c2a425e-42bb-4b3c-a397-a998cea80ff6",
6464
"metadata": {},
6565
"outputs": [],
@@ -71,6 +71,27 @@
7171
"raw = circStudio.io.read_atr(os.path.join(fpath, 'data', 'test_sample_atr.txt'))"
7272
]
7373
},
74+
{
75+
"cell_type": "code",
76+
"execution_count": 102,
77+
"id": "b5808c98-90d1-467e-8b3d-66d99f76f3f6",
78+
"metadata": {},
79+
"outputs": [
80+
{
81+
"data": {
82+
"text/plain": [
83+
"0.75"
84+
]
85+
},
86+
"execution_count": 102,
87+
"metadata": {},
88+
"output_type": "execute_result"
89+
}
90+
],
91+
"source": [
92+
"pd.Timedelta(hours=6)/pd.Timedelta(hours=8)"
93+
]
94+
},
7495
{
7596
"cell_type": "markdown",
7697
"id": "a88e0e70-27b0-4983-be19-d68cb186b291",

0 commit comments

Comments
 (0)