|
| 1 | +## Switchbox |
| 2 | +## 2025-08-25 |
| 3 | + |
| 4 | +import numpy as np |
| 5 | +import polars as pl |
| 6 | +from polars.testing import assert_frame_equal |
| 7 | + |
| 8 | +from src.npa_howtopay.capex_project import ( |
| 9 | + compute_depreciation_expense_from_capex_projects, |
| 10 | + compute_ratebase_from_capex_projects, |
| 11 | + get_grid_upgrade_capex_projects, |
| 12 | + get_lpp_gas_capex_projects, |
| 13 | + get_non_lpp_gas_capex_projects, |
| 14 | + get_non_npa_electric_capex_projects, |
| 15 | + get_npa_capex_projects, |
| 16 | + get_synthetic_initial_capex_projects, |
| 17 | +) |
| 18 | + |
| 19 | + |
| 20 | +def test_get_synthetic_initial_capex_projects(): |
| 21 | + # 3000 * (1 + 2/3 + 1/3) = 6000 |
| 22 | + df = get_synthetic_initial_capex_projects(start_year=2025, initial_ratebase=6000, depreciation_lifetime=3) |
| 23 | + ref_df = pl.DataFrame({ |
| 24 | + "project_year": [2023, 2024, 2025], |
| 25 | + "original_cost": [3000, 3000, 3000], |
| 26 | + "depreciation_lifetime": [3, 3, 3], |
| 27 | + }) |
| 28 | + print(df) |
| 29 | + print(ref_df) |
| 30 | + assert_frame_equal(ref_df, df, check_dtypes=False) |
| 31 | + |
| 32 | + |
| 33 | +def test_get_non_lpp_gas_capex_projects(): |
| 34 | + df = get_non_lpp_gas_capex_projects( |
| 35 | + year=2025, current_ratebase=1000, baseline_non_lpp_gas_ratebase_growth=0.015, depreciation_lifetime=60 |
| 36 | + ) |
| 37 | + ref_df = pl.DataFrame({ |
| 38 | + "project_year": [2025], |
| 39 | + "original_cost": [15], |
| 40 | + "depreciation_lifetime": [60], |
| 41 | + }) |
| 42 | + assert_frame_equal(ref_df, df, check_dtypes=False) |
| 43 | + |
| 44 | + |
| 45 | +def test_get_non_npa_electric_capex_projects(): |
| 46 | + df = get_non_npa_electric_capex_projects( |
| 47 | + year=2025, current_ratebase=1000, baseline_electric_ratebase_growth=0.03, depreciation_lifetime=60 |
| 48 | + ) |
| 49 | + ref_df = pl.DataFrame({ |
| 50 | + "project_year": [2025], |
| 51 | + "original_cost": [30], |
| 52 | + "depreciation_lifetime": [60], |
| 53 | + }) |
| 54 | + assert_frame_equal(ref_df, df, check_dtypes=False) |
| 55 | + |
| 56 | + |
| 57 | +## NPA TESTS |
| 58 | +npas_this_year = pl.DataFrame({ |
| 59 | + "year": [2025, 2025, 2025], |
| 60 | + "num_converts": [10, 20, 5], # 35 total |
| 61 | + "pipe_value_per_user": [1000, 100, 3000], # $27_000 total |
| 62 | + "pipe_decomm_cost_per_user": [100, 200, 100], # 5_500; does not affect capex? |
| 63 | + "peak_kw_winter_headroom": [10, 100, 1], |
| 64 | + "peak_kw_summer_headroom": [10, 1, 10], |
| 65 | + "aircon_percent_adoption_pre_npa": [0.2, 0.8, 0.8], |
| 66 | +}) |
| 67 | + |
| 68 | + |
| 69 | +def test_get_lpp_gas_capex_projects(): |
| 70 | + lpp_costs_standard = pl.DataFrame({ |
| 71 | + "year": [2025, 2025, 2026], |
| 72 | + "cost": [30000, 20000, 30000], # 50k in 2025 |
| 73 | + }) |
| 74 | + df = get_lpp_gas_capex_projects( |
| 75 | + year=2025, |
| 76 | + gas_bau_lpp_costs_per_year=lpp_costs_standard, |
| 77 | + npas_this_year=npas_this_year, |
| 78 | + depreciation_lifetime=60, |
| 79 | + ) |
| 80 | + ref_df = pl.DataFrame({ |
| 81 | + "project_year": [2025], |
| 82 | + "original_cost": [23000], |
| 83 | + "depreciation_lifetime": [60], |
| 84 | + }) |
| 85 | + assert_frame_equal(ref_df, df, check_dtypes=False) |
| 86 | + |
| 87 | + # test zero bound |
| 88 | + lpp_costs_small = pl.DataFrame({ |
| 89 | + "year": [2025, 2025, 2026], |
| 90 | + "cost": [100, 200, 300], # 300 in 2025 |
| 91 | + }) |
| 92 | + df_zero = get_lpp_gas_capex_projects( |
| 93 | + year=2025, gas_bau_lpp_costs_per_year=lpp_costs_small, npas_this_year=npas_this_year, depreciation_lifetime=60 |
| 94 | + ) |
| 95 | + assert df_zero.is_empty() |
| 96 | + |
| 97 | + |
| 98 | +def test_get_grid_upgrade_capex_projects(): |
| 99 | + df = get_grid_upgrade_capex_projects( |
| 100 | + year=2025, |
| 101 | + npas_this_year=npas_this_year, |
| 102 | + peak_hp_kw=2, |
| 103 | + peak_aircon_kw=3, |
| 104 | + distribution_cost_per_peak_kw_increase=1000, |
| 105 | + grid_upgrade_depreciation_lifetime=30, |
| 106 | + ) |
| 107 | + ref_df = pl.DataFrame({ |
| 108 | + "project_year": [2025], |
| 109 | + "original_cost": [34000], # three projects increase peak_kw by 14, 11, 9 |
| 110 | + "depreciation_lifetime": [30], |
| 111 | + }) |
| 112 | + assert_frame_equal(ref_df, df, check_dtypes=False) |
| 113 | + |
| 114 | + |
| 115 | +def test_get_npa_capex_projects(): |
| 116 | + df = get_npa_capex_projects(year=2025, npas_this_year=npas_this_year, npa_install_cost=1000, npa_lifetime=10) |
| 117 | + ref_df = pl.DataFrame({ |
| 118 | + "project_year": [2025], |
| 119 | + "original_cost": [35000], |
| 120 | + "depreciation_lifetime": [10], |
| 121 | + }) |
| 122 | + assert_frame_equal(ref_df, df, check_dtypes=False) |
| 123 | + |
| 124 | + |
| 125 | +## COMPUTE TESTS |
| 126 | +capex_df = pl.DataFrame({ |
| 127 | + "project_year": [2025, 2026, 2027], |
| 128 | + "original_cost": [1000, 1000, 1000], |
| 129 | + "depreciation_lifetime": [10, 20, 10], |
| 130 | +}) |
| 131 | + |
| 132 | + |
| 133 | +def test_compute_ratebase_from_capex_projects(): |
| 134 | + ratebases = [compute_ratebase_from_capex_projects(year, capex_df) for year in [2025, 2026, 2027, 2028, 2045, 2046]] |
| 135 | + assert np.isclose(ratebases, [1000, 1900, 2750, 2500, 50, 0]).all() |
| 136 | + |
| 137 | + |
| 138 | +def test_compute_depreciation_expense_from_capex_projects(): |
| 139 | + depreciations = [ |
| 140 | + compute_depreciation_expense_from_capex_projects(year, capex_df) |
| 141 | + for year in [2025, 2026, 2027, 2028, 2045, 2046, 2047] |
| 142 | + ] |
| 143 | + assert np.isclose(depreciations, [0, 100, 150, 250, 50, 50, 0]).all() |
0 commit comments