reV.SAM.generation.AbstractSamPv

class AbstractSamPv(resource, meta, sam_sys_inputs, site_sys_inputs=None, output_request=None, drop_leap=False)[source]

Bases: AbstractSamSolar, ABC

Photovoltaic (PV) generation with either pvwatts of detailed pv.

Initialize a SAM solar object.

See the PySAM Pvwattsv8 (or older version model) or Pvsamv1 documentation for the configuration keys required in the sam_sys_inputs config for the respective models. Some notable keys include the following to enable a lifetime simulation (non-exhaustive):

  • system_use_lifetime_output : Integer flag indicating whether or not to run a full lifetime model (0 for off, 1 for on). If running a lifetime model, the resource file will be repeated for the number of years specified as the lifetime of the plant and a performance degradation term will be used to simulate reduced performance over time.

  • analysis_period : Integer representing the number of years to include in the lifetime of the model generator. Required if ``system_use_lifetime_output``=1.

  • dc_degradation : List of percentage values representing the annual DC degradation of capacity factors. Maybe a single value that will be compound each year or a vector of yearly rates. Required if ``system_use_lifetime_output``=1.

You may also include the following reV-specific keys:

  • reV_outages : Specification for reV-scheduled stochastic outage losses. For example:

    outage_info = [
        {
            'count': 6,
            'duration': 24,
            'percentage_of_capacity_lost': 100,
            'allowed_months': ['January', 'March'],
            'allow_outage_overlap': True
        },
        {
            'count': 10,
            'duration': 1,
            'percentage_of_capacity_lost': 10,
            'allowed_months': ['January'],
            'allow_outage_overlap': False
        },
        ...
    ]
    

    See the description of add_scheduled_losses() or the reV losses demo notebook for detailed instructions on how to specify this input.

  • reV_outages_seed : Integer value used to seed the RNG used to compute stochastic outage losses.

  • time_index_step : Integer representing the step size used to sample the time_index in the resource data. This can be used to reduce temporal resolution (i.e. for 30 minute NSRDB input data, time_index_step=1 yields the full 30 minute time series as output, while time_index_step=2 yields hourly output, and so forth).

    Note

    The reduced data shape (i.e. after applying a step size of time_index_step) must still be an integer multiple of 8760, or the execution will fail.

  • clearsky : Boolean flag value indicating wether computation should use clearsky resource data to compute generation data.

Parameters:
  • resource (pd.DataFrame) – Timeseries solar or wind resource data for a single location with a pandas DatetimeIndex. There must be columns for all the required variables to run the respective SAM simulation. Remapping will be done to convert typical NSRDB/WTK names into SAM names (e.g. DNI -> dn and wind_speed -> windspeed)

  • meta (pd.DataFrame | pd.Series) – Meta data corresponding to the resource input for the single location. Should include values for latitude, longitude, elevation, and timezone.

  • sam_sys_inputs (dict) – Site-agnostic SAM system model inputs arguments.

  • site_sys_inputs (dict) – Optional set of site-specific SAM system inputs to complement the site-agnostic inputs.

  • output_request (list) – Requested SAM outputs (e.g., ‘cf_mean’, ‘annual_energy’, ‘cf_profile’, ‘gen_profile’, ‘energy_yield’, ‘ppa_price’, ‘lcoe_fcr’).

  • drop_leap (bool) – Drops February 29th from the resource data. If False, December 31st is dropped from leap years.

Methods

ac()

Get AC inverter power generation profile (local timezone) in kW.

add_scheduled_losses([resource])

Add stochastically scheduled losses to SAM config file.

agg_albedo(time_index, albedo)

Aggregate a timeseries of albedo data to monthly values w len 12 as required by pysam Pvsamv1

annual_energy()

Get annual energy generation value in kWh from SAM.

assign_inputs()

Assign the self.sam_sys_inputs attribute to the PySAM object.

cf_mean()

Get mean capacity factor (fractional) from SAM.

cf_mean_ac()

Get mean AC capacity factor (fractional) from SAM.

cf_profile()

Get hourly capacity factor (frac) profile in local timezone.

cf_profile_ac()

Get hourly AC capacity factor (frac) profile in local timezone.

check_resource_data(resource)

Check resource dataframe for NaN values

clipped_power()

Get the clipped DC power generated behind the inverter (local timezone) in kW.

collect_outputs([output_lookup])

Collect SAM output_request, convert timeseries outputs to UTC, and save outputs to self.outputs property.

dc()

Get DC array power generation profile (local timezone) in kW.

default()

Get the executed default pysam object.

drop_leap(resource)

Drop Feb 29th from resource df with time index.

energy_yield()

Get annual energy yield value in kwh/kw from SAM.

ensure_res_len(arr, time_index)

