<jupyter_start><jupyter_text>Average temperatures by day and nightThe following plots show the evolution of the average temperatures, separated between day and night time. The difference is also plotted. The criteria to distinguis night and day is the value read by the light sensor. When the value is over 50 the reading is considered to correspond to daytime.  Preparation and reading of dataThe data is read from the monthly HDF files, which contain a *daily* dataset with the average values for the four measured magnitudes already separated by day and night.All the datasets present in the data directory are appended to the ```dailies``` dataframe. The monthly datasets are also available in the ```datasets``` array.<jupyter_code>import os
import pandas as pd
import plotnine as gg

hdfDirectory = os.path.join(os.path.curdir, 'data')

files = [ os.path.join(hdfDirectory,f) for f in os.listdir(hdfDirectory)]
dailies = pd.DataFrame(columns = ['date','count','daytime','humidity','light','pressure','temperature'])

datasets = [ pd.read_hdf(f,key='daily') for f in files]
for d in datasets:
    dailies = dailies.append(d)<jupyter_output><empty_output><jupyter_text>Plot definitionThis pyhon function generates a plot which shows the day and night time averages as well and its difference. The plot only considers the days for which we have **both** a day and a night average and discards the rest.<jupyter_code>def plotTemps(d,intv='1 week'):
    """
    plotTemps - generate a day/night temperature plot
    Parameters:
    - d: DataFrame containing the data to plot. This function makes a copy of a slice of
    this dataframe containing just the 'date','daytime' and 'temperature' columns.
    - intv: Interval between x axis datapoints.
    Returns:
    - ggplot object ready to be drawn
    """
    tempsByDay = d[['date','daytime','temperature']].copy(deep=True)
    tempsByDay['daytime'] = tempsByDay.apply(lambda x: 'Day' if x['daytime']==1 else 'Night', axis=1)
 
    tempsByDay = tempsByDay.pivot(index='date',values='temperature',columns='daytime').dropna()
    tempsByDay['Difference'] = tempsByDay.apply(lambda x: x['Day']-x['Night'],axis=1)
    tempsByDay = tempsByDay.stack().reset_index()
    tempsByDay.columns = ['date','daytime','temperature']
    return gg.ggplot(tempsByDay) + \
           gg.geom_line(gg.aes(x='date',y='temperature',color='daytime')) + \
           gg.scale_color_manual(values=['red','blue','green'],
                           limits=['Day','Night','Difference'], 
                           name="Daytime") + \
           gg.scale_x_datetime(date_breaks=intv) + \
           gg.theme(axis_text_x = gg.element_text(angle=90)) + \
           gg.xlab('Date') + gg.ylab('ºC') + gg.ggtitle('Average temperatures')<jupyter_output><empty_output><jupyter_text>Plots Accumulated plotThis plot contains all the available information (just the part which has been dumped to the HDF files).<jupyter_code>plotTemps(dailies).draw()<jupyter_output><empty_output><jupyter_text>Monthly plotsThe following plots contain each one information corresponding to a single month.<jupyter_code>for d in datasets:
    plotTemps(d,intv='3 days').draw()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11260137242669994, 'fraction_numerical': 0.0028072364316905803, 'mean_word_length': 4.558058925476603, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '444378', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 980, 'n_tokens_neox': 940, 'n_words': 301, 'path': 'analytics/DailyAvgTemps.ipynb', 'repo_name': 'jguillaumes/MeteoClient', 'size': '3206'}