def run_schedule_by_schedule_comparison(time_range, predicted_pv_data_path, real_pv_data_path): control_sim_name = f"baseline_pred" control_oemof_file_name = 'baseline_pred.oemof' run_simulation(time_range, predicted_pv_data_path, 'hal_plugin/data/sh_intensity=15_area=46.5.csv', control_sim_name, control_oemof_file_name) hal_schedule_file_name = 'hal_offline' oemoef_schedule_file_name = 'oemof_offline' run_both_with_existing_schedule(control_oemof_file_name, control_sim_name, time_range, real_pv_data_path, hal_schedule_file_name, oemoef_schedule_file_name) # plot control plot_results(control_sim_name, oemof_file=control_oemof_file_name, show=False) # plot schedule sim oemof_dir = Path.cwd() / 'oemof_runs' / 'results' hal_scheduled_results = get_oemof_results(oemof_dir, hal_schedule_file_name, exclude_storage=True) oemof_scheduled_results = get_oemof_results(oemof_dir, oemoef_schedule_file_name, exclude_storage=True) oemof_schedule_costs = load_oemof_costs(oemof_scheduled_results) hal_schedule_costs = load_oemof_costs(hal_scheduled_results) fig, axes = plt.subplots(nrows=3) mixed_costs = pd.DataFrame({'hal_KWh': hal_schedule_costs['wh'] / 1000, 'oemof_KWh': oemof_schedule_costs['wh'] / 1000, 'KWh_diff': oemof_schedule_costs['wh'] / 1000 - hal_schedule_costs['wh'] / 1000}, index=oemof_schedule_costs.index) mixed_costs.plot(title=f"Imported KWh", ax=axes[0]) mixed_costs.cumsum().plot(title='Cummulated Imported KWh', ax=axes[1]) mixed_costs.sum().plot.bar(title='Total KWh Comparison', ax=axes[2], grid=True) plt.show()
def get_baseline(dec_setup_path): oemof_baseline = load_oemof_costs( get_oemof_results(dec_setup_path, 'baseline_pred.oemof', True)) hal_baseline = hal_load_import_kwh(dec_setup_path / 'baseline_pred', 'baseline_pred') oemof_dec = load_oemof_costs( get_oemof_results(dec_setup_path, 'real_data_offline.oemof', True)) hal_dec = hal_load_import_kwh(dec_setup_path / 'real_data_online', 'real_data_online') total_hal_baseline = hal_baseline['wh_total'] / 1000 total_oemof_baseline = oemof_baseline['wh_total'] / 1000 total_hal_dec = hal_dec['wh_total'] / 1000 total_oemof_dec = oemof_dec['wh_total'] / 1000 return total_hal_baseline, total_oemof_baseline, total_hal_dec, total_oemof_dec
def get_storage_mocks_from_oemof(result_path: Path, file_name: str): oemof_results = get_oemof_results(result_path, file_name) storage_input = oemof_results['storage_data'][(('b1', 'storage'), 'flow')] storage_output = oemof_results['storage_data'][(('storage', 'b1'), 'flow')] heat_storage_input = oemof_results['heat_storage'][(('b_h', 'heat_storage'), 'flow')] heat_storage_output = oemof_results['heat_storage'][(('heat_storage', 'b_h'), 'flow')] return heat_storage_input, heat_storage_output, storage_input, storage_output
def incremental_net_import_analysis(): base_path = Path().cwd() / 'result_data' incr_path = base_path / 'incremental setup - sept' oemof_baseline = load_oemof_costs( get_oemof_results(base_path, 'oemof_baseline_result_pvol.oemof')) hal_sim_name = 'hal_baseline_result_pvol' hal_baseline = hal_load_import_kwh(base_path / hal_sim_name, hal_sim_name) split_24h = load_oemof_costs( get_oemof_split_results(incr_path / 'sliced_24h', 30)) split_12h = load_oemof_costs( get_oemof_split_results(incr_path / 'sliced_12h', 60)) split_6h = load_oemof_costs( get_oemof_split_results(incr_path / 'sliced_6h', 120)) fig, axes = plt.subplots(nrows=2) total_hal_baseline = hal_baseline['wh_total'] / 1000 total_oemof_baseline = oemof_baseline['wh_total'] / 1000 total_oemof_24h = split_24h['wh_total'] / 1000 total_oemof_12h = split_12h['wh_total'] / 1000 total_oemof_6h = split_6h['wh_total'] / 1000 mixed_costs = pd.DataFrame( { 'BL HAL': total_hal_baseline, 'BL OEMOF': total_oemof_baseline, '24h split': total_oemof_24h, '12h split': total_oemof_12h, '6h split': total_oemof_6h, }, index=total_oemof_baseline.index) mixed_costs.cumsum().plot(ax=axes[0]).set_ylabel('KWh') total_plot = mixed_costs.sum().plot.bar(ax=axes[1], grid=True) total_plot.set_ylabel('KWh') total_plot.set_xlabel('t') fig.subplots_adjust(left=0.12, right=0.97, top=0.92, bottom=0.19, hspace=0.53) plt.savefig("praktikumsbericht/images/splits_total.pdf") fig, axes = plt.subplots(nrows=1) mixed_costs.boxplot(grid=True, showfliers=False, ax=axes) dataframe_to_stat_table(incr_path / 'stats.csv', mixed_costs) fig.subplots_adjust(left=0.12, right=0.96, top=0.93, bottom=0.07, hspace=0.20) # plt.show() plt.savefig("praktikumsbericht/images/splits_peaks.pdf")
def get_imports(oemof_dir, oemof_file, hal_dir, hal_sim_name, split_max=None): if split_max is not None: oemof_results = get_oemof_split_results(oemof_dir, split_max) else: oemof_results = get_oemof_results(oemof_dir, oemof_file, exclude_storage=True) hal_import = hal_load_import_kwh(hal_dir, hal_sim_name) oemof_import = load_oemof_costs(oemof_results) return oemof_import, hal_import
def real_data_net_import_analysis(): base_path = Path().cwd() / 'result_data' sept_setup_path = base_path / 'schedule vs real - sept' oemof_baseline = load_oemof_costs(get_oemof_results(sept_setup_path, 'baseline_pred.oemof', True)) hal_baseline = hal_load_import_kwh(sept_setup_path / 'baseline_pred', 'baseline_pred') oemof_sept = load_oemof_costs(get_oemof_results(sept_setup_path, 'real_data_offline.oemof', True)) hal_sept = hal_load_import_kwh(sept_setup_path / 'real_data_online', 'real_data_online') total_hal_baseline = hal_baseline['wh_total'] / 1000 total_oemof_baseline = oemof_baseline['wh_total'] / 1000 total_hal_sept = hal_sept['wh_total'] / 1000 total_oemof_sept = oemof_sept['wh_total'] / 1000 mixed_costs = pd.DataFrame({ 'Pred HAL': total_hal_baseline, 'Pred OEMOF': total_oemof_baseline, 'Real HAL': total_hal_sept, 'Real OEMOF': total_oemof_sept, }, index=total_oemof_baseline.index) fig, axes = plt.subplots(nrows=1) mixed_costs.sum().plot.bar(ax=axes, grid=True).set_ylabel('KWh') fig.subplots_adjust(left=0.12, right=0.97, top=0.92, bottom=0.19, hspace=0.53) plt.savefig("praktikumsbericht/images/sept_real_total.pdf") dataframe_to_stat_table(sept_setup_path / 'stats.csv', mixed_costs) hal_stor_load = load_hal_storage_df(sept_setup_path / 'real_data_online', 'real_data_online')[0]['power[W]'] pred_oemof_results = get_oemof_results(sept_setup_path, 'baseline_pred.oemof', exclude_storage=True) real_oemof_results = get_oemof_results(sept_setup_path, 'real_data_offline.oemof', exclude_storage=True) oemof_stor_load = real_oemof_results['b1_data'][(('b1', 'sink_storage'), 'flow')] - real_oemof_results['b1_data'][(('source_storage', 'b1'), 'flow')] pv_pred = pred_oemof_results['b1_data'][(('source_pv', 'b1'), 'flow')] pv_real = real_oemof_results['b1_data'][(('source_pv', 'b1'), 'flow')] pl = DataFrame({ 'HAL controlled Storage Balance': hal_stor_load, 'Schedule controlled Storage Balance': oemof_stor_load, 'Pred PV Output': pv_pred, 'Actual PV Output': pv_real, }, index=real_oemof_results['b1_data'].index) corr = pl.corr() # print(corr.to_latex()) print(corr.to_latex(open("praktikumsbericht/images/sept_real_correlation.tex", 'w'), label='t/res/real', header=['HAL', 'Schedule', 'Pred PV', 'Actual PV'], caption='Correlation between PV input and storage consumption', float_format="%.2f")) fig, axes = plt.subplots(nrows=1) pl["2016-09-01"].plot(ax=axes) axes.set_ylabel('W') plt.savefig("praktikumsbericht/images/sept_real_example.pdf") # Percentiles fig, axes = plt.subplots(nrows=1) boxplot = mixed_costs.boxplot(grid=True, showfliers=False, ax=axes) boxplot.set_ylabel('KWh') fig.subplots_adjust(left=0.12, right=0.96, top=0.93, bottom=0.07, hspace=0.20) plt.savefig("praktikumsbericht/images/sept_real_peaks.pdf") dataframe_to_stat_table(sept_setup_path / 'stats.csv', mixed_costs)
from pathlib import Path import matplotlib.pyplot as plt from pandas import DataFrame from plotting.hal_data_processing import hal_load_import_kwh, load_hal_storage_df from plotting.oemof_data_processing import load_oemof_costs from plotting.plot_run import get_oemof_results, to_percentiles, params_from_hal_path, params_from_oemof_path base_path = Path.cwd() / 'result_data' / 'noise setup - sept 1w' hal_dir = base_path / 'hal variance' oemof_dir = base_path / 'oemof variance' hal_dirs = [dir for dir in os.listdir(hal_dir) if re.search('_([0-9\.]+)_([0-9\.]+)_([0-9])+$', dir) is not None] oemof_file_names = [file_name for file_name in os.listdir(oemof_dir) if re.search('_([0-9\.]+)_([0-9\.]+)_([0-9])+.oemof', file_name) is not None] oemof_control_results = get_oemof_results(base_path, 'ensemble_control.oemof', exclude_storage=True) hal_costs = [(dir, hal_load_import_kwh(hal_dir / dir, dir)['wh'].sum() / 1000) for dir in hal_dirs] hal_costs_by_param, hal_mean, hal_percentiles = to_percentiles(hal_costs, params_from_hal_path) oemof_costs = [(file_name, load_oemof_costs(get_oemof_results(oemof_dir, file_name, exclude_storage=True))['wh'].sum() / 1000) for file_name in oemof_file_names] oemof_costs_by_param, oemof_mean, oemof_percentiles = to_percentiles(oemof_costs, params_from_oemof_path) stds = [t[1] for t in hal_costs_by_param.keys()] fig, axes = plt.subplots(1, 1) axes.fill_between(stds, hal_percentiles[0], hal_percentiles[1], alpha=0.4) axes.plot(stds, hal_mean, 'x-') axes.fill_between(stds, oemof_percentiles[0], oemof_percentiles[1], alpha=0.4) axes.plot(stds, oemof_mean, 'x-')