def main():
    distance_factors = (None, )
    if COMPUTE_CONSTANT_DISTANCE_FACTORS:
        distance_factors += DISTANCE_FACTORS

    params = product(new_turbine_models() + ('mixed', ), distance_factors)

    with Pool(processes=NUM_PROCESSES) as pool:
        pool.map(calc_optimal_locations_worker, params)
Example #2
0
def savefig_repower_potential():
    repower_potentials = []
    for distance_factor in DISTANCE_FACTORS:
        for turbine_model_new in ('mixed',) + new_turbine_models():
            repower_potentials.append(load_repower_potential(turbine_model_new, distance_factor))

    plot_repower_potential(*repower_potentials, variable='power_generation')
    plt.savefig(FIGURES_DIR / 'repower_potential_power_generation.pdf', bbox_inches='tight')

    plot_repower_potential(*repower_potentials, variable='num_turbines')
    plt.savefig(FIGURES_DIR / 'repower_potential_num_turbines.pdf', bbox_inches='tight')
def calc_optimal_locations_worker(params):
    logging.info("Start calculating repower_potential: %s", params)
    turbine_model_new, distance_factor = params

    turbine_model_old = ge15_77

    if turbine_model_new == 'mixed':
        turbine_models = new_turbine_models()
    else:
        turbine_models = (turbine_model_new, )

    power_generation_new = xr.concat([
        load_simulated_energy_per_location(turbine_model_new)
        for turbine_model_new in turbine_models
    ],
                                     dim='turbine_model')

    is_optimal_location = xr.concat([
        load_optimal_locations(turbine_model_new, distance_factor)
        for turbine_model_new in turbine_models
    ],
                                    dim='turbine_model')

    power_generation_old = load_simulated_energy_per_location(
        turbine_model_old, capacity_scaling=True)

    cluster_per_location = load_cluster_per_location(distance_factor)

    repower_potential = calc_repower_potential(
        power_generation_new=power_generation_new,
        power_generation_old=power_generation_old,
        is_optimal_location=is_optimal_location,
        cluster_per_location=cluster_per_location)

    turbine_model_new_fname = (turbine_model_new.file_name
                               if turbine_model_new != 'mixed' else 'mixed')

    repower_potential.attrs['turbine_model_new'] = turbine_model_new_fname
    repower_potential.attrs['turbine_model_old'] = turbine_model_old.file_name
    repower_potential.attrs['distance_factor'] = (
        distance_factor if distance_factor is not None else 0)

    df_filename = '' if distance_factor is None else f'_{distance_factor}'

    fname = (INTERIM_DIR / 'repower_potential' /
             f'repower_potential_{turbine_model_old.file_name}_'
             f'{turbine_model_new_fname}{df_filename}.nc')

    repower_potential.to_netcdf(fname)
def main():
    prevail_wind_direction = load_prevail_wind_direction()
    distance_factors = (load_distance_factors(), )

    if COMPUTE_CONSTANT_DISTANCE_FACTORS:
        distance_factors += DISTANCE_FACTORS

    params = product(new_turbine_models(), distance_factors,
                     [prevail_wind_direction])

    # FIXME there is a deadlock because of logging... :-/
    #  https://codewithoutrules.com/2018/09/04/python-multiprocessing/

    # NUM_PROCESSES=1 because need more RAM, 24GB is not enough for 2 processes
    with Pool(processes=1) as pool:
        pool.map(calc_optimal_locations_worker, params)
Example #5
0
def plot_power_curves():
    fig, ax = plt.subplots(1, 1, figsize=FIGSIZE)

    x = np.linspace(0, 40, num=100)
    for turbine_model, color in zip((ge15_77, ) + new_turbine_models(),
                                    TURBINE_COLORS):
        linestyle = 'dashed' if turbine_model == ge15_77 else '-'
        ax.plot(x,
                turbine_model.power_curve(x),
                label=turbine_model.name,
                color=color,
                linestyle=linestyle)
    plt.legend()
    plt.ylabel('Power generation [kW]')
    plt.xlabel('Wind speed [m/s]')

    plt.grid()

    return fig
Example #6
0
def savefig_repower_potential_direction():
    repower_potentials = []
    for turbine_model_new in new_turbine_models() + ('mixed',):
        repower_potentials.append(load_repower_potential(turbine_model_new, distance_factor=None))

    _, stacklabels = plot_repower_potential(*repower_potentials, variable='power_generation')
    plt.savefig(FIGURES_DIR / 'repower_potential-direction-dependent_power_generation.pdf',
                bbox_inches='tight')

    plot_repower_potential(load_repower_potential('mixed', distance_factor=None),
                           variable='power_gain_per_model', stacklabels=stacklabels)
    plt.savefig(FIGURES_DIR / 'repower_potential-direction-dependent_power_generation-stacked.pdf',
                bbox_inches='tight')

    plot_repower_potential(*repower_potentials, variable='num_turbines')
    plt.savefig(FIGURES_DIR / 'repower_potential-direction-dependent_num_turbines.pdf',
                bbox_inches='tight')

    plot_repower_potential(load_repower_potential('mixed', distance_factor=None),
                           variable='power_generation', relative_ylabel=True, linestyle='-',
                           legend=False)
    plt.savefig(FIGURES_DIR / 'repower_potential_power_generation-relative.pdf', bbox_inches='tight')
