Esempio n. 1
0
def test_model_weather_input_not_np_array():
    model = AverageDailyTemperatureSensitivityModel(heating=False,
                                                    cooling=False)
    params = model.param_type([1])
    observed_temps = [[70], [65, 60]]
    usages = model.transform(observed_temps, params)
    assert_allclose(usages, [1, 1], rtol=1e-2, atol=1e-2)
Esempio n. 2
0
def test_average_daily_baseload_heating_cooling_consumption_model():
    initial_params = {
        "base_daily_consumption": 0,
        "heating_slope": 0,
        "cooling_slope": 0,
        "heating_balance_temperature": 55,
        "cooling_balance_temperature": 57,
    }
    param_bounds = {
        "base_daily_consumption": [0, 100],
        "heating_slope": [0, 100],
        "cooling_slope": [0, 100],
        "heating_balance_temperature": [50, 60],
        "cooling_balance_temperature": [52, 72],
    }

    model = AverageDailyTemperatureSensitivityModel(
        cooling=True,
        heating=True,
        initial_params=initial_params,
        param_bounds=param_bounds)

    params = model.param_type([1, 60, 1, 65, 1])
    observed_temps = np.array([[i] for i in range(50, 70)])
    usages = model.transform(observed_temps, params)
    assert_allclose(usages[8:18], [3, 2, 1, 1, 1, 1, 1, 1, 2, 3],
                    rtol=1e-2,
                    atol=1e-2)
    opt_params = model.fit(observed_temps, usages)
    assert_allclose(params.to_list(),
                    opt_params.to_list(),
                    rtol=1e-2,
                    atol=1e-2)
Esempio n. 3
0
def consumption_generator_2(request):
    model_params, fuel_type, consumption_unit_name, temperature_unit_name = \
            request.param
    model = AverageDailyTemperatureSensitivityModel(cooling=True, heating=True)
    params = {
        "base_daily_consumption": model_params[0],
        "heating_slope": model_params[1],
        "heating_balance_temperature": model_params[2],
        "cooling_slope": model_params[3],
        "cooling_balance_temperature": model_params[4]
    }
    generator = MonthlyBillingConsumptionGenerator(fuel_type,
            consumption_unit_name, temperature_unit_name, model, params)
    params = model.param_type(params)
    return generator, params
Esempio n. 4
0
def test_TemperatureSensitivityModel_with_cooling():
    initial_params = {
        "base_daily_consumption": 0,
        "cooling_slope": 0,
        "cooling_balance_temperature": 57,
    }
    param_bounds = {
        "base_daily_consumption": [0,100],
        "cooling_slope": [0,100],
        "cooling_balance_temperature": [52,72],
    }
    model = AverageDailyTemperatureSensitivityModel(heating=False,cooling=True,initial_params=initial_params,param_bounds=param_bounds)
    params = model.param_type([1,60,1])
    observed_temps = np.array([[i] for i in range(50,70)])
    usages = model.transform(observed_temps, params)
    assert_allclose(usages[8:13],[1,1,1,2,3])
    opt_params = model.fit(observed_temps, usages)
    assert_allclose(params.to_list(), opt_params.to_list(), rtol=1e-2, atol=1e-2)
