Sleep

Functions to predict sleep

Two Process Model

The below model uses a simple two process model for sleep to take a circadian trajectory and create a prediction of the homeostat (sleep hunger) which increases during wake and decreases during sleep. The steps parameter can be used to force wake, values of that array that are above the threshold will force a wake state.

model = Hannay19()
time = np.arange(0, 24*30, 0.10)
light = LightSchedule.SlamShift()
light_est = light(time) 
trajectory = model(time, input=light_est)
sleep_model = TwoProcessModel()
homeostat = sleep_model(trajectory.time, trajectory.states[:,1], light_est)

# Where the homeostat is increasing, we are awake where decreasing we are asleep
wake_predicted = np.where(np.diff(homeostat.states[:,0],prepend=0.0) > 0.0, 1.0, 0.0)
ax = plt.gca()
Actogram(time, light_vals=light_est, threshold=10.0, color='black', alpha=0.5, smooth=False, ax=ax)
Actogram(time, light_vals=wake_predicted, threshold=0.50, color='green', alpha=0.1, smooth=False, ax=ax);
ax.set_title('Sleep During a Slam Shift: Twp Process Model');