rex.renewable_resource.WindResource

class WindResource(h5_file, mode='r', unscale=True, str_decode=True, group=None, use_lapse_rate=True, hsds=False, hsds_kwargs=None)[source]

Bases: AbstractInterpolatedResource

Class to handle Wind BaseResource .h5 files

Notes

Interpolation between hub-heights is performed using linear interpolation. While wind follows a log profile macroscopically, using power law interpolation doesn’t allow for negative wind shear, which we see often at the taller hub heights we care about. In other words, power law interpolation is a bad assumption for near surface wind, and linear interpolation is a much better approach. Extrapolation beyond the resource data hub heights is still performed using power law interpolation.

See also

resource.AbstractInterpolatedResource

Parent class

Examples

>>> import os
>>> from rex import TESTDATADIR, WindResource
>>> file = os.path.join(TESTDATADIR, 'wtk/ri_100_wtk_2012.h5')
>>> with WindResource(file) as res:
>>>     print(res.datasets)
['meta', 'pressure_0m', 'pressure_100m', 'pressure_200m',
'temperature_100m', 'temperature_80m', 'time_index', 'winddirection_100m',
'winddirection_80m', 'windspeed_100m', 'windspeed_80m']

WindResource can interpolate between available hub-heights (80 & 100)

>>> with WindResource(file) as res:
>>>     wspd_90m = res['windspeed_90m']
>>>
>>> wspd_90m
[[ 6.865      6.77       6.565     ...  8.65       8.62       8.415    ]
 [ 7.56       7.245      7.685     ...  5.9649997  5.8        6.2      ]
 [ 9.775      9.21       9.225     ...  7.12       7.495      7.675    ]
  ...
 [ 8.38       8.440001   8.85      ... 11.934999  12.139999  12.4      ]
 [ 9.900001   9.895      9.93      ... 12.825     12.86      12.965    ]
 [ 9.895     10.01      10.305     ... 14.71      14.79      14.764999 ]]

WindResource can also extrapolate beyond available hub-heights

>>> with WindResource(file) as res:
>>>     wspd_150m = res['windspeed_150m']
>>>
>>> wspd_150m
ExtrapolationWarning: 150 is outside the height range (80, 100).
Extrapolation to be used.
[[ 7.336291   7.2570405  7.0532546 ...  9.736436   9.713792   9.487364 ]
 [ 8.038219   7.687255   8.208041  ...  6.6909685  6.362647   6.668326 ]
 [10.5515785  9.804363   9.770399  ...  8.026898   8.468434   8.67222  ]
 ...
 [ 9.079792   9.170363   9.634542  ... 13.472508  13.7102585 14.004617 ]
 [10.710078  10.710078  10.698757  ... 14.468795  14.514081  14.6386175]
 [10.698757  10.857258  11.174257  ... 16.585903  16.676476  16.653833 ]]
Parameters:
  • h5_file (str) – Path to .h5 resource file

  • mode (str, optional) – Mode to instantiate h5py.File instance, by default ‘r’

  • unscale (bool) – Boolean flag to automatically unscale variables on extraction

  • str_decode (bool) – Boolean flag to decode the bytestring meta data into normal strings. Setting this to False will speed up the meta data read.

  • group (str) – Group within .h5 resource file to open

  • use_lapse_rate (bool) – If a dataset is only available at a single hub-height and this flag value is set to True, pressure / temperature values will be calculated using linear lapse rate adjustment from the available hub height to the requested one. If the flag value is set to False, the value of these variables at the single available hub-height will be returned for all requested heights. This option has no effect if data is available at multiple hub-heights.

  • hsds (bool, optional) – Boolean flag to use h5pyd to handle .h5 ‘files’ hosted on AWS behind HSDS, by default False

  • hsds_kwargs (dict, optional) – Dictionary of optional kwargs for h5pyd, e.g., bucket, username, password, by default None

Methods

circular_interp(ts_1, h_1, ts_2, h_2, h)

Circular interpolate/extrapolate time-series data to height h

close()

Close h5 instance

df_str_decode(df)

Decode a dataframe with byte string columns into ordinary str cols.

get_SAM_df(site, height[, require_wind_dir, ...])

Get SAM wind resource DataFrame for given site

get_attrs([dset])

Get h5 attributes either from file or dataset

get_dset_properties(dset)

Get dataset properties (shape, dtype, chunks)

get_meta_arr(rec_name[, rows])

Get a meta array by name (faster than DataFrame extraction).

get_scale_factor(dset)

Get dataset scale factor

get_units(dset)

Get dataset units

monin_obukhov_extrapolation(ts_1, h_1, z0, L, h)

Monin-Obukhov extrapolation

open_dataset(ds_name)

Open resource dataset

power_law_interp(ts_1, h_1, ts_2, h_2, h[, mean])

