CGM plots


source

CGMPlot

 CGMPlot (cgm_df:pandas.core.frame.DataFrame,
          diet_df:Optional[pandas.core.frame.DataFrame]=None,
          cgm_date_col:str='collection_timestamp', gluc_col:str='glucose',
          diet_date_col:str='collection_timestamp',
          diet_text_col:str='short_food_name',
          ax:Optional[matplotlib.axes._axes.Axes]=None, smooth:bool=False,
          sleep_tuples:Optional[List[Tuple[pandas._libs.tslibs.timestamps.
          Timestamp,pandas._libs.tslibs.timestamps.Timestamp]]]=None)

*Initialize a CGMPlot object.

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 “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 “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.*

cgm_df= pd.read_parquet("./examples/cgm/cgm.parquet")
cgm_df.head()
glucose
participant_id collection_timestamp
0 2020-06-22 00:14:00+03:00 106.2
2020-06-22 00:29:00+03:00 100.8
2020-06-22 00:44:00+03:00 97.2
2020-06-22 00:59:00+03:00 95.4
2020-06-22 01:14:00+03:00 93.6
diet_df = pd.read_parquet("./examples/diet_logging/diet_logging.parquet")
diet_df.head()
short_food_name food_category weight_g calories_kcal carbohydrate_g lipid_g protein_g sodium_mg alcohol_g dietary_fiber_g
participant_id collection_timestamp
0 2020-06-21 16:06:00+03:00 Quinoa Pasta, Grains and Side dishes_wholewheat 56.0 78.3104 12.1744 1.2992 2.8000 37.1504 0.0 1.4896
2020-06-21 16:06:00+03:00 Hummus Salad Pulses and products 80.0 215.2000 9.4400 16.8000 6.5600 377.6000 NaN 0.0000
2020-06-21 16:06:00+03:00 Meatballs Beef, veal, lamb, and other meat products 180.0 311.0940 16.1280 15.4440 24.7320 1164.5460 0.0 2.3904
2020-06-21 19:28:00+03:00 Banana Fruits 128.0 113.9200 25.9072 0.4224 1.3952 1.2800 0.0 3.3280
2020-06-21 21:07:00+03:00 Bread Bread 60.0 162.6000 28.3800 2.1000 5.2800 367.8000 0.0 1.6200
start_date = pd.to_datetime('2020-06-22', utc=True).tz_convert('Asia/Jerusalem')
end_date = pd.to_datetime('2020-06-24',utc=True).tz_convert('Asia/Jerusalem')


sample_cgm = cgm_df[(cgm_df.index.get_level_values('collection_timestamp') >= start_date) \
                     & (cgm_df.index.get_level_values('collection_timestamp') <= end_date)]
sample_diet = diet_df[(diet_df.index.get_level_values('collection_timestamp') >= start_date) \
                     & (diet_df.index.get_level_values('collection_timestamp') <= end_date)]
cgmplt = CGMPlot(cgm_df=sample_cgm,
                 gluc_col="glucose",
                 diet_df=sample_diet,
                 smooth=True)
cgmplt.plot()

AGP


source

AGP

 AGP (cgm_df:pandas.core.frame.DataFrame,
      cgm_date_col:str='collection_timestamp', gluc_col:str='glucose',
      ax:Optional[matplotlib.axes._axes.Axes]=None)

*Initialize an AGP object.

Args: cgm_df (pd.DataFrame): DataFrame containing the glucose measurements. 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”. ax (Optional[plt.Axes], optional): Matplotlib Axes object to plot on. Defaults to None.*

agp = AGP(cgm_df=cgm_df.reset_index(), cgm_date_col="collection_timestamp", gluc_col="glucose")
agp.plot()