Breakthrough-Energy / PreREISE

Generate input data for scenario framework
https://breakthrough-energy.github.io/docs/
MIT License
21 stars 28 forks source link

test: correct_cumsum values for all demand outputs #312

Open dmuldrew opened 2 years ago

dmuldrew commented 2 years ago

We currently have an integration test for the LDV Smart Charging function which has following assertion:

    correct_cumsum = np.array(
        [
            0.0,
            9796092.83844097,
            19198735.09458018,
            27636677.75177433,
            36032644.7281563,
            44112809.4024421,
            52256940.31259822,
            61077768.57472202,
        ]
    )

    np.testing.assert_allclose(demand.cumsum()[::1095], correct_cumsum)

which checks the cumulative sum of the demand values every 1095 hours within the year. Ideally these values would come from the Matlab code...

There are potentially 16 categories to test, for both immediate and smart charging cases:

  1. LDV, urban, for ranges of 100, 200, and 300 miles
  2. LDV, rural, for ranges of 100, 200, and 300 miles
  3. LDT, urban, for ranges of 100, 200, and 300 miles
  4. LDT, rural, for ranges of 100, 200, and 300 miles
  5. MDV, urban
  6. MDV, rural
  7. HDV, urban
  8. HDV, rural

Should we test for all 9 census divisions? That would mean an additional 8*12 = 96 tests, or 112 total. This seems excessive…

Really we just need to test the code for each type. Might be able to just do:

Immediate and smart charging:

  1. LDV, urban, pick one of the ranges
  2. LDV, rural, pick one of the ranges
  3. HDV, urban
  4. HDV, rural

Existing test parameters for immediate charging LDV:


    immediate_charging(
        census_region=1,
        model_year=2017,
        veh_range=100,
        kwhmi=0.242,
        power=6.6,
        location_strategy=2,
        veh_type="LDV",
        filepath=path_to_file,
    )

Existing test parameters for smart charging LDV:

    result = smart_charging.smart_charging(
        census_region=1,
        model_year=2017,
        veh_range=100,
        kwhmi=0.242,
        power=6.6,
        location_strategy=2,
        veh_type="LDV",
        filepath=path_to_file,
        daily_values=daily_values,
        load_demand=load_demand,
        trip_strategy=1,
    )

Example code for immediate case 3:

    result = immediate_charging_HDV.immediate_charging(
        model_year=2050,
        veh_range=200,
        power=80,
        location_strategy=1,
        veh_type="HDV",
        filepath=path_to_file,
        trip_strategy=1,
    )
    bev_vmt = load_urbanized_scaling_factor(
        model_year=2050,
        veh_type="HDV",
        veh_range=200,
        urbanized_area="Antioch",
        state="CA",
        filepath= path_to_file,
    )
    final_result = immediate_charging_HDV.adjust_bev(
        model_year=2050,
        veh_type="HDV",
        veh_range=200,
        model_year_profile=result,
        bev_vmt=bev_vmt,
        charging_efficiency=0.95,
    )
    correct_cumsum = np.array(
        [
            10.8255287099344,
            10458.16992,
            20964.88916,
            31443.09284,
            41900.81189,
            52407.05727,
            62866.27995,
            73352.53979,
        ],
    )

    np.testing.assert_allclose(final_result.cumsum()[::1095], correct_cumsum)

Example code for smart charging case 3:

    bev_vmt = data_helper.load_urbanized_scaling_factor(
        model_year=2050,
        veh_type="HDV",
        veh_range=200,
        urbanized_area="Antioch",
        state="CA",
        filepath=path_to_file,
    )
    result = smart_charging_HDV.smart_charging(
        model_year=2050,
        veh_range=200,
        power=80,
        location_strategy=1,
        veh_type="HDV",
        filepath=path_to_file,
        initial_load=load_demand,
        bev_vmt=bev_vmt,
        trip_strategy=1,
    )

    correct_cumsum = np.array(
        [
            1.22854177233283,
            4729.417063,
            9456.028814,
            14087.49171,
            18817.56654,
            23521.75604,
            28175.75066,
            32904.52077,
        ]
    )
   np.testing.assert_allclose(result.cumsum()[::1095], correct_cumsum)
