Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_TemperatureSensitivityModel_with_heating():
initial_params = {
"base_daily_consumption": 0,
"heating_slope": 0,
"heating_balance_temperature": 55,
}
param_bounds = {
"base_daily_consumption": [0,100],
"heating_slope": [0,100],
"heating_balance_temperature": [50,60],
}
model = AverageDailyTemperatureSensitivityModel(heating=True, cooling=False, 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],[3,2,1,1,1], 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)
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)
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
@pytest.mark.slow
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)
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, \
@pytest.mark.slow
def test_annualized_gross_savings_metric(
generated_consumption_data_pre_post_with_annualized_gross_savings_1,
gsod_722880_2012_2014_weather_source, tmy3_722880_weather_source):
model = AverageDailyTemperatureSensitivityModel(heating=True, cooling=True)
meter = AnnualizedGrossSavingsMeter(temperature_unit_str="degF", model=model)
cd, params_pre, params_post, retrofit_date, savings = \
generated_consumption_data_pre_post_with_annualized_gross_savings_1
reporting_period = Period(retrofit_date, datetime(2015,1,1))
result = meter.evaluate_raw(
model_params_baseline=params_pre,
model_params_reporting=params_post,
consumption_data_reporting=cd.filter_by_period(reporting_period),
weather_normal_source=tmy3_722880_weather_source,
energy_unit_str="kWh")
assert_allclose(result["annualized_gross_savings"], savings,
rtol=RTOL, atol=ATOL)
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)
def generated_consumption_data_with_hdd_1(request,
gsod_722880_2012_2014_weather_source):
model_params, period, total_hdd, base, temp_unit = 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, total_hdd, base, temp_unit
def test_annualized_gross_savings_metric(
generated_consumption_data_pre_post_with_annualized_gross_savings_1,
gsod_722880_2012_2014_weather_source, tmy3_722880_weather_source):
model = AverageDailyTemperatureSensitivityModel(heating=True, cooling=True)
meter = AnnualizedGrossSavingsMeter(temperature_unit_str="degF", model=model)
cd, params_pre, params_post, retrofit_date, savings = \
generated_consumption_data_pre_post_with_annualized_gross_savings_1
reporting_period = Period(retrofit_date, datetime(2015,1,1))
result = meter.evaluate_raw(
model_params_baseline=params_pre,
model_params_reporting=params_post,
consumption_data_reporting=cd.filter_by_period(reporting_period),
weather_normal_source=tmy3_722880_weather_source,
energy_unit_str="kWh")
assert_allclose(result["annualized_gross_savings"], savings,
rtol=RTOL, atol=ATOL)
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,