Beispiel #1
0
 def _check_section_option_is_valid(self, option, second):
     """
     Sanity check the section and option are strings and return the flattened option key
     """
     if second is None:
         if not is_text_string(option):
             raise TypeError('Found invalid type ({}) for option ({}) must be a string'.format(type(option), option))
         return option
     else: # fist argument is actually the section/group
         if not is_text_string(option):
             raise TypeError('Found invalid type ({}) for section ({}) must be a string'.format(type(option), option))
         if not is_text_string(second):
             raise TypeError('Found invalid type ({}) for option ({}) must be a string'.format(type(second), second))
         return joinsettings(option, second)
Beispiel #2
0
 def _check_section_option_is_valid(self, option, second):
     """
     Sanity check the section and option are strings and return the flattened option key
     """
     if second is None:
         if not is_text_string(option):
             raise TypeError('Found invalid type ({}) for option ({}) must be a string'.format(type(option), option))
         return option
     else: # fist argument is actually the section/group
         if not is_text_string(option):
             raise TypeError('Found invalid type ({}) for section ({}) must be a string'.format(type(option), option))
         if not is_text_string(second):
             raise TypeError('Found invalid type ({}) for option ({}) must be a string'.format(type(second), second))
         return joinsettings(option, second)
Beispiel #3
0
def convert_value_to_arg_string(value):
    """
    Converts a given object into a string representation of that object
    which can be passed to a function. It is recursive so works on objects
    such as lists.
    """
    if is_text_string(value):
        return "'{}'".format(value)
    if isinstance(value, (list, np.ndarray, tuple)):
        return "[{}]".format(', '.join([convert_value_to_arg_string(v) for v in value]))
    if isinstance(value, dict):
        kv_pairs = []
        for key, val in value.items():
            kv_pairs.append("{}: {}".format(convert_value_to_arg_string(key),
                                            convert_value_to_arg_string(val)))
        return "{{{}}}".format(', '.join(kv_pairs))
    if isinstance(value, (float, np.float)):
        return str(round_to_sig_figs(value, 5))
    return str(value)
Beispiel #4
0
def figure_title(workspaces, fig_num):
    """Create a default figure title from a single workspace, list of workspaces or
    workspace names and a figure number. The name of the first workspace in the list
    is concatenated with the figure number.

    :param workspaces: A single workspace, list of workspaces or workspace name/list of workspace names
    :param fig_num: An integer denoting the figure number
    :return: A title for the figure
    """

    def wsname(w):
        return w.name() if hasattr(w, 'name') else w

    if is_text_string(workspaces) or not isinstance(workspaces, collections.Sequence):
        # assume a single workspace
        first = workspaces
    else:
        assert len(workspaces) > 0
        first = workspaces[0]

    return wsname(first) + '-' + str(fig_num)
Beispiel #5
0
def figure_title(workspaces, fig_num):
    """Create a default figure title from a single workspace, list of workspaces or
    workspace names and a figure number. The name of the first workspace in the list
    is concatenated with the figure number.

    :param workspaces: A single workspace, list of workspaces or workspace name/list of workspace names
    :param fig_num: An integer denoting the figure number
    :return: A title for the figure
    """

    def wsname(w):
        return w.name() if hasattr(w, 'name') else w

    if is_text_string(workspaces) or not isinstance(workspaces, collections.Sequence):
        # assume a single workspace
        first = workspaces
    else:
        assert len(workspaces) > 0
        first = workspaces[0]

    return wsname(first) + '-' + str(fig_num)