Example #1
0
def plot_cumsum_plot(baseline, scenario1, scenario2, scenario3):
    journal = Journal.POWERPOINT_A3

    fig, ax = init_figure(nrows=1,
                          ncols=1,
                          columnes=Columnes.ONE,
                          journal=journal)

    lbase = plot_cumsum_by_scenario(baseline[baseline.is_home], ax, label='Baseline')
    l1 = plot_cumsum_by_scenario(scenario1[scenario1.is_home], ax, label='Scenario 1')
    l2 = plot_cumsum_by_scenario(scenario2, ax, label='Scenario 2')
    l3 = plot_cumsum_by_scenario(scenario3, ax, label='Scenario 3')

    xlim = plt.xlim()
    lxy = plt.plot(np.arange(0, xlim[1]), np.arange(0, xlim[1]), label='x=y (only using pv generation)', color='k',
                   linestyle=':', linewidth=2)
    lyx = plt.plot(np.arange(0, xlim[1]), - np.arange(0, xlim[1]), label='x=-y (only using grid generation)', color='k',
                   linestyle=':', linewidth=2)

    lyx = plt.plot(np.arange(0, xlim[1]), 0 * np.arange(0, xlim[1]), label=None, color='k',
                   linestyle='--', linewidth=2)
    xlim = plt.xlim()

    ylim = plt.ylim()
    ylim = (ylim[0], xlim[1])
    print(ylim)
    ax.set_ylim(ylim)
    ax.set_xlim((0, xlim[1]))
    plt.xlabel('Total energy used by cars (cumulative) [MWh]', labelpad=15)
    plt.ylabel('PV charging - grid charging \n (cumulative) [MWh]', labelpad=15)
    leg = plt.legend(ncol=3, loc='upper left', bbox_to_anchor=(-0.15, -0.2), borderpad=0., frameon=False)
    plt.tight_layout()
    bbox_extra_artists = [fig, leg, ax]
    save_figure(os.path.join('plots', 'cumulative_energy_plot', 'cumsum_all_scenarios.png'),
                bbox_extra_artists=bbox_extra_artists)
Example #2
0
        df_all = pd.concat((df_b, df_s1, df_s2, df_s3))

        # mask missing data
        dates_to_exclude = [
            datetime.datetime(2017, 10, 2, 0, 0) + datetime.timedelta(days=i)
            for i in range(14)
        ]
        data_exclude_ix = df_all['start'].isin(dates_to_exclude)
        df_all.loc[data_exclude_ix, 'co2'] = np.nan

        journal = Journal.POWERPOINT_A3

        fig, ax = init_figure(nrows=1,
                              ncols=1,
                              columnes=Columnes.ONE,
                              journal=journal,
                              sharex=True,
                              sharey=True)

        sns.lineplot(data=df_all,
                     x="start",
                     y="co2",
                     hue="scenario",
                     linewidth=3,
                     ax=ax)

        # ax.set_xticks(ax.get_xticks()[::2]) # skip every second tick
        ax.xaxis.set_major_formatter(mdates.DateFormatter('%b'))
        # ax.xaxis.set_minor_formatter(mdates.DateFormatter('%b'))

        handles, labels = ax.get_legend_handles_labels()
Example #3
0
    with Pool(24) as pool:
        daily_pv_per_user['generated_by_pv'] = pool.map(get_PV_generated_from_pandas_row_partial,
                                                        daily_pv_per_user.iterrows())
        pool.close()
        pool.join()

    ############### get kwp

    df_kwp.set_index('vin', inplace=True)
    df_kwp['area'] = 0
    df_kwp['user'] = 0
    df_kwp = get_kwp(df_kwp)

    journal = Journal.POWERPOINT_A3
    fig, axes = init_figure(nrows=1, ncols=2,
                            columnes=Columnes.ONE, fig_height_mm=120,
                            journal=journal, sharex=False, sharey=False,
                            gridspec_kw={'width_ratios': [2, 1]})
    plt.sca(axes[0])
    ax = axes[0]
    sns.lineplot(data=daily_pv_per_user, x="start", y="generated_by_pv",
                 linewidth=1.5, ax=ax)
    ax.set_xlabel('Days in 2017 [d]')
    ax.set_ylabel('Daily PV generation [kWh]')
    t_start = project_constants['t_start']
    t_end = project_constants['t_end']
    x_dates = pd.date_range(start=t_start,
                            end=t_end,
                            freq='M', ) + datetime.timedelta(days=1)
    axes[0].set_xticks(x_dates[::2])
    axes[0].xaxis.set_major_formatter(mdates.DateFormatter('%b'))
