Skip to content

Commit

Permalink
SC point gid, row and col inds, now part of standard output
Browse files Browse the repository at this point in the history
  • Loading branch information
ppinchuk committed Jun 10, 2024
1 parent e789492 commit f5992ba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
17 changes: 6 additions & 11 deletions reV/bespoke/bespoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,28 +838,23 @@ def meta(self):
[float(np.round(n, 1)) for n in self.sc_point.gid_counts]
)

with SupplyCurveExtent(
self.sc_point._excl_fpath, resolution=self.sc_point.resolution
) as sc:
row_ind, col_ind = sc.get_sc_row_col_ind(self.sc_point.gid)

self._meta = pd.DataFrame(
{
SupplyCurveField.SC_POINT_GID: self.sc_point.gid,
SupplyCurveField.SC_ROW_IND: row_ind,
SupplyCurveField.SC_COL_IND: col_ind,
SupplyCurveField.GID: self.sc_point.gid,
SupplyCurveField.LATITUDE: self.sc_point.latitude,
SupplyCurveField.LONGITUDE: self.sc_point.longitude,
SupplyCurveField.TIMEZONE: self.sc_point.timezone,
SupplyCurveField.COUNTRY: self.sc_point.country,
SupplyCurveField.STATE: self.sc_point.state,
SupplyCurveField.COUNTY: self.sc_point.county,
SupplyCurveField.ELEVATION: self.sc_point.elevation,
SupplyCurveField.OFFSHORE: self.sc_point.offshore,
SupplyCurveField.TIMEZONE: self.sc_point.timezone,
SupplyCurveField.SC_POINT_GID: self.sc_point.sc_point_gid,
SupplyCurveField.SC_ROW_IND: self.sc_point.sc_row_ind,
SupplyCurveField.SC_COL_IND: self.sc_point.sc_col_ind,
SupplyCurveField.RES_GIDS: res_gids,
SupplyCurveField.GID_COUNTS: gid_counts,
SupplyCurveField.N_GIDS: self.sc_point.n_gids,
SupplyCurveField.OFFSHORE: self.sc_point.offshore,
SupplyCurveField.GID: self.sc_point.gid,
SupplyCurveField.AREA_SQ_KM: self.sc_point.area,
},
index=[self.sc_point.gid],
Expand Down
60 changes: 38 additions & 22 deletions reV/supply_curve/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def __init__(self, gid, exclusion_shape, resolution=64):

self._gid = gid
self._resolution = resolution
self._rows, self._cols = self._parse_slices(
gid, resolution, exclusion_shape
)
self._rows = self._cols = self._sc_row_ind = self._sc_col_ind = None
self._parse_sc_row_col_ind(resolution, exclusion_shape)
self._parse_slices(resolution, exclusion_shape)

@staticmethod
def _ordered_unique(seq):
Expand All @@ -74,32 +74,33 @@ def _ordered_unique(seq):

return [x for x in seq if not (x in seen or seen.add(x))]

def _parse_slices(self, gid, resolution, exclusion_shape):
"""Parse inputs for the definition of this SC point.
def _parse_sc_row_col_ind(self, resolution, exclusion_shape):
"""Parse SC row and column index.
Parameters
----------
gid : int | None
gid for supply curve point to analyze.
resolution : int | None
SC resolution, must be input in combination with gid.
exclusion_shape : tuple
Shape of the exclusions extent (rows, cols). Inputing this will
speed things up considerably.
Returns
-------
rows : slice
Row slice to index the high-res layer (exclusions) for the gid in
the agg layer (supply curve).
cols : slice
Col slice to index the high-res layer (exclusions) for the gid in
the agg layer (supply curve).
Shape of the exclusions extent (rows, cols).
"""
n_sc_cols = int(np.ceil(exclusion_shape[1] / resolution))

rows, cols = self.get_agg_slices(gid, exclusion_shape, resolution)
self._sc_row_ind = self._gid // n_sc_cols
self._sc_col_ind = self._gid % n_sc_cols

return rows, cols
def _parse_slices(self, resolution, exclusion_shape):
"""Parse row and column resource/generation grid slices.
Parameters
----------
resolution : int | None
SC resolution, must be input in combination with gid.
exclusion_shape : tuple
Shape of the exclusions extent (rows, cols).
"""
inds = self.get_agg_slices(self._gid, exclusion_shape, resolution)
self._rows, self._cols = inds

@property
def gid(self):
Expand All @@ -117,6 +118,16 @@ def sc_point_gid(self):
"""
return self._gid

@property
def sc_row_ind(self):
"""int: Supply curve row index"""
return self._sc_row_ind

@property
def sc_col_ind(self):
"""int: Supply curve column index"""
return self._sc_col_ind

@property
def resolution(self):
"""Get the supply curve grid aggregation resolution"""
Expand Down Expand Up @@ -1273,6 +1284,8 @@ def summary(self):
"""
meta = {
SupplyCurveField.SC_POINT_GID: self.sc_point_gid,
SupplyCurveField.SC_ROW_IND: self.sc_row_ind,
SupplyCurveField.SC_COL_IND: self.sc_col_ind,
SupplyCurveField.SOURCE_GIDS: self.h5_gid_set,
SupplyCurveField.GID_COUNTS: self.gid_counts,
SupplyCurveField.N_GIDS: self.n_gids,
Expand Down Expand Up @@ -2264,15 +2277,19 @@ def point_summary(self, args=None):
ARGS = {
SupplyCurveField.LATITUDE: self.latitude,
SupplyCurveField.LONGITUDE: self.longitude,
SupplyCurveField.TIMEZONE: self.timezone,
SupplyCurveField.COUNTRY: self.country,
SupplyCurveField.STATE: self.state,
SupplyCurveField.COUNTY: self.county,
SupplyCurveField.ELEVATION: self.elevation,
SupplyCurveField.TIMEZONE: self.timezone,
SupplyCurveField.SC_POINT_GID: self.sc_point_gid,
SupplyCurveField.SC_ROW_IND: self.sc_row_ind,
SupplyCurveField.SC_COL_IND: self.sc_col_ind,
SupplyCurveField.RES_GIDS: self.res_gid_set,
SupplyCurveField.GEN_GIDS: self.gen_gid_set,
SupplyCurveField.GID_COUNTS: self.gid_counts,
SupplyCurveField.N_GIDS: self.n_gids,
SupplyCurveField.OFFSHORE: self.offshore,
SupplyCurveField.MEAN_CF_AC: (
self.mean_cf if self.mean_cf_ac is None else self.mean_cf_ac
),
Expand All @@ -2287,7 +2304,6 @@ def point_summary(self, args=None):
}

extra_atts = {
SupplyCurveField.OFFSHORE: self.offshore,
SupplyCurveField.SC_POINT_CAPITAL_COST: self.sc_point_capital_cost,
SupplyCurveField.SC_POINT_FIXED_OPERATING_COST: (
self.sc_point_fixed_operating_cost
Expand Down
6 changes: 0 additions & 6 deletions reV/supply_curve/sc_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,6 @@ def run_serial(
summary = []

with SupplyCurveExtent(excl_fpath, resolution=resolution) as sc:
points = sc.points
exclusion_shape = sc.exclusions.shape
if gids is None:
gids = sc.valid_sc_points(tm_dset)
Expand Down Expand Up @@ -1147,11 +1146,6 @@ def run_serial(
except EmptySupplyCurvePointError:
logger.debug("SC point {} is empty".format(gid))
else:
pointsum[SupplyCurveField.SC_POINT_GID] = gid
pointsum[SupplyCurveField.SC_ROW_IND] = \
points.loc[gid, 'row_ind']
pointsum[SupplyCurveField.SC_COL_IND] = \
points.loc[gid, 'col_ind']
pointsum['res_class'] = ri

summary.append(pointsum)
Expand Down

0 comments on commit f5992ba

Please sign in to comment.