From f5992ba2e6492fb2096209c0d89c67d5b058f644 Mon Sep 17 00:00:00 2001 From: ppinchuk Date: Mon, 10 Jun 2024 12:59:01 -0600 Subject: [PATCH] SC point gid, row and col inds, now part of standard output --- reV/bespoke/bespoke.py | 17 +++------ reV/supply_curve/points.py | 60 +++++++++++++++++++----------- reV/supply_curve/sc_aggregation.py | 6 --- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/reV/bespoke/bespoke.py b/reV/bespoke/bespoke.py index 907d51767..29f445e17 100644 --- a/reV/bespoke/bespoke.py +++ b/reV/bespoke/bespoke.py @@ -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], diff --git a/reV/supply_curve/points.py b/reV/supply_curve/points.py index a58933ba3..b024c255f 100644 --- a/reV/supply_curve/points.py +++ b/reV/supply_curve/points.py @@ -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): @@ -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): @@ -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""" @@ -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, @@ -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 ), @@ -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 diff --git a/reV/supply_curve/sc_aggregation.py b/reV/supply_curve/sc_aggregation.py index ef6274a02..1dd3ae774 100644 --- a/reV/supply_curve/sc_aggregation.py +++ b/reV/supply_curve/sc_aggregation.py @@ -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) @@ -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)