Skip to content

Commit

Permalink
adding more test cases to test_agg_zones
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgleason committed Jan 20, 2025
1 parent 9d36e5f commit 7fe9236
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 42 deletions.
7 changes: 7 additions & 0 deletions tests/data/sc_out/baseline_agg_summary_zones_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sc_gid,latitude,longitude,country,state,county,elevation_m,timezone,sc_point_gid,sc_row_ind,sc_col_ind,res_gids,gen_gids,gid_counts,n_gids,offshore,capacity_factor_ac,capacity_factor_dc,lcoe_site_usd_per_mwh,resource,area_developable_sq_km,capacity_ac_mw,capacity_dc_mw,multiplier_cc_eos,multiplier_cc_regional,annual_energy_site_mwh,cost_site_occ_usd_per_ac_mw,cost_base_occ_usd_per_ac_mw,cost_site_foc_usd_per_ac_mw,cost_base_foc_usd_per_ac_mw,cost_site_voc_usd_per_ac_mw,cost_base_voc_usd_per_ac_mw,fixed_charge_rate,res_class,zone_id
0,41.99292076811808,-71.80788736558492,United States,Rhode Island,Providence,194.64,-5,1,0,1,[1316631],[7],[12.0],12,,0.12399998,,124.00283,3.9910002,0.0972,3.4991999999999996,,1,1,3800.970489114761,,,,,,,0,0,11
1,41.99292076811808,-71.80788736558492,United States,Rhode Island,Providence,194.64,-5,1,0,1,[1316631],[7],[13.0],13,,0.12399998,,124.00282,3.9910002,0.10529999999999999,3.7907999999999995,,1,1,4117.718029874324,,,,,,,0,0,21
2,41.993086159675855,-71.73837273978268,United States,Rhode Island,Providence,135.3,-5,2,0,2,[1318507],[40],[14.0],14,,0.123999976,,123.88893,4.001,0.1134,4.0824,,1,1,4434.465304187536,,,,,,,0,0,12
3,41.993086159675855,-71.73837273978268,United States,Rhode Island,Providence,135.3,-5,2,0,2,[1318507],[40],[14.0],14,,0.123999976,,123.88893,4.001,0.1134,4.0824,,1,1,4434.465304187536,,,,,,,0,0,22
4,41.993209457643076,-71.66885760530704,United States,Rhode Island,Providence,116.0,-5,3,0,3,[1321872],[76],[6.0],6,,0.124000005,,123.658875,4.0159993,0.0486,1.7495999999999998,,1,1,1900.4855871312616,,,,,,,0,0,13
5,41.993209457643076,-71.66885760530704,United States,Rhode Island,Providence,116.0,-5,3,0,3,[1321872],[76],[1.0],1,,0.124,,123.658875,4.016,0.0081,0.29159999999999997,,1,1,316.747578823328,,,,,,,0,0,23
10 changes: 10 additions & 0 deletions tests/data/sc_out/baseline_agg_summary_zones_3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sc_gid,latitude,longitude,country,state,county,elevation_m,timezone,sc_point_gid,sc_row_ind,sc_col_ind,res_gids,gen_gids,gid_counts,n_gids,offshore,capacity_factor_ac,capacity_factor_dc,lcoe_site_usd_per_mwh,resource,area_developable_sq_km,capacity_ac_mw,capacity_dc_mw,multiplier_cc_eos,multiplier_cc_regional,annual_energy_site_mwh,cost_site_occ_usd_per_ac_mw,cost_base_occ_usd_per_ac_mw,cost_site_foc_usd_per_ac_mw,cost_base_foc_usd_per_ac_mw,cost_site_voc_usd_per_ac_mw,cost_base_voc_usd_per_ac_mw,fixed_charge_rate,res_class,zone_id
0,41.99292076811808,-71.80788736558492,United States,Rhode Island,Providence,194.64,-5,1,0,1,[1316631],[7],[12.0],12,,0.12399998,,124.00283,3.9910002,0.0972,3.4991999999999996,,1,1,3800.970489114761,,,,,,,0,0,11
1,41.99292076811808,-71.80788736558492,United States,Rhode Island,Providence,194.64,-5,1,0,1,[1316631],[7],[13.0],13,,0.12399998,,124.00282,3.9910002,0.10529999999999999,3.7907999999999995,,1,1,4117.718029874324,,,,,,,0,0,21
2,41.99292076811808,-71.80788736558492,United States,Rhode Island,Providence,194.64,-5,1,0,1,[1316631],[7],[13.0],13,,0.12399998,,124.00282,3.9910002,0.10529999999999999,3.7907999999999995,,1,1,4117.718029874324,,,,,,,0,0,31
3,41.993086159675855,-71.73837273978268,United States,Rhode Island,Providence,135.3,-5,2,0,2,[1318507],[40],[14.0],14,,0.123999976,,123.88893,4.001,0.1134,4.0824,,1,1,4434.465304187536,,,,,,,0,0,12
4,41.993086159675855,-71.73837273978268,United States,Rhode Island,Providence,135.3,-5,2,0,2,[1318507],[40],[14.0],14,,0.123999976,,123.88893,4.001,0.1134,4.0824,,1,1,4434.465304187536,,,,,,,0,0,22
5,41.993086159675855,-71.73837273978268,United States,Rhode Island,Providence,135.3,-5,2,0,2,[1318507],[40],[11.0],11,,0.12399998,,123.88894,4.001,0.0891,3.2076,,1,1,3484.222948355198,,,,,,,0,0,32
6,41.993209457643076,-71.66885760530704,United States,Rhode Island,Providence,116.0,-5,3,0,3,[1321872],[76],[6.0],6,,0.124000005,,123.658875,4.0159993,0.0486,1.7495999999999998,,1,1,1900.4855871312616,,,,,,,0,0,13
7,41.993209457643076,-71.66885760530704,United States,Rhode Island,Providence,116.0,-5,3,0,3,[1321872],[76],[1.0],1,,0.124,,123.658875,4.016,0.0081,0.29159999999999997,,1,1,316.747578823328,,,,,,,0,0,23
8,41.993209457643076,-71.66885760530704,United States,Rhode Island,Providence,116.0,-5,3,0,3,[1321872],[76],[3.0],3,,0.12399999,,123.658875,4.016,0.0243,0.8747999999999999,,1,1,950.2426793743372,,,,,,,0,0,33
75 changes: 33 additions & 42 deletions tests/test_supply_curve_sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,19 +712,12 @@ def test_format_res_fpath_with_year_pattern():
assert _format_res_fpath(config) == {"res_fpath": tf.format(2010)}