all_users_df = pd.concat(user_df_resampled_list, axis=1).mean(axis=1)
all_users_df = pd.DataFrame(all_users_df, columns=['value'])
all_users_df['hour'] = all_users_df.index.hour
all_users_df['day'] = all_users_df.index.floor('D')

matrix = all_users_df.pivot(index=['day'], columns=['hour'], values='value')
matrix = matrix.transpose()

# plot
journal = Journal.POWERPOINT_A3
fig, ax = init_figure(
    nrows=1,
    ncols=1,
    fig_height_mm=150,
    # height_scale=5.0,
    columnes=Columnes.ONE,
    journal=journal,
    disabled_spines=[],
    # gridspec_kw={"height_ratios":[1, 0.05]})
)

plt.sca(ax)
# sns.heatmap(matrix, ax=ax)
im = ax.imshow(matrix, aspect='auto', cmap='viridis', interpolation='None')
# PCM=ax.get_children()[-2] #get the mappable, the 1st and the 2nd are the x and y axes
# plt.colorbar(PCM, ax=ax)

# plt.colorbar()
plt.grid(b=None)
plt.xlabel("Days in study")
plt.ylabel("Hours of the day")
    user_df_resampled_list.append(user_df_resampled)

all_users_df = pd.concat(user_df_resampled_list, axis=1).mean(axis=1)
all_users_df = pd.DataFrame(all_users_df, columns=['value'])
all_users_df['hour'] = all_users_df.index.hour
all_users_df['day'] = all_users_df.index.floor('D')

matrix = all_users_df.pivot(index=['day'], columns=['hour'], values='value')
matrix = matrix.transpose()

# plot
journal = Journal.POWERPOINT_A3
fig, ax = init_figure(
    nrows=1,
    ncols=1,
    fig_height_mm=150,
    columnes=Columnes.ONE,
    journal=journal,
    disabled_spines=[],
)

plt.sca(ax)
im = ax.imshow(matrix, aspect='auto', cmap='viridis', interpolation='None')

# plt.colorbar()
plt.grid(b=None)
plt.xlabel("Days in study")
plt.ylabel("Hours of the day")

plt.yticks([0, 6, 12, 18, 24])

im.set_clim([0, 1])
Example #6
0
                                          columns=['timestamp', 'soc'])

charging_state_timeseries = pd.concat([charging_state_timeseries1, charging_state_timeseries2],
                                      axis=0,
                                      sort=False,
                                      ignore_index=True)

charging_state_timeseries['timestamp'] = charging_state_timeseries['timestamp'].astype(
    'datetime64[ns]')  # transform it to timestamps again!

# set index and plot
charging_state_timeseries.set_index('timestamp', inplace=True)

f, ax = init_figure(nrows=1,
                    ncols=1,
                    columnes=Columnes.ONE,
                    journal=Journal.POWERPOINT_A3,
                    disabled_spines=['top'])

charging_state_timeseries.plot(ax=ax,
                               color="k",
                               linewidth=3,
                               zorder=2,
                               legend=False)

lines, labels = ax.get_legend_handles_labels()
l1 = lines[0]

# %% plot ishome areas
with open(os.path.join(".", "data", "Car_is_at_home_table_UTC.csv"), 'r') as data_file:
    all_data_df = pd.read_csv(data_file)
Example #7
0
                consumed_electric_energy_total
                from bmw where zustand = 'fahrt'"""

    df = pd.read_sql_query(query, con=engine)
    df.to_csv(os.path.join('.', 'data', 'power_factor_data.csv'))

# data_PV_Solar preparation
df['dsoc'] = df['soc_customer_start'] - df['soc_customer_end']
df['pow'] = df['consumed_electric_energy_total']

# filter all that is zero
df = df.drop(df[(df['dsoc'] <= 0) | (df['pow'] <= 0)].index)

# create plot
f, ax = init_figure(nrows=1,
                    ncols=1,
                    columnes=Columnes.ONE,
                    journal=Journal.POWERPOINT_A3)

hb = ax.hexbin(df['dsoc'],
               df['pow'],
               gridsize=100,
               bins='log',
               cmap=plt.get_cmap('bone_r'),
               mincnt=1,
               linewidths=0.2,
               edgecolors='slategray')

cb = f.colorbar(hb, ax=ax)
cb.set_label(r'log10(n), n = Number of points in cell', labelpad=20)

ax.set_ylabel(r"Consumed power [\si{\kilo\watthour}]", labelpad=20)