Skip to content

Commit

Permalink
adding new test case for test_agg_zones, related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgleason committed Jan 20, 2025
1 parent ef05599 commit 9d36e5f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion reV/supply_curve/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __init__(
assert inclusion_mask.size == len(self._gids), msg
self._incl_mask = inclusion_mask.copy()

self._zone_mask = zone_mask
self._zone_mask = zone_mask.copy()
self._check_zone_mask()

self._centroid = None
Expand Down
2 changes: 1 addition & 1 deletion reV/supply_curve/sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ def run_serial(
zones = cls._get_gid_zones(
excl_fpath, zones_dset, gid, slice_lookup
)
zone_ids = np.unique(zones).tolist()
zone_ids = np.unique(zones[zones != 0]).tolist()

for ri, res_bin in enumerate(res_class_bins):
for zone_id in zone_ids:
Expand Down
4 changes: 4 additions & 0 deletions tests/data/sc_out/baseline_agg_summary_zones_one_partial.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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.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
2,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
43 changes: 34 additions & 9 deletions tests/test_supply_curve_sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,12 +712,15 @@ 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"])
@pytest.mark.parametrize("zone_config", [
"one_full",
"one_partial",
])
def test_agg_zones(zone_config):
"""Test sc aggregation with zones within each sc site."""
# TODO: other test permutations:
# multiple zone configurations:
# single zone (full), single zone (one_partial) 2 zones (two), 3 zones
# single zone (one_partial) 2 zones (two), 3 zones
# (four)?
# run parallel, run serial, run with inclusion mask
# separate test for running via cli
Expand All @@ -741,16 +744,36 @@ def test_agg_zones(zone_config):
attrs["profile"] = json.dumps(profile)
data = np.zeros(shape, dtype=np.uint32)
if zone_config == "one_full":
# each supply curve cell is a single zone, where the zone ID is
# 10 + the gid
for gid, gid_slice in slice_lookup.items():
data[gid_slice] = gid + 10
# use the standard test dataset
baseline = AGG_BASELINE
excl_dict = EXCL_DICT.copy()
res_class_bins = RES_CLASS_BINS
apply_legacy_remap = True
else:
raise NotImplementedError(
"Test for zone_config {zone_config} not yet implemented"
excl_dict = {
k: v for k, v in EXCL_DICT.items() if k == "ri_srtm_slope"
}
res_class_bins = None
baseline = os.path.join(
TESTDATADIR,
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)
zone_cols = slice(gid_cols.stop - 4, gid_cols.stop)
data[(zone_rows, zone_cols)] = gid + 10

test_dset = "parcels"
f.create_dataset(test_dset, shape, data=data)
for k, v in attrs.items():
Expand All @@ -759,17 +782,19 @@ def test_agg_zones(zone_config):
sca = SupplyCurveAggregation(
excl_temp,
TM_DSET,
excl_dict=EXCL_DICT,
excl_dict=excl_dict,
res_class_dset=RES_CLASS_DSET,
res_class_bins=RES_CLASS_BINS,
res_class_bins=res_class_bins,
zones_dset=test_dset,
resolution=resolution,
power_density=36.0,
gids=gids,
)
summary = sca.summarize(GEN)

s_baseline = pd.read_csv(baseline)
s_baseline = s_baseline.rename(columns=LEGACY_SC_COL_MAP)
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)
Expand Down

0 comments on commit 9d36e5f

Please sign in to comment.