Esempio n. 5
0
def default_residential_outputs_1(request, gsod_722880_2012_2014_weather_source):
    elec_model_params, gas_model_params, \
            elec_annualized_usage, gas_annualized_usage, \
            elec_gross_savings, gas_gross_savings, \
            elec_rmse, gas_rmse, elec_r_squared, gas_r_squared, \
            temp_unit, cdd_tmy, hdd_tmy, total_cdd, total_hdd \
            = request.param

    period = Period(datetime(2012,1,1,tzinfo=pytz.utc),
            datetime(2014,12,31,tzinfo=pytz.utc))
    retrofit_start_date = datetime(2013,6,1,tzinfo=pytz.utc)
    retrofit_completion_date = datetime(2013,8,1,tzinfo=pytz.utc)

    datetimes = generate_monthly_billing_datetimes(period,randint(30,31))

    # generate electricity consumption
    elec_model = AverageDailyTemperatureSensitivityModel(cooling=True,heating=True)
    elec_params = {
        "base_daily_consumption": elec_model_params[0],
        "heating_balance_temperature": elec_model_params[1],
        "heating_slope": elec_model_params[2],
        "cooling_balance_temperature": elec_model_params[3],
        "cooling_slope": elec_model_params[4],
    }
    elec_gen = MonthlyBillingConsumptionGenerator("electricity", "kWh", temp_unit,
            elec_model, elec_params)
    elec_consumption_data = elec_gen.generate(gsod_722880_2012_2014_weather_source, datetimes)
    elec_consumption_kWh_per_day, elec_consumption_n_days = \
            elec_consumption_data.average_daily_consumptions()
    elec_params = elec_model.param_type(elec_params)

    # generate natural_gas consumption
    gas_model = AverageDailyTemperatureSensitivityModel(cooling=False,heating=True)
    gas_params = {
        "base_daily_consumption": gas_model_params[0],
        "heating_balance_temperature": gas_model_params[1],
        "heating_slope": gas_model_params[2],
    }
    gas_gen = MonthlyBillingConsumptionGenerator("natural_gas", "therm", temp_unit,
            gas_model, gas_params)
    gas_consumption_data = gas_gen.generate(gsod_722880_2012_2014_weather_source, datetimes)
    gas_consumption_kWh_per_day, gas_consumption_n_days = \
            gas_consumption_data.average_daily_consumptions()
    gas_params = gas_model.param_type(gas_params)

    fixture = elec_consumption_data, gas_consumption_data, \
            elec_params, gas_params, \
            elec_annualized_usage, gas_annualized_usage, \
            elec_gross_savings, gas_gross_savings, \
            elec_rmse, gas_rmse, \
            elec_r_squared, gas_r_squared, \
            elec_consumption_kWh_per_day, gas_consumption_kWh_per_day, \
            elec_consumption_n_days, gas_consumption_n_days, \
            temp_unit, retrofit_start_date, retrofit_completion_date, \
            cdd_tmy, hdd_tmy, total_cdd, total_hdd
    return fixture
Esempio n. 6
0
def generated_consumption_data_with_n_periods_cdd_1(request,
        gsod_722880_2012_2014_weather_source):
    model_params, period, n_periods_1, n_periods_2, n_periods_3 = request.param
    model = AverageDailyTemperatureSensitivityModel(cooling=True,heating=True)
    params = {
        "base_daily_consumption": model_params[0],
        "heating_slope": model_params[1],
        "heating_balance_temperature": model_params[2],
        "cooling_slope": model_params[3],
        "cooling_balance_temperature": model_params[4]
    }
    gen = MonthlyBillingConsumptionGenerator("electricity", "kWh", "degF",
            model, params)

    datetimes = generate_monthly_billing_datetimes(period, dist=randint(30,31))
    consumption_data = gen.generate(gsod_722880_2012_2014_weather_source,
            datetimes)
    return consumption_data, n_periods_1, n_periods_2, n_periods_3
Esempio n. 7
0
def test_gross_savings_metric(
        generated_consumption_data_pre_post_with_gross_savings_1,
        gsod_722880_2012_2014_weather_source):

    model = AverageDailyTemperatureSensitivityModel(heating=True, cooling=True)
    meter = GrossSavingsMeter(temperature_unit_str="degF", model=model)

    cd, params_pre, params_post, retrofit_date, savings = \
            generated_consumption_data_pre_post_with_gross_savings_1

    reporting_period = Period(retrofit_date, datetime(2015, 1, 1))

    result = meter.evaluate_raw(
        consumption_data_reporting=cd.filter_by_period(reporting_period),
        model_params_baseline=params_pre,
        weather_source=gsod_722880_2012_2014_weather_source,
        energy_unit_str="kWh")

    assert_allclose(result["gross_savings"], savings, rtol=RTOL, atol=ATOL)
Esempio n. 8
0
df_t = pd.Series(formattedWeatherData.data)

df_t.index = df_t.index.to_datetime()
df_t = pd.DataFrame(df_t)
df_t.columns = ["TempC"]
    
    
model = AverageDailyTemperatureSensitivityModel(
            heating=True,
            cooling=True,
            initial_params={
                "base_daily_consumption": 0,
                "heating_slope": 0,
                "heating_balance_temperature": 10,
                "cooling_slope": 0,
                "cooling_balance_temperature": 20,
            },
            param_bounds={
                "base_daily_consumption": [0,1000000],
                "heating_slope": [0,1000],
                "heating_balance_temperature": [5,16],
                "cooling_slope": [0,1000],
                "cooling_balance_temperature": [13,24],
            })
            
            