Ensure time_index has a constant time-step and only covers 365 days (no leap days).

execute()

Call the PySAM execute method.

gen_profile()

Get AC inverter power generation profile (local timezone) in kW.

get_sam_res(*args, **kwargs)

Get the SAM resource iterator object (single year, single file).

get_time_interval(time_index)

Get the time interval.

make_datetime(series)

Ensure that pd series is a datetime series with dt accessor

outputs_to_utc_arr()

Convert array-like SAM outputs to UTC np.ndarrays

reV_run(points_control, res_file, site_df[, ...])

Execute SAM generation based on a reV points control instance.

run()

Run a reV-SAM generation object by assigning inputs, executing the SAM simulation, collecting outputs, and converting all arrays to UTC.

run_gen_and_econ()

Run SAM generation with possibility for follow on econ analysis.

set_latitude_tilt_az(sam_sys_inputs, meta)

Check if tilt is specified as latitude and set tilt=lat, az=180 or 0

set_resource_data(resource, meta)

Set NSRDB resource data arrays.

system_capacity_ac()

Get AC system capacity from SAM inputs.

tz_elev_check(sam_sys_inputs, ...)

Check timezone+elevation input and use json config timezone+elevation if not in resource meta.

Attributes

DIR

IGNORE_ATTRS

MODULE

OUTAGE_CONFIG_KEY

Specify outage information in the config file using this key.

OUTAGE_SEED_CONFIG_KEY

Specify a randomizer seed in the config file using this key.

PYSAM

attr_dict

Get the heirarchical PySAM object attribute dictionary.

has_timezone

Returns true if instance has a timezone set

input_list

Get the list of lowest level input attribute/variable names.

meta

Get meta data property.

module

Get module property.

outage_seed

A value to use as the seed for the outage losses.

pysam

Get the pysam object.

site

Get the site number for this SAM simulation.

PYSAM = None
set_resource_data(resource, meta)[source]

Set NSRDB resource data arrays.

Parameters:
  • resource (pd.DataFrame) – Timeseries solar or wind resource data for a single location with a pandas DatetimeIndex. There must be columns for all the required variables to run the respective SAM simulation. Remapping will be done to convert typical NSRDB/WTK names into SAM names (e.g. DNI -> dn and wind_speed -> windspeed)

  • meta (pd.Series) – Meta data corresponding to the resource input for the single location. Should include values for latitude, longitude, elevation, and timezone.

:raises ValueError : If lat/lon outside of -90 to 90 and -180 to 180,: respectively.

static set_latitude_tilt_az(sam_sys_inputs, meta)[source]

Check if tilt is specified as latitude and set tilt=lat, az=180 or 0

Parameters:
  • sam_sys_inputs (dict) – Site-agnostic SAM system model inputs arguments.

  • meta (pd.Series) – Meta data corresponding to the resource input for the single location. Should include values for latitude, longitude, elevation, and timezone.

Returns:

sam_sys_inputs (dict) – Site-agnostic SAM system model inputs arguments. If for a pv simulation the “tilt” parameter was originally not present or set to ‘lat’ or ‘latitude’, the tilt will be set to the absolute value of the latitude found in meta and the azimuth will be 180 if lat>0, 0 if lat<0.

system_capacity_ac()[source]

Get AC system capacity from SAM inputs.

NOTE: AC nameplate = DC nameplate / ILR

Returns:

cf_profile (float) – AC nameplate = DC nameplate / ILR

cf_mean()[source]

Get mean capacity factor (fractional) from SAM.

NOTE: PV capacity factor is the AC power production / the DC nameplate

Returns:

output (float) – Mean capacity factor (fractional). PV CF is calculated as AC power / DC nameplate.

cf_mean_ac()[source]

Get mean AC capacity factor (fractional) from SAM.

NOTE: This value only available in PVWattsV8 and up.

Returns:

output (float) – Mean AC capacity factor (fractional). PV AC CF is calculated as AC power / AC nameplate.

cf_profile()[source]

Get hourly capacity factor (frac) profile in local timezone. See self.outputs attribute for collected output data in UTC.

NOTE: PV capacity factor is the AC power production / the DC nameplate

Returns:

cf_profile (np.ndarray) – 1D numpy array of capacity factor profile. Datatype is float32 and array length is 8760*time_interval. PV CF is calculated as AC power / DC nameplate.

cf_profile_ac()[source]

Get hourly AC capacity factor (frac) profile in local timezone. See self.outputs attribute for collected output data in UTC.

NOTE: PV AC capacity factor is the AC power production / the AC nameplate. AC nameplate = DC nameplate / ILR

Returns:

cf_profile (np.ndarray) – 1D numpy array of capacity factor profile. Datatype is float32 and array length is 8760*time_interval. PV AC CF is calculated as AC power / AC nameplate.

