# Activity levels.
= 5 # Mean of low activity levels.
mu_l = 25 # Mean of high activity levels.
mu_h = 0 # Mean of sleep activity levels.
mu_s
# Activity uncertainty.
= 7.5 # Std of low activity levels.
sigma_l = 30 # Std of high activity levels.
sigma_h = 2 # Std of activity during sleep.
sigma_s = 1.5 # Std of sleep onset/offset timing.
sigma_t
# The person's activity level from 0 to 1.
= 0.5
active_level
# Number of days and samples of interest.
= 12
num_days = 60*24*num_days num_samples
Synthetic Data
Generating Activity from Light Schedules
This function generates an ‘activity’ schedule from an input LightSchedule.
It essentially corrupts the light pulse train based on three normal distributions. When the light pulse is on, the function draws from a high or low activity distribution based on a parameter representing how active the person is, and when it is off, the function draws from a sleep activity distribution.
There are 7 parameters for the method: * mu_l - mean low activity level * mu_h - mean high activity level * mu_s - mean sleep activity level * sigma_l - std of high activity level * sigma_h - std of high activity level * sigma_s - std of sleep activity - how active the person is in their sleep * active_level - [0, 1] value representing how active the person is. When close to 1, they have a higher probability of being in the high activity distribution at any point in time
Examples
This section uses the Circadian package to generate the 4 light schedules: * Regular * Shift Work * Slam Shift * Social Jetlag
then passes each to the function to generate ‘activity’ schedules from them.
# Create the time, light and activity signals.
# Time vector.
= np.arange(0, 24*num_days, 1/60)
time
# Light schedules.
= LightSchedule.Regular()
regular_light = LightSchedule.ShiftWork()
shift_light = LightSchedule.SlamShift()
slam_light = LightSchedule.SocialJetlag()
social_jetlag
# Create the activity signals.
= generate_activity_from_light(
regular_activity
time, regular_light,
mu_l, mu_h, mu_s, sigma_l, sigma_h, sigma_s,
active_level,
)= generate_activity_from_light(
shift_activity
time, shift_light,
mu_l, mu_h, mu_s, sigma_l, sigma_h, sigma_s,
active_level,
)= generate_activity_from_light(
slam_activity
time, slam_light,
mu_l, mu_h, mu_s, sigma_l, sigma_h, sigma_s,
active_level,
)= generate_activity_from_light(
social_jetlag_activity
time, social_jetlag,
mu_l, mu_h, mu_s, sigma_l, sigma_h, sigma_s,
active_level )
Visualization
Here, we visualize the ‘activity’ schedules with their corresponding input light schedules.
= 2, 1 nrows, ncols
# Regular plots.
= plt.subplots(nrows=nrows, ncols=ncols)
fig, ax
regular_light.plot(=0.0,
plot_start_time=24*num_days,
plot_end_time=num_samples,
num_samples=ax[0]
ax
)0].set_ylabel("Light (lux)")
ax[0].set_title("Regular Light Schedule")
ax[0].set_xticks(np.arange(min(time), max(time), 24))
ax[0].grid()
ax[1].plot(
ax[
time, regular_activity
)1].set_ylabel("Activity (steps/min)")
ax[1].set_xlabel("Time (hours)")
ax[1].set_title("Regular Activity Schedule")
ax[1].set_xticks(np.arange(min(time), max(time), 24))
ax[1].grid()
ax[
plt.tight_layout()
# Shift Work plots.
= plt.subplots(nrows=nrows, ncols=ncols)
fig, ax
shift_light.plot(=0.0,
plot_start_time=24*num_days,
plot_end_time=num_samples,
num_samples=ax[0]
ax
)0].set_ylabel("Light (lux)")
ax[0].set_title("Shift Work Light Schedule")
ax[0].set_xticks(np.arange(min(time), max(time), 24))
ax[0].grid()
ax[1].plot(
ax[
time, shift_activity
)1].set_ylabel("Activity (steps/min)")
ax[1].set_xlabel("Time (hours)")
ax[1].set_title("Shift Work Activity Schedule")
ax[1].set_xticks(np.arange(min(time), max(time), 24))
ax[1].grid()
ax[
plt.tight_layout()
# Slam Shift plots.
= plt.subplots(nrows=nrows, ncols=ncols)
fig, ax
slam_light.plot(=0.0,
plot_start_time=24*num_days,
plot_end_time=num_samples,
num_samples=ax[0]
ax
)0].set_ylabel("Light (lux)")
ax[0].set_title("Slam Shift Light Schedule")
ax[0].set_xticks(np.arange(min(time), max(time), 24))
ax[0].grid()
ax[1].plot(
ax[
time, slam_activity
)1].set_ylabel("Activity (steps/min)")
ax[1].set_xlabel("Time (hours)")
ax[1].set_title("Slam Shift Activity Schedule")
ax[1].set_xticks(np.arange(min(time), max(time), 24))
ax[1].grid()
ax[
plt.tight_layout()
# Social Jetlag plots.
= plt.subplots(nrows=nrows, ncols=ncols)
fig, ax
social_jetlag.plot(=0.0,
plot_start_time=24*num_days,
plot_end_time=num_samples,
num_samples=ax[0]
ax
)0].set_ylabel("Light (lux)")
ax[0].set_title("Social Jetlag Light Schedule")
ax[0].set_xticks(np.arange(min(time), max(time), 24))
ax[0].grid()
ax[1].plot(
ax[
time, social_jetlag_activity
)1].set_ylabel("Activity (steps/min)")
ax[1].set_xlabel("Time (hours)")
ax[1].set_title("Social Jetlag Activity Schedule")
ax[1].set_xticks(np.arange(min(time), max(time), 24))
ax[1].grid()
ax[
plt.tight_layout()
API Documentation
generate_activity_from_light
generate_activity_from_light (time:numpy.ndarray, light:circadian.lights.LightSchedule, mu_l:float=5.0, mu_h:float=25.0, mu_s:float=0.0, sigma_l:float=7.5, sigma_h:float=30.0, sigma_s:float=2.0, active_level:float=0.5)
Generates an ‘activity’ schedule from an input light schedule. The activity schedule produced is a corrupted version of the light schedule.
Type | Default | Details | |
---|---|---|---|
time | ndarray | time points. | |
light | LightSchedule | light schedule. | |
mu_l | float | 5.0 | mean of low activity levels. |
mu_h | float | 25.0 | mean of high activity levels. |
mu_s | float | 0.0 | mean of sleep activity levels. |
sigma_l | float | 7.5 | std of low activity levels. |
sigma_h | float | 30.0 | std of high activity levels. |
sigma_s | float | 2.0 | std of activity during sleep. |
active_level | float | 0.5 | person’s activity level from 0 to 1. Represents the probability of choosing from the high or low activity distributions at any point in time. Values close to 1 increase the proportion of high activity values. |
Returns | ndarray |