# This weather source base !!
#ThisWeatherData= WeatherSourceBase()            

ExtractedData_chosenBuilding = pd.DataFrame(ExtractedData_chosenBuilding)
to_load = ExtractedData_chosenBuilding.resample('D').sum().tz_localize(None)
Esempio n. 9
0
def get_example_project(zipcode):

    # location
    location = Location(zipcode=zipcode)
    station = location.station
    weather_source = GSODWeatherSource(station,2011,2015)

    # model
    model_e = AverageDailyTemperatureSensitivityModel(cooling=True, heating=True)
    model_g = AverageDailyTemperatureSensitivityModel(cooling=False, heating=True)

    # model params
    params_e_b = {
        "cooling_slope": 1,
        "heating_slope": 1,
        "base_daily_consumption": 30,
        "cooling_balance_temperature": 73,
        "heating_balance_temperature": 68,
    }
    params_e_r = {
        "cooling_slope": .5,
        "heating_slope": .5,
        "base_daily_consumption": 15,
        "cooling_balance_temperature": 73,
        "heating_balance_temperature": 68,
    }
    params_g_b = {
        "heating_slope": .2,
        "base_daily_consumption": 2,
        "heating_balance_temperature": 68,
    }
    params_g_r = {
        "heating_slope": .1,
        "base_daily_consumption": 1,
        "heating_balance_temperature": 68,
    }

    #generators
    gen_e_b = MonthlyBillingConsumptionGenerator("electricity", "kWh", "degF",
            model_e, params_e_b)
    gen_e_r = MonthlyBillingConsumptionGenerator("electricity", "kWh", "degF",
            model_e, params_e_r)
    gen_g_b = MonthlyBillingConsumptionGenerator("natural_gas", "therm", "degF",
            model_g, params_g_b)
    gen_g_r = MonthlyBillingConsumptionGenerator("natural_gas", "therm", "degF",
            model_g, params_g_r)

    # time periods
    period = Period(datetime(2011,1,1,tzinfo=pytz.utc), datetime(2015,1,1,tzinfo=pytz.utc))
    datetimes = generate_monthly_billing_datetimes(period, dist=randint(30,31))

    # consumption data
    cd_e_b = gen_e_b.generate(weather_source, datetimes, daily_noise_dist=None)
    cd_e_r = gen_e_r.generate(weather_source, datetimes, daily_noise_dist=None)
    cd_g_b = gen_g_b.generate(weather_source, datetimes, daily_noise_dist=None)
    cd_g_r = gen_g_r.generate(weather_source, datetimes, daily_noise_dist=None)

    # periods
    periods = cd_e_b.periods()
    reporting_period = Period(datetime(2013,1,1,tzinfo=pytz.utc), datetime(2015,1,1,tzinfo=pytz.utc))
    baseline_period = Period(datetime(2011,1,1,tzinfo=pytz.utc), datetime(2013,1,1,tzinfo=pytz.utc))

    # records
    records_e = []
    records_g = []
    for e_b, e_r, g_b, g_r, p in zip(cd_e_b.data, cd_e_r.data, cd_g_b.data, cd_g_r.data, periods):
        e = e_r if p in reporting_period else e_b
        g = g_r if p in reporting_period else g_b
        record_e = {"start": p.start, "end": p.end, "value": e}
        record_g = {"start": p.start, "end": p.end, "value": g}
        records_e.append(record_e)
        records_g.append(record_g)

    # consumption_data
    cd_e = ConsumptionData(records_e, "electricity", "kWh",
            record_type="arbitrary")
    cd_g = ConsumptionData(records_g, "natural_gas", "therm",
            record_type="arbitrary")
    consumptions = [cd_e, cd_g]

    # project
    project = Project(location, consumptions, baseline_period, reporting_period)

    return project
Esempio n. 10
0
def test_model_weather_input_not_np_array():
    model = AverageDailyTemperatureSensitivityModel(heating=False,cooling=False)
    params = model.param_type([1])
    observed_temps = [[70],[65,60]]
    usages = model.transform(observed_temps, params)
    assert_allclose(usages, [1,1], rtol=1e-2, atol=1e-2)