reV.generation.base.BaseGen

class BaseGen(points_control, output_request, site_data=None, drop_leap=False, memory_utilization_limit=0.4, scale_outputs=True)[source]

Bases: ABC

Base class for reV gen and econ classes to run SAM simulations.

Parameters:
  • points_control (reV.config.project_points.PointsControl) – Project points control instance for site and SAM config spec.

  • output_request (list | tuple) – Output variables requested from SAM.

  • site_data (str | pd.DataFrame | None) – Site-specific input data for SAM calculation. String should be a filepath that points to a csv, DataFrame is pre-extracted data. Rows match sites, columns are input keys. Need a “gid” column. Input as None if no site-specific data.

  • drop_leap (bool) – Drop leap day instead of final day of year during leap years.

  • memory_utilization_limit (float) – Memory utilization limit (fractional). This sets how many site results will be stored in-memory at any given time before flushing to disk.

  • scale_outputs (bool) – Flag to scale outputs in-place immediately upon Gen returning data.

Methods

add_site_data_to_pp(site_data)

Add the site df (site-specific inputs) to project points dataframe.

flush()

Flush the output data in self.out attribute to disk in .h5 format.

get_pc(points, points_range, sam_configs, tech)

Get a PointsControl instance.

get_sites_per_worker(res_file[, default])

Get the nominal sites per worker (x-chunk size) for a given file.

handle_leap_ti(ti[, drop_leap])

Handle a time index for a leap year by dropping a day.

site_index(site_gid[, out_index])

Get the index corresponding to the site gid.

unpack_futures(futures)

Combine list of futures results into their native dict format/type.

unpack_output(site_gid, site_output)

Unpack a SAM SiteOutput object to the output attribute.

Attributes

ECON_ATTRS

LCOE_ARGS

OPTIONS

OUT_ATTRS

meta

Get resource meta for all sites in project points.

out

Get the reV gen or econ output results.

out_chunk

Get the current output chunk index range (INCLUSIVE).

output_request

Get the output variables requested from the user.

points_control

Get project points controller.

project_points

Get project points

run_attrs

Run time attributes (__init__ args and kwargs)

sam_configs

Get the sam config dictionary.

sam_metas

SAM configurations including runtime module

sam_module

Get the SAM module class to be used for SAM simulations.

site_data

Get the site-specific inputs in dataframe format.

site_limit

Get the number of sites results that can be stored in memory at once

site_mem

Get the memory (MB) required to store all results for a single site.

tech

Get the reV technology string.

time_index

Get the resource time index data.

year

Get the resource year.

property output_request

Get the output variables requested from the user.

Returns:

output_request (list) – Output variables requested from SAM.

property out_chunk

Get the current output chunk index range (INCLUSIVE).

Returns:

_out_chunk (tuple) – Two entry tuple (start, end) indicies (inclusive) for where the current data in-memory belongs in the final output.

property site_data

Get the site-specific inputs in dataframe format.

Returns:

_site_data (pd.DataFrame) – Site-specific input data for gen or econ calculation. Rows match sites, columns are variables.

property site_limit

Get the number of sites results that can be stored in memory at once

Returns:

_site_limit (int) – Number of site result sets that can be stored in memory at once without violating memory limits.

property site_mem

Get the memory (MB) required to store all results for a single site.

Returns:

_site_mem (float) – Memory (MB) required to store all results in requested in output_request for a single site.

property points_control

Get project points controller.

Returns:

points_control (reV.config.project_points.PointsControl) – Project points control instance for site and SAM config spec.

property project_points

Get project points

Returns:

project_points (reV.config.project_points.ProjectPoints) – Project points from the points control instance.

property sam_configs

Get the sam config dictionary.

Returns:

sam_configs (dict) – SAM config from the project points instance.

property sam_metas

SAM configurations including runtime module

Returns:

sam_metas (dict) – Nested dictionary of SAM configuration files with module used at runtime

property sam_module

Get the SAM module class to be used for SAM simulations.

Returns:

sam_module (object) – SAM object like PySAM.Pvwattsv7 or PySAM.Lcoefcr

property meta

Get resource meta for all sites in project points.

Returns:

meta (pd.DataFrame) – Meta data df for sites in project points. Column names are meta data variables, rows are different sites. The row index does not indicate the site number if the project points are non-sequential or do not start from 0, so a SiteDataField.GID column is added.

property time_index

Get the resource time index data.

Returns:

_time_index (pandas.DatetimeIndex) – Time-series datetime index

property run_attrs

Run time attributes (__init__ args and kwargs)

Returns:

run_attrs (dict) – Dictionary of runtime args and kwargs

property year