gen_profile()[source]

Get AC inverter power generation profile (local timezone) in kW. This is an alias of the “ac” SAM output variable if PySAM version>=3. See self.outputs attribute for collected output data in UTC.

Returns:

output (np.ndarray) – 1D array of AC inverter power generation in kW. Datatype is float32 and array length is 8760*time_interval.

ac()[source]

Get AC inverter power generation profile (local timezone) in kW. See self.outputs attribute for collected output data in UTC.

Returns:

output (np.ndarray) – 1D array of AC inverter power generation in kW. Datatype is float32 and array length is 8760*time_interval.

dc()[source]

Get DC array power generation profile (local timezone) in kW. See self.outputs attribute for collected output data in UTC.

Returns:

output (np.ndarray) – 1D array of DC array power generation in kW. Datatype is float32 and array length is 8760*time_interval.

clipped_power()[source]

Get the clipped DC power generated behind the inverter (local timezone) in kW. See self.outputs attribute for collected output data in UTC.

Returns:

clipped (np.ndarray) – 1D array of clipped DC power in kW. Datatype is float32 and array length is 8760*time_interval.

abstract static default()[source]

Get the executed default pysam object.

collect_outputs(output_lookup=None)[source]

Collect SAM output_request, convert timeseries outputs to UTC, and save outputs to self.outputs property.

Parameters:

output_lookup (dict | None) – Lookup dictionary mapping output keys to special output methods. None defaults to generation default outputs.

OUTAGE_CONFIG_KEY = 'reV_outages'

Specify outage information in the config file using this key.

OUTAGE_SEED_CONFIG_KEY = 'reV_outages_seed'

Specify a randomizer seed in the config file using this key.

add_scheduled_losses(resource=None)

Add stochastically scheduled losses to SAM config file.

This function reads the information in the reV_outages key of the sam_sys_inputs dictionary and computes stochastically scheduled losses from that input. If the value for reV_outages is a string, it must have been generated by calling json.dumps() on the list of dictionaries containing outage specifications. Otherwise, the outage information is expected to be a list of dictionaries containing outage specifications. See Outage for a description of the specifications allowed for each outage. The scheduled losses are passed to SAM via the hourly key to signify which hourly capacity factors should be adjusted with outage losses. If no outage info is specified in sam_sys_inputs, no scheduled losses are added.

Parameters:

resource (pd.DataFrame, optional) – Time series resource data for a single location with a pandas DatetimeIndex. The year value of the index will be used to seed the stochastically scheduled losses. If None, no yearly seed will be used.

See also

Outage

Single outage specification.

Notes

The scheduled losses are passed to SAM via the hourly key to signify which hourly capacity factors should be adjusted with outage losses. If the user specifies other hourly adjustment factors via the hourly key, the effect is combined. For example, if the user inputs a 33% hourly adjustment factor and reV schedules an outage for 70% of the farm down for the same hour, then the resulting adjustment factor is

This means the generation will be reduced by ~80%, because the user requested 33% losses for the 30% the farm that remained operational during the scheduled outage (i.e. 20% remaining of the original generation).

static agg_albedo(time_index, albedo)

Aggregate a timeseries of albedo data to monthly values w len 12 as required by pysam Pvsamv1

Tech spec from pysam docs: https://nrel-pysam.readthedocs.io/en/master/modules/Pvsamv1.html #PySAM.Pvsamv1.Pvsamv1.SolarResource.albedo

Parameters:
  • time_index (pd.DatetimeIndex) – Timeseries solar resource datetimeindex

  • albedo (list) – Timeseries Albedo data to be aggregated. Should be 0-1 and likely hourly or less.

Returns:

monthly_albedo (list) – 1D list of monthly albedo values with length 12

annual_energy()

Get annual energy generation value in kWh from SAM.

Returns:

output (float) – Annual energy generation (kWh).

assign_inputs()

Assign the self.sam_sys_inputs attribute to the PySAM object.

property attr_dict

Get the heirarchical PySAM object attribute dictionary.

Returns:

_attr_dict (dict) –

Dictionary with:

keys: variable groups values: lowest level attribute/variable names

check_resource_data(resource)

Check resource dataframe for NaN values

Parameters:

resource (pd.DataFrame) – Timeseries solar or wind resource data for a single location with a pandas DatetimeIndex. There must be columns for all the required variables to run the respective SAM simulation. Remapping will be done to convert typical NSRDB/WTK names into SAM names (e.g. DNI -> dn and wind_speed -> windspeed)

static drop_leap(resource)

Drop Feb 29th from resource df with time index.

Parameters:

resource (pd.DataFrame) – Resource dataframe with an index containing a pandas time index object with month and day attributes.

Returns:

resource (pd.DataFrame) – Resource dataframe with all February 29th timesteps removed.

