reV.supply_curve.aggregation.Aggregation

class Aggregation(excl_fpath, tm_dset, *agg_dset, excl_dict=None, area_filter_kernel='queen', min_area=None, resolution=64, excl_area=None, gids=None, pre_extract_inclusions=False)[source]

Bases: BaseAggregation

Concrete but generalized aggregation framework to aggregate ANY reV h5 file to a supply curve grid (based on an aggregated exclusion grid).

Parameters:
  • excl_fpath (str | list | tuple) – Filepath to exclusions h5 with techmap dataset (can be one or more filepaths).

  • tm_dset (str) – Dataset name in the techmap file containing the exclusions-to-resource mapping data.

  • agg_dset (str) – Dataset to aggreate, can supply multiple datasets. The datasets should be scalar values for each site. This method cannot aggregate timeseries data.

  • excl_dict (dict | None) – Dictionary of exclusion keyword arugments of the format {layer_dset_name: {kwarg: value}} where layer_dset_name is a dataset in the exclusion h5 file and kwarg is a keyword argument to the reV.supply_curve.exclusions.LayerMask class. by default None

  • area_filter_kernel (str, optional) – Contiguous area filter method to use on final exclusions mask, by default “queen”

  • min_area (float, optional) – Minimum required contiguous area filter in sq-km, by default None

  • resolution (int, optional) – SC resolution, must be input in combination with gid. Prefered option is to use the row/col slices to define the SC point instead, by default None

  • excl_area (float, optional) – Area of an exclusion pixel in km2. None will try to infer the area from the profile transform attribute in excl_fpath, by default None

  • gids (list, optional) – List of supply curve point gids to get summary for (can use to subset if running in parallel), or None for all gids in the SC extent, by default None

  • pre_extract_inclusions (bool, optional) – Optional flag to pre-extract/compute the inclusion mask from the provided excl_dict, by default False. Typically faster to compute the inclusion mask on the fly with parallel workers.

Methods

aggregate(h5_fpath[, agg_method, ...])

Aggregate with given agg_method

run(excl_fpath, h5_fpath, tm_dset, *agg_dset)

Get the supply curve points aggregation summary.

run_parallel(h5_fpath[, agg_method, ...])

Aggregate in parallel

run_serial(excl_fpath, h5_fpath, tm_dset, ...)

Standalone method to aggregate - can be parallelized.

save_agg_to_h5(h5_fpath, out_fpath, aggregation)

Save aggregated data to disc in .h5 format

Attributes

gids

1D array of supply curve point gids to aggregate

shape

Get the shape of the full exclusions raster.

classmethod run_serial(excl_fpath, h5_fpath, tm_dset, *agg_dset, agg_method='mean', excl_dict=None, inclusion_mask=None, area_filter_kernel='queen', min_area=None, resolution=64, excl_area=0.0081, gids=None, gen_index=None)[source]

Standalone method to aggregate - can be parallelized.

Parameters:
  • excl_fpath (str | list | tuple) – Filepath to exclusions h5 with techmap dataset (can be one or more filepaths).

  • h5_fpath (str) – Filepath to .h5 file to aggregate

  • tm_dset (str) – Dataset name in the techmap file containing the exclusions-to-resource mapping data.

  • agg_dset (str) – Dataset to aggreate, can supply multiple datasets. The datasets should be scalar values for each site. This method cannot aggregate timeseries data.

  • agg_method (str, optional) – Aggregation method, either mean or sum/aggregate, by default “mean”

  • excl_dict (dict | None) – Dictionary of exclusion keyword arugments of the format {layer_dset_name: {kwarg: value}} where layer_dset_name is a dataset in the exclusion h5 file and kwarg is a keyword argument to the reV.supply_curve.exclusions.LayerMask class. by default None

  • inclusion_mask (np.ndarray, optional) – 2D array pre-extracted inclusion mask where 1 is included and 0 is excluded. This must be either match the full exclusion shape or be a list of single-sc-point exclusion masks corresponding to the gids input, by default None

  • area_filter_kernel (str, optional) – Contiguous area filter method to use on final exclusions mask, by default “queen”

  • min_area (float, optional) – Minimum required contiguous area filter in sq-km, by default None

  • resolution (int, optional) – SC resolution, must be input in combination with gid. Prefered option is to use the row/col slices to define the SC point instead, by default 0.0081

  • excl_area (float, optional) – Area of an exclusion pixel in km2. None will try to infer the area from the profile transform attribute in excl_fpath, by default None

  • gids (list, optional) – List of supply curve point gids to get summary for (can use to subset if running in parallel), or None for all gids in the SC extent, by default None

  • gen_index (np.ndarray, optional) – Array of generation gids with array index equal to resource gid. Array value is -1 if the resource index was not used in the generation run, by default None

Returns:

agg_out (dict) – Aggregated values for each aggregation dataset

run_parallel(h5_fpath, agg_method='mean', excl_area=None, max_workers=None, sites_per_worker=100)[source]

Aggregate in parallel

Parameters:
  • h5_fpath (str) – Filepath to .h5 file to aggregate

  • agg_method (str, optional) – Aggregation method, either mean or sum/aggregate, by default “mean”

  • excl_area (float, optional) – Area of an exclusion cell (square km), by default None

  • max_workers (int, optional) – Number of cores to run summary on. None is all available cpus, by default None

  • sites_per_worker (int, optional) – Number of SC points to process on a single parallel worker, by default 100

Returns:

agg_out (dict) – Aggregated values for each aggregation dataset

aggregate(h5_fpath, agg_method='mean', max_workers=None, sites_per_worker=100)[source]

Aggregate with given agg_method

Parameters:
  • h5_fpath (str) – Filepath to .h5 file to aggregate

  • agg_method (str, optional) – Aggregation method, either mean or sum/aggregate, by default “mean”

  • max_workers (int, optional) – Number of cores to run summary on. None is all available cpus, by default None

  • sites_per_worker (int, optional) – Number of SC points to process on a single parallel worker, by default 100

Returns:

agg (dict) – Aggregated values for each aggregation dataset

property gids

1D array of supply curve point gids to aggregate

Returns:

ndarray

static save_agg_to_h5(h5_fpath, out_fpath, aggregation, config_file=None)[source]

Save aggregated data to disc in .h5 format

Parameters:
  • out_fpath (str) – Output .h5 file path

  • aggregation (dict) – Aggregated values for each aggregation dataset

  • config_file (str, optional) – Path to config file used for this aggregation run (if applicable). This is used to store information about the run in the output file attrs. By default, None.

property shape

Get the shape of the full exclusions raster.

Returns:

tuple

classmethod run(excl_fpath, h5_fpath, tm_dset, *agg_dset, excl_dict=None, area_filter_kernel='queen', min_area=None, resolution=64, excl_area=None, gids=None, pre_extract_inclusions=False, agg_method='mean', max_workers=None, sites_per_worker=100, out_fpath=None, config_file=None)[source]

Get the supply curve points aggregation summary.

Parameters:
  • excl_fpath (str | list | tuple) – Filepath to exclusions h5 with techmap dataset (can be one or more filepaths).

  • h5_fpath (str) – Filepath to .h5 file to aggregate

  • tm_dset (str) – Dataset name in the techmap file containing the exclusions-to-resource mapping data.

  • agg_dset (str) – Dataset to aggreate, can supply multiple datasets. The datasets should be scalar values for each site. This method cannot aggregate timeseries data.

  • excl_dict (dict | None) – Dictionary of exclusion keyword arugments of the format {layer_dset_name: {kwarg: value}} where layer_dset_name is a dataset in the exclusion h5 file and kwarg is a keyword argument to the reV.supply_curve.exclusions.LayerMask class. by default None

  • area_filter_kernel (str, optional) – Contiguous area filter method to use on final exclusions mask, by default “queen”

  • min_area (float, optional) – Minimum required contiguous area filter in sq-km, by default None

  • resolution (int, optional) – SC resolution, must be input in combination with gid. Prefered option is to use the row/col slices to define the SC point instead, by default None

  • excl_area (float, optional) – Area of an exclusion pixel in km2. None will try to infer the area from the profile transform attribute in excl_fpath, by default None

  • gids (list, optional) – List of supply curve point gids to get summary for (can use to subset if running in parallel), or None for all gids in the SC extent, by default None

  • pre_extract_inclusions (bool, optional) – Optional flag to pre-extract/compute the inclusion mask from the provided excl_dict, by default False. Typically faster to compute the inclusion mask on the fly with parallel workers.

  • agg_method (str, optional) – Aggregation method, either mean or sum/aggregate, by default “mean”

  • max_workers (int, optional) – Number of cores to run summary on. None is all available cpus, by default None

  • sites_per_worker (int, optional) – Number of SC points to process on a single parallel worker, by default 100

  • out_fpath (str, optional) – Output .h5 file path, by default None

  • config_file (str, optional) – Path to config file used for this aggregation run (if applicable). This is used to store information about the run in the output file attrs. By default, None.

Returns:

agg (dict) – Aggregated values for each aggregation dataset