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

Added mean temperature and light report at predictions.csv #53

Merged
merged 3 commits into from
Jul 30, 2024

Conversation

spiousas
Copy link
Contributor

@spiousas spiousas commented Jul 18, 2024

I added an optional report of the mean temperature and light for each 30-second interval. This will work only for wearables containing temperature and light data stored in columns named temperature and light, respectively (for example, Axivity AX3).

When adding the parameter --report_light_and_temp to the get_sleep function call, two columns will be added to the predictions.csv file. They contain the mean light and temperature for the interval in the units and scale the wearable provides.

Use:

get_sleep sample.cwa --report_light_and_temp

Example output:

Total sample count : 10973
13it [05:48, 26.80s/it]
Save predictions to outputs/sample/y_pred.npy
Save prediction probs to outputs/sample/pred_prob.npy
Time used 349.3510031700134
predictions_df shape: (40111, 6)
                     time sleep_wake sleep_stage  raw_label  temperature     light
0 2024-06-14 12:07:38.460       wake        wake          0    20.829166  3.448910
1 2024-06-14 12:08:08.460       wake        wake          0    20.456833  3.242949
2 2024-06-14 12:08:38.460       wake        wake          0    20.450001  3.243973
3 2024-06-14 12:09:08.460       wake        wake          0    20.416834  3.237355
4 2024-06-14 12:09:38.460       wake        wake          0    20.299999  3.241414
Predictions saved to: outputs/sample/predictions.csv
                          start                           end      interval_start        interval_end  wear_duration_H  is_longest_block
0 2024-06-14 17:05:38.460000000 2024-06-14 17:14:38.460000000 2024-06-14 12:00:00 2024-06-15 11:59:59        14.375000              True
1 2024-06-16 01:51:08.459999999 2024-06-16 10:55:38.460000000 2024-06-15 12:00:00 2024-06-16 11:59:59        24.000000              True
2 2024-06-16 17:35:08.460000000 2024-06-16 17:39:08.460000000 2024-06-16 12:00:00 2024-06-17 11:59:59        17.516667             False
3 2024-06-17 00:40:08.460000000 2024-06-17 07:51:08.459999999 2024-06-16 12:00:00 2024-06-17 11:59:59        17.516667              True
4 2024-06-17 17:59:08.460000000 2024-06-17 18:02:08.460000000 2024-06-17 12:00:00 2024-06-18 11:59:59        24.000000             False

@spiousas
Copy link
Contributor Author

It might be a good idea to add an error catch in case columns temperature or light are not present in the raw data.

@angerhang angerhang self-requested a review July 23, 2024 14:42
@angerhang angerhang self-assigned this Jul 23, 2024
@angerhang
Copy link
Member

Hey @spiousas thanks for the PR, would you mind sharing the sample test output and the command used like in this PR #52

Copy link
Member

@angerhang angerhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add the error handling.

# Grouping by time
grouped = data.groupby(pd.Grouper(key='time', freq='30S', origin=data['time'].min()))
# Calculating the mean temperature and light for each group
mean_values = grouped[['temperature', 'light']].mean().iloc[:-1]
Copy link
Member

@angerhang angerhang Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you include an exception handler here to exit the file processing when no temperature or light data is available? No all the devices have these information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also some of the CI testes failed. Would be good if these are also addressed :D

https://github.com/OxWearables/asleep/actions/runs/9999071709/job/27810403819?pr=53

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spiousas the CI test still failed though. The formatting should be easy to fix :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry, I missed some fixes. Now it should be OK.

Copy link
Member

@angerhang angerhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@angerhang angerhang merged commit 0d342d8 into OxWearables:main Jul 30, 2024
4 checks passed
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.

2 participants