Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time series plots #31

Merged
merged 45 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6b89bfd
added: timeseries plots TimeSeriesFigure class
alondmnt Aug 19, 2024
6c06dbc
added: diet_plots plot_bar_meals & plot_lollipop_meals
alondmnt Aug 22, 2024
43e345a
improved: docstring
alondmnt Aug 23, 2024
277ac7b
added: plot_events_fill
alondmnt Aug 27, 2024
14931dc
improved: diet_plots standardised signature
alondmnt Aug 27, 2024
d2be11c
added: diet_plots.plot_meals_events
alondmnt Aug 28, 2024
425ce1c
improved: TimeSeriesFigure adjust limits after each plot
alondmnt Aug 29, 2024
4d24d38
improved: plot_events_bars inverted y-axis
alondmnt Aug 29, 2024
2e4f929
renamed: arg color -> hue
alondmnt Aug 30, 2024
096b0cc
renamed: arg cmap -> palette
alondmnt Aug 30, 2024
dfe8dfb
improved: plot_meals_lollipop size='total_g'
alondmnt Aug 30, 2024
d749a25
added: config LEGEND_SHIFT
alondmnt Aug 30, 2024
0d00606
improved: plot_events_fill accepts multiple axes
alondmnt Aug 30, 2024
adb7f20
improved: legend position
alondmnt Aug 30, 2024
be7dace
improved: re-wrote plot_sleep with new ts funcs
alondmnt Aug 30, 2024
b697756
improved: plot_events_fill behind other plots
alondmnt Aug 31, 2024
d1ea9ad
added: plot_diet_cgm_sleep
alondmnt Aug 31, 2024
5a5a08c
rename: diet plots funcs
alondmnt Sep 1, 2024
7f4293b
improved: plot_diet_cgm_sleep default channels
alondmnt Sep 2, 2024
6b0fb40
improved: plot_meals_hbars with size legend
alondmnt Sep 2, 2024
558eac9
improved: plot_diet_cgm_sleep diet / cgm on single subplot
alondmnt Sep 3, 2024
de30a05
refactored: second_y arg moved to TimeSeriesFigure.plot
alondmnt Sep 3, 2024
a0ddbdb
improved: plot_diet_cgm_sleep calibration
alondmnt Sep 3, 2024
dd4425e
improved: plot_events_bars accepts hue=None
alondmnt Sep 3, 2024
c215fa5
improved: plot_diet_cgm_sleep accepts kwargs for each subplot
alondmnt Sep 6, 2024
e52be33
improved: new args nut_exclude nut_include
alondmnt Sep 8, 2024
d86f294
added: get_events_period, get_sleep_period
alondmnt Sep 9, 2024
c6e75c1
chore: PR notes
alondmnt Sep 26, 2024
52bb19d
renamed: filter_df -> format_timeseries
alondmnt Nov 7, 2024
e8dd67b
renamed: prepare_events -> prep_to_plot_timeseries
alondmnt Nov 7, 2024
cb30d3b
added: TimeSeriesFigure.plot args adjust_time, adjust_by_axis
alondmnt Nov 7, 2024
a087bd6
fixed: cgm_plots for new example data
alondmnt Nov 7, 2024
5ded0cc
chore: clean cells
alondmnt Nov 7, 2024
e672c1b
improved: timeseries_plots: set_periodic_ticks arg start_time
alondmnt Nov 7, 2024
4d4a9bb
added: timeseries_plots tutorial
alondmnt Nov 7, 2024
04451f5
improved: timeseries_plots: text
alondmnt Nov 7, 2024
599fc79
improved: timeseries_plots: text
alondmnt Nov 8, 2024
9d0d62c
added: sleep_plots tutorial
alondmnt Nov 8, 2024
78d1817
added: diet_plots: tutorial
alondmnt Nov 8, 2024
69aeba3
improved: sleep_plots: tutorial
alondmnt Nov 8, 2024
e4a2eea
improved: timeseries_plots: title
alondmnt Nov 8, 2024
05ab94d
improved: diet_plots: food category rename
alondmnt Nov 8, 2024
7a10bc4
added: new example datasets (time series)
alondmnt Nov 8, 2024
c3f5436
fixed: deploy error
alondmnt Nov 8, 2024
2ecd297
fixed: deploy error
alondmnt Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions nbs/00_config.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"outputs": [],
"source": [
"#| export\n",
"DEFAULT_PALETTE = 'muted'\n",
"REF_COLOR = \"k\"\n",
"FEMALE_COLOR = \"C1\"\n",
"MALE_COLOR = \"C0\"\n",
Expand All @@ -62,6 +63,9 @@
"GLUC_COLOR = \"C0\"\n",
"FOOD_COLOR = \"C1\"\n",
"\n",
"LEGEND_SHIFT = (1.05, 1.05)\n",
"TIME_FORMAT = '%d/%m\\n%H:%M'\n",
"\n",
"DATASETS_PATH = '/home/ec2-user/studies/hpp_datasets/'\n",
"COHORT = None\n",
"EVENTS_DATASET = 'events'\n",
Expand All @@ -70,8 +74,7 @@
"BULK_DATA_PATH = {}\n",
"PREFERRED_LANGUAGE = 'english'\n",
"\n",
"config_found = False\n",
"\n"
"config_found = False"
]
},
{
Expand Down
723 changes: 479 additions & 244 deletions nbs/06_sleep_plots.ipynb

Large diffs are not rendered by default.

237 changes: 152 additions & 85 deletions nbs/08_cgm_plots.ipynb

Large diffs are not rendered by default.

921 changes: 921 additions & 0 deletions nbs/15_timeseries_plots.ipynb

Large diffs are not rendered by default.

1,105 changes: 1,105 additions & 0 deletions nbs/16_diet_plots.ipynb

Large diffs are not rendered by default.

Binary file modified nbs/examples/cgm/cgm.parquet
Binary file not shown.
Binary file modified nbs/examples/diet_logging/diet_logging.parquet
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
tabular_field_name,field_string,description_string,parent_dataframe,relative_location,value_type,units,field_type,array,cohorts,data_type,debut,pandas_dtype,sampling_rate
collection_timestamp,Collection timestamp,Collection timestamp,,diet_logging/diet_logging.parquet,Time,Time,Data,Single,10K,Time Series,2019-01-29,"datetime64[ns, Asia/Jerusalem]",
collection_date,Date,Datetime column relecting the time food item was logged,,diet_logging/diet_logging.parquet,Time,Time,Data,Single,10K,Time Series,2019-09-01,datetime64[ns],
food_id,Food ID,IDs in the diet logging app representing specific food ,,diet_logging/diet_logging.parquet,Categorical (single) ,None,Data,Single,10K,Time Series,2019-09-01,integer,
logging_day,Logging day per participant,Integer indicating which day of logging period ,,diet_logging/diet_logging.parquet,Integer,None ,Data,Single,10K,Time Series,2019-09-01,float,
weight,Weight,Weight of food item logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
short_food_name,Short food name,Classifcation of food item logged into a short food name category,,diet_logging/diet_logging.parquet,Categorical (single) ,None,Data,Single,10K,Time Series,2019-09-01,object,
food_category,Food category,Classifcation of food item logged into a food category,,diet_logging/diet_logging.parquet,Categorical (single) ,None,Data,Single,10K,Time Series,2019-09-01,object,
product_name,Product name ,Product name of food logged,,diet_logging/diet_logging.parquet,Categorical (single) ,None,Data,Single,10K,Time Series,2019-09-01,object,
calories,Calories,Calories of food item logged,,diet_logging/diet_logging.parquet,Continuous,kcal,Data,Single,10K,Time Series,2019-09-01,float,
weight_g,Weight,Weight of food item logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
calories_kcal,Calories,Calories of food item logged,,diet_logging/diet_logging.parquet,Continuous,kcal,Data,Single,10K,Time Series,2019-09-01,float,
carbohydrate_g,Carbohydrate intake per food logged,Carbohydrate intake per food logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
llipid_g,Fat intake per food logged,Fat intake per food logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
lipid_g,Fat intake per food logged,Fat intake per food logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
protein_g,Protein intake per food logged,Protein intake per food logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
sodium_mg ,Sodium intake per food logged,Sodium intake per food logged,,diet_logging/diet_logging.parquet,Continuous,mg,Data,Single,10K,Time Series,2019-09-01,float,
sodium_mg,Sodium intake per food logged,Sodium intake per food logged,,diet_logging/diet_logging.parquet,Continuous,mg,Data,Single,10K,Time Series,2019-09-01,float,
alcohol_g ,Alcohol intake per food logged,Alcohol intake per food logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
dietary_fiber_g,Dietary fiber intake per food logged,Dietary fiber intake per food logged,,diet_logging/diet_logging.parquet,Continuous,g,Data,Single,10K,Time Series,2019-09-01,float,
local_timestamp,Local timestamp,Local timestamp of food logging,,diet_logging/diet_logging.parquet,Time,Time,Data,Single,10K,Time Series,2019-09-01,datetime64[ns],
eaten_in_restaurant,Eaten at restaurant indication,Indication if food was eatn at home or at a restaurant,,diet_logging/diet_logging.parquet,Boolean,None,Data,Single,10K,Time Series,2019-09-01,bool,
total_logging_days,Total number of days logged,Total number of days diet was logged per research stage,,diet_logging/diet_logging.parquet,Integer,None,Data,Single,10K,Time Series,2019-09-01,integer,
8 changes: 5 additions & 3 deletions nbs/examples/sleep/metadata/sleep_data_dictionary.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tabular_field_name,field_string,description_string,parent_dataframe,relative_location,value_type,units,sampling_rate,item_type,array,cohorts,field_type,debut,pandas_dtype
ahi,AHI,AHI (Apnea-Hypopnea Index),,sleep/sleep.parquet,Continuous,Events / Hour,,Data,Multiple,10K,Continuous,2020-01-15,float64
total_sleep_time,Total sleep time,Total sleep time,,sleep/sleep.parquet,Integer,Seconds,,Data,Multiple,10K,Continuous,2020-01-15,float64
tabular_field_name,field_string,description_string,parent_dataframe,relative_location,units,sampling_rate,array,cohorts,field_type,debut,pandas_dtype
ahi,AHI,AHI (Apnea-Hypopnea Index),,sleep/sleep.parquet,Events / Hour,,Multiple,10K,Continuous,2020-01-15,float
total_sleep_time,Total sleep time,Total sleep time,,sleep/sleep.parquet,Seconds,,Multiple,10K,Continuous,2020-01-15,int
channels_time_series,Channels time series,Sensor and derived channels time series parquet files,,sleep/sleep.parquet,,,Multiple,10K,Time series file (individual),2020-01-15,string
events_time_series,Events time series,"Events during sleep derived from the raw channels, such as sleep stages, respiratory events, pulse rate events, and others",,sleep/sleep.parquet,,Data,Multiple,10K,Time series file (group),2020-01-15,string
Binary file modified nbs/examples/sleep/sleep.parquet
Binary file not shown.
Binary file added nbs/examples/sleep/time_series/channels.parquet
Binary file not shown.
Binary file added nbs/examples/sleep/time_series/events.parquet
Binary file not shown.
1 change: 1 addition & 0 deletions nbs/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ website:
- 01_basic_plots.ipynb
- 02_blandaltman_plots.ipynb
- 03_age_reference_plots.ipynb
- 15_timeseries_plots.ipynb
- 04_date_plots.ipynb
- 06_sleep_plots.ipynb
- 08_cgm_plots.ipynb
Expand Down
12 changes: 6 additions & 6 deletions pheno_utils/cgm_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
cgm_date_col: str = "collection_timestamp",
gluc_col: str = "glucose",
diet_date_col: str = "collection_timestamp",
diet_text_col: str = "shortname_eng",
diet_text_col: str = "short_food_name",
ax: Optional[plt.Axes] = None,
smooth: bool = False,
sleep_tuples: Optional[List[Tuple[pd.Timestamp, pd.Timestamp]]] = None,
Expand All @@ -39,15 +39,15 @@ def __init__(
Args:
cgm_df (pd.DataFrame): DataFrame containing the glucose measurements.
diet_df (Optional[pd.DataFrame], optional): DataFrame containing the diet data. Defaults to None.
cgm_date_col (str, optional): Name of the date column in cgm_df. Defaults to "Date".
cgm_date_col (str, optional): Name of the date column in cgm_df. Defaults to "collection_timestamp".
gluc_col (str, optional): Name of the glucose column in cgm_df. Defaults to "glucose".
diet_date_col (str, optional): Name of the date column in diet_df. Defaults to "Date".
diet_text_col (str, optional): Name of the text column in diet_df. Defaults to "shortname_eng".
diet_date_col (str, optional): Name of the date column in diet_df. Defaults to "collection_timestamp".
diet_text_col (str, optional): Name of the text column in diet_df. Defaults to "short_food_name".
ax (Optional[plt.Axes], optional): Matplotlib Axes object to plot on. Defaults to None.
smooth (bool, optional): Apply smoothing to the glucose curve. Defaults to False.
sleep_tuples (Optional[List[Tuple[pd.Timestamp, pd.Timestamp]]], optional): List of sleep start and end times. Defaults to None.
"""
self.cgm_df = cgm_df
self.cgm_df = cgm_df.reset_index()
self.diet_df = diet_df
self.cgm_date_col = cgm_date_col
self.gluc_col = gluc_col
Expand Down Expand Up @@ -110,7 +110,7 @@ def plot_diet(self) -> None:
for i, (food_datetime, group) in enumerate(
self.diet_df.groupby(self.diet_date_col)
):
food_str = "\n".join(group[self.diet_text_col])
food_str = "\n".join(group[self.diet_text_col].dropna())

txt_x = food_datetime - pd.to_timedelta(7.5, "m")
if i % 2 == 0:
Expand Down
16 changes: 9 additions & 7 deletions pheno_utils/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_config.ipynb.

# %% auto 0
__all__ = ['REF_COLOR', 'FEMALE_COLOR', 'MALE_COLOR', 'ALL_COLOR', 'GLUC_COLOR', 'FOOD_COLOR', 'DATASETS_PATH', 'COHORT',
'EVENTS_DATASET', 'ERROR_ACTION', 'CONFIG_FILES', 'BULK_DATA_PATH', 'PREFERRED_LANGUAGE', 'config_found',
'DICT_PROPERTY_PATH', 'DATA_CODING_PATH', 'copy_tre_config', 'get_dictionary_properties_file_path',
'get_data_coding_file_path', 'generate_synthetic_data', 'generate_synthetic_data_like',
'generate_categorical_synthetic_data']
__all__ = ['DEFAULT_PALETTE', 'REF_COLOR', 'FEMALE_COLOR', 'MALE_COLOR', 'ALL_COLOR', 'GLUC_COLOR', 'FOOD_COLOR', 'LEGEND_SHIFT',
'TIME_FORMAT', 'DATASETS_PATH', 'COHORT', 'EVENTS_DATASET', 'ERROR_ACTION', 'CONFIG_FILES', 'BULK_DATA_PATH',
'PREFERRED_LANGUAGE', 'config_found', 'DICT_PROPERTY_PATH', 'DATA_CODING_PATH', 'copy_tre_config',
'get_dictionary_properties_file_path', 'get_data_coding_file_path', 'generate_synthetic_data',
'generate_synthetic_data_like', 'generate_categorical_synthetic_data']

# %% ../nbs/00_config.ipynb 3
import os
Expand All @@ -16,6 +16,7 @@
from glob import glob

# %% ../nbs/00_config.ipynb 4
DEFAULT_PALETTE = 'muted'
REF_COLOR = "k"
FEMALE_COLOR = "C1"
MALE_COLOR = "C0"
Expand All @@ -24,6 +25,9 @@
GLUC_COLOR = "C0"
FOOD_COLOR = "C1"

LEGEND_SHIFT = (1.05, 1.05)
TIME_FORMAT = '%d/%m\n%H:%M'

DATASETS_PATH = '/home/ec2-user/studies/hpp_datasets/'
COHORT = None
EVENTS_DATASET = 'events'
Expand All @@ -34,8 +38,6 @@

config_found = False



# %% ../nbs/00_config.ipynb 5
def copy_tre_config():
default_config_found = False
Expand Down
Loading
Loading