22import numpy as np
33import re
44from circStudio .analysis .tools import *
5- from statistics import mean
6- import statsmodels .api as sm
5+ import plotly .graph_objects as go
76
87
9- def daily_profile (data , cyclic = False , time_origin = None , whs = "1h" ):
8+ def daily_profile (data , cyclic = False , time_origin = None , whs = "1h" , plot = False , log = False ):
109 r"""Average daily activity/light/temperature distribution
1110
1211 Calculate the daily profile of activity. Data are averaged over all the
@@ -33,15 +32,58 @@ def daily_profile(data, cyclic=False, time_origin=None, whs="1h"):
3332 onset/offset time. Relevant only if time_origin is set to
3433 'AonT' or AoffT'.
3534 Default is '1h'.
35+ plot: bool, optional
36+ Whether to plot the daily profile. Default is False.
37+ log: bool, optional
38+ Whether the daily profile should be transformed to a log10 scale.
3639
3740 Returns
3841 -------
3942 raw : pandas.Series
4043 A Series containing the daily activity profile with a 24h index.
4144 """
42- if time_origin is None :
43- return _average_daily_activity (data , cyclic = cyclic )
45+ def _format (to_plot , to_log , profile ):
46+ """
47+ Internal function that decides whether to present daily profile as pd.Series
48+ or as an interactive Plotly figure.
49+
50+ Parameters
51+ ----------
52+ to_plot : bool
53+ Whether the daily profile should be plotted.
54+ to_log : bool
55+ Whether the daily profile should be transformed to a log10 scale.
56+ profile
57+ The daily profile returned by this function.
58+
59+ Returns
60+ -------
61+ pandas.Series or go.Figure
62+
63+ """
64+ if to_plot :
65+ layout = go .Layout (
66+ title = "Daily profile" ,
67+ xaxis = dict (title = "Date time" ),
68+ yaxis = dict (title = "Data" ),
69+ showlegend = False
70+ )
71+ if to_log :
72+ fig = go .Figure (data = [
73+ go .Scatter (x = profile .index .astype (str ), y = np .log10 (profile + 1 ))
74+ ], layout = layout )
75+ return fig
76+ else :
77+ fig = go .Figure (data = [
78+ go .Scatter (x = profile .index .astype (str ), y = profile )
79+ ], layout = layout )
80+ return fig
81+ else :
82+ return profile
4483
84+ if time_origin is None :
85+ _daily_profile = _average_daily_activity (data , cyclic = cyclic )
86+ return _format (plot , log , _daily_profile )
4587 else :
4688 if cyclic is True :
4789 raise NotImplementedError (
@@ -85,7 +127,8 @@ def daily_profile(data, cyclic=False, time_origin=None, whs="1h"):
85127
86128 shift = int ((pd .Timedelta ("12h" ) - time_origin ) / data .index .freq )
87129
88- return _shift_time_axis (avgdaily , shift )
130+ _daily_profile = _shift_time_axis (avgdaily , shift )
131+ return _format (plot , log , _daily_profile )
89132
90133
91134def daily_profile_auc (data , start_time = None , stop_time = None , time_origin = None ):
@@ -252,7 +295,7 @@ def l5(data):
252295
253296 Returns
254297 -------
255- l5 : float
298+ l5_onset, l5 : float
256299
257300 Notes
258301 -----
@@ -291,7 +334,7 @@ def m10(data):
291334
292335 Returns
293336 -------
294- m10: float
337+ m10_onset, m10 : float
295338
296339 Notes
297340 -----
0 commit comments