@pytest.mark.parametrize("zone_config", [
"one_full",
"one_partial",
])
@pytest.mark.parametrize("zone_config", ["one_full", 1, 2, 3])
def test_agg_zones(zone_config):
"""Test sc aggregation with zones within each sc site."""
# TODO: other test permutations:
# multiple zone configurations:
# single zone (one_partial) 2 zones (two), 3 zones
# (four)?
# run parallel, run serial, run with inclusion mask
# separate test for running via cli
# test with only 1 or the other of the 2 inputs (should produce warnings)

resolution = 64
gids = [1, 2, 3]
Expand All @@ -744,6 +737,7 @@ def test_agg_zones(zone_config):
attrs["profile"] = json.dumps(profile)
data = np.zeros(shape, dtype=np.uint32)
if zone_config == "one_full":
# each entire cell is one zone
for gid, gid_slice in slice_lookup.items():
data[gid_slice] = gid + 10
# use the standard test dataset
Expand All @@ -761,18 +755,15 @@ def test_agg_zones(zone_config):
f"sc_out/baseline_agg_summary_zones_{zone_config}.csv"
)
apply_legacy_remap = False
if zone_config == "one_partial":
for gid, gid_slice in slice_lookup.items():
gid_rows, gid_cols = gid_slice
zone_rows = slice(gid_rows.stop - 4, gid_rows.stop)
zone_cols = slice(gid_cols.stop - 4, gid_cols.stop)
data[(zone_rows, zone_cols)] = gid + 10
elif zone_config == "two":
for gid, gid_slice in slice_lookup.items():
gid_rows, gid_cols = gid_slice
zone_rows = slice(gid_rows.stop - 4, gid_rows.stop)
for gid, gid_slice in slice_lookup.items():
gid_rows, gid_cols = gid_slice
for z in range(0, zone_config):
zone_rows = slice(
gid_rows.stop - (z + 1) * 4,
gid_rows.stop - z * 4
)
zone_cols = slice(gid_cols.stop - 4, gid_cols.stop)
data[(zone_rows, zone_cols)] = gid + 10
data[(zone_rows, zone_cols)] = gid + 10 * (z + 1)

test_dset = "parcels"
f.create_dataset(test_dset, shape, data=data)
Expand All @@ -792,31 +783,31 @@ def test_agg_zones(zone_config):
)
summary = sca.summarize(GEN)

s_baseline = pd.read_csv(baseline)
if apply_legacy_remap:
s_baseline = s_baseline.rename(columns=LEGACY_SC_COL_MAP)
s_baseline = s_baseline.set_index(s_baseline.columns[0])
s_baseline_subset = s_baseline[
s_baseline["sc_point_gid"].isin(gids)
].copy()
list_cols = ["res_gids", "gen_gids", "gid_counts"]
# convert columns containing lists of integers as strings to lists
# of integers
for list_col in list_cols:
s_baseline_subset[list_col] = s_baseline_subset[list_col].apply(
json.loads
)
s_baseline = pd.read_csv(baseline)
if apply_legacy_remap:
s_baseline = s_baseline.rename(columns=LEGACY_SC_COL_MAP)
s_baseline = s_baseline.set_index(s_baseline.columns[0])
s_baseline_subset = s_baseline[
s_baseline["sc_point_gid"].isin(gids)
].copy()
list_cols = ["res_gids", "gen_gids", "gid_counts"]
# convert columns containing lists of integers as strings to lists
# of integers
for list_col in list_cols:
s_baseline_subset[list_col] = s_baseline_subset[list_col].apply(
json.loads
)

summary = summary.fillna("None")
s_baseline_subset = s_baseline_subset.fillna("None")
summary = summary.fillna("None")
s_baseline_subset = s_baseline_subset.fillna("None")

compare_cols = list(
set(s_baseline_subset.columns).intersection(summary.columns)
)
assert_frame_equal(
summary[compare_cols],
s_baseline_subset[compare_cols], check_dtype=False, rtol=0.0001
)
compare_cols = list(
set(s_baseline_subset.columns).intersection(summary.columns)
)
assert_frame_equal(
summary[compare_cols],
s_baseline_subset[compare_cols], check_dtype=False, rtol=0.0001
)


def execute_pytest(capture="all", flags="-rapP"):
Expand Down

0 comments on commit 7fe9236

Please sign in to comment.