Ejemplo n.º 1
0
def test_project_attributes(generated_consumption_data_1):
    cd,params = generated_consumption_data_1
    baseline_period = Period(datetime(2014,1,1),datetime(2014,1,1))
    location = Location(zipcode="91104")
    project = Project(location,[cd,cd],baseline_period,None)
    meter = ProjectFuelTypes(project)
    result = meter.evaluate_raw(project=project)
    assert len(result["fuel_types"]) == 2
    assert result["fuel_types"][0]["value"] == "electricity"
    assert result["fuel_types"][0]["tags"] == ["electricity"]
    assert result["fuel_types"][1]["value"] == "electricity"
    assert result["fuel_types"][1]["tags"] == ["electricity"]
Ejemplo n.º 2
0
def test_project_null_station():
    location = Location(zipcode="INVALID")

    with pytest.raises(ValueError):
        baseline_period = Period(datetime(2014,1,1), datetime(2015,1,1))
        reporting_period = None
        project = Project(location, consumption=[],
                baseline_period=baseline_period,
                reporting_period=reporting_period,
                other_periods=[],
                weather_source=None,
                weather_normal_source=None)
Ejemplo n.º 3
0
def test_project():
    location = Location(zipcode="60604")
    baseline_period = Period(datetime(2014,1,1), datetime(2015,1,1))
    reporting_period = None
    project = Project(location, consumption=[],
            baseline_period=baseline_period,
            reporting_period=reporting_period,
            other_periods=[],
            weather_source=None,
            weather_normal_source=None)

    assert project.consumption == []
    assert project.baseline_period.start == datetime(2014,1,1)
    assert project.baseline_period.end == datetime(2015,1,1)
    assert project.reporting_period is None
    assert project.other_periods == []
    assert project.weather_source.station_id == "725340"
    assert project.weather_normal_source.station_id == "725340"
    assert len(project.all_periods()) == 1
    assert project._total_date_range()[0] == datetime(2014,1,1)
    assert project._total_date_range()[1] == datetime(2015,1,1)
    assert len(project.segmented_consumption_data()) == 0
Ejemplo n.º 4
0
def test_project():
    location = Location(zipcode="60604")
    baseline_period = Period(datetime(2014,1,1), datetime(2015,1,1))
    reporting_period = None
    project = Project(location, consumption=[],
            baseline_period=baseline_period,
            reporting_period=reporting_period,
            other_periods=[],
            weather_source=None,
            weather_normal_source=None)

    assert project.consumption == []
    assert project.baseline_period.start == datetime(2014,1,1)
    assert project.baseline_period.end == datetime(2015,1,1)
    assert project.reporting_period is None
    assert project.other_periods == []
    assert project.weather_source.station_id == "725340"
    assert project.weather_normal_source.station_id == "725340"
    assert len(project.all_periods()) == 1
    assert project._total_date_range()[0] == datetime(2014,1,1)
    assert project._total_date_range()[1] == datetime(2015,1,1)
    assert len(project.segmented_consumption_data()) == 0
Ejemplo n.º 5
0
def test_project_attributes(generated_consumption_data_1):
    cd,params = generated_consumption_data_1
    baseline_period = Period(datetime(2014,1,1),datetime(2014,1,1))
    location = Location(zipcode="91104")
    project = Project(location,[cd],baseline_period,None)
    meter = ProjectAttributes(project)
    result = meter.evaluate_raw(project=project)
    assert result["location"].zipcode == location.zipcode
    assert result["consumption"][0] is not None
    assert result["baseline_period"] is not None
    assert result["reporting_period"] is None
    assert result["other_periods"] == []
    assert result["weather_source"].station_id == "722880"
    assert result["weather_normal_source"].station_id == "722880"
Ejemplo n.º 6
0
def test_project_consumption_baseline_reporting(generated_consumption_data_1):
    cd, _ = generated_consumption_data_1
    baseline_period = Period(datetime(2011,1,1),datetime(2013,6,1))
    reporting_period = Period(datetime(2013,6,1),datetime(2016,1,1))
    location = Location(zipcode="91104")
    project = Project(location,[cd],baseline_period,reporting_period)
    meter = ProjectConsumptionDataBaselineReporting()
    result = meter.evaluate_raw(project=project)
    assert result["consumption"][0]["value"].data.index[0] == datetime(2012,1,1)
    assert result["consumption"][0]["value"].data.index[17] == datetime(2013,5,25)
    assert result["consumption"][0]["tags"][0] == "electricity"
    assert result["consumption"][0]["tags"][1] == "baseline"
    assert result["consumption"][1]["value"].data.index[0] == datetime(2013,6,24)
    assert result["consumption"][1]["value"].data.index[18] == datetime(2014,12,16)
    assert result["consumption"][1]["tags"][0] == "electricity"
    assert result["consumption"][1]["tags"][1] == "reporting"