Example #7
0
def plot_repower_potential(*repower_potentials,
                           variable='power_generation',
                           stacklabels=None,
                           relative_ylabel=False,
                           linestyle=None,
                           legend=True):
    """This function plots either expected power generation or total number of installed
    turbines."""
    fig, ax = plt.subplots(1, 1, figsize=FIGSIZE)
    plt.xlabel('Number of repowered turbines')

    ylabel = {
        'power_generation': 'Annual wind power generation [TWh/yr]',
        'power_gain_per_model':
        'Additional annual wind power generation [TWh/yr]',
        'num_turbines': 'Total number of turbines',
    }
    factor = {
        'power_generation': 1e-3,
        'power_gain_per_model': 1e-3,
        'num_turbines': 1.,
    }
    if relative_ylabel:
        ylabel = {
            'power_generation': 'Wind power generation [%]',
        }
        factor = {
            'power_generation': 100. / repower_potentials[0][variable][0]
        }

    plt.ylabel(ylabel[variable])  # FIXME make sure that this is GW!
    plt.grid(True)

    colors = TURBINE_COLORS
    turbine_names = ['mixed'] + [t.file_name for t in new_turbine_models()]
    turbine_color = dict(zip(turbine_names, colors))

    styles = ('--', '--', 'dotted', '-.', '-')
    distance_factor_style = dict(zip(DISTANCE_FACTORS + (0, ), styles))
    distance_factor_style = {k: v for k, v in distance_factor_style.items()}

    distance_factors = []

    labels = []

    for repower_potential in repower_potentials:
        num_new_turbines = repower_potential.num_new_turbines

        turbine_model_name = repower_potential.attrs['turbine_model_new']
        distance_factor = repower_potential.attrs['distance_factor']
        distance_factors.append(distance_factor)
        linestyle = linestyle or distance_factor_style[distance_factor]

        if turbine_model_name != 'mixed':
            turbine_model = getattr(turbine_models, turbine_model_name)
        else:

            class Turbine:
                pass  # ok, this a bit dirty...

            turbine_model = Turbine()
            turbine_model.name = 'Best turbine model per cluster'
            linestyle = linestyle or '--'
        color = turbine_color[turbine_model_name]

        label = turbine_model.name if distance_factor in (2,
                                                          0) else '_nolegend_'
        if turbine_model_name != 'mixed':
            labels.append(label)

        if variable == 'power_gain_per_model':
            ax.stackplot(num_new_turbines,
                         factor[variable] * repower_potential[variable],
                         labels=stacklabels,
                         colors=TURBINE_COLORS[1:])
        else:
            ax.plot(num_new_turbines,
                    factor[variable] * repower_potential[variable],
                    linestyle=linestyle,
                    label=label,
                    color=color)

    xlabels = ['{:,.0f}K'.format(x) for x in ax.get_xticks() / 1000]
    ax.set_xticklabels(xlabels)

    if legend:
        loc = 'upper left' if variable != 'num_turbines' else None
        legend1 = ax.legend(loc=loc)

    dist_factors = [
        Line2D([], [],
               color='black',
               linestyle=distance_factor_style[df],
               label=f"Distance factor {df}") for df in distance_factors
        if df != 0
    ]

    if legend and dist_factors:
        ax.legend(handles=dist_factors, loc='upper right')
        ax.add_artist(legend1)

    return plt.gca(), labels
import logging

from wind_repower_usa.calculations import calc_simulated_energy
from wind_repower_usa.config import MONTHS, INTERIM_DIR
from wind_repower_usa.load_data import load_wind_speed, load_turbines
from wind_repower_usa.logging_config import setup_logging
from wind_repower_usa.turbine_models import ge15_77, new_turbine_models

setup_logging()

year = 2017
turbines = load_turbines()
turbine_models = [ge15_77] + list(new_turbine_models())

for turbine_model in turbine_models:
    # simulates the power generation in the current situation for first turbine
    capacity_scaling = turbine_model == ge15_77

    scaling_str = '' if not capacity_scaling else '_capacity_scaled'
    fname = (INTERIM_DIR / 'simulated_energy_per_location' /
             f'simulated_energy_{turbine_model.file_name}{scaling_str}_gwh.nc')

    if fname.exists():
        logging.info("Skipping %s, file already exists", fname)
        continue

    logging.info("Calculating simulated energy for %s", turbine_model.name)

    # power generation per turbine for one year
    wind_speed = load_wind_speed(year, MONTHS)