rex.multi_file_resource.MultiFileWTK

class MultiFileWTK(h5_source, unscale=True, str_decode=True, check_files=False)[source]

Bases: rex.multi_file_resource.MultiFileResource, rex.renewable_resource.WindResource

Class to handle 5min WIND Toolkit data

See also

resource.MultiFileResource

Parent class

resource.WindResource

Parent class

Examples

MultiFileWTK automatically searches for files of the form *m.h5

>>> file = '$TESTDATADIR/wtk'
>>> with MultiFileWTK(file) as res:
>>>     print(list(res._h5_files)
>>>     print(res.datasets)
['$TESTDATADIR/wtk_2010_200m.h5',
 '$TESTDATADIR/wtk_2010_100m.h5']
['coordinates', 'meta', 'pressure_100m', 'pressure_200m',
 'temperature_100m', 'temperature_200m', 'time_index',
 'winddirection_100m', 'winddirection_200m', 'windspeed_100m',
 'windspeed_200m']

MultiFileWTK, like WindResource can interpolate / extrapolate hub-heights

>>> with MultiFileWTK(file) as res:
>>>     wspd = res['windspeed_150m']
>>>
>>> wspd
[[16.19     16.25     16.305    ... 16.375    16.39     16.39    ]
 [16.15     16.205    16.255001 ... 16.35     16.365    16.39    ]
 [16.154999 16.195    16.23     ... 16.335    16.32     16.34    ]
 ...
 [10.965    11.675    12.08     ... 15.18     14.805    14.42    ]
 [11.66     11.91     12.535    ... 13.31     12.23     12.335   ]
 [12.785    13.295    14.014999 ... 12.205    11.360001 11.64    ]]
Parameters
  • h5_source (str | list) – Unix shell style pattern path with * wildcards to multi-file resource file sets. Files must have the same time index and coordinates but can have different datasets. Can also be an explicit list of complete filepaths.

  • 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.

  • check_files (bool) – Check to ensure files have the same coordinates and time_index

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_nearest_h(h, heights)

Get two nearest h values in heights.

get_scale_factor(dset)

Get dataset scale factor

get_units(dset)

Get dataset units

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

Linear interpolate/extrapolate time-series data to height h

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_source, 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

SCALE_ATTR

UNIT_ATTR

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.

heights

Extract available heights for pressure, temperature, windspeed, precip, and winddirection variables.

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 preload_SAM(h5_source, sites, hub_heights, unscale=True, str_decode=True, time_index_step=None, means=False, require_wind_dir=False, precip_rate=False, icing=False, check_files=False)[source]

Placeholder for classmethod that will pre-load project_points for SAM

Parameters
  • h5_source (str | list) – Unix shell style pattern path with * wildcards to multi-file resource file sets. Files must have the same time index and coordinates but can have different datasets. Can also be an explicit list of complete filepaths.

  • sites (list) – List of sites to be provided to SAM

  • 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.

  • 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) – Boolean flag as to whether wind direction will be loaded.

  • precip_rate (bool) – Boolean flag as to whether precipitationrate_0m will be preloaded

  • icing (bool) – Boolean flag as to whether icing is analyzed. This will preload relative humidity.

  • check_files (bool) – Check to ensure files have the same coordinates and time_index

Returns

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

property attrs

Dictionary of all dataset attributes

Returns

attrs (dict)

property chunks

Dictionary of all dataset chunk sizes

Returns

chunks (dict)

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

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

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_SAM_df(site, height, require_wind_dir=False, icing=False)

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

Returns

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

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.

static get_nearest_h(h, heights)

Get two nearest h values in heights. Determine if h is inside or outside the range of heights (requiring extrapolation instead of interpolation)

Parameters
  • h (int | float) – Height value of interest

  • heights (list) – List of available heights

Returns

  • nearest_h (list) – list of 1st and 2nd nearest height in heights

  • extrapolate (bool) – Flag as to whether h is inside or outside heights range

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 heights

Extract available heights for pressure, temperature, windspeed, precip, and winddirection variables. Used for interpolation/extrapolation.

Returns

self._heights (dict) – Dictionary of available heights for: windspeed, winddirection, temperature, and pressure

property lat_lon

Extract (latitude, longitude) pairs

Returns

lat_lon (ndarray)

static linear_interp(ts_1, h_1, ts_2, h_2, h)

Linear 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

property meta

Resource meta data DataFrame

Returns

meta (pandas.DataFrame)

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

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.

open_dataset(ds_name)

Open resource dataset

Parameters

ds_name (str) – Dataset name to open

Returns

ds (ResourceDataset) – Resource for open resource dataset

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

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

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)

static shortest_angle(a0, a1)

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

static stability_function(zeta)

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

Parameters

zeta (ndarray) – Normalized length

Returns

numpy.ndarray – stability measurements.

property time_index

Resource DatetimeIndex

Returns

time_index (pandas.DatetimeIndex)

property units

Dictionary of all dataset units

Returns

units (dict)