Skip to content

Commit

Permalink
removing separate zones_fpath input, other minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgleason committed Jan 20, 2025
1 parent 5de7124 commit ae8a911
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 62 deletions.
10 changes: 5 additions & 5 deletions reV/supply_curve/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ def _get_gid_inclusion_mask(
return gid_inclusions

@staticmethod
def _get_gid_zones(zones_fpath, zones_dset, gid, slice_lookup):
def _get_gid_zones(excl_fpath, zones_dset, gid, slice_lookup):
"""
Get zones 2D array for desired gid.
Parameters
----------
zones_fpath : str | None, optional
excl_fpath : str | None, optional
Filepath to HDF5 file containing `zones_dset`. If not specified,
output of function will be an array containing all values equal to
1.
Expand All @@ -466,12 +466,12 @@ def _get_gid_zones(zones_fpath, zones_dset, gid, slice_lookup):
"""

row_slice, col_slice = slice_lookup[gid]
if zones_fpath is not None and zones_dset is not None:
with ExclusionLayers(zones_fpath) as fh:
if excl_fpath is not None and zones_dset is not None:
with ExclusionLayers(excl_fpath) as fh:
if zones_dset not in fh:
msg = (
f"Could not find zones_dset {zones_dset} in "
f"zones_fpath {zones_fpath}."
f"zones_fpath {excl_fpath}."
)
logger.error(msg)
raise FileInputError(msg)
Expand Down
8 changes: 4 additions & 4 deletions reV/supply_curve/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,11 @@ def zone_mask(self):

if self._zone_mask is None:
return None
else:
out_of_extent = self._gids.reshape(self._zone_mask.shape) == -1
self._zone_mask[out_of_extent] = 0.0

return self._zone_mask
out_of_extent = self._gids.reshape(self._zone_mask.shape) == -1
self._zone_mask[out_of_extent] = 0.0

return self._zone_mask

@property
def include_mask(self):
Expand Down
65 changes: 13 additions & 52 deletions reV/supply_curve/sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ def __init__(self, excl_fpath, tm_dset, econ_fpath=None,
res_class_bins=None, cf_dset='cf_mean-means',
lcoe_dset='lcoe_fcr-means', h5_dsets=None, data_layers=None,
power_density=None, friction_fpath=None, friction_dset=None,
cap_cost_scale=None, recalc_lcoe=True, zones_fpath=None,
zones_dset=None):
cap_cost_scale=None, recalc_lcoe=True, zones_dset=None):
r"""ReV supply curve points aggregation framework.
``reV`` supply curve aggregation combines a high-resolution
Expand Down Expand Up @@ -544,22 +543,12 @@ def __init__(self, excl_fpath, tm_dset, econ_fpath=None,
generation HDF5 output, or if `recalc_lcoe` is set to
``False``, the mean LCOE will be computed from the data
stored under the `lcoe_dset` instead. By default, ``True``.
zones_fpath : str, optional
Filepath to HDF5 file containing `zones_dset`. If both
`zones_fpath` and `zones_dset` are specified, supply curve
aggregation will be applied separately for each zone within each
supply curve site. This file should match the format of a typical
exclusions HDF5 file. If specified without zones_dset, a warning
will be logged.
zones_dset: str, optoinal
Dataset name in the `zones_fpath` file containing the zones to be
applied. This data layer should consist of unique integer values
for each zone, and should be consistent in shape with datasets in
`excl_fpath`. Values of zero will be treated as no data /ignored.
If both `zones_fpath` and `zones_dset` are specified, supply curve
aggregation will be applied separately for each zone within each
supply curve site. If specified without `zones_fpath`, a warning
will be logged.
Dataset name in `excl_fpath` containing the zones to be applied.
This data layer should consist of unique integer values for each
zone. Values of zero will be treated as no data /ignored. If
`zones_dset` is provided, supply curve aggregation will be applied
separately for each zone within each supply curve site.
Examples
--------
Expand Down Expand Up @@ -724,7 +713,6 @@ def __init__(self, excl_fpath, tm_dset, econ_fpath=None,
self._friction_dset = friction_dset
self._data_layers = data_layers
self._recalc_lcoe = recalc_lcoe
self._zones_fpath = zones_fpath
self._zones_dset = zones_dset

logger.debug("Resource class bins: {}".format(self._res_class_bins))
Expand All @@ -739,22 +727,6 @@ def __init__(self, excl_fpath, tm_dset, econ_fpath=None,
logger.warning(msg)
warn(msg, InputWarning)

if self._zones_fpath is not None and self._zones_dset is None:
msg = (
"zones_fpath specified without zones_dset. Supply curve "
"aggregation will be performed without zones."
)
logger.warning(msg)
warn(msg, InputWarning)

if self._zones_dset is not None and self._zones_fpath is None:
msg = (
"_zones_dset specified without _zones_fpath. Supply curve "
"aggregation will be performed without zones."
)
logger.warning(msg)
warn(msg, InputWarning)

self._check_data_layers()

def _check_data_layers(
Expand Down Expand Up @@ -984,7 +956,6 @@ def run_serial(
excl_area=None,
cap_cost_scale=None,
recalc_lcoe=True,
zones_fpath=None,
zones_dset=None,
):
"""Standalone method to create agg summary - can be parallelized.
Expand Down Expand Up @@ -1079,20 +1050,12 @@ def run_serial(
datasets to be aggregated in the h5_dsets input: system_capacity,
fixed_charge_rate, capital_cost, fixed_operating_cost,
and variable_operating_cost.
zones_fpath : str | None, optional
Filepath to HDF5 file containing `zones_dset`. If both
`zones_fpath` and `zones_dset` are specified, supply curve
aggregation will be applied separately for each zone within each
supply curve site. This file should match the format of a typical
exclusions HDF5 file.
zones_dset: str | None, optional
Dataset name in the `zones_fpath` file containing the zones to be
applied. This data layer should consist of unique integer values
for each zone, and should be consistent in shape with datasets in
`excl_fpath`. Values of zero will be treated as no data /ignored.
Ifboth `zones_fpath` and `zones_dset` are specified, supply curve
aggregation will be applied separately for each zone within each
supply curve site.
zones_dset: str, optoinal
Dataset name in `excl_fpath` containing the zones to be applied.
This data layer should consist of unique integer values for each
zone. Values of zero will be treated as no data /ignored. If
`zones_dset` is provided, supply curve aggregation will be applied
separately for each zone within each supply curve site.
Returns
-------
Expand Down Expand Up @@ -1144,7 +1107,7 @@ def run_serial(
)

zones = cls._get_gid_zones(
zones_fpath, zones_dset, gid, slice_lookup
excl_fpath, zones_dset, gid, slice_lookup
)
zone_ids = np.unique(zones).tolist()

Expand Down Expand Up @@ -1288,7 +1251,6 @@ def run_parallel(
excl_area=self._excl_area,
cap_cost_scale=self._cap_cost_scale,
recalc_lcoe=self._recalc_lcoe,
zones_fpath=self._zones_fpath,
zones_dset=self._zones_dset,
)
)
Expand Down Expand Up @@ -1428,7 +1390,6 @@ def summarize(
excl_area=self._excl_area,
cap_cost_scale=self._cap_cost_scale,
recalc_lcoe=self._recalc_lcoe,
zones_fpath=self._zones_fpath,
zones_dset=self._zones_dset,
)
else:
Expand Down
1 change: 0 additions & 1 deletion tests/test_supply_curve_sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ def test_agg_zones(zone_config):
excl_dict=EXCL_DICT,
res_class_dset=RES_CLASS_DSET,
res_class_bins=RES_CLASS_BINS,
zones_fpath=excl_temp,
zones_dset=test_dset,
resolution=resolution,
gids=gids,
Expand Down

0 comments on commit ae8a911

Please sign in to comment.