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:

str

shakemap.utils.config.get_configspec(config=None)[source]

Returns the full path to a ShakeMap config spec file.

Parameters:

config (str) – Name of config spec to find, or None.

Returns:

The path to a config spec, or

Return type:

str

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:

tuple

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.get_model_config(install_path, datadir, logger)[source]
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:
  • s (str) – The string into which the replacements are made.

  • ip (str) – The string with which to replace <INSTALL_DIR>.

  • dp (str) – The string with which to replace <DATA_DIR>.

  • gp (str) – The string with which to replace <GLOBAL_DATA>.

  • ei (str) – The string with which to replace <EVENT_ID>.

Returns:

A new string with the sub-string replacements.

Return type:

str

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.check_all_configs(configdir)[source]
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.

Parameters:

value (str) – A string representing a float NaN or Inf.

Returns:

The input value converted to its float equivalent.

Return type:

float

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.

Parameters:

value (str) – A string representing a float or a float appended with ‘d’, ‘m’, or ‘c’ (for degrees, minutes, seconds).

Returns:

The input value converted to decimal degrees.

Return type:

float

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.

Parameters:

value (str) – A string representing a list of floats.

Returns:

The input string converted to a list of floats.

Return type:

list

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.

Parameters:

value (str) – A string representing a list of floats.

Returns:

The input string converted to a list of floats.

Return type:

list

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.

Parameters:

value (str) – A string representing a list of GMPEs.

Returns:

The input string converted to a list of GMPEs.

Return type:

list

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.

Parameters:

value (str) – A string representing a list of geographic coordinates.

Returns:

The input string converted to a list of floats.

Return type:

list

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

Parameters:

value (str) – A string representing the path to a file.

Returns:

The input string.

Return type:

str

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

Parameters:

value (str) – A string representing the path to a directory.

Returns:

The input string.

Return type:

str

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.

Parameters:

value (str) – A status string.

Returns:

The input string. ‘automatic’ is returned if value is empty.

Return type:

str

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.

Parameters:

value (str or list) – A string or list of strings to be converted to a list of floats.

Returns:

The input converted to a list of floats.

Return type:

list

Raises:

ValidateError

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.

Parameters:

value (str) – A string to be converted to a float.

Returns:

The input converted to a float.

Return type:

float

Raises:

ValidateError

shakemap.utils.config.cfg_bool(value)[source]

Converts (if possible) the input string to a bool. Raises ValidateError if the input can’t be converted to a bool.

Parameters:

value (str) – A string to be converted to a bool.

Returns:

The input converted to a bool.

Return type:

bool

Raises:

ValidateError

shakemap.utils.config.check_profile_config(config)[source]

Validation checks on the profile config. At least one profile must exist (otherwise exit) and the paths for each profile should exist, otherwise the profile entry is removed.

Parameters:

config (ConfigObj) – The ConfigObj instance.