Skip to content

Commit

Permalink
fix visu sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
angerhang committed Apr 16, 2024
1 parent 05d7c03 commit 2febb2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name = "asleep" # Required
#
# For a discussion on single-sourcing the version, see
# https://packaging.python.org/guides/single-sourcing-package-version/
version = "0.4.9" # Required
version = "0.4.10" # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[options.entry_points]
console_scripts =
get_sleep = asleep.get_sleep:main
visu_sleep = asleep.visu_sleep:main
11 changes: 10 additions & 1 deletion src/asleep/visu_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def main():
# check all the files are there
prediction_path = os.path.join(args.filepath, 'predictions.csv')
sleep_blocks_path = os.path.join(args.filepath, 'sleep_block.csv')
raw_x_path = os.path.join('outputs/test', 'data2model.npy')
raw_x_path = os.path.join(args.filepath, 'data2model.npy')
plot_path = os.path.join(args.filepath, 'sleep.png')

if not os.path.exists(prediction_path):
Expand All @@ -62,6 +62,8 @@ def main():
exact_date_df = sleep_block_df.loc[sleep_block_df['is_longest_block']].copy()
exact_date_df['interval_start'] = pd.to_datetime(exact_date_df['interval_start'])
exact_date_df['interval_end'] = pd.to_datetime(exact_date_df['interval_end'])
exact_date_df['start'] = pd.to_datetime(exact_date_df['start'])
exact_date_df['end'] = pd.to_datetime(exact_date_df['end'])

y_df['enmo'] = raw_enmo
y_df['time'] = pd.to_datetime(y_df['time'])
Expand All @@ -81,6 +83,8 @@ def main():
for _, row in exact_date_df.iterrows():
day_start = row['interval_start']
day_end = row['interval_end']
long_sleep_start = row['start']
long_sleep_end = row['end']
day_df = y_df[(y_df['time'] >= day_start) & (y_df['time'] <= day_end)].copy()
day_df['is_nonwear'] = day_df['enmo'] == 0
day_df.loc[day_df['is_nonwear'], 'sleep_wake'] = 'non_wear'
Expand All @@ -95,6 +99,11 @@ def main():
ax.set_ylim(0, 2)
ax.set_xlim(day_start, day_end)

plt.vlines(x=long_sleep_start, ymin=0, ymax=2,
colors='yellow')
plt.vlines(x=long_sleep_end, ymin=0, ymax=2,
colors='yellow')

a = np.array([is_sleep, is_wake, is_nonwear]) * MAXRANGE

ax.stackplot(day_df['time'], a,
Expand Down

0 comments on commit 2febb2e

Please sign in to comment.