Skip to content

Commit

Permalink
Used python formatter to format code
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Suffian <[email protected]>
  • Loading branch information
ssuffian committed Feb 4, 2023
1 parent 69aa541 commit 819817d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 50 deletions.
1 change: 0 additions & 1 deletion eemeter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def cli():
def _get_data(
sample, meter_file, temperature_file, heating_balance_points, cooling_balance_points
):

if sample is not None:
with resource_stream("eemeter.samples", "metadata.json") as f:
metadata = json.loads(f.read().decode("utf-8"))
Expand Down
8 changes: 4 additions & 4 deletions eemeter/derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _compute_ols_error(
):
ols_model_agg_error = (
(t_stat * rmse_base_residuals * post_obs)
/ (base_obs ** 0.5)
/ (base_obs**0.5)
* (1.0 + ((base_avg - post_avg) ** 2.0 / base_var)) ** 0.5
)

Expand All @@ -46,7 +46,7 @@ def _compute_ols_error(
)

ols_total_agg_error = (
ols_model_agg_error ** 2.0 + ols_noise_agg_error ** 2.0
ols_model_agg_error**2.0 + ols_noise_agg_error**2.0
) ** 0.5

return ols_total_agg_error, ols_model_agg_error, ols_noise_agg_error
Expand Down Expand Up @@ -75,7 +75,7 @@ def _compute_fsu_error(

fsu_error_band = total_base_energy * (
t_stat
* (a_coeff * months_reporting ** 2.0 + b_coeff * months_reporting + c_coeff)
* (a_coeff * months_reporting**2.0 + b_coeff * months_reporting + c_coeff)
* (rmse_base_residuals / base_avg)
* ((base_obs / nprime) * (1.0 + (2.0 / nprime)) * (1.0 / post_obs)) ** 0.5
)
Expand Down Expand Up @@ -372,7 +372,7 @@ def _compute_error_bands_modeled_savings(
"FSU Error Band: Baseline": fsu_error_band_baseline,
"FSU Error Band: Reporting": fsu_error_band_reporting,
"FSU Error Band": (
fsu_error_band_baseline ** 2.0 + fsu_error_band_reporting ** 2.0
fsu_error_band_baseline**2.0 + fsu_error_band_reporting**2.0
)
** 0.5,
}
Expand Down
3 changes: 0 additions & 3 deletions eemeter/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def _compute_columns(temps):
def _compute_columns(temps):
count = temps.shape[0]
if count > 24:

day_groups = np.floor(np.arange(count) / 24)
daily_temps = temps.groupby(day_groups).agg(["mean", "count"])
n_limit_period = percent_hourly_coverage_per_billing_period * count
Expand Down Expand Up @@ -267,7 +266,6 @@ def _compute_columns(temps):
for bp in heating_balance_points
}
else: # faster route for daily case, should have same effect.

if count > n_limit_daily:
count_cols = {"n_days_kept": 1, "n_days_dropped": 0}
# CalTRACK 2.2.2.3
Expand Down Expand Up @@ -833,7 +831,6 @@ def compute_temperature_bin_features(temperatures, bin_endpoints):
bins = {}

for i, (left_bin, right_bin) in enumerate(zip(bin_endpoints, bin_endpoints[1:])):

bin_name = "bin_{}".format(i)

in_bin = (temperatures > left_bin) & (temperatures <= right_bin)
Expand Down
23 changes: 12 additions & 11 deletions eemeter/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,10 @@ def __init__(
or self.degrees_of_freedom < 1
or self.observed_length < self.num_parameters
):

self.cvrmse_auto_corr_correction = None
self.approx_factor_auto_corr_correction = None
self.fsu_base_term = None
else:

# factor to correct cvrmse_adj for autocorrelation of inputs
# i.e., divide by (n' - n_param) instead of by (n - n_param)
self.cvrmse_auto_corr_correction = (
Expand All @@ -411,15 +409,18 @@ def __init__(
)

def __repr__(self):
return "ModelMetrics(merged_length={}, r_squared_adj={}, cvrmse_adj={}, " "mape_no_zeros={}, nmae={}, nmbe={}, autocorr_resid={}, confidence_level={})".format(
self.merged_length,
round(self.r_squared_adj, 3),
round(self.cvrmse_adj, 3),
round(self.mape_no_zeros, 3),
round(self.nmae, 3),
round(self.nmbe, 3),
round(self.autocorr_resid, 3),
round(self.confidence_level, 3),
return (
"ModelMetrics(merged_length={}, r_squared_adj={}, cvrmse_adj={}, "
"mape_no_zeros={}, nmae={}, nmbe={}, autocorr_resid={}, confidence_level={})".format(
self.merged_length,
round(self.r_squared_adj, 3),
round(self.cvrmse_adj, 3),
round(self.mape_no_zeros, 3),
round(self.nmae, 3),
round(self.nmbe, 3),
round(self.autocorr_resid, 3),
round(self.confidence_level, 3),
)
)

def json(self):
Expand Down
14 changes: 8 additions & 6 deletions tests/test_caltrack_usage_per_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def cdd_hdd_h54_c67_billing_monthly_totals(il_electricity_cdd_hdd_billing_monthl


def test_caltrack_predict_design_matrix_input_avg_false_output_avg_true(
cdd_hdd_h54_c67_billing_monthly_totals
cdd_hdd_h54_c67_billing_monthly_totals,
):
data = cdd_hdd_h54_c67_billing_monthly_totals
prediction = _caltrack_predict_design_matrix(
Expand All @@ -694,7 +694,7 @@ def test_caltrack_predict_design_matrix_input_avg_false_output_avg_true(


def test_caltrack_predict_design_matrix_input_avg_false_output_avg_false(
cdd_hdd_h54_c67_billing_monthly_totals
cdd_hdd_h54_c67_billing_monthly_totals,
):
data = cdd_hdd_h54_c67_billing_monthly_totals
prediction = _caltrack_predict_design_matrix(
Expand Down Expand Up @@ -730,7 +730,7 @@ def cdd_hdd_h54_c67_billing_monthly_avgs(il_electricity_cdd_hdd_billing_monthly)


def test_caltrack_predict_design_matrix_input_avg_true_output_avg_false(
cdd_hdd_h54_c67_billing_monthly_avgs
cdd_hdd_h54_c67_billing_monthly_avgs,
):
data = cdd_hdd_h54_c67_billing_monthly_avgs
prediction = _caltrack_predict_design_matrix(
Expand All @@ -750,7 +750,7 @@ def test_caltrack_predict_design_matrix_input_avg_true_output_avg_false(


def test_caltrack_predict_design_matrix_input_avg_true_output_avg_true(
cdd_hdd_h54_c67_billing_monthly_avgs
cdd_hdd_h54_c67_billing_monthly_avgs,
):
data = cdd_hdd_h54_c67_billing_monthly_avgs
prediction = _caltrack_predict_design_matrix(
Expand Down Expand Up @@ -792,7 +792,7 @@ def test_caltrack_predict_design_matrix_n_days(cdd_hdd_h54_c67_billing_monthly_t


def test_caltrack_predict_design_matrix_no_days_fails(
cdd_hdd_h54_c67_billing_monthly_totals
cdd_hdd_h54_c67_billing_monthly_totals,
):
# This makes sure that the method fails if neither n_days nor
# a DatetimeIndex is available.
Expand Down Expand Up @@ -1443,7 +1443,9 @@ def test_select_best_candidate_ok(
assert best_candidate.r_squared_adj == 1


def test_select_best_candidate_none(candidate_model_disqualified,):
def test_select_best_candidate_none(
candidate_model_disqualified,
):
candidates = [candidate_model_disqualified]

best_candidate, warnings = select_best_candidate(candidates)
Expand Down
12 changes: 0 additions & 12 deletions tests/test_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def reporting_temperature_data():
def test_metered_savings_cdd_hdd_daily(
baseline_model_daily, reporting_meter_data_daily, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_daily, reporting_meter_data_daily, reporting_temperature_data
)
Expand Down Expand Up @@ -153,7 +152,6 @@ def reporting_meter_data_billing():
def test_metered_savings_cdd_hdd_billing(
baseline_model_billing, reporting_meter_data_billing, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_billing, reporting_meter_data_billing, reporting_temperature_data
)
Expand All @@ -174,7 +172,6 @@ def test_metered_savings_cdd_hdd_billing(
def test_metered_savings_cdd_hdd_billing_no_reporting_data(
baseline_model_billing, reporting_meter_data_billing, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_billing,
reporting_meter_data_billing[:0],
Expand All @@ -192,7 +189,6 @@ def test_metered_savings_cdd_hdd_billing_no_reporting_data(
def test_metered_savings_cdd_hdd_billing_single_record_reporting_data(
baseline_model_billing, reporting_meter_data_billing, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_billing,
reporting_meter_data_billing[:1],
Expand Down Expand Up @@ -232,7 +228,6 @@ def test_metered_savings_cdd_hdd_billing_single_record_baseline_data(
reporting_meter_data_billing,
reporting_temperature_data,
):

results, error_bands = metered_savings(
baseline_model_billing_single_record_baseline_data,
reporting_meter_data_billing,
Expand Down Expand Up @@ -265,7 +260,6 @@ def test_metered_savings_cdd_hdd_billing_reporting_data_wrong_timestamp(
reporting_meter_data_billing_wrong_timestamp,
reporting_temperature_data,
):

results, error_bands = metered_savings(
baseline_model_billing,
reporting_meter_data_billing_wrong_timestamp,
Expand All @@ -283,7 +277,6 @@ def test_metered_savings_cdd_hdd_billing_reporting_data_wrong_timestamp(
def test_metered_savings_cdd_hdd_daily_hourly_degree_days(
baseline_model_daily, reporting_meter_data_daily, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_daily, reporting_meter_data_daily, reporting_temperature_data
)
Expand All @@ -309,7 +302,6 @@ def test_metered_savings_cdd_hdd_no_params(
def test_metered_savings_cdd_hdd_daily_with_disaggregated(
baseline_model_daily, reporting_meter_data_daily, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_daily,
reporting_meter_data_daily,
Expand Down Expand Up @@ -547,7 +539,6 @@ def reporting_meter_data_hourly():
def test_metered_savings_cdd_hdd_hourly(
baseline_model_hourly, reporting_meter_data_hourly, reporting_temperature_data
):

results, error_bands = metered_savings(
baseline_model_hourly, reporting_meter_data_hourly, reporting_temperature_data
)
Expand Down Expand Up @@ -592,7 +583,6 @@ def normal_year_temperature_data():
def test_modeled_savings_cdd_hdd_billing(
baseline_model_billing, reporting_model_billing, normal_year_temperature_data
):

results, error_bands = modeled_savings(
baseline_model_billing,
reporting_model_billing,
Expand Down Expand Up @@ -624,7 +614,6 @@ def test_metered_savings_not_aligned_reporting_data(
reporting_meter_data_billing_not_aligned,
reporting_temperature_data,
):

results, error_bands = metered_savings(
baseline_model_billing,
reporting_meter_data_billing_not_aligned,
Expand Down Expand Up @@ -658,7 +647,6 @@ def test_metered_savings_model_single_record(
reporting_meter_data_billing,
reporting_temperature_data,
):

assert pd.isnull(baseline_model_billing_single_record.totals_metrics.autocorr_resid)

# simulating deserialization
Expand Down
20 changes: 12 additions & 8 deletions tests/test_json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def test_json_hourly():
)

# create a design matrix for occupancy and segmentation
preliminary_design_matrix = eemeter.create_caltrack_hourly_preliminary_design_matrix(
baseline_meter_data, temperature_data
preliminary_design_matrix = (
eemeter.create_caltrack_hourly_preliminary_design_matrix(
baseline_meter_data, temperature_data
)
)

# build 12 monthly models - each step from now on operates on each segment
Expand All @@ -110,12 +112,14 @@ def test_json_hourly():
)

# build a design matrix for each monthly segment
segmented_design_matrices = eemeter.create_caltrack_hourly_segmented_design_matrices(
preliminary_design_matrix,
segmentation,
occupancy_lookup,
occupied_temperature_bins,
unoccupied_temperature_bins,
segmented_design_matrices = (
eemeter.create_caltrack_hourly_segmented_design_matrices(
preliminary_design_matrix,
segmentation,
occupancy_lookup,
occupied_temperature_bins,
unoccupied_temperature_bins,
)
)

# build a CalTRACK hourly model
Expand Down
10 changes: 5 additions & 5 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def test_get_baseline_data_with_ignored_gap(il_electricity_cdd_hdd_billing_month


def test_get_baseline_data_with_overshoot_and_ignored_gap(
il_electricity_cdd_hdd_billing_monthly
il_electricity_cdd_hdd_billing_monthly,
):
meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
baseline_data, warnings = get_baseline_data(
Expand All @@ -335,7 +335,7 @@ def test_get_baseline_data_with_overshoot_and_ignored_gap(


def test_get_baseline_data_n_days_billing_period_overshoot(
il_electricity_cdd_hdd_billing_monthly
il_electricity_cdd_hdd_billing_monthly,
):
meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
baseline_data, warnings = get_baseline_data(
Expand Down Expand Up @@ -548,7 +548,7 @@ def test_get_reporting_data_with_ignored_gap(il_electricity_cdd_hdd_billing_mont


def test_get_reporting_data_with_overshoot_and_ignored_gap(
il_electricity_cdd_hdd_billing_monthly
il_electricity_cdd_hdd_billing_monthly,
):
meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
reporting_data, warnings = get_reporting_data(
Expand Down Expand Up @@ -792,7 +792,7 @@ def test_as_freq_hourly_to_daily_include_coverage(il_electricity_cdd_hdd_hourly)


def test_clean_caltrack_billing_daily_data_billing(
il_electricity_cdd_hdd_billing_monthly
il_electricity_cdd_hdd_billing_monthly,
):
meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
cleaned_data = clean_caltrack_billing_daily_data(meter_data, "billing_monthly")
Expand Down Expand Up @@ -848,7 +848,7 @@ def test_clean_caltrack_billing_data_estimated(il_electricity_cdd_hdd_billing_mo


def test_clean_caltrack_billing_data_uneven_datetimes(
il_electricity_cdd_hdd_billing_monthly
il_electricity_cdd_hdd_billing_monthly,
):
meter_data = il_electricity_cdd_hdd_billing_monthly["meter_data"]
too_short_meter_data = pd.concat(
Expand Down

0 comments on commit 819817d

Please sign in to comment.