Beispiel #1
0
def check_wind_csv_profile(context):
    wind = list(
        filter(lambda x: x.name == "Wind Turbine",
               context.simulation.area.children))[0]
    from d3a.setup.strategy_tests.user_profile_wind_csv import user_profile_path
    profile_data = _readCSV(user_profile_path)
    for timepoint, energy in wind.strategy.energy_production_forecast_kWh.items(
    ):
        if timepoint in profile_data.keys():
            actual_energy = profile_data[timepoint] * \
                            (wind.config.slot_length / duration(hours=1)) / 1000.0
            assert energy == actual_energy
        else:
            assert energy == 0
Beispiel #2
0
def check_pv_csv_profile(context):
    house1 = list(
        filter(lambda x: x.name == "House 1",
               context.simulation.area.children))[0]
    pv = list(filter(lambda x: x.name == "H1 PV", house1.children))[0]
    from d3a.setup.strategy_tests.user_profile_pv_csv import user_profile_path
    profile_data = _readCSV(user_profile_path)
    for timepoint, energy in pv.strategy.energy_production_forecast_kWh.items(
    ):
        time = str(timepoint.format(PENDULUM_TIME_FORMAT))
        if time in profile_data.keys():
            assert energy == profile_data[time] / \
                   (duration(hours=1) / pv.config.slot_length) / 1000.0
        else:
            assert energy == 0
Beispiel #3
0
def check_pv_profile_csv(context):
    house1 = list(
        filter(lambda x: x.name == "House 1",
               context.simulation.area.children))[0]
    pv = list(filter(lambda x: x.name == "H1 PV", house1.children))[0]
    input_profile = _readCSV(context._device_profile)
    produced_energy = {
        f'{k.hour:02}:{k.minute:02}': v
        for k, v in pv.strategy.energy_production_forecast_kWh.items()
    }
    for timepoint, energy in produced_energy.items():
        if timepoint in input_profile:
            assert energy == input_profile[timepoint] / \
                   (duration(hours=1) / pv.config.slot_length) / 1000.0
        else:
            assert False
Beispiel #4
0
def check_load_profile_csv(context, single_or_multi):
    from d3a.models.read_user_profile import _readCSV
    house1 = next(
        filter(lambda x: x.name == "House 1",
               context.simulation.area.children))
    load = next(filter(lambda x: x.name == "H1 DefinedLoad", house1.children))
    if single_or_multi == "single":
        path = user_profile_load_csv.profile_path
    else:
        path = user_profile_load_csv_multiday.profile_path
    input_profile = _readCSV(path)
    desired_energy_Wh = load.strategy.state.desired_energy_Wh
    for timepoint, energy in desired_energy_Wh.items():
        if timepoint in input_profile.keys():
            assert energy == input_profile[timepoint] / \
                   (duration(hours=1) / load.config.slot_length)
        else:
            assert False
Beispiel #5
0
def check_wind_csv_profile(context):
    wind = list(
        filter(lambda x: x.name == "Wind Turbine",
               context.simulation.area.children))[0]
    from d3a.setup.strategy_tests.user_profile_wind_csv import user_profile_path
    profile_data = _readCSV(user_profile_path)
    for timepoint, energy in wind.strategy.energy_production_forecast_kWh.items(
    ):

        time = str(timepoint.format(PENDULUM_TIME_FORMAT))
        accumulated_energy = 0
        for time_str in profile_data.keys():
            if int(time_str[:2]) == int(timepoint.hour):
                accumulated_energy += (profile_data[time_str] * 0.25)
        if time in profile_data.keys():
            actual_energy = accumulated_energy / 1000.0
            assert energy == actual_energy
        else:
            assert energy == 0
Beispiel #6
0
def check_load_profile_csv(context):
    from d3a.models.read_user_profile import _readCSV
    house1 = next(
        filter(lambda x: x.name == "House 1",
               context.simulation.area.children))
    load = next(filter(lambda x: x.name == "H1 DefinedLoad", house1.children))
    input_profile = _readCSV(user_profile_load_csv.profile_path)

    desired_energy_Wh = {
        f'{k.hour:02}:{k.minute:02}': v
        for k, v in load.strategy.state.desired_energy_Wh.items()
    }

    for timepoint, energy in desired_energy_Wh.items():
        if timepoint in input_profile:
            assert energy == input_profile[timepoint] / \
                   (duration(hours=1) / load.config.slot_length)
        else:
            assert False
Beispiel #7
0
def check_pv_profile(context):
    house1 = list(
        filter(lambda x: x.name == "House 1",
               context.simulation.area.children))[0]
    pv = list(filter(lambda x: x.name == "H1 PV", house1.children))[0]
    if pv.strategy._power_profile_index == 0:
        path = os.path.join(d3a_path, "resources/Solar_Curve_W_sunny.csv")
    if pv.strategy._power_profile_index == 1:
        path = os.path.join(d3a_path, "resources/Solar_Curve_W_partial.csv")
    if pv.strategy._power_profile_index == 2:
        path = os.path.join(d3a_path, "resources/Solar_Curve_W_cloudy.csv")
    profile_data = _readCSV(path)
    for timepoint, energy in pv.strategy.energy_production_forecast_kWh.items(
    ):
        time = str(timepoint.format(PENDULUM_TIME_FORMAT))
        if time in profile_data.keys():
            assert energy == profile_data[time] / \
                   (duration(hours=1) / pv.config.slot_length) / 1000.0
        else:
            assert energy == 0
Beispiel #8
0
def convert_energy_profile_to_power(input_profile, output_file):
    profile = _readCSV(input_profile)
    # Create a minute-resolution profile, filling the empty slots with previous values
    profile = _fill_gaps_in_profile(profile)
    GlobalConfig.sim_duration = duration(days=1) - duration(minutes=1)
    output_dict = default_profile_dict(0)
    for k, v in output_dict.items():
        # Average market slot values
        iter_duration = duration(minutes=0)
        averaged_value = 0
        while iter_duration < GlobalConfig.slot_length:
            averaged_value += profile[k + iter_duration]
            iter_duration += duration(minutes=1)
        averaged_value /= GlobalConfig.slot_length.minutes
        output_dict[k] = averaged_value

    power_profile = {
        k: convert_energy_to_power(float(v))
        for k, v in output_dict.items()
    }
    with open(output_file, 'w') as csv_file:
        writer = csv.writer(csv_file)
        for key, value in power_profile.items():
            writer.writerow([key, value])