keforres commented 1 year ago
LDV_Smart Census 1

2795.40526819163
5392399.00167295
10476301.8640339
15112876.5701284
19646567.5541691
23971230.6905578
28480964.7352026
33245787.2869580
keforres commented 1 year ago

Note on Dec 9: These test values are in part incorrect. See Kate's next post for corrected values. Note on Dec 12: Immediate cases are correct. Smart charging to be updated in next post.


MDV -immediate, normalized, not adjusted
range = 200
powerlevel = 80
kwhmi = 0.85
locationstrategy = 1

5.75406895274069e-05
0.124493640260117
0.249728376065088
0.375158317711785
0.499447656197848
0.624871556183613
0.749921475128377
0.874578195645712

MDV - immediate, normalized, adjusted, URBAN AREA
range = 200
powerlevel = 80
kwhmi = 0.85
locationstrategy = 1

4.12357418935908e-05
0.109119485255229
0.227155694790996
0.354838435249396
0.485843497579740
0.623447025360398
0.754675882948241
0.880227875083750

MDV - immediate, normalized, adjusted, RURAL AREA
range = 200
powerlevel = 80
kwhmi = 0.85
locationstrategy = 1

4.83373894430938e-05
0.109056306528193
0.227585966508714
0.354629377704698
0.486377285934617
0.623356984456343
0.754964504650831
0.880196237246907

MDV - Year 2050, UA Region: Anchorage, AK (VMT = 49301)
range = 200
powerlevel = 80
kwhmi = 0.85
locationstrategy = 1
chargingeff = 0.95

0.232000000000000
4158.07099999998
9691.93100000000
15209.3110000000
20709.2810000002
26245.5910000004
31735.8410000007
37261.3610000009
42795.4810000011

HDV - immediate, normalized, not adjusted
range = 200
powerlevel = 80
kwhmi = 1.64
locationstrategy = 1

0.000125864739011464
0.124751755908958
0.250071231889402
0.375073873954657
0.499802930111036
0.625118168914047
0.749898309798150
0.874972605413689

HDV - immediate, normalized, adjusted, URBAN AREA
range = 200
powerlevel = 80
kwhmi = 1.64
locationstrategy = 1

9.01992300406669e-05
0.109369792218885
0.227444470789743
0.354746182790468
0.486167436470722
0.623734609358925
0.754656238674532
0.880636796759769

HDV - immediate, normalized, adjusted, RURAL AREA
range = 200
powerlevel = 80
kwhmi = 1.64
locationstrategy = 1

0.000105733402861865
0.109293091238994
0.227921529565012
0.354541622474110
0.486754536043949
0.623630548981300
0.754941477226917
0.880584553873268

HDV - Year 2050, UA Region: Anchorage, AK (41419)
range = 200
powerlevel = 80
kwhmi = 1.64
locationstrategy = 1
chargingeff = 0.95

1.10000000000000
6837.87200000000
15796.5220000000
24716.9320000001
33658.3420000001
42605.4020000005
51514.7820000008
60473.7320000012
69410.0120000014

MDV - smart
range = 200
powerlevel = 80
kwhmi = 0.85
locationstrategy = 1

1008.90781623510
866022.148197912
1726819.55574606
2585068.80050497
3450185.13075542
4307686.09478324
5173551.88544357
6035272.46646403

HDV - smart
range = 200
powerlevel = 80
kwhmi = 1.64
locationstrategy = 1

1380.30981545918
1391857.50586238
2784877.62008721
4154503.88296593
5549228.04099581
6930893.73062316
8311924.87558323
9704099.91220240