Example #1
0
def test_get_baseline_data_with_ignored_gap(
        il_electricity_cdd_hdd_billing_monthly):
    meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
    baseline_data, warnings = get_baseline_data(
        meter_data,
        end=datetime(2016, 11, 9, tzinfo=pytz.UTC),
        max_days=45,
        ignore_billing_period_gap_for_day_count=True,
    )
    assert baseline_data.shape == (2, 1)
    assert round(baseline_data.value.sum(), 2) == 632.31
    assert len(warnings) == 0

    baseline_data, warnings = get_baseline_data(
        meter_data,
        end=datetime(2016, 11, 9, tzinfo=pytz.UTC),
        max_days=45,
        ignore_billing_period_gap_for_day_count=False,
    )
    assert baseline_data.shape == (1, 1)
    assert round(baseline_data.value.sum(), 2) == 0
    assert len(warnings) == 0

    baseline_data, warnings = get_baseline_data(
        meter_data,
        end=datetime(2016, 11, 9, tzinfo=pytz.UTC),
        max_days=25,
        ignore_billing_period_gap_for_day_count=True,
    )
    assert baseline_data.shape == (1, 1)
    assert round(baseline_data.value.sum(), 2) == 0
    assert len(warnings) == 0
Example #2
0
def test_get_baseline_data_with_timezones(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    baseline_data, warnings = get_baseline_data(
        meter_data.tz_convert("America/New_York"))
    assert len(warnings) == 0
    baseline_data, warnings = get_baseline_data(
        meter_data.tz_convert("Australia/Sydney"))
    assert len(warnings) == 0
Example #3
0
def test_get_baseline_data_with_end(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    blackout_start_date = il_electricity_cdd_hdd_hourly["blackout_start_date"]
    baseline_data, warnings = get_baseline_data(meter_data,
                                                end=blackout_start_date)
    assert meter_data.shape != baseline_data.shape == (8761, 1)
    assert len(warnings) == 0
Example #4
0
def baseline_model_hourly(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    temperature_data = il_electricity_cdd_hdd_hourly["temperature_data"]
    blackout_start_date = il_electricity_cdd_hdd_hourly["blackout_start_date"]
    baseline_meter_data, warnings = get_baseline_data(meter_data,
                                                      end=blackout_start_date)
    preliminary_hourly_design_matrix = create_caltrack_hourly_preliminary_design_matrix(
        baseline_meter_data, temperature_data)
    segmentation = segment_time_series(preliminary_hourly_design_matrix.index,
                                       "three_month_weighted")
    occupancy_lookup = estimate_hour_of_week_occupancy(
        preliminary_hourly_design_matrix, segmentation=segmentation)
    occupied_temperature_bins, unoccupied_temperature_bins = fit_temperature_bins(
        preliminary_hourly_design_matrix,
        segmentation=segmentation,
        occupancy_lookup=occupancy_lookup,
    )
    design_matrices = create_caltrack_hourly_segmented_design_matrices(
        preliminary_hourly_design_matrix,
        segmentation,
        occupancy_lookup,
        occupied_temperature_bins,
        unoccupied_temperature_bins,
    )
    segmented_model = fit_caltrack_hourly_model(
        design_matrices,
        occupancy_lookup,
        occupied_temperature_bins,
        unoccupied_temperature_bins,
    )
    return segmented_model
Example #5
0
def baseline_data_daily(il_electricity_cdd_hdd_daily):
    meter_data = il_electricity_cdd_hdd_daily["meter_data"]
    temperature_data = il_electricity_cdd_hdd_daily["temperature_data"]
    blackout_start_date = il_electricity_cdd_hdd_daily["blackout_start_date"]
    baseline_meter_data, warnings = get_baseline_data(meter_data,
                                                      end=blackout_start_date)
    baseline_data = create_caltrack_daily_design_matrix(
        baseline_meter_data, temperature_data)
    return baseline_data
Example #6
0
def baseline_model_billing(il_electricity_cdd_hdd_billing_monthly):
    meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
    temperature_data = il_electricity_cdd_hdd_billing_monthly[
        "temperature_data"]
    blackout_start_date = il_electricity_cdd_hdd_billing_monthly[
        "blackout_start_date"]
    baseline_meter_data, warnings = get_baseline_data(meter_data,
                                                      end=blackout_start_date)
    baseline_data = create_caltrack_billing_design_matrix(
        baseline_meter_data, temperature_data)
    model_results = fit_caltrack_usage_per_day_model(baseline_data,
                                                     use_billing_presets=True,
                                                     weights_col="n_days_kept")
    return model_results
Example #7
0
def test_get_baseline_data_start_gap(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    start = meter_data.index.min() - timedelta(days=1)
    baseline_data, warnings = get_baseline_data(meter_data, start=start)
    assert meter_data.shape == baseline_data.shape == (19417, 1)
    assert len(warnings) == 1
    warning = warnings[0]
    assert warning.qualified_name == "eemeter.get_baseline_data.gap_at_baseline_start"
    assert (warning.description ==
            "Data does not have coverage at requested baseline start date.")
    assert warning.data == {
        "data_start": "2015-11-22T06:00:00+00:00",
        "requested_start": "2015-11-21T06:00:00+00:00",
    }
Example #8
0
def test_get_baseline_data_n_days_billing_period_overshoot(
        il_electricity_cdd_hdd_billing_monthly):
    meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
    baseline_data, warnings = get_baseline_data(
        meter_data,
        end=datetime(2017, 11, 9, tzinfo=pytz.UTC),
        max_days=45,
        allow_billing_period_overshoot=True,
        n_days_billing_period_overshoot=45,
        ignore_billing_period_gap_for_day_count=True,
    )
    assert baseline_data.shape == (2, 1)
    assert round(baseline_data.value.sum(), 2) == 526.25
    assert len(warnings) == 0
Example #9
0
def test_get_baseline_data_end_gap(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    end = meter_data.index.max() + timedelta(days=1)
    baseline_data, warnings = get_baseline_data(meter_data,
                                                end=end,
                                                max_days=None)
    assert meter_data.shape == baseline_data.shape == (19417, 1)
    assert len(warnings) == 1
    warning = warnings[0]
    assert warning.qualified_name == "eemeter.get_baseline_data.gap_at_baseline_end"
    assert (warning.description ==
            "Data does not have coverage at requested baseline end date.")
    assert warning.data == {
        "data_end": "2018-02-08T06:00:00+00:00",
        "requested_end": "2018-02-09T06:00:00+00:00",
    }
Example #10
0
def test_get_baseline_data_too_far_from_date(
        il_electricity_cdd_hdd_billing_monthly):
    meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
    end_date = datetime(2020, 11, 9, tzinfo=pytz.UTC)
    max_days = 45
    baseline_data, warnings = get_baseline_data(
        meter_data,
        end=end_date,
        max_days=max_days,
        ignore_billing_period_gap_for_day_count=True,
    )
    assert baseline_data.shape == (2, 1)
    assert round(baseline_data.value.sum(), 2) == 1393.4
    assert len(warnings) == 0
    with pytest.raises(NoBaselineDataError):
        get_baseline_data(
            meter_data,
            end=end_date,
            max_days=max_days,
            n_days_billing_period_overshoot=45,
            ignore_billing_period_gap_for_day_count=True,
        )
    baseline_data, warnings = get_baseline_data(
        meter_data,
        end=end_date,
        max_days=max_days,
        allow_billing_period_overshoot=True,
        ignore_billing_period_gap_for_day_count=True,
    )
    assert baseline_data.shape == (3, 1)
    assert round(baseline_data.value.sum(), 2) == 2043.92
    assert len(warnings) == 0
    # Includes 3 data points because data at index -3 is closer to start target
    # then data at index -2
    start_target = baseline_data.index[-1] - timedelta(days=max_days)
    assert abs((baseline_data.index[0] - start_target).days) < abs(
        (baseline_data.index[1] - start_target).days)
    with pytest.raises(NoBaselineDataError):
        get_baseline_data(
            meter_data,
            end=end_date,
            max_days=max_days,
            allow_billing_period_overshoot=True,
            n_days_billing_period_overshoot=45,
            ignore_billing_period_gap_for_day_count=True,
        )
Example #11
0
def test_get_baseline_data_empty(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    blackout_start_date = il_electricity_cdd_hdd_hourly["blackout_start_date"]
    with pytest.raises(NoBaselineDataError):
        get_baseline_data(meter_data,
                          end=pd.Timestamp("2000").tz_localize("UTC"))
Example #12
0
def test_get_baseline_data(il_electricity_cdd_hdd_hourly):
    meter_data = il_electricity_cdd_hdd_hourly["meter_data"]
    baseline_data, warnings = get_baseline_data(meter_data)
    assert meter_data.shape == baseline_data.shape == (19417, 1)
    assert len(warnings) == 0