rex.sam_resource.SAMResource
- class SAMResource(sites, tech, time_index, hub_heights=None, depths=None, require_wind_dir=False, means=False)[source]
Bases:
object
Resource container for SAM. Resource handlers preload the datasets needed by SAM for the sites of interest. SAMResource handles all ETL needed before resource data is passed into SAM.
Examples
>>> import os >>> from rex import TESTDATADIR, WindResource >>> file = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012.h5')
Here we load a SAM Resource container for a windpower analysis for sites 7 and 8 at a hub height of 90m:
>>> sam = WindResource.preload_SAM(file, sites=[7, 8], hub_heights=90) >>> sam SAMResource with 2 windpower sites
You can then use the SAMResource object to easily retrieve the data that is needed to run the SAM windpower module:
>>> sam[7] winddirection pressure temperature windspeed 2012-01-01 00:00:00+00:00 0.0 0.965329 4.270 7.565000 2012-01-01 01:00:00+00:00 0.0 0.965921 3.870 8.040000 2012-01-01 02:00:00+00:00 0.0 0.966612 4.070 10.370000 2012-01-01 03:00:00+00:00 0.0 0.966721 4.060 11.174999 2012-01-01 04:00:00+00:00 0.0 0.967224 3.515 8.570000 ... ... ... ... ... 2012-12-31 19:00:00+00:00 0.0 0.967826 -1.965 6.515000 2012-12-31 20:00:00+00:00 0.0 0.967036 -2.095 6.750000 2012-12-31 21:00:00+00:00 0.0 0.966740 -2.495 9.215000 2012-12-31 22:00:00+00:00 0.0 0.966158 -2.735 10.680000 2012-12-31 23:00:00+00:00 0.0 0.965852 -2.460 10.805000
[8784 rows x 4 columns]
>>> sam['meta', 7] latitude 41.975849 longitude -71.762329 country United States state RI county Providence timezone -5 elevation 208 offshore 0 Name: 7, dtype: object
>>> sam['meta', 8] latitude 41.993584 longitude -71.754852 country United States state RI county Providence timezone -5 elevation 180 offshore 0 Name: 8, dtype: object
>>> sam['meta', 9] KeyError: 9
- Parameters:
sites (int | list | tuple | slice) – int, list, tuple, or slice indicating sites to send to SAM (sites is synonymous with gids aka spatial indices)
tech (str) – SAM technology string. See class attributes for options.
time_index (pandas.DatetimeIndex) – Time-series datetime index
hub_heights (int | float | list, optional) – Hub height(s) to extract wind data at, by default None
depths (int | float | list, optional) – Depth(s) to extract wind data at, by default None
require_wind_dir (bool, optional) – Boolean flag indicating that wind direction is required, by default False
means (bool, optional) – Boolean flag to compute mean resource when res_array is set, by default False
Methods
append_var_list
(var)Append a new variable to the SAM resource protected var_list.
bias_correct
(bc_df)Bias correct wind or irradiance data using a table of linear correction factors per resource gid.
check_irradiance_datasets
(datasets[, clearsky])Check available irradiance datasets
check_units
(var_name, var_array, tech)Check units of variable array and convert to SAM units if needed
compute_irradiance
([clearsky])Fillin missing irradiance dataset from available values and SZA
curtail_windspeed
(gids, curtailment)Apply temporal curtailment mask to windspeed resource at given sites
enforce_arr_range
(var, arr, valid_range, sites)Check an array for valid data range, warn, patch, and return.
load_rex_resource
(rex_res, var_list, ...[, ...])Load data from a rex Resource handler into this SAMResource container.
roll_timeseries
(time_series, timezone, ...)Roll timeseries array to given timezone from UTC
runnable
()Check to see if SAMResource iterator is runnable: - Meta must be loaded - Variables in var_list must be loaded
Make the NSRDB var list for solar based on clearsky irradiance.
Attributes
ALIASES
CSP_DATA_RANGES
DATA_RANGES
FLAT_VARS
GEOTHERMAL_DATA_RANGES
LF_DATA_RANGES
PV_DATA_RANGES
RES_VARS
SWH_DATA_RANGES
TPPH_DATA_RANGES
WAVE_DATA_RANGES
WIND_DATA_RANGES
Get depths for geothermal sites
Get heights for wind sites
site latitudes and longitudes
Return sites meta
Shape of variable arrays
Sites being pre-loaded for SAM
Get the sites in slice format if possible
Solar zenith angle for sites of interest
Return time_index
Return variable list associated with SAMResource type
- property sites
Sites being pre-loaded for SAM
- Returns:
sites (list) – List of sites to be provided to SAM (sites is synonymous with gids aka spatial indices)
- property sites_slice
Get the sites in slice format if possible
- Returns:
sites (list | slice) – Sites slice belonging to this instance of ProjectPoints. The type is slice if possible. Will be a list only if sites are non-sequential. (sites is synonymous with gids aka spatial indices)
- property shape
Shape of variable arrays
- Returns:
self._shape (tuple) – Shape (time_index, sites) of variable arrays
- property var_list
Return variable list associated with SAMResource type
- Returns:
_var_list (list) – List of resource variables associated with resource type (‘solar’ or ‘wind’)
- property time_index
Return time_index
- Returns:
self._time_index (pandas.DatetimeIndex) – Time-series datetime index
- property meta
Return sites meta
- Returns:
self._meta (pandas.DataFrame) – DataFrame of sites meta data
- property h
Get heights for wind sites
- Returns:
self._h (int | float | list) – Hub height or height(s) for wind resource, None for other resource
- property d
Get depths for geothermal sites
- Returns:
self._d (int | float | list) – Depth(s) for geothermal resource, None for other resource
- property lat_lon
site latitudes and longitudes
- Returns:
ndarray
- property sza
Solar zenith angle for sites of interest
- Returns:
ndarray
- static check_units(var_name, var_array, tech)[source]
Check units of variable array and convert to SAM units if needed
- Parameters:
var_name (str) – Variable name
var_array (ndarray) – Variable data
tech (str) – SAM technology string (windpower, pvwattsv5, solarwaterheat, etc..)
- Returns:
var_array (ndarray) – Variable data with updated units if needed
- static enforce_arr_range(var, arr, valid_range, sites)[source]
Check an array for valid data range, warn, patch, and return.
- Parameters:
var (str) – variable name
arr (np.ndarray) – Array to be checked and patched
valid_range (np.ndarray | tuple | list) – arr data will be ensured within the min/max values of valid_range
sites (list) – Resource gid site list for warning printout. (sites is synonymous with gids aka spatial indices)
- Returns:
arr (np.ndarray) – Patched array with valid range.
- static roll_timeseries(time_series, timezone, time_interval)[source]
Roll timeseries array to given timezone from UTC
- Parameters:
time_series (ndarray) – time_series array to roll
timezone (int) – Time zone as UTC offset
time_interval (int) – Number of step-steps in an hour, needed to compute time shift
- Returns:
time_series (ndarray) – Time series in local time
- check_irradiance_datasets(datasets, clearsky=False)[source]
Check available irradiance datasets
- Parameters:
datasets (list) – List of available datasets in resource .h5 file
clearsky (bool, optional) – Flag to check for clearsky irradiance datasets, by default False
- compute_irradiance(clearsky=False)[source]
Fillin missing irradiance dataset from available values and SZA
- Parameters:
clearsky (bool, optional) – Flag to check for clearsky irradiance datasets, by default False
- append_var_list(var)[source]
Append a new variable to the SAM resource protected var_list.
- Parameters:
var (str) – New resource variable to be added to the protected var_list property.
- bias_correct(bc_df)[source]
Bias correct wind or irradiance data using a table of linear correction factors per resource gid.
- Parameters:
bc_df (pd.DataFrame) – DataFrame with wind or solar resource bias correction table. This must have columns “gid” and “method”, where “gid” is the resource file indices, and “method” is a function name from the
rex.bias_correction
module. Only windspeed or GHI+DNI+DHI are corrected, depending on the technology. See therex.bias_correction
module for more details on available bias correction methods.
- runnable()[source]
Check to see if SAMResource iterator is runnable: - Meta must be loaded - Variables in var_list must be loaded
- Returns:
bool – Returns True if runnable check passes
- curtail_windspeed(gids, curtailment)[source]
Apply temporal curtailment mask to windspeed resource at given sites
- Parameters:
gids (int | list) – gids for site or list of sites to curtail
curtailment (ndarray) – Temporal multiplier for curtailment
- load_rex_resource(rex_res, var_list, time_slice, sites, hh=None, hh_unit='m')[source]
Load data from a rex Resource handler into this SAMResource container.
- Parameters:
rex_res (rex.Resource) – rex Resource handler or similar (NSRDB, WindResource, MultiFileResource, etc…)
var_list (list) – List of variables to retrieve from rex_res. These names may be manipulated with suffixes such as _100m (for a 100m hh input)
time_slice (slice) – Slicing argument for the resource temporal dimension (axis=0)
sites (list | slice | int) – List of site indices (axis=1) (sites is synonymous with gids aka spatial indices)
hh (None | int) – Optional single hub height in meters that datasets are to be loaded from rex_res at
hh_unit (str) – Unit suffix for the hub height input.