Skip to main content

Tools for the simulation and analysis of circadian rhythms

Project description

Circadian

Install

pip install circadian

Quick start

The below shows how to simulate a shift worker schedule for three models and make an actogram plot

from circadian.plots import Actogram
from circadian.models import *
from circadian.lights import Light

import matplotlib.pyplot as plt
import numpy as np

days_night = 3
days_day = 2
slam_shift = Light.ShiftWorkLight(lux = 300.0, 
                                  dayson=days_night, 
                                  daysoff=days_day)
ts = np.arange(0, 24*30,0.10)
light_values = slam_shift(ts, repeat_period=24*(days_night+days_day))

model = Forger99Model()
spm_model = SinglePopModel()
tpm_model = TwoPopulationModel()
initial_conditions_forger = model.initial_conditions_loop(ts, light_est=light_values, num_loops=1)
initial_conditions_spm = spm_model.initial_conditions_loop(ts, light_est=light_values, num_loops=1)
initial_conditions_tpm = tpm_model.initial_conditions_loop(ts, light_est=light_values, num_loops=1)

Integrate the models using a explicit RK4 scheme

trajectory = model.integrate_model(ts=ts, light_est=light_values, state = initial_conditions_forger)
trajectory_spm = spm_model.integrate_model(ts=ts, light_est=light_values, state = initial_conditions_spm)
trajectory_tpm = tpm_model.integrate_model(ts=ts, light_est=light_values, state = initial_conditions_tpm)

Find the dlmos (Dim Light Melatonin Onset) a experimental measurement of circadian phase

dlmo = model.dlmos(trajectory)
dlmo_spm = spm_model.dlmos(trajectory_spm)
dlmo_tpm = tpm_model.dlmos(trajectory_tpm)

Now let’s make an actogram plot of the light schedule with the DLMOs shown for the simulated shiftworker

acto = Actogram(ts, light_vals=light_values, opacity=1.0, smooth=False)
acto.plot_phasemarker(dlmo, color='blue', label= "DLMO Forger99")
acto.plot_phasemarker(dlmo_spm, color='darkgreen', label = "DLMO SPM")
acto.plot_phasemarker(dlmo_tpm, color='red', label = "DLMO TPM" )
plt.title("Actogram for a Simulated Shift Worker")
plt.tight_layout()
plt.show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

circadian-0.0.2.tar.gz (36.3 kB view hashes)

Uploaded Source

Built Distribution

circadian-0.0.2-py3-none-any.whl (37.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page