def collect_res_bug(cls, key_path=[], nameFile=None, allPrefix='res_', folderName=None): """Extract results stored in (a) txt file(s) and group them according to some key values (where key_path provides the path in the potentially nested structure of the results to find the key(s)) Output: a dictionary where key is the concatenation of the unique set of keys found and value is the res is a list of all res matching this key """ listRes = cls.read_res_bug(nameFile, allPrefix, folderName) res_keys = [ tuple([ut.extract_from_nested(res, k) for k in key_path]) for res in listRes ] res_keys_unique = list(set(res_keys)) res = { ut.concat2String(*k_u): [listRes[n] for n, r in enumerate(res_keys) if r == k_u] for k_u in res_keys_unique } return res
def collect_res(cls, key_path = [], nameFile = None, allPrefix = 'res_', folderName = None, replace_func = None): """ collect results and group them according to some key values Arguments --------- key_path: <list> if not empty defines how to group results: provides a path in the dict structure of the results to get a value used for the grouping nameFile, allPrefix, folderName: cf. read_res() Output: ------- a dictionary where key is the concatenation of the unique set of keys found and value is the res is a list of all res matching this key """ listRes, listNames = cls.read_res(nameFile, allPrefix, folderName, returnName=True, replace_func=replace_func) if(len(key_path) == 0): res = {k:v for k,v in zip(listNames, listRes)} else: res_keys = [tuple([ut.extract_from_nested(res, k) for k in key_path]) for res in listRes] res_keys_unique = list(set(res_keys)) res = {ut.concat2String(*k_u):[listRes[n] for n, r in enumerate(res_keys) if r == k_u] for k_u in res_keys_unique} return res
def _gen_frequencies(self, T, nb_freq=1, freq_type=None): """Generate (potentially randomized) frequencies based on 'freq_type' 'principal' or None om[l] = 2 * Pi * l /T 'CRAB' om[l] = 2 * Pi * l * (1 + eps[l]) /T with eps iid U[-0.5, 0.5] 'DCRAB' om[l] ~ U[0, w_max] others """ Om_ref = 2 * np.pi / T #dico_args = {'freq_type':freq_type} args_rdm = freq_type.split("_") rgen = self._rdm_gen #Use this rdamgen (provided or created at init of the factory) if (args_rdm[0] in [None, 'principal']): Om = (1 + np.arange(nb_freq)) * Om_ref elif (args_rdm[0] == 'CRAB'): rdv_method = 'uniform_-0.5_0.5' rdvgen = rgen.gen_rdmnb_from_string(rdv_method, nb_freq) Om = (1 + np.arange(nb_freq) + rdvgen) * Om_ref elif (args_rdm[0] == 'DCRAB'): if (len(args_rdm) > 1): Nmax = int(args_rdm[1]) else: Nmax = nb_freq wmax = Nmax * Om_ref rdv_method = ut.concat2String('uniform', 0, wmax) Om = rgen.gen_rdmnb_from_string(rdv_method, nb_freq) Om = np.sort(Om) #dico_args['flag'] = 'DCRAB' # Omega is also a param with some specific boundaries elif (args_rdm[0] == 'CRAB_FREEOM'): om = (1 + np.arange(nb_freq)) * Om_ref om_bounds = [(0.5 + nb, 1.5 + nb) * Om_ref for nb in np.arange(nb_freq)] Om = (om, om_bounds) else: Om = rgen.gen_rdmnb_from_string(freq_type, nb_freq) Om = np.sort(Om) #dico_args['omegas'] = om return Om