Options#
- class pybads.bads.Options(default_options_path: str, evaluation_parameters: dict = None, user_options: dict = None)[source]#
This class is responsible for Options.
- Parameters:
- default_options_pathstr
The path to default options that can be overwritten by the user.
- evaluation_parametersdict
Parameters used to evaluate the options.
- user_optionsdict
User defined values to overwrite default options.
- Attributes:
- unset_user_optionsset
The names of the user options whose value is
None, which stands for the default: they are not set, and not inuseroptions, but their names are checked byvalidate_option_names().
Notes
The mapping entry
options["useroptions"]holds the set of option names supplied by the user with non-None values.load_options_file()leaves their values unchanged.- eval(key: str, evaluation_parameters: dict)[source]#
Evaluate an option using evaluation_parameters if it is a callable, otherwise return the value of the option.
- Parameters:
- keystr
The name of the option.
- evaluation_parametersdict
Parameters for the options in case it is a callable. These have to match the key arguments of the callable and are ignored if it is not a callable.
- Returns:
- valobject
Value of the object which has been evaluated if it is a callable.
- classmethod init_from_existing_options(default_options_path: str, evaluation_parameters: dict = None, other: Options = None)[source]#
Initialize an options instance using default options and another options instance.
Only the user-definied options from the other object will overwrite the default options. Everything else will come from the default options.
- Parameters:
- default_options_pathstr
The path to default options that can be overwritten by the user.
- evaluation_parametersdict
Parameters used to evaluate the options.
- otherOptions
User defined values to overwrite default options.
- Returns:
- new_optionsOptions
The new options object with the values merged as described above.
- load_options_file(options_path: str, evaluation_parameters: dict = None)[source]#
Load options from an ini file and evaluate them using the specified
evaluation_parameters.Note that strings starting with # in the .ini file act as description to the option in the following line.
- Parameters:
- options_pathstr
The path to an options ini file that should be loaded.
- evaluation_parametersdict, optional
Parameters used to evaluate the options.
- validate_boolean_options(options_paths: list, extra_names: tuple = (), excluded_names: tuple = ())[source]#
Check that the user’s value of each boolean option is
TrueorFalse.The boolean options are those whose default in the ini files specified by
options_pathsisTrueorFalse, and those named inextra_names, except those named inexcluded_names. NumPy booleans are booleans. Any other value is refused, a MATLAB-style string such as"off", which is truthy, included.- Parameters:
- options_pathslist of str
A list of paths to the ini files that hold the default options.
- extra_namestuple of str, optional
The names of other options that take
TrueorFalse, and whose default isNone.- excluded_namestuple of str, optional
The names of options whose default is
TrueorFalseand that take other values too.
- Raises:
- ValueError
Raised when the user’s value of a boolean option is not a boolean.
- validate_option_names(options_paths: list)[source]#
Check that ini files specified by the list of
options_pathscontain the option names from this options object at least once.Note that this method checks not if there are option names in files that are not in the object.
- Parameters:
- options_pathslist of str
A list of paths to ini files can contain the allowed option names.
- Raises:
- ValueError
Raised when an option exists in this object but not in one of the specified ini files.