"""
Utilities not related to neuronal network simulation.

"""

def path_to_modline(filepath):
    """Returns a string representation for module import of a file."""
    # Import the set of parameters
    pathsplit = filepath.split('/')
    modname = pathsplit[-1][:-3]
    return '.'.join(pathsplit[:-1] + [modname])

def print_dict(dictio, level=0):
    """Pretty print a dictionnary."""
    for k in dictio:
        if type(dictio[k]) == type({}):
            print ' '*2*level + str(k)
            print_dict(dictio[k], level + 1)
        else:
            print ' '*2*level + str(k) + ': ' + str(dictio[k])

@@ -1,12 +1,35 @@
+# -*- coding:utf-8 -*-%0A
 %22%22%22%0AUtilitie
@@ -78,16 +78,153 @@
 on.%0A%0A%22%22%22
+%0Afrom numpy import arange%0Afrom os import path%0Afrom copy import deepcopy%0Afrom importlib import import_module%0Afrom itertools import product
 %0A%0Adef pa
@@ -472,16 +472,17 @@
 name%5D)%0A%0A
+%0A
 def prin
@@ -703,16 +703,16 @@
   else:%0A
-
         
@@ -766,8 +766,2141 @@
 tio%5Bk%5D)%0A
+%0A%0Adef gen_parameters(template_file, params, output_dir):%0A    %22%22%22Generate parameter sets from template.%0A%0A    template: filename with a dictionnary of parameters%0A    params: dictionnary of parameters with start, stop, step and unit%0A    output_dir: directory to put the created parameter sets in%0A%0A    Example of params:%0A    params = %7B'Input': %7B'g_Ein0': %7B'start': 0.,%0A                                  'stop' : 1.,%0A                                  'step' : 0.2,%0A                                  'unit' : siemens*meter**-2%7D%7D%7D%0A    %22%22%22%0A    original_template = get_template(template_file)%0A    for category in params:%0A        for var in params%5Bcategory%5D:%0A            # Get the info for the parameter to change%0A            var_details = params%5Bcategory%5D%5Bvar%5D%0A            var_range = arange(var_details%5B'start'%5D, var_details%5B'stop'%5D, var_details%5B'step'%5D)%0A            var_units = var_details%5B'unit'%5D%0A%0A            # Create a new file for each variable value%0A            for value in var_range:%0A                new_parameters = deepcopy(original_template)%0A                new_parameters%5Bcategory%5D%5Bvar%5D = value*var_units%0A                units = str(var_units).replace(' ', '_')%0A                fname = '__'.join(%5Bcategory, var, str(value), units%5D)%0A                fname = fname.replace('.', '_')  # So we can import it easily as a module%0A                fname += '.py'%0A                with open(path.join(output_dir, fname), 'w') as f:%0A                    f.write('PARAMETERS = ' + str(new_parameters))%0A%0A    # Put a __init__.py to make the modules importable%0A    f = open(path.join(output_dir, '__init__.py'), 'w')%0A    f.close()%0A%0A%0Adef get_template(template_file, varname=%22PARAMETERS%22):%0A    %22%22%22Return the parameter variable from a template_file%22%22%22%0A    module = import_module(path_to_modline(template_file))%0A    return getattr(module, varname)%0A%0A%0Afrom brian import *%0Aif __name__ == '__main__':%0A    d = %7B%22Input%22:%0A            %7B'g_Ein0': %7B'start': 0., 'stop': 1, 'step': 0.5, 'unit': siemens*meter**-2%7D,%0A            'tau_Ein': %7B'start': 0., 'stop': 3, 'step': 0.5, 'unit': second%7D%7D%0A        %7D%0A    gen_parameters('paramsets/std_beta.py', d, '/tmp/ps2')%0A

Add a draft function to generate parameter sets