Ejemplo n.º 7
0
def create_eemeter_project(project_row, consumption_data_rows):
    """
    Given a row a pd.DataFrame for projects
    and a set of rows for consumption data rows, 
    return eemeter project. 
    """
    location = Location(zipcode=project_row.zipcode,
                        lat_lng=(project_row.latitude, project_row.longitude),
                        station=project_row.weather_station)
    baseline_period = Period(project_row.baseline_period_start,
                             project_row.baseline_period_end)
    reporting_period = Period(project_row.reporting_period_start,
                              project_row.reporting_period_end)
    consumptions = _create_eemeter_consumptions(consumption_data_rows)
    project = Project(location, consumptions, baseline_period,
                      reporting_period)

    return project
Ejemplo n.º 8
0
def create_project(params_e_pre, params_e_post, params_g_pre, params_g_post,
                   baseline_period_start_date, baseline_period_end_date,
                   reporting_period_start_date, reporting_period_end_date,
                   has_electricity, has_gas, weather_source, zipcode):

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

    # generate consumption
    baseline_period = Period(baseline_period_start_date,
                             reporting_period_start_date)
    datetimes_pre = generate_monthly_billing_datetimes(baseline_period,
                                                       dist=randint(29, 31))

    reporting_period = Period(datetimes_pre[-1], reporting_period_end_date)
    datetimes_post = generate_monthly_billing_datetimes(reporting_period,
                                                        dist=randint(29, 31))
    location = Location(zipcode=zipcode)
    baseline_period = Period(baseline_period_start_date,
                             baseline_period_end_date)
    reporting_period = Period(reporting_period_start_date,
                              reporting_period_end_date)

    cds = []

    if has_electricity:
        cd_e = generate_consumption_records(model_e, params_e_pre,
                                            params_e_post, datetimes_pre,
                                            datetimes_post, "electricity",
                                            "kWh", weather_source)
        cds.append(cd_e)

    if has_gas:
        cd_g = generate_consumption_records(model_g, params_g_pre,
                                            params_g_post, datetimes_pre,
                                            datetimes_post, "natural_gas",
                                            "therm", weather_source)
        cds.append(cd_g)

    return Project(location, cds, baseline_period, reporting_period)
Ejemplo n.º 9
0
    def generate(self, location, period_elec, period_gas,
            baseline_period, reporting_period,
            noise_elec=None, noise_gas=None):
        """Returns a simple simulated project consisting of generated
        electricity and gas consumptions and estimated savings for each.

        Parameters
        ----------
        location : eemeter.location.Location
            Location of project
        """
        early_date = None
        late_date = None

        if not period_elec.closed or not period_gas.closed:
            message = "Periods of consumption must have start and end."
            raise ValueError(message)

        all_periods = [period_elec, period_gas, baseline_period,
                reporting_period]
        for period in all_periods:
            if early_date is None:
                early_date = period.start
            if late_date is None:
                late_date = period.end
            if period.start is not None and period.start < early_date:
                early_date = period.start
            if period.end is not None and late_date < period.end:
                late_date = period.end

        weather_source = GSODWeatherSource(location.station,early_date.year,
                late_date.year)
        weather_normal_source = TMY3WeatherSource(location.station)

        cd_elec, est_savings_elec, elec_bl_params, elec_rp_params = \
                self._generate_fuel_consumptions(
                        weather_source, weather_normal_source, period_elec,
                        self.electricity_model, self.elec_param_dists,
                        self.elec_param_delta_dists, noise_elec,
                        baseline_period, reporting_period,
                        "electricity", "kWh", self.temperature_unit_name)

        cd_gas, est_savings_gas, gas_bl_params, gas_rp_params = \
                self._generate_fuel_consumptions(
                        weather_source, weather_normal_source, period_gas,
                        self.gas_model, self.gas_param_dists,
                        self.gas_param_delta_dists, noise_gas,
                        baseline_period, reporting_period,
                        "natural_gas", "therm", self.temperature_unit_name)

        project = Project(location, [cd_elec, cd_gas], baseline_period,
                reporting_period)

        results = {
            "project": project,
            "electricity_estimated_savings": est_savings_elec,
            "natural_gas_estimated_savings": est_savings_gas,
            "electricity_pre_params": elec_bl_params,
            "natural_gas_pre_params": gas_bl_params,
            "electricity_post_params": elec_rp_params,
            "natural_gas_post_params": gas_rp_params,
        }

        return results
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def test_default_residential_meter(default_residential_outputs_1,
        gsod_722880_2012_2014_weather_source, tmy3_722880_weather_source):
    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 = \
            default_residential_outputs_1

    meter = DefaultResidentialMeter(temperature_unit_str=temp_unit)

    location = Location(station="722880")
    baseline_period = Period(datetime(2012,1,1,tzinfo=pytz.utc),retrofit_start_date)
    reporting_period = Period(retrofit_completion_date, datetime(2014,12,31,tzinfo=pytz.utc))
    project = Project(location, [elec_consumption_data, gas_consumption_data], baseline_period,
            reporting_period)

    data_collection = DataCollection(project=project)
    result = meter.evaluate(data_collection)

    assert_allclose(result.get_data('annualized_usage',
            tags=['electricity','baseline']).value, elec_annualized_usage,
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('annualized_usage',
            tags=['natural_gas','baseline']).value, gas_annualized_usage,
            rtol=RTOL, atol=ATOL)


    assert_allclose(result.get_data('annualized_usage',
            tags=['electricity','reporting']).value, elec_annualized_usage,
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('annualized_usage',
            tags=['natural_gas','reporting']).value, gas_annualized_usage,
            rtol=RTOL, atol=ATOL)


    assert_allclose(result.get_data('gross_savings',
            tags=['electricity']).value, elec_gross_savings,
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('gross_savings',
            tags=['natural_gas']).value, gas_gross_savings,
            rtol=RTOL, atol=ATOL)


    assert_allclose(result.get_data('average_daily_usages',
            tags=['electricity', 'baseline']).value, elec_consumption_kWh_per_day[:17],
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('average_daily_usages',
            tags=['natural_gas', 'baseline']).value, gas_consumption_kWh_per_day[:17],
            rtol=RTOL, atol=ATOL)


    assert_allclose(result.get_data('average_daily_usages',
            tags=['electricity', 'reporting']).value, elec_consumption_kWh_per_day[20:],
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('average_daily_usages',
            tags=['natural_gas', 'reporting']).value, gas_consumption_kWh_per_day[20:],
            rtol=RTOL, atol=ATOL)


    assert_allclose(result.get_data('cdd_tmy',
            tags=['electricity', 'baseline']).value, cdd_tmy,
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('cdd_tmy',
            tags=['natural_gas', 'baseline']).value, cdd_tmy,
            rtol=RTOL, atol=ATOL)


    assert_allclose(result.get_data('cdd_tmy',
            tags=['electricity', 'reporting']).value, cdd_tmy,
            rtol=RTOL, atol=ATOL)

    assert_allclose(result.get_data('cdd_tmy',
            tags=['natural_gas', 'reporting']).value, cdd_tmy,
            rtol=RTOL, atol=ATOL)


    elec_rmse_results = result.search('rmse', ['electricity'])
    assert elec_rmse_results.count() == 2
    for data_container in elec_rmse_results.iteritems():
        assert_allclose(data_container.value, elec_rmse, rtol=RTOL, atol=ATOL)

    gas_rmse_results = result.search('rmse', ['natural_gas'])
    assert gas_rmse_results.count() == 2
    for data_container in gas_rmse_results.iteritems():
        assert_allclose(data_container.value, gas_rmse, rtol=RTOL, atol=ATOL)

    elec_r_squared_results = result.search('r_squared', ['electricity'])
    assert elec_r_squared_results.count() == 2
    for data_container in elec_r_squared_results.iteritems():
        assert_allclose(data_container.value, elec_r_squared, rtol=RTOL, atol=ATOL)

    gas_r_squared_results = result.search('r_squared', ['natural_gas'])
    assert gas_r_squared_results.count() == 2
    for data_container in gas_r_squared_results.iteritems():
        assert_allclose(data_container.value, gas_r_squared, rtol=RTOL, atol=ATOL)