Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utilities for generating sleep windows from predicted onsets and offsets #112

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

clane9
Copy link

@clane9 clane9 commented Oct 1, 2024

This adds utilities for generating and filtering sleep windows from model predicted onset and offset events.

  • generate_sleep_windows: generates all sleep windows longer than a given duration from all pairs of onset and offsets
  • filter_non_sleep_windows: removes windows that contain non-sleep periods, based on an instantaneous (per timestep) sleep score.
  • nms_windows: apply non-maximum suppression to de-duplicate overlapping windows.

@clane9 clane9 marked this pull request as ready for review October 1, 2024 21:11
@Asanto32
Copy link
Collaborator

Asanto32 commented Oct 1, 2024

I assume this is specifically for the onset/offset (I thought our preferred nomenclature was onset/wakeup?) sleep detection algorithm from kaggle-14 that Reinder is working on implementing? I guess that model outputs some scores that we need to filter? I will let Reinder decide if he wants to merge it into his branch as I am not 100% aware of the state of that implementation

@Asanto32
Copy link
Collaborator

Asanto32 commented Oct 1, 2024

Also it has a big red X so I don't need to look at it , right? (or that's what I pretend anyway :P)

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (feature/kaggle-14@87dafe9). Learn more about missing BASE report.

Additional details and impacted files
@@                 Coverage Diff                  @@
##             feature/kaggle-14     #112   +/-   ##
====================================================
  Coverage                     ?   99.35%           
====================================================
  Files                        ?        8           
  Lines                        ?      463           
  Branches                     ?        0           
====================================================
  Hits                         ?      460           
  Misses                       ?        3           
  Partials                     ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@clane9
Copy link
Author

clane9 commented Oct 2, 2024

Ok fixed most checks except for a ruff complaint in a different file.

The offsets term I took from here, but yeah I can change that if wakeups is preferred, np.

For context, the model predicts unpaired onset and offset events, but what we need are sleep windows. So basically here I am adding utilities to generate candidate windows from the onset/offset events, and then filter out invalid ones.

One question is whether there is a smarter way to generate candidate windows than just taking all possible onset/offset pairs.

@ReinderVosDeWael
Copy link
Contributor

Since we only have event scores, what would we use for instantaneous sleep scores in the filter function?

@clane9
Copy link
Author

clane9 commented Oct 2, 2024

I was thinking we could use the current heuristic GGIR-style sleep scores. Just need something to be able to eliminate windows that clearly contain non-sleep.

This is necessary because for example if you have two sleep periods in a night [(onset_1, offset_1), (onset_2, offset_2)], the generate_sleep_windows function will also produce (onset_1, offset_2), which we don't want.

@ReinderVosDeWael
Copy link
Contributor

Gotcha - I'm thinking it'll probably be easier for me to merge this straight into my branch and run into issues when using it, rather than trying to get out ahead of any potential issues in the PR. So I'll merge it and let you know when something comes up :)

@ReinderVosDeWael ReinderVosDeWael merged commit 1a6b010 into feature/kaggle-14 Oct 2, 2024
27 of 28 checks passed
@Asanto32
Copy link
Collaborator

Asanto32 commented Oct 2, 2024

I was thinking we could use the current heuristic GGIR-style sleep scores. Just need something to be able to eliminate windows that clearly contain non-sleep.

This is necessary because for example if you have two sleep periods in a night [(onset_1, offset_1), (onset_2, offset_2)], the generate_sleep_windows function will also produce (onset_1, offset_2), which we don't want.

Just one thing to keep in mind, is that in certain cases those two sleep windows should be merged into one. I believe the clinical suggestion is if the awake time is less than one hour to consider it one sleep period. Currently this is how it is set, but it is a variable that can be set in

sleep_idx_array_filled = self._fill_false_blocks(

But also note that we keep the 'sib_periods', that represent sustained inactivity bouts aka actual sleeping time, separate from the onset/wakeup times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants