diff --git a/docs/pyerrors/input/sfcf.html b/docs/pyerrors/input/sfcf.html index 8479d85a..e735bd92 100644 --- a/docs/pyerrors/input/sfcf.html +++ b/docs/pyerrors/input/sfcf.html @@ -364,164 +364,162 @@ 286def _find_correlator(file_name, version, pattern, b2b, silent=False): 287 T = 0 288 -289 file = open(file_name, "r") +289 with open(file_name, "r") as my_file: 290 -291 content = file.read() -292 match = re.search(pattern, content) -293 if match: -294 if version == "0.0": -295 start_read = content.count('\n', 0, match.start()) + 1 -296 T = content.count('\n', start_read) -297 else: -298 start_read = content.count('\n', 0, match.start()) + 5 + b2b -299 end_match = re.search(r'\n\s*\n', content[match.start():]) -300 T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b -301 if not T > 0: -302 raise ValueError("Correlator with pattern\n" + pattern + "\nis empty!") -303 if not silent: -304 print(T, 'entries, starting to read in line', start_read) +291 content = my_file.read() +292 match = re.search(pattern, content) +293 if match: +294 if version == "0.0": +295 start_read = content.count('\n', 0, match.start()) + 1 +296 T = content.count('\n', start_read) +297 else: +298 start_read = content.count('\n', 0, match.start()) + 5 + b2b +299 end_match = re.search(r'\n\s*\n', content[match.start():]) +300 T = content[match.start():].count('\n', 0, end_match.start()) - 4 - b2b +301 if not T > 0: +302 raise ValueError("Correlator with pattern\n" + pattern + "\nis empty!") +303 if not silent: +304 print(T, 'entries, starting to read in line', start_read) 305 -306 else: -307 file.close() -308 raise ValueError('Correlator with pattern\n' + pattern + '\nnot found.') -309 -310 file.close() -311 return start_read, T -312 -313 -314def _read_compact_file(rep_path, config_file, start_read, T, b2b, name, im): -315 with open(rep_path + config_file) as fp: -316 lines = fp.readlines() -317 # check, if the correlator is in fact -318 # printed completely -319 if (start_read + T + 1 > len(lines)): -320 raise Exception("EOF before end of correlator data! Maybe " + rep_path + config_file + " is corrupted?") -321 corr_lines = lines[start_read - 6: start_read + T] -322 del lines -323 t_vals = [] -324 -325 if corr_lines[1 - b2b].strip() != 'name ' + name: -326 raise Exception('Wrong format in file', config_file) -327 -328 for k in range(6, T + 6): -329 floats = list(map(float, corr_lines[k].split())) -330 t_vals.append(floats[-2:][im]) -331 return t_vals -332 -333 -334def _read_compact_rep(path, rep, sub_ls, start_read, T, b2b, name, im): -335 rep_path = path + '/' + rep + '/' -336 no_cfg = len(sub_ls) -337 deltas = [] -338 for t in range(T): -339 deltas.append(np.zeros(no_cfg)) -340 for cfg in range(no_cfg): -341 cfg_file = sub_ls[cfg] -342 cfg_data = _read_compact_file(rep_path, cfg_file, start_read, T, b2b, name, im) -343 for t in range(T): -344 deltas[t][cfg] = cfg_data[t] -345 return deltas -346 -347 -348def _read_chunk(chunk, gauge_line, cfg_sep, start_read, T, corr_line, b2b, pattern, im, single): -349 try: -350 idl = int(chunk[gauge_line].split(cfg_sep)[-1]) -351 except Exception: -352 raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line) -353 -354 found_pat = "" -355 data = [] -356 for li in chunk[corr_line + 1:corr_line + 6 + b2b]: -357 found_pat += li -358 if re.search(pattern, found_pat): -359 for t, line in enumerate(chunk[start_read:start_read + T]): -360 floats = list(map(float, line.split())) -361 data.append(floats[im + 1 - single]) -362 return idl, data -363 -364 -365def _read_append_rep(filename, pattern, b2b, cfg_separator, im, single): -366 with open(filename, 'r') as fp: -367 content = fp.readlines() -368 data_starts = [] -369 for linenumber, line in enumerate(content): -370 if "[run]" in line: -371 data_starts.append(linenumber) -372 if len(set([data_starts[i] - data_starts[i - 1] for i in range(1, len(data_starts))])) > 1: -373 raise Exception("Irregularities in file structure found, not all runs have the same output length") -374 chunk = content[:data_starts[1]] -375 for linenumber, line in enumerate(chunk): -376 if line.startswith("gauge_name"): -377 gauge_line = linenumber -378 elif line.startswith("[correlator]"): -379 corr_line = linenumber -380 found_pat = "" -381 for li in chunk[corr_line + 1: corr_line + 6 + b2b]: -382 found_pat += li -383 if re.search(pattern, found_pat): -384 start_read = corr_line + 7 + b2b -385 break -386 else: -387 raise ValueError("Did not find pattern\n", pattern, "\nin\n", filename) -388 endline = corr_line + 6 + b2b -389 while not chunk[endline] == "\n": -390 endline += 1 -391 T = endline - start_read -392 -393 # all other chunks should follow the same structure -394 rep_idl = [] -395 rep_data = [] -396 -397 for cnfg in range(len(data_starts)): -398 start = data_starts[cnfg] -399 stop = start + data_starts[1] -400 chunk = content[start:stop] -401 idl, data = _read_chunk(chunk, gauge_line, cfg_separator, start_read, T, corr_line, b2b, pattern, im, single) -402 rep_idl.append(idl) -403 rep_data.append(data) +306 else: +307 raise ValueError('Correlator with pattern\n' + pattern + '\nnot found.') +308 +309 return start_read, T +310 +311 +312def _read_compact_file(rep_path, config_file, start_read, T, b2b, name, im): +313 with open(rep_path + config_file) as fp: +314 lines = fp.readlines() +315 # check, if the correlator is in fact +316 # printed completely +317 if (start_read + T + 1 > len(lines)): +318 raise Exception("EOF before end of correlator data! Maybe " + rep_path + config_file + " is corrupted?") +319 corr_lines = lines[start_read - 6: start_read + T] +320 del lines +321 t_vals = [] +322 +323 if corr_lines[1 - b2b].strip() != 'name ' + name: +324 raise Exception('Wrong format in file', config_file) +325 +326 for k in range(6, T + 6): +327 floats = list(map(float, corr_lines[k].split())) +328 t_vals.append(floats[-2:][im]) +329 return t_vals +330 +331 +332def _read_compact_rep(path, rep, sub_ls, start_read, T, b2b, name, im): +333 rep_path = path + '/' + rep + '/' +334 no_cfg = len(sub_ls) +335 deltas = [] +336 for t in range(T): +337 deltas.append(np.zeros(no_cfg)) +338 for cfg in range(no_cfg): +339 cfg_file = sub_ls[cfg] +340 cfg_data = _read_compact_file(rep_path, cfg_file, start_read, T, b2b, name, im) +341 for t in range(T): +342 deltas[t][cfg] = cfg_data[t] +343 return deltas +344 +345 +346def _read_chunk(chunk, gauge_line, cfg_sep, start_read, T, corr_line, b2b, pattern, im, single): +347 try: +348 idl = int(chunk[gauge_line].split(cfg_sep)[-1]) +349 except Exception: +350 raise Exception("Couldn't parse idl from directory, problem with chunk around line ", gauge_line) +351 +352 found_pat = "" +353 data = [] +354 for li in chunk[corr_line + 1:corr_line + 6 + b2b]: +355 found_pat += li +356 if re.search(pattern, found_pat): +357 for t, line in enumerate(chunk[start_read:start_read + T]): +358 floats = list(map(float, line.split())) +359 data.append(floats[im + 1 - single]) +360 return idl, data +361 +362 +363def _read_append_rep(filename, pattern, b2b, cfg_separator, im, single): +364 with open(filename, 'r') as fp: +365 content = fp.readlines() +366 data_starts = [] +367 for linenumber, line in enumerate(content): +368 if "[run]" in line: +369 data_starts.append(linenumber) +370 if len(set([data_starts[i] - data_starts[i - 1] for i in range(1, len(data_starts))])) > 1: +371 raise Exception("Irregularities in file structure found, not all runs have the same output length") +372 chunk = content[:data_starts[1]] +373 for linenumber, line in enumerate(chunk): +374 if line.startswith("gauge_name"): +375 gauge_line = linenumber +376 elif line.startswith("[correlator]"): +377 corr_line = linenumber +378 found_pat = "" +379 for li in chunk[corr_line + 1: corr_line + 6 + b2b]: +380 found_pat += li +381 if re.search(pattern, found_pat): +382 start_read = corr_line + 7 + b2b +383 break +384 else: +385 raise ValueError("Did not find pattern\n", pattern, "\nin\n", filename) +386 endline = corr_line + 6 + b2b +387 while not chunk[endline] == "\n": +388 endline += 1 +389 T = endline - start_read +390 +391 # all other chunks should follow the same structure +392 rep_idl = [] +393 rep_data = [] +394 +395 for cnfg in range(len(data_starts)): +396 start = data_starts[cnfg] +397 stop = start + data_starts[1] +398 chunk = content[start:stop] +399 idl, data = _read_chunk(chunk, gauge_line, cfg_separator, start_read, T, corr_line, b2b, pattern, im, single) +400 rep_idl.append(idl) +401 rep_data.append(data) +402 +403 data = [] 404 -405 data = [] -406 -407 for t in range(T): -408 data.append([]) -409 for c in range(len(rep_data)): -410 data[t].append(rep_data[c][t]) -411 return T, rep_idl, data -412 -413 -414def _get_rep_names(ls, ens_name=None): -415 new_names = [] -416 for entry in ls: -417 try: -418 idx = entry.index('r') -419 except Exception: -420 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") -421 -422 if ens_name: -423 new_names.append('ens_name' + '|' + entry[idx:]) -424 else: -425 new_names.append(entry[:idx] + '|' + entry[idx:]) -426 return new_names -427 -428 -429def _get_appended_rep_names(ls, prefix, name, ens_name=None): -430 new_names = [] -431 for exc in ls: -432 if not fnmatch.fnmatch(exc, prefix + '*.' + name): -433 ls = list(set(ls) - set([exc])) -434 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) -435 for entry in ls: -436 myentry = entry[:-len(name) - 1] -437 try: -438 idx = myentry.index('r') -439 except Exception: -440 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") -441 -442 if ens_name: -443 new_names.append('ens_name' + '|' + entry[idx:]) -444 else: -445 new_names.append(myentry[:idx] + '|' + myentry[idx:]) -446 return new_names +405 for t in range(T): +406 data.append([]) +407 for c in range(len(rep_data)): +408 data[t].append(rep_data[c][t]) +409 return T, rep_idl, data +410 +411 +412def _get_rep_names(ls, ens_name=None): +413 new_names = [] +414 for entry in ls: +415 try: +416 idx = entry.index('r') +417 except Exception: +418 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") +419 +420 if ens_name: +421 new_names.append('ens_name' + '|' + entry[idx:]) +422 else: +423 new_names.append(entry[:idx] + '|' + entry[idx:]) +424 return new_names +425 +426 +427def _get_appended_rep_names(ls, prefix, name, ens_name=None): +428 new_names = [] +429 for exc in ls: +430 if not fnmatch.fnmatch(exc, prefix + '*.' + name): +431 ls = list(set(ls) - set([exc])) +432 ls.sort(key=lambda x: int(re.findall(r'\d+', x)[-1])) +433 for entry in ls: +434 myentry = entry[:-len(name) - 1] +435 try: +436 idx = myentry.index('r') +437 except Exception: +438 raise Exception("Automatic recognition of replicum failed, please enter the key word 'names'.") +439 +440 if ens_name: +441 new_names.append('ens_name' + '|' + entry[idx:]) +442 else: +443 new_names.append(myentry[:idx] + '|' + myentry[idx:]) +444 return new_names