energy_yield()

Get annual energy yield value in kwh/kw from SAM.

Returns:

output (float) – Annual energy yield (kwh/kw).

static ensure_res_len(arr, time_index)

Ensure time_index has a constant time-step and only covers 365 days (no leap days). If not remove last day

Parameters:
  • arr (ndarray) – Array to truncate if time_index has a leap day

  • time_index (pandas.DatatimeIndex) – Time index associated with arr, used to check time-series frequency and number of days

Returns:

arr (ndarray) – Truncated array of data such that there are 365 days

execute()

Call the PySAM execute method. Raise SAMExecutionError if error. Include the site index if available.

static get_sam_res(*args, **kwargs)

Get the SAM resource iterator object (single year, single file).

classmethod get_time_interval(time_index)

Get the time interval.

Parameters:

time_index (pd.series) – Datetime series. Must have a dt attribute to access datetime properties (added using make_datetime method).

Returns:

time_interval (int:) – This value is the number of indices over which an hour is counted. So if the timestep is 0.5 hours, time_interval is 2.

property has_timezone

Returns true if instance has a timezone set

property input_list

Get the list of lowest level input attribute/variable names.

Returns:

_inputs (list) – List of lowest level input attributes.

static make_datetime(series)

Ensure that pd series is a datetime series with dt accessor

property meta

Get meta data property.

property module

Get module property.

property outage_seed

A value to use as the seed for the outage losses.

Type:

int

outputs_to_utc_arr()

Convert array-like SAM outputs to UTC np.ndarrays

property pysam

Get the pysam object.

classmethod reV_run(points_control, res_file, site_df, lr_res_file=None, output_request=('cf_mean',), drop_leap=False, gid_map=None, nn_map=None, bias_correct=None)

Execute SAM generation based on a reV points control instance.

Parameters:
  • points_control (config.PointsControl) – PointsControl instance containing project points site and SAM config info.

  • res_file (str) – Resource file with full path.

  • site_df (pd.DataFrame) – Dataframe of site-specific input variables. Row index corresponds to site number/gid (via df.loc not df.iloc), column labels are the variable keys that will be passed forward as SAM parameters.

  • lr_res_file (str | None) – Optional low resolution resource file that will be dynamically mapped+interpolated to the nominal-resolution res_file. This needs to be of the same format as resource_file, e.g. they both need to be handled by the same rex Resource handler such as WindResource

  • output_request (list | tuple) – Outputs to retrieve from SAM.

  • drop_leap (bool) – Drops February 29th from the resource data. If False, December 31st is dropped from leap years.

  • gid_map (None | dict) – Mapping of unique integer generation gids (keys) to single integer resource gids (values). This enables the user to input unique generation gids in the project points that map to non-unique resource gids. This can be None or a pre-extracted dict.

  • nn_map (np.ndarray) – Optional 1D array of nearest neighbor mappings associated with the res_file to lr_res_file spatial mapping. For details on this argument, see the rex.MultiResolutionResource docstring.

  • bias_correct (None | pd.DataFrame) – Optional DataFrame or CSV filepath to a wind or solar resource bias correction table. This has columns:

    • gid: GID of site (can be index name of dataframe)

    • method: function name from rex.bias_correction module

    The gid field should match the true resource gid regardless of the optional gid_map input. Only windspeed or GHI + DNI + DHI are corrected, depending on the technology (wind for the former, PV or CSP for the latter). See the functions in the rex.bias_correction module for available inputs for method. Any additional kwargs required for the requested method can be input as additional columns in the bias_correct table e.g., for linear bias correction functions you can include scalar and adder inputs as columns in the bias_correct table on a site-by-site basis. If None, no corrections are applied. By default, None.

Returns:

out (dict) – Nested dictionaries where the top level key is the site index, the second level key is the variable name, second level value is the output variable value.

run()

Run a reV-SAM generation object by assigning inputs, executing the SAM simulation, collecting outputs, and converting all arrays to UTC.

run_gen_and_econ()

Run SAM generation with possibility for follow on econ analysis.

property site

Get the site number for this SAM simulation.

static tz_elev_check(sam_sys_inputs, site_sys_inputs, meta)

Check timezone+elevation input and use json config timezone+elevation if not in resource meta.

Parameters:
  • sam_sys_inputs (dict) – Site-agnostic SAM system model inputs arguments.

  • site_sys_inputs (dict) – Optional set of site-specific SAM system inputs to complement the site-agnostic inputs.

  • meta (pd.DataFrame | pd.Series) – Meta data corresponding to the resource input for the single location. Should include values for latitude, longitude, elevation, and timezone.

Returns:

meta (pd.DataFrame | pd.Series) – Datafram or series for a single site. Will include “timezone” and “elevation” from the sam and site system inputs if found.