Power-law interpolate/extrapolate time-series data to height h

preload_SAM(h5_file, sites, hub_heights[, ...])

Placeholder for classmethod that will pre-load project_points for SAM

shortest_angle(a0, a1)

Calculate the shortest angle distance between a0 and a1

stability_function(zeta)

Calculate stability function depending on sign of L (negative is unstable, positive is stable)

Attributes

ADD_ATTR

INTERPOLABLE_DSETS

LAPSE_RATES

Air Temperature and Pressure lapse rate in C/km and Pa/km

SCALE_ATTR

UNIT_ATTR

VARIABLE_NAME

VARIABLE_UNIT

adders

Dictionary of all dataset add offset factors

attrs

Dictionary of all dataset attributes

chunks

Dictionary of all dataset chunk sizes

coordinates

(lat, lon) pairs

data_version

Get the version attribute of the data.

datasets

Datasets available

dsets

Datasets available

dtypes

Dictionary of all dataset dtypes

global_attrs

Global (file) attributes

groups

Groups available

h5

Open h5py File instance.

lat_lon

Extract (latitude, longitude) pairs

meta

Resource meta data DataFrame

res_dsets

Available resource datasets

resource_datasets

Available resource datasets

scale_factors

Dictionary of all dataset scale factors

shape

Resource shape (timesteps, sites) shape = (len(time_index), len(meta))

shapes

Dictionary of all dataset shapes

time_index

Resource DatetimeIndex

units

Dictionary of all dataset units

classmethod monin_obukhov_extrapolation(ts_1, h_1, z0, L, h)[source]

Monin-Obukhov extrapolation

Parameters:

ts_1 (ndarray) – Time-series array at height h_1

h_1int | float

Height corresponding to time-seris ts_1

z0: int | float | ndarray

Roughness length

Lndarray

time-series of Obukhov length (m; measure of stability)

hint | float

Desired height

Returns:

ndarray – new wind speed from MO extrapolation.

static stability_function(zeta)[source]

Calculate stability function depending on sign of L (negative is unstable, positive is stable)

Parameters:

zeta (ndarray) – Normalized length

Returns:

numpy.ndarray – stability measurements.

static power_law_interp(ts_1, h_1, ts_2, h_2, h, mean=True)[source]

Power-law interpolate/extrapolate time-series data to height h

Parameters:
  • ts_1 (ndarray) – Time-series array at height h_1

  • h_1 (int | float) – Height corresponding to time-seris ts_1

  • ts_2 (ndarray) – Time-series array at height h_2

  • h_2 (int | float) – Height corresponding to time-seris ts_2

  • h (int | float) – Height of desired time-series

  • mean (bool) – Calculate average alpha versus point by point alpha

Returns:

out (ndarray) – Time-series array at height h

Notes

While wind follows a log profile macroscopically, using power law interpolation doesn’t allow for negative wind shear, which we see often at the taller hub heights we care about. This means yous should prefer linear interpolation over power law interpolation when possible for near surface wind.

static shortest_angle(a0, a1)[source]

Calculate the shortest angle distance between a0 and a1

Parameters:
  • a0 (int | float) – angle 0 in degrees

  • a1 (int | float) – angle 1 in degrees

Returns:

da (int | float) – shortest angle distance between a0 and a1

classmethod circular_interp(ts_1, h_1, ts_2, h_2, h)[source]

Circular interpolate/extrapolate time-series data to height h

Parameters:
  • ts_1 (ndarray) – Time-series array at height h_1

  • h_1 (int | float) – Height corresponding to time-seris ts_1

  • ts_2 (ndarray) – Time-series array at height h_2

  • h_2 (int | float) – Height corresponding to time-seris ts_2

  • h (int | float) – Height of desired time-series

Returns:

out (ndarray) – Time-series array at height h

get_SAM_df(site, height, require_wind_dir=False, icing=False, add_header=False)[source]

Get SAM wind resource DataFrame for given site

Parameters:
  • site (int) – Site to extract SAM DataFrame for

  • height (int) – Hub height to extract SAM variables at

  • require_wind_dir (bool, optional) – Boolean flag as to whether wind direction will be loaded, by default False

  • icing (bool, optional) – Boolean flag to include relativehumitidy for icing calculation, by default False

  • add_header (bool, optional) – Add units and hub_height below variable names, needed for SAM .csv, by default False

Returns:

res_df (pandas.DataFrame) – time-series DataFrame of resource variables needed to run SAM

classmethod preload_SAM(h5_file, sites, hub_heights, unscale=True, str_decode=True, group=None, hsds=False, hsds_kwargs=None, time_index_step=None, means=False, require_wind_dir=False, precip_rate=False, icing=False)[source]

Placeholder for classmethod that will pre-load project_points for SAM

