sparc.api module
- class sparc.api.SparcAPI(json_api=None)[source]
Bases:
object
An interface to the parameter settings in SPARC-X calculator. User can use the SparcAPI instance to validate and translate parameters that matches a certain version of the SPARC-X code.
- sparc_version
Version of SPARC.
- Type:
str
- categories
Categories of parameters.
- Type:
dict
- parameters
Detailed parameters information.
- Type:
dict
- other_parameters
Additional parameters.
- Type:
dict
- data_types
Supported data types.
- Type:
dict
- convert_string_to_value(parameter, string)[source]
Converts string input to the appropriate data type.
- convert_string_to_value(parameter, string)[source]
Converts a string input to the appropriate value type of the parameter.
- Parameters:
parameter (str) – The name of the parameter.
string (str) – The string input to convert.
- Returns:
The converted value, type depends on parameter’s expected type.
- Raises:
TypeError – If the input is not a string.
ValueError – If the string is not a valid input for the parameter.
- convert_value_to_string(parameter, value)[source]
Converts a value to its string representation based on the parameter type.
- Parameters:
parameter (str) – The name of the parameter.
value – The value to convert.
- Returns:
The string representation of the value.
- Return type:
str
- Raises:
ValueError – If the value is not valid for the parameter.
- get_parameter_dict(parameter)[source]
Retrieves the dictionary for a specified parameter.
- Parameters:
parameter (str) – The name of the parameter.
- Returns:
Dictionary containing details of the parameter.
- Return type:
dict
- Raises:
KeyError – If the parameter is not known to the SPARC version.
- help_info(parameter)[source]
Provides a detailed information string for a given parameter.
- Parameters:
parameter (str) – The name of the parameter to get information for.
- Returns:
A formatted string with detailed information about the parameter.
- Return type:
str
- validate_input(parameter, input)[source]
Validates if the given input is appropriate for the specified parameter’s type.
- Parameters:
parameter (str) – The name of the parameter.
input – The input to validate, can be of various types (string, int, float, numpy types).
- Returns:
True if input is valid, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the data type of the parameter is not supported.