h2integrate.resource.resource_base#
Classes
|
Base configuration class for resource data downloaded from an API. |
|
Base model for downloading resource data from API calls or loading resource data for a single site from a file. |
- class h2integrate.resource.resource_base.ResourceBaseAPIConfig(*, latitude, longitude, timezone, use_fixed_resource_location=True)#
Base configuration class for resource data downloaded from an API.
Subclasses should include the following attributes that are not set in this BaseConfig:
- resource_year (int): Year to download resource data for.
Recommended to have a range_val validator.
- resource_data (dict, optional): Dictionary of user-provided resource data.
Defaults to {}.
- resource_dir (str | Path, optional): Folder to save resource files to or
load resource files from. Defaults to "".
- resource_filename (str, optional): Filename to save resource data to or load
resource data from. Defaults to None.
- valid_intervals (list[int]): time interval(s) in minutes that resource data can be
downloaded in.
Note
Attributes should be updated in subclasses and should not be modifiable by the user. These should be inherit attributes of the subclass.
- Parameters:
latitude (float) -- latitude to download resource data for.
longitude (float) -- longitude to download resource data for.
timezone (float | int) -- timezone to output data in. May be used to determine whether to download data in UTC or local timezone. This should be populated by the value in sim_config['timezone']
use_fixed_resource_location (bool) -- Whether to update resource data in the compute() method. Set to False if the site location is being swept, set to True if the resource data should not be updated to the location (plant_config['site']['latitude'], plant_config['site']['longitude']). Set to True to reduce computation time during optimizations or design sweeps if site location is not being swept. Defaults to True.
- dataset_desc#
description of the dataset, used in file naming. Should be updated in a subclass.
- Type:
str
- resource_type#
type of resource data downloaded, used in folder naming. Should be updated in a subclass.
- Type:
str
- latitude: float#
- longitude: float#
- timezone: int | float#
- use_fixed_resource_location: bool#
- dataset_desc: str#
- resource_type: str#
- class h2integrate.resource.resource_base.ResourceBaseAPIModel(**kwargs)#
Base model for downloading resource data from API calls or loading resource data for a single site from a file.
- Attributes
resource_data (dict | None): resource data that is created in setup() method. dt (int): timestep in seconds. config (object): configuration class that inherits ResourceBaseAPIConfig.
- Inputs:
latitude (float): latitude corresponding to location for resource data longitude (float): longitude corresponding to location for resource data
- Outputs:
dict: dictionary of resource data.
- initialize()#
Perform any one-time initialization run at instantiation.
- setup()#
Declare inputs and outputs.
- Available attributes:
name pathname comm options
- helper_setup_method()#
Prepares and configures resource specifications for the resource API based on plant and site configuration options.
This method extracts relevant configuration details from the self.options dictionary, pulls values for latitude, longitude, resource directory and timezone from the
sitesection ofplant_configif these parameters are not specified in theresource_configand returns the updated resource specifications dictionary.- Returns:
dict -- The resource specifications dictionary with defaults set for latitude, longitude, resource_dir, and timezone.
- create_filename(latitude, longitude)#
Create default filename to save downloaded data to. Suggested filename formatting is:
"{latitude}_{longitude}_{resource_year}_{dataset_desc}_{interval}min_{tz_desc}_tz.csv" where "tz_desc" is "utc" if the timezone is zero, or "local" otherwise.
- Parameters:
latitude (float) -- latitude corresponding to location for resource data
longitude (float) -- longitude corresponding to location for resource data
- Returns:
str -- filename for resource data to be saved to or loaded from.
- create_url(latitude, longitude)#
Create url for data download.
- Parameters:
latitude (float) -- latitude corresponding to location for resource data
longitude (float) -- longitude corresponding to location for resource data
- Returns:
str -- url to use for API call.
- download_data(url, fpath)#
Download data from url to a file.
- Parameters:
url (str) -- url to call to access data.
fpath (Path | str) -- filepath to save data to.
- Returns:
bool -- True if data was downloaded successfully, False if error was encountered.
- load_data(fpath)#
Loads data from a file, reformats data to follow a standardized naming convention, converts data to standardized units, and creates a data time profile.
- Parameters:
fpath (str | fpath) -- filepath to load the data from.
- Raises:
NotImplementedError -- this method should be implemented in a subclass.
- Returns:
dict --
- dictionary of data that follows the corresponding standardized
naming convention and is in standardized units. The time profile created should be found in the 'time' key.
- get_data(latitude, longitude, first_call=True)#
Get resource data to handle any of the expected inputs. This method does the following:
- If this is not the first resource call of the simulation, check if latitude and longitude
inputs are different than the previous latitude and longitude values. If resource data has not been already loaded for the, continue to Step 1.
Check if resource data was input. If not, continue to Step 2.
Get valid resource_dir with the method check_resource_dir()
- Create a filename if resource_filename was not input or if the site location changed
with the method create_filename(). Otherwise, use resource_filename as the filename.
- If the resulting resource_dir and filename from Steps 2 and 3 make a valid filepath,
load data using load_data(). Otherwise, continue to Step 5.
Create the url to download data using create_url() and continue to Step 6.
- Download data from the url created in Step 5 and save to a filepath created from the
resulting resource_dir and filename from Steps 2 and 3. Continue to Step 7.
Load data from the file created in Step 6 using load_data()
- Parameters:
latitude (float) -- latitude corresponding to location for resource data
longitude (float) -- longitude corresponding to location for resource data
first_call (bool) -- True if called from setup() method, False if called from compute() method to prevent unnecessary reloading of data.
- Raises:
ValueError -- If data was not successfully downloaded from the API
ValueError -- An unexpected case was encountered in handling data
- Returns:
Any -- resource data in the format expected by the subclass.
- compute(inputs, outputs, discrete_inputs, discrete_outputs)#
Compute outputs given inputs. The model is assumed to be in an unscaled state.
An inherited component may choose to either override this function or to define a compute_primal function.
- Parameters:
inputs (Vector) -- Unscaled, dimensional input variables read via inputs[key].
outputs (Vector) -- Unscaled, dimensional output variables read via outputs[key].
discrete_inputs (dict-like or None) -- If not None, dict-like object containing discrete input values.
discrete_outputs (dict-like or None) -- If not None, dict-like object containing discrete output values.