getdist.inifile

class getdist.inifile.IniFile(settings=None, keep_includes=False, expand_environment_variables=True)[source]

Class for storing option parameter values and reading/saving to file

Unlike standard .ini files, IniFile allows inheritance, in that a .ini file can use INCLUDE(..) and DEFAULT(...) to include or override settings in another file (to avoid duplication)

Variables:
  • params – dictionary of name, values stored
  • comments – dictionary of optional comments for parameter names
Parameters:
  • settings – a filename of a .ini file to read, or a dictionary of name/values
  • keep_includes
    • False: load all INCLUDE and DEFAULT files, making one params dictionary
    • True: only load settings in main file, and store INCLUDE and DEFAULT entries into defaults and includes filename lists.
  • expand_environment_variables – whether to expand $(var) placeholders in parameter values using environment variables
array_bool(name, index=1, default=None)[source]

Get one boolean value, for entries of the form name(index)

Parameters:
  • name – base parameter name
  • index – index (in brackets)
  • default – default value
array_float(name, index=1, default=None)[source]

Get one float value, for entries of the form name(index)

Parameters:
  • name – base parameter name
  • index – index (in brackets)
  • default – default value
array_int(name, index=1, default=None)[source]

Get one int value, for entries of the form name(index)

Parameters:
  • name – base parameter name
  • index – index (in brackets)
  • default – default value
array_string(name, index=1, default=None)[source]

Get one str value, for entries of the form name(index)

Parameters:
  • name – base parameter name
  • index – index (in brackets)
  • default – default value
bool(name, default=False)[source]

Get boolean value

Parameters:
  • name – parameter name
  • default – default value if not set
bool_list(name, default=None)[source]

Get list of boolean values, e.g. from name = T F T

Parameters:
  • name – parameter name
  • default – default value if not set
expand_placeholders(s)[source]

Expand shell variables of the forms $(var), like in Makefiles

float(name, default=None)[source]

Get float value

Parameters:
  • name – parameter name
  • default – default value
float_list(name, default=None)[source]

Get list of float values

Parameters:
  • name – parameter name
  • default – default value
hasKey(name)[source]

Test if key name exists

Parameters:name – parameter name
Returns:True or False test if key name exists
int(name, default=None)[source]

Get int value

Parameters:
  • name – parameter name
  • default – default value
int_list(name, default=None)[source]

Get list of int values

Parameters:
  • name – parameter name
  • default – default value
isSet(name, allowEmpty=False)[source]

Tests whether value for name is set or is empty

Parameters:
  • name – name of parameter
  • allowEmpty – whether to allow empty strings (return True is parameter name exists but is not set, “x = ”)
list(name, default=None, tp=None)[source]

Get list (from space-separated values)

Parameters:
  • name – parameter name
  • default – default value
  • tp – type for each member of the list
ndarray(name, default=None, tp=<type 'numpy.float64'>)[source]

Get numpy array of values

Parameters:
  • name – parameter name
  • default – default value
  • tp – type for array
saveFile(filename=None)[source]

Save to a .ini file

Parameters:filename – name of file to save to
setAttr(name, instance, default=None, allowEmpty=False)[source]

Set attribute of an object to value of parameter, using same type as existing value or default

Parameters:
  • name – parameter name
  • instance – instance of an object, so instance.name is the value to set
  • default – default value if instance.name does not exist
  • allowEmpty – whether to allow empty values
split(name, default=None, tp=None)[source]

Gets a list of values, optionally cast to type tp

Parameters:
  • name – parameter name
  • default – default value
  • tp – type for each list member
string(name, default=None, allowEmpty=True)[source]

Get string value

Parameters:
  • name – parameter name
  • default – default value if not set
  • allowEmpty – whether to return empty string if value is empty (otherwise return default)