Parameters:
  • h5_file (str) – h5_file to extract resource from

  • sites (list) – List of sites to be provided to SAM (sites is synonymous with gids aka spatial indices)

  • hub_heights (int | float | list) – Hub heights to extract for SAM

  • unscale (bool) – Boolean flag to automatically unscale variables on extraction

  • str_decode (bool) – Boolean flag to decode the bytestring meta data into normal strings. Setting this to False will speed up the meta data read.

  • group (str) – Group within .h5 resource file to open

  • hsds (bool, optional) – Boolean flag to use h5pyd to handle .h5 ‘files’ hosted on AWS behind HSDS, by default False

  • hsds_kwargs (dict, optional) – Dictionary of optional kwargs for h5pyd, e.g., bucket, username, password, by default None

  • time_index_step (int, optional) – Step size for time_index, used to reduce temporal resolution, by default None

  • means (bool, optional) – Boolean flag to compute mean resource when res_array is set, by default False

  • require_wind_dir (bool, optional) – Boolean flag as to whether wind direction will be loaded, by default False

  • precip_rate (bool, optional) – Boolean flag as to whether precipitationrate_0m will be preloaded, by default False

  • icing (bool, optional) – Boolean flag as to whether icing is analyzed. This will preload relative humidity, by default False

Returns:

SAM_res (SAMResource) – Instance of SAMResource pre-loaded with Solar resource for sites in project_points

LAPSE_RATES = {'pressure': 11109, 'temperature': 6.56}

Air Temperature and Pressure lapse rate in C/km and Pa/km

property adders

Dictionary of all dataset add offset factors

Returns:

adders (dict)

property attrs

Dictionary of all dataset attributes

Returns:

attrs (dict)

property chunks

Dictionary of all dataset chunk sizes

Returns:

chunks (dict)

close()

Close h5 instance

property coordinates

(lat, lon) pairs

Returns:

lat_lon (ndarray)

Type:

Coordinates

property data_version

Get the version attribute of the data. None if not available.

Returns:

version (str | None)

property datasets

Datasets available

Returns:

list

static df_str_decode(df)

Decode a dataframe with byte string columns into ordinary str cols.

Parameters:

df (pd.DataFrame) – Dataframe with some columns being byte strings.

Returns:

df (pd.DataFrame) – DataFrame with str columns instead of byte str columns.

property dsets

Datasets available

Returns:

list

property dtypes

Dictionary of all dataset dtypes

Returns:

dtypes (dict)

get_attrs(dset=None)

Get h5 attributes either from file or dataset

Parameters:

dset (str) – Dataset to get attributes for, if None get file (global) attributes

Returns:

attrs (dict) – Dataset or file attributes

get_dset_properties(dset)

Get dataset properties (shape, dtype, chunks)

Parameters:

dset (str) – Dataset to get scale factor for

Returns:

  • shape (tuple) – Dataset array shape

  • dtype (str) – Dataset array dtype

  • chunks (tuple) – Dataset chunk size

get_meta_arr(rec_name, rows=slice(None, None, None))

Get a meta array by name (faster than DataFrame extraction).

Parameters:
  • rec_name (str) – Named record from the meta data to retrieve.

  • rows (slice) – Rows of the record to extract.

Returns:

meta_arr (np.ndarray) – Extracted array from the meta data record name.

get_scale_factor(dset)

Get dataset scale factor

Parameters:

dset (str) – Dataset to get scale factor for

Returns:

float – Dataset scale factor, used to unscale int values to floats

get_units(dset)

Get dataset units

Parameters:

dset (str) – Dataset to get units for

Returns:

str – Dataset units, None if not defined

property global_attrs

Global (file) attributes

Returns:

global_attrs (dict)

property groups

Groups available

Returns:

groups (list) – List of groups

property h5

Open h5py File instance. If _group is not None return open Group

Returns:

h5 (h5py.File | h5py.Group)

property lat_lon

Extract (latitude, longitude) pairs

Returns:

lat_lon (ndarray)

property meta

Resource meta data DataFrame

Returns:

meta (pandas.DataFrame)

open_dataset(ds_name)

Open resource dataset

Parameters:

ds_name (str) – Dataset name to open

Returns:

ds (ResourceDataset) – Resource for open resource dataset

property res_dsets

Available resource datasets

Returns:

list

property resource_datasets

Available resource datasets

Returns:

list

property scale_factors

Dictionary of all dataset scale factors

Returns:

scale_factors (dict)

property shape

Resource shape (timesteps, sites) shape = (len(time_index), len(meta))

Returns:

shape (tuple)

property shapes

Dictionary of all dataset shapes

Returns:

shapes (dict)

property time_index

Resource DatetimeIndex

Returns:

time_index (pandas.DatetimeIndex)

property units

Dictionary of all dataset units

Returns:

units (dict)