<jupyter_start><jupyter_text>Analyzing dataClass [CycleAnalyzer](chronobiology.rstchronobiology.chronobiology.CycleAnalyzer) is used for calculating and plotting circadian cycles data.    For more info about the analysis methods, see [the paper](paper.pdf).Here's an example of analyzing randomly generated activity data.<jupyter_code>import numpy as np
from chronobiology.chronobiology import CycleAnalyzer, generate_data
# Generate random activity data.
data = generate_data()

# Prepare input arrays for CycleAnalyzer.
# When working with InfluxDB, same arrays must be selected using a DBQuery instance.
timestamps = data['time'] # timestamps of measurements
values = data['value']    # activity values
nights = data['is_night'] # night activity markers

print(f'{len(timestamps)} measurements generated.')
np.set_printoptions(threshold=10)
data
# Create a cycle analyzer.
ca = CycleAnalyzer(timestamps, values, nights)<jupyter_output><empty_output><jupyter_text>ActogramThe most obvious way of assessing circadian disruption is to simply look at experimentalactograms. This visual inspection should always take the form of circadian disruption into account,and whether this is environmental or genetic in origin. This will also determine the appropriatecontrols, be they baseline conditions or wildtype littermates, respectively. Furthermore, when studyingcircadian disruption under different lighting paradigms, comparing activity relative to the external LDcycle is critical. This initial visual inspection of actogram data will guide the choice of which additionalmeasurements are likely to be most informative.<jupyter_code>ca.plot_actogram()<jupyter_output><empty_output><jupyter_text>PeriodogramThe power of a periodogram provides a measure of the strength and regularity of the underlyingrhythm, with higher values indicating robust rhythms. In circadian disruption — where rhythms aretypically less robust — periodogram power is expected to be reduced and low values may indicate theabsence of a significant circadian rhythm. The power of the chi-square periodogram ($Q_p$) has beenwidely used as a measure of the robustness of circadian rhythms, and can be traced back to studieson the effects of constant light on the strength of activity and sleep rhythms in rats. Analysis of$Q_p$ based upon simulated and empirical data sets has shown that this provides a valuable measure ofthe robustness of circadian rhythms. Periodogram analysis is particularly informative in internaldesynchrony, where the power of multiple periodicities within a dataset will be evident.<jupyter_code>ca.plot_periodogram()<jupyter_output><empty_output><jupyter_text>Activity onesetA hallmark of normal circadian function is that activity onset is consistent from day to day.In most records, the onset of activity is typically a more precise phase marker than theoffset of activity. As such, the variability in activity onset across multiple days -- either relative tothe light/dark cycle (phase angle of entrainment) or under constant conditions -- provides a usefulmetric to describe the precision of circadian rhythms. Phase angle of entrainment and the variabilityin activity onset have been widely used in the study of circadian entrainment. Activity onsetis particularly informative when studying circadian misalignment and chronodisruption, where thephasing of activity with regard to environmental zeitgebers is expected to differ.<jupyter_code>ca.activity_onset()
ca.plot_activity_onset()<jupyter_output><empty_output><jupyter_text>Light phase activityIn nocturnal species, such as laboratory mice, activity is normally confined to the dark phase ofthe light/dark cycle. A hallmark of disrupted rhythms is therefore an increased activity in thenormally inactive light phase, and such changes are expected to occur in both circadian misalignmentand chronodisruption. In diurnal species, dark phase activity can similarly be used to quantify theamount of activity occurring in the normal inactive phase. Light phase activity has been widely usedto study defects in circadian entrainment to light as well as in disease-relevant models.Light phase activity also provides an ideal measure to assess theimpact of misaligned feeding, a specific example of circadian misalignment.<jupyter_code>ca.light_activity(auc=True)
ca.plot_light_activity()<jupyter_output><empty_output><jupyter_text>Activity boutsAs a result of less consolidated activity and rest phases, circadian disruption is associated with anincreased number and reduced duration of activity bouts. The number and duration of activity boutsare frequently used as a measure of fragmentation in circadian disruption. Due to the inappropriatephasing of activity/rest cycles with regard to the external environmental, circadian misalignment,internal desynchrony and chronodisruption are all expected to affect activity bouts.<jupyter_code>ca.daily_bouts()
ca.plot_daily_bouts()
ca.plot_bout_histogram()<jupyter_output><empty_output><jupyter_text>Inter-daily stabilityInter-daily stability (IS) measures the day-to-day reproducibility of rest/activity cycles. Patternsof activity are typically reproducible in healthy individuals, whereas circadian disruption results inmore variable rhythms. IS was first described in the study of elderly human patients with Alzheimer’sdisease. It has subsequently been widely used in a number of human studies, and hasalso been adopted for studying circadian disruption in animal models. Due to the day-to-day changesin the relationship between circadian and environmental time, decreased IS may be expected in internaldesynchrony. However, circadian misalignment and chronodisruption may not influence IS if a stablenew phase-relationship is established.<jupyter_code>ca.interdaily_stability()<jupyter_output><empty_output><jupyter_text>Intra-daily variabilityIntra-daily variability (IV) is a measure of the fragmentation of activity rhythms. First introducedfor the study of patients with Alzheimer’s disease, like IS it has been readily adopted for thestudy of animal models of circadian disruption. IV measures the frequency of transitions betweenactivity and rest across the day. More transitions between activity and rest result in higher IV scores.As with activity bouts, circadian misalignment, internal desynchrony and chronodisruption mayall increase IV due to the inappropriate phasing of activity/rest cycles with regard to the externalenvironment. A good example of this occurs in aging, where IV increases steadily with age in mice.<jupyter_code>ca.intradaily_variability()
ca.plot_intradaily_variability()<jupyter_output><empty_output><jupyter_text>Relative amplitudePerhaps the most obvious measure of the strength of any biological rhythm is its amplitude.A simple metric that has been widely used in human studies is relative amplitude (RA), againoriginating from studies in patients with Alzheimer’s disease. RA is a simple measure ofthe difference between periods of peak activity and rest. As healthy rhythms are assumed to displayconsolidated activity and rest periods, RA is expected to be reduced when normal circadian rhythmsare disrupted. Both circadian misalignment and chronodisruption will reduce RA, with internaldesynchrony potentially resulting in RA values that fluctuate as periods move in and out of phase.<jupyter_code>ca.relative_amplitude(auc=True)
ca.plot_relative_amplitude()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.039569313593539705, 'fraction_numerical': 0.00026917900403768504, 'mean_word_length': 6.483383685800605, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '158916', 'license': 'MIT', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1661, 'n_words': 883, 'path': 'docs/analyzing_data.ipynb', 'repo_name': 'electrosaurus/Chronobiology', 'size': '7430'}