'''Sets up simulation directories and parameters for NEST simulations
 including LFP approximations'''
import os
import parameters as ps
import numpy as np
from nest_parameters import get_unique_id, NEST_PSET

if __name__ == '__main__':
    ## Add the random varying parameters
    PSET = ps.ParameterSpace(NEST_PSET)
    PSET['eta'] = ps.ParameterRange(np.linspace(0.8, 4.0, 9))
    PSET['g'] = ps.ParameterRange(np.linspace(3.5, 8.0, 10))
    PSET['J'] = ps.ParameterRange(np.linspace(0.05, 0.4, 8))
    PSET['sigma_factor'] = ps.ParameterRange([1.0])
    PSET['simtime'] = 3000.

    PSET['tauMem_gaussian'] = True
    PSET['delay_gaussian'] = False
    PSET['J_gaussian'] = False
    PSET['t_ref_gaussian'] = False
    PSET['theta_gaussian'] = False

    # set up directory structure
    savefolder = os.path.join('./lfp_simulations_gaussian_taumem/')
    parameterset_dest = os.path.join(savefolder, 'parameters')
    log_dir = os.path.join(savefolder, 'logs')
    nest_jobscript_dest = os.path.join(savefolder, 'nest_jobs')
    nest_output = os.path.join(savefolder, 'nest_output')

    if not os.path.isdir(savefolder):
        os.mkdir(savefolder)
    Returns
    -------
    key: str
        hash key

    '''
    sorted_params = sort_deep_dict(paramset)
    string = pickle.dumps(sorted_params)
    key = hashlib.md5(string).hexdigest()
    return key


PSPACES = dict()

# check scaling with MPI pool size
PSPACES['MPI'] = ps.ParameterSpace(dict())
PSPACES['MPI'].update(
    dict(
        # Population sizes
        POP_SIZE_REF=[2400, 480],

        # allow different seeds for different network iterations
        GLOBALSEED=ps.ParameterRange([1234, 65135, 216579876]),

        # MPI pool size
        MPISIZE=ps.ParameterRange([120, 240, 480, 960, 1920, 2880]),

        # bool flag switching LFP calculations on or off (faster)
        COMPUTE_LFP=ps.ParameterRange([False, True]),

        # population size scaling (multiplied with values in