rex.multi_res_resource.MultiResolutionResource

class MultiResolutionResource(h5_hr, h5_lr, handler_class=<class 'rex.resource.Resource'>, handle_kwargs=None, nn_map=None, nn_d=None)[source]

Bases: object

Multi-resolution resource handler. Uses two resource handlers for files at two different spatiotemporal resolutions, and then interpolates the lower resolution data to the higher resolution data on the fly.

Parameters:
  • h5_hr (str) – Filepath to high-resolution h5 resource file.

  • h5_lr (str) – Filepath to low-resolution h5 resource file.

  • handler_class (str) – rex Resource handler class (not initialized) to open both the high and low resolution h5 files (both files must be of the same resource handler class).

  • handle_kwargs (dict, optional) – Dictionary of optional keyword arguments to initialize the handler_class for the h5_hr and h5_lr

  • nn_map (np.ndarray) – Optional 1D array of nearest neighbor mappings. This will be created if not provided. This is created by making a kdtree of the lr_res coords and then querying with the hr_res coords. As an example, nn_map[10] will return the lr_res index corresponding to gid 10 from the hr_res data

  • nn_d (np.ndarray) – Optional 1D array of nearest neighbor distances. This will be created if not provided. This is created by making a kdtree of the lr_res coords and then querying with the hr_res coords. As an example, nn_map[10] will return the distance between hr_res gid=10 and the corresponding lr_res site

Methods

close()

Close active file handlers.

make_nn_map(hr_res, lr_res)

Make the low-res-to-high-res resource nearest neighbor mapping

map_ds_slice(ds_slice)

Map the requested dataset slice from high-res spatial indices to low-res spatial indices

preload_SAM(h5_hr, h5_lr, sites, *args[, ...])

Pre-load resource data in a SAM resource handler for PySAM / reV run

time_interp(arr)

Perform temporal interpolation on the low-res data to match the high-res data.

Attributes

HR_ATTRS

Attributes that are always taken only from the high-res data handler

INTERPOLABLE_DSETS

VARIABLE_NAME

VARIABLE_UNIT

HR_ATTRS = ('meta', 'time_index', 'coordinates', 'lat_lon', 'data_version', 'global_attrs', 'get_meta_arr', 'shape')

Attributes that are always taken only from the high-res data handler

static make_nn_map(hr_res, lr_res)[source]

Make the low-res-to-high-res resource nearest neighbor mapping

Parameters:
  • hr_res (Resource | MultiFileResource | MultiYearResource) – rex resource handler for the high-resolution data. All retrieval gid’s are based on this dataset, and the lr_res data is mapped to this.

  • lr_res (Resource | MultiFileResource | MultiYearResource) – rex resource handler for the low-resolution data. The data from this handler is mapped to the hr_res data.

Returns:

  • nn_d (np.ndarray) – 1D array of nearest neighbor distances. This is created by making a kdtree of the lr_res coords and then querying with the hr_res coords. As an example, nn_map[10] will return the distance between hr_res gid=10 and the corresponding lr_res site

  • nn_map (np.ndarray) – 1D array of nearest neighbor mappings. This is created by making a kdtree of the lr_res coords and then querying with the hr_res coords. As an example, nn_map[10] will return the lr_res index corresponding to gid 10 from the hr_res data

map_ds_slice(ds_slice)[source]

Map the requested dataset slice from high-res spatial indices to low-res spatial indices

Parameters:

ds_slice (tuple) – Tuple where each entry is a slice or list index argument for the respective axis, e.g. (slice(None), [0, 2]) retrieves the full axis=0 and indices 0 and 2 from axis=1.

Returns:

ds_slice (tuple) – Tuple where each entry is a slice or list index argument for the respective axis, e.g. (slice(None), [0, 2]) retrieves the full axis=0 and indices 0 and 2 from axis=1. The returned value is now low-res spatial indices using simple nearest neighbor.

time_interp(arr)[source]

Perform temporal interpolation on the low-res data to match the high-res data.

Parameters:

arr (np.ndarray) – 2D array with shape (time, sites) where time corresponds to the low-resolution resource.

Returns:

arr (np.ndarray) – 2D array with shape (time, sites) where the time axis has been linearly interpolated to the high-resolution time index.

close()[source]

Close active file handlers.

classmethod preload_SAM(h5_hr, h5_lr, sites, *args, handler_class=<class 'rex.resource.Resource'>, nn_map=None, nn_d=None, **kwargs)[source]

Pre-load resource data in a SAM resource handler for PySAM / reV run

Parameters:
  • h5_hr (str) – Filepath to high-resolution h5 resource file.

  • h5_lr (str) – Filepath to low-resolution h5 resource file.

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

  • *args (list) – Additional arguments required by the resource-specific data handler preload_SAM() method (e.g. “hub_heights” is required by WindResource handlers and can be provided here).

  • handler_class (str) – rex Resource handler class (not initialized) to open both the high and low resolution h5 files (both files must be of the same resource handler class).

  • nn_map (np.ndarray) – Optional 1D array of nearest neighbor mappings. This will be created if not provided. This is created by making a kdtree of the lr_res coords and then querying with the hr_res coords. As an example, nn_map[10] will return the lr_res index corresponding to gid 10 from the hr_res data

  • nn_d (np.ndarray) – Optional 1D array of nearest neighbor distances. This will be created if not provided. This is created by making a kdtree of the lr_res coords and then querying with the hr_res coords. As an example, nn_map[10] will return the distance between hr_res gid=10 and the corresponding lr_res site

  • **kwargs (dict) – Additional arguments required to either initialize the resource-specific data handler or call the resource-specific preload_SAM() method (e.g. “hub_heights” is required by WindResource.preload_SAM() method and can be provided here in addition to optional args like “icing” or “precip_rate”).

Returns:

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