Exemple #1
0
def read_expmt_groups(fparam):
    lines = fio.clean_lines(fparam)
    lines = [line for line in lines if line.split(': ')[0] == 'expmt_groups']

    try:
        return lines[0].split(': ')[1][1:-1].split(', ')
    except:
        print("Couldn't get a handle on expmts")
        return 0
Exemple #2
0
def read_sim_prefix(fparam):
    lines = fio.clean_lines(fparam)
    param_list = [line for line in lines if line.split(': ')[0].startswith('sim_prefix')]

    # Assume we found something ...
    if param_list:
        return param_list[0].split(" ")[1]
    else:
        print("No sim_prefix found")
        return 0
Exemple #3
0
    def __check_server(self):
        f_server = os.path.join(self.dproj, '.server_default')

        if os.path.isfile(f_server):
            # read the file and set the default server
            lines_f = fio.clean_lines(f_server)

            # there should only be one thing in this file, so assume that's the server name
            return lines_f[0]
        else:
            return ''
Exemple #4
0
def changed_vars(fparam):
    # Strip empty lines and comments
    lines = fio.clean_lines(fparam)
    lines = [line for line in lines if line[0] != '#']

    # grab the keys and vals in a list of lists
    # each item of keyvals is a pair [key, val]
    keyvals = [line.split(": ") for line in lines]

    # match the list for changed items starting with "AKL[(" on the 1st char of the val
    var_list = [line for line in keyvals if re.match('[AKL[\(]', line[1][0])]

    # additional default info to add always
    list_meta = ['N_trials', 'N_sims', 'Run_Date']

    # list concatenate these lists
    var_list += [line for line in keyvals if line[0] in list_meta]

    # return the list of "changed" or "default" vars
    return var_list
Exemple #5
0
def read(fparam):
    lines = fio.clean_lines(fparam)
    p = {}
    gid_dict = {}
    for line in lines:
        if line.startswith('#'): continue
        keystring, val = line.split(": ")
        key = keystring.strip()
        if val[0] is '[':
            val_range = val[1:-1].split(', ')
            if len(val_range) is 2:
                ind_start = int(val_range[0])
                ind_end = int(val_range[1]) + 1
                gid_dict[key] = np.arange(ind_start, ind_end)
            else:
                gid_dict[key] = np.array([])
        else:
            try:
                p[key] = float(val)
            except ValueError:
                p[key] = str(val)
    return gid_dict, p
Exemple #6
0
    def __read_sim(self, f_psim):
        lines = fio.clean_lines(f_psim)

        # ignore comments
        lines = [line for line in lines if line[0] is not '#']
        p = {}

        for line in lines:
            # splits line by ':'
            param, val = line.split(": ")

            # sim_prefix is not a rotated variable
            # not sure why `if param is 'sim_prefix':` does not work here
            if param == 'sim_prefix':
                p[param] = str(val)

            # expmt_groups must be listed before other vals
            elif param == 'expmt_groups':
                # this list will be the preservation of the original order
                self.expmt_groups = [
                    expmt_group for expmt_group in val[1:-1].split(', ')
                ]

                # this dict here for easy access
                # p_group saves each of the changed params per group
                self.p_group = dict.fromkeys(self.expmt_groups)

                # create empty dicts in each
                for group in self.p_group:
                    self.p_group[group] = {}

            elif param.startswith('prng_seedcore_'):
                p[param] = int(val)
                # key = param.split('prng_seedcore_')[-1]
                # self.prng_seedcore[key] = val

                # only add values that will change
                if p[param] == -1:
                    self.prng_seed_list.append(param)

            elif param.startswith('distribution_'):
                p[param] = str(val)

            elif param == 'Run_Date':
                pass

            else:
                # assign group params first
                if val[0] is '{':
                    # check for a linspace as a param!
                    if val[1] is 'L':
                        # in this case, val_range must be as long as the correct expmt_group length
                        # everything beyond that will be truncated by the zip operation below
                        # param passed will strip away the curly braces and just pass the linspace
                        val_range = self.__expand_linspace(val[1:-1])
                    else:
                        val_range = self.__expand_array(val)

                    # add the expmt_group param to the list if it's not already present
                    if param not in self.expmt_group_params:
                        self.expmt_group_params.append(param)

                    # parcel out vals to exp groups with assigned param names
                    for expmt_group, val in zip(self.expmt_groups, val_range):
                        self.p_group[expmt_group][param] = val

                # interpret this as a list of vals
                # type floats to a np array
                elif val[0] is '[':
                    p[param] = self.__expand_array(val)

                # interpret as a linspace
                elif val[0] is 'L':
                    p[param] = self.__expand_linspace(val)

                elif val[0] is 'A':
                    p[param] = self.__expand_arange(val)

                else:
                    try:
                        p[param] = float(val)
                    except ValueError:
                        p[param] = str(val)

        # hack-y. sorry, future
        # tstop_* = 0 is valid now, resets to the actual tstop
        # with the added bonus of saving this time to the indiv params
        for param, val in p.items():
            if param.startswith('tstop_'):
                if isinstance(val, float):
                    if val == 0:
                        p[param] = p['tstop']
                elif isinstance(val, np.ndarray):
                    p[param][p[param] == 0] = p['tstop']

        return p