nrel.hive.util.fs

Module Contents

Functions

global_hive_config_search(...)

searches for the global hive config, and if found, loads it. if not, loads the default from nrel.hive.resources

construct_asset_path(→ str)

constructs the path to a scenario asset relative to a scenario directory. attempts to load at both

construct_scenario_asset_path(→ str)

constructs the path to a scenario asset relative to a scenario directory. attempts to load at both

find_scenario(→ pathlib.Path)

allows users to declare built-in scenario filenames without absolute/relative paths or

searches for the global hive config, and if found, loads it. if not, loads the default from nrel.hive.resources :return: global hive config

nrel.hive.util.fs.construct_asset_path(file: str | pathlib.Path, scenario_directory: str | pathlib.Path, default_directory_name: str, resources_subdirectory: str) str[source]

constructs the path to a scenario asset relative to a scenario directory. attempts to load at both the user-provided relative path, and if that fails, attempts to load at the default directory; finally, checks the resources directory for a fallback.

for example, with file “leaf.yaml”, scenario_directory “/home/jimbob/hive/denver” and default_directory “powertrain”, this will test “/home/jimbob/hive/denver/leaf.yaml” then “/home/jimbob/hive/denver/vehicles/leaf.yaml” and finally “hive/resources/powertrain/leaf.yaml” and return the first path where the file is found to exist.

Parameters:
  • file – file we are seaching for

  • scenario_directory – the scenario directory

  • default_directory_name – the directory name where assets of this type are typically saved

  • resources_subdirectory – the subdirectory of resources where we also expect this could be saved

Returns:

the path string if the file exists, otherwise None

Raises:

FileNotFoundError if asset is not found

nrel.hive.util.fs.construct_scenario_asset_path(file: str | pathlib.Path, scenario_directory: str | pathlib.Path, default_directory_name: str) str[source]

constructs the path to a scenario asset relative to a scenario directory. attempts to load at both the user-provided relative path, and if that fails, attempts to load at the default directory.

for example, with file “vehicles.csv”, scenario_directory “/home/jimbob/hive/denver” and default_directory “vehicles”, this will test “/home/jimbob/hive/denver/vehicles.csv” then “/home/jimbob/hive/denver/vehicles/vehicles.csv” and return the first path where the file is found to exist.

Parameters:
  • file – file we are searching for

  • scenario_directory – the directory where the scenario file was found

  • default_directory_name – the default directory name for the type of asset we are checking for

Returns:

the path string if the file exists, otherwise None

Raises:

FileNotFoundError if asset is not found

nrel.hive.util.fs.find_scenario(user_provided_scenario: str) pathlib.Path[source]

allows users to declare built-in scenario filenames without absolute/relative paths or expects the user has provided a valid relative/absolute to another file

Parameters:

user_provided_scenario – the scenario requested

Returns:

the absolute path of this scenario if it exists

Raises:

FileNotFoundError