def correlate(chan_id, weather_variable, subplot_index, annotate_y): # 25 = lighting circuit # (R^2 = 0.443) # 8 = kitchen lights (R^2 = 0.194) # 2 = boiler (versus radiation R^2 = 0.052, # versus mean_temp R^2 = 0.298, # versus max_temp R^2 = 0.432, # versus min_temp R^2 = 0.212) # 3 = solar (R^2 = 0.798) # 12 = fridge vs min_temp R^2 = 0.255 (with on_power_threshold = 20) print("Opening channel data...") channel = Channel(DATA_DIR, chan_id) print("Calculating...") channel.on_power_threshold = 20 hours_on = channel.usage_per_period('D', tz_convert='UTC').hours_on hours_on = hours_on[hours_on > ON_DURATION_THRESHOLD] hours_on.description = 'hours on' print("Got {} days of data from usage_per_period.".format(hours_on.size)) print("Plotting...") x_aligned, y_aligned = pda.stats.align(weather_variable, hours_on) print(x_aligned.description) slope, intercept, r_value, p_value, std_err = linregress(x_aligned.values, y_aligned.values) ax = fig.add_subplot(2,2,subplot_index) ax = spfl.format_axes(ax) ax = pda.stats.plot_regression_line(ax, x_aligned, y_aligned, slope, intercept, r_value, annotate_y=annotate_y) print("R^2={:.3f}".format(r_value**2)) ax.set_title('Correlation between ' + channel.get_long_name() + ' and ' + metoffice.get_long_name(weather_variable.name))
range=(min_power, max_power), bins=int(round((max_power-min_power)/2))) # Draw histogram for unnormalised values ax.hist(c.series.values, histtype='step', color=UNNORMALISED_LINE_COLOR, alpha=0.5, range=(min_power, max_power), bins=int(round((max_power-min_power)/2))) # format plot ax.set_axis_bgcolor('#eeeeee') yticks = ax.get_yticks() ax.set_yticks([]) spfl.format_axes(ax) ax.spines['left'].set_visible(False) if c.name == 'washing_machine': ax.set_ylim([0, np.max(n)*0.2]) title_x = 0.5 elif c.name in ['bedroom_ds_lamp', 'kitchen_lights']: ax.set_ylim([0, np.max(n)*1.65]) title_x = 0.5 elif c.name == 'lcd_office': ax.set_ylim([0, np.max(n)*1.5]) title_x = 0.5 elif c.name == 'htpc': ax.set_ylim([0, np.max(n)*1.2]) title_x = 0.4 elif c.name == 'breadmaker': ax.set_ylim([0, np.max(n)*0.5])
range=(min_power, max_power), bins=int(round((max_power - min_power) / 2))) # Draw histogram for unnormalised values ax.hist(c.series.values, histtype='step', color=UNNORMALISED_LINE_COLOR, alpha=0.5, range=(min_power, max_power), bins=int(round((max_power - min_power) / 2))) # format plot ax.set_axis_bgcolor('#eeeeee') yticks = ax.get_yticks() ax.set_yticks([]) spfl.format_axes(ax) ax.spines['left'].set_visible(False) if c.name == 'washing_machine': ax.set_ylim([0, np.max(n) * 0.2]) title_x = 0.5 elif c.name in ['bedroom_ds_lamp', 'kitchen_lights']: ax.set_ylim([0, np.max(n) * 1.65]) title_x = 0.5 elif c.name == 'lcd_office': ax.set_ylim([0, np.max(n) * 1.5]) title_x = 0.5 elif c.name == 'htpc': ax.set_ylim([0, np.max(n) * 1.2]) title_x = 0.4 elif c.name == 'breadmaker': ax.set_ylim([0, np.max(n) * 0.5])