Get the resource year.

Returns:

_year (int) – Year of the time-series datetime index.

property tech

Get the reV technology string.

Returns:

tech (str) – SAM technology to analyze (pvwattsv7, windpower, tcsmoltensalt, solarwaterheat, troughphysicalheat, lineardirectsteam, econ) The string should be lower-cased with spaces and _ removed.

property out

Get the reV gen or econ output results.

Returns:

out (dict) – Dictionary of gen or econ results from SAM.

static handle_leap_ti(ti, drop_leap=False)[source]

Handle a time index for a leap year by dropping a day.

Parameters:
  • ti (pandas.DatetimeIndex) – Time-series datetime index with or without leap days.

  • drop_leap (bool) – Option to drop leap days (if True) or drop the last day of each leap year (if False).

Returns:

ti (pandas.DatetimeIndex) – Time-series datetime index with length a multiple of 365.

classmethod get_pc(points, points_range, sam_configs, tech, sites_per_worker=None, res_file=None, curtailment=None)[source]

Get a PointsControl instance.

Parameters:
  • points (int | slice | list | str | pandas.DataFrame | PointsControl) – Single site integer, or slice or list specifying project points, or string pointing to a project points csv, or a pre-loaded project points DataFrame, or a fully instantiated PointsControl object.

  • points_range (list | None) – Optional two-entry list specifying the index range of the sites to analyze. To be taken from the reV.config.PointsControl.split_range property.

  • sam_configs (dict | str | SAMConfig) – SAM input configuration ID(s) and file path(s). Keys are the SAM config ID(s) which map to the config column in the project points CSV. Values are either a JSON SAM config file or dictionary of SAM config inputs. Can also be a single config file path or a pre loaded SAMConfig object.

  • tech (str) – SAM technology to analyze (pvwattsv7, windpower, tcsmoltensalt, solarwaterheat, troughphysicalheat, lineardirectsteam) The string should be lower-cased with spaces and _ removed.

  • sites_per_worker (int) – Number of sites to run in series on a worker. None defaults to the resource file chunk size.

  • res_file (str) – Filepath to single resource file, multi-h5 directory, or /h5_dir/prefix*suffix

  • curtailment (NoneType | dict | str | config.curtailment.Curtailment) – Inputs for curtailment parameters. If not None, curtailment inputs are expected. Can be:

    • Explicit namespace of curtailment variables (dict)

    • Pointer to curtailment config json file with path (str)

    • Instance of curtailment config object (config.curtailment.Curtailment)

Returns:

pc (reV.config.project_points.PointsControl) – PointsControl object instance.

static get_sites_per_worker(res_file, default=100)[source]

Get the nominal sites per worker (x-chunk size) for a given file.

This is based on the concept that it is most efficient for one core to perform one read on one chunk of resource data, such that chunks will not have to be read into memory twice and no sites will be read redundantly.

Parameters:
  • res_file (str) – Filepath to single resource file, multi-h5 directory, or /h5_dir/prefix*suffix

  • default (int) – Sites to be analyzed on a single core if the chunk size cannot be determined from res_file.

Returns:

sites_per_worker (int) – Nominal sites to be analyzed per worker. This is set to the x-axis chunk size for windspeed and dni datasets for the WTK and NSRDB data, respectively.

static unpack_futures(futures)[source]

Combine list of futures results into their native dict format/type.

Parameters:

futures (list) – List of dictionary futures results.

Returns:

out (dict) – Compiled results of the native future results type (dict).

add_site_data_to_pp(site_data)[source]

Add the site df (site-specific inputs) to project points dataframe.

This ensures that only the relevant site’s data will be passed through to parallel workers when points_control is iterated and split.

Parameters:

site_data (pd.DataFrame) – Site-specific data for econ calculation. Rows correspond to sites, columns are variables.

unpack_output(site_gid, site_output)[source]

Unpack a SAM SiteOutput object to the output attribute.

Parameters:
  • site_gid (int) – Resource-native site gid (index).

  • site_output (dict) – SAM site output object.

site_index(site_gid, out_index=False)[source]

Get the index corresponding to the site gid.

Parameters:
  • site_gid (int) – Resource-native site index (gid).

  • out_index (bool) – Option to get output index (if true) which is the column index in the current in-memory output array, or (if false) the global site index from the project points site list.

Returns:

index (int) – Global site index if out_index=False, otherwise column index in the current in-memory output array.

flush()[source]

Flush the output data in self.out attribute to disk in .h5 format.

The data to be flushed is accessed from the instance attribute “self.out”. The disk target is based on the instance attributes “self._out_fpath”. Data is not flushed if _fpath is None or if .out is empty.