shakemap.utils.config¶
- shakemap.utils.config.get_data_path()[source]¶
Return the path to the shakemap package data directory holding modelspec.conf, the template config files, and the example config files.
- Returns:
The full path to the data directory.
- Return type:
- shakemap.utils.config.get_configspec(config=None)[source]¶
Returns the full path to a ShakeMap config spec file.
- shakemap.utils.config.get_config_paths()[source]¶
Returns two paths based on the currently selected profile in the user’s ~/.shakemap/profile.conf: 1) the path to the ShakeMap installation directory; 2) the path to the data directory.
If this function is called within a pytest process, it will return the paths to the repository’s test install and data directories.
- Returns:
The paths to the ShakeMap install directory and the data directory.
- Return type:
- Raises:
FileNotFoundError -- if the profile file can't be found. –
ValueError -- If the correct profile can't be foun in profiles.conf. –
- shakemap.utils.config.path_macro_sub(s, ip='', dp='', gp='', ei='')[source]¶
Replace macros with current paths:
<INSTALL_DIR> is replaced with the contents of ip
<DATA_DIR> is replaced with the contents of dp
<GLOBAL_DATA> is replaced with the contents of gp
<EVENT_ID> is replaced with the contents of ei
e.g., path_macro_sub(“<INSTALL_DIR>/<DATA_DIR>”, “hello”, “world”) would return “hello/world”. It is not an error if the original string does not contain one or any of the substitution strings.
- Parameters:
- Returns:
A new string with the sub-string replacements.
- Return type:
- shakemap.utils.config.get_custom_validator()[source]¶
Returns a validator suitable for validating the ShakeMap config files.
- Returns:
A Validator object.
- Return type:
Validator
- shakemap.utils.config.config_error(config, results)[source]¶
Parse the results of a ConfigObj validation and log the errors. Throws a RuntimeError exception upon completion if any errors or missing sections are encountered.
- Parameters:
config (ConfigObj) – The ConfigObj instance representing the parsed config.
results (dict) – The dictionary returned by the validation of the ‘config’ arguments.
- Returns:
Nothing
- Return type:
Nothing
- Raises:
RuntimeError – Should always raise this exception.
- shakemap.utils.config.check_extra_values(config, logger)[source]¶
Checks the config and warns the user if there are any extra entries in their config file. This function is based on suggested usage in the ConfigObj manual.
- Parameters:
config (ConfigObj) – A ConfigObj instance.
logger (logger) – The logger to which to write complaints.
- Returns:
Nothing.
- Return type:
Nothing
- shakemap.utils.config.check_config(config, logger)[source]¶
Checks that the gmpe, gmice, ipe, and ccf parameters in config are defined in their respective sections. Raises a ValidateError exception if an error is encountered.
- Parameters:
config (ConfigObj) – A ConfigObj instance.
logger (logger) – The logger to which to write complaints.
- Returns:
Nothing.
- Return type:
Nothing
- shakemap.utils.config.nanfloat_type(value)[source]¶
Checks to see if value is a float, or NaN, nan, Inf, -Inf, etc. Raises a ValidateError exception on failure.
- shakemap.utils.config.annotatedfloat_type(value)[source]¶
Checks to see if value is a float, or a float with a ‘c’, ‘m’, or ‘d’ appended. Then converts the value to decimal degrees where an unadorned float or a float plus ‘d’ is interpreted as decimal degrees, ‘m’ is interpreted as arc-minutes, and ‘c’ is interpreted as arc-seconds. Raises a ValidateError exception on failure.
- shakemap.utils.config.weight_list(value, min)[source]¶
Checks to see if value is a list of floats at least min elements long, and whose values add up to 1.0. Raises a ValidateError exception on failure.
- shakemap.utils.config.nanfloat_list(value, min)[source]¶
Checks to see if value is a list of floats, including NaN and Inf. Raises a ValidateError exception on failure.
- shakemap.utils.config.gmpe_list(value, min)[source]¶
Checks to see if value is a list of strings at least min elements long. The entries are not checked for their validity as GMPEs. Raises a ValidateError exception on failure.
- shakemap.utils.config.extent_list(value)[source]¶
Checks to see if value is an empty list or a list of four floats, whose values are valid coordinates in (longitude, longitude, latitude, latitude) order. Returns a list upon success; raises a ValidateError exception on failure.
- shakemap.utils.config.file_type(value)[source]¶
Checks to see if value is a valid file or an empty string. Raises a ValidateError exception on failure. Does macro substitution of <INSTALL_DIR>, <DATA_DIR>, and <GLOBAL_DATA_DIR>.
- shakemap.utils.config.directory_type(value)[source]¶
Checks to see if value is a valid directory or an empty string. Raises a ValidateError exception on failure. Does macro substitution of <INSTALL_DIR>, <DATA_DIR>, and <GLOBAL_DATA_DIR>.
- shakemap.utils.config.status_string(value, min)[source]¶
Checks to see if value is one of the ShakeMap status string of ‘automatic’, ‘released’, or ‘reviewed. Raises a ValidateError exception on failure.
- shakemap.utils.config.cfg_float_list(value)[source]¶
Converts (if possible) the input list (or string) to a list of floats. Raises ValidateError if the input can’t be converted to a list of floats.
- shakemap.utils.config.cfg_float(value)[source]¶
Converts (if possible) the input string to a float. Raises ValidateError if the input can’t be converted to a float.