Skip to content

Paper companion notebook

import ethoscopy as etho
import pandas as pd
# This tutorial required version 1.1.8 or greater
etho.__version__
'2.0.5'

One-time setup: fetch the tutorial datasets

Section titled “One-time setup: fetch the tutorial datasets”

The tutorial pickle files (~36 MB total, dominated by overview_data.pkl) are not bundled with the PyPI package, to keep pip install ethoscopy lean.

Run the cell below once per environment to download them into the installed package directory. Subsequent runs are idempotent (already-present files are skipped).

You can also fetch them manually from https://github.com/gilestrolab/ethoscopy/tree/main/src/ethoscopy/misc/tutorial_data.

# Idempotent: skips files that are already present.
import ethoscopy as etho
etho.download_tutorial_data()
[skip] overview_data.pkl (already present)
[skip] overview_meta.pkl (already present)
[skip] circadian_data.pkl (already present)
[skip] circadian_meta.pkl (already present)
[skip] 4_states_F_WT.pkl (already present)
[skip] 4_states_M_WT.pkl (already present)
Tutorial data ready in: ~/.cache/ethoscopy/tutorial_data
PosixPath('~/.cache/ethoscopy/tutorial_data')
# import this function to get the tutorial dataset
from ethoscopy.misc.get_tutorials import get_tutorial
# We'll be using the same dataset as in the overview tutorial, so use the same function below with the argument 'overview'
# Load the data and metadata, and then initialise it into a behavpy object
data, metadata = get_tutorial('overview')
df = etho.behavpy(data, metadata, check = True)
df = df.t_filter(start_time = 24, end_time = 144)
fig = df.xmv('sleep_deprived', False).heatmap(variable = 'asleep', title = 'Control')
fig.show()

Paper companion notebook (a)

# As we saw in the overview tutorial the dataset we have has half the specimens sleep deprived later in the experiment
fig = df.xmv('sleep_deprived', True).heatmap(variable = 'asleep', title = 'Sleep Deprived')
fig.show()

As we saw in the overview tutorial the dataset we have has half the specimens sleep deprived later…

fig = df.t_filter(start_time = 24, end_time = 96).plot_overtime(variable = 'asleep', wrapped = True, title = 'Baseline Sleep')
fig.show()

Paper companion notebook (b)

# Ethoscopy also has pretrained HMMs for both Male and Female CS Drosophila, trained on several days worth of data on hundreds of flies
from ethoscopy.misc.get_HMM import get_HMM
# Have the argument as "M" or "F" for the male or female dataset respectively
h = get_HMM("M")
fig = df.plot_hmm_overtime(
hmm = h,
variable = 'moving',
wrapped = True,
labels = ['Deep sleep', 'Light sleep', 'Quiet awake', 'Full awake'],
t_bin = 60,
title = 'Hidden Markov Analysis of sleep stages'
)
fig.show()

Paper companion notebook (c)