def read_log(filename): """ Read data saved by :class:`Log` into a text file. Parameters ---------- filename : str The name of a text log file. Returns ------- log : dict The log with data names as keys and ``(xs, ys, vlines)`` as values. info : dict The log plot configuration with subplot numbers as keys. """ from sfepy.base.base import as_float_or_complex as afc log = {} info = {} fd = open(filename, 'r') last_xval = None for line in fd: if line[0] == '#': ls = line.split(':') if ls[0] == '# groups': n_gr = int(ls[1]) for ig in range(n_gr): next(fd) line_info = next(fd) xlabel, ylabel, yscales = line_info.split(',') line_names = next(fd) names = line_names.split(':')[1] line_plot_kwargs = next(fd) info[ig] = (xlabel.split(':')[1].strip().strip('"'), ylabel.split(':')[1].strip().strip('"'), yscales.split(':')[1].strip().strip('"'), [name.strip().strip('"') for name in names.split(',')], eval(line_plot_kwargs[19:].strip().strip('"') + ',')) continue ls = line.split(':') key = ls[0] xs, ys, vlines = log.setdefault(key, ([], [], [])) if (len(ls) == 2) and (last_xval is not None): vlines.append(last_xval) else: try: xval = afc(ls[1]) yval = afc(ls[2]) except ValueError: continue xs.append(xval) ys.append(yval) last_xval = xval fd.close() for key, (xs, ys, vlines) in six.iteritems(log): log[key] = (nm.array(xs), nm.array(ys), nm.array(vlines)) return log, info
def read_log(filename): """ Read data saved by :class:`Log` into a text file. Parameters ---------- filename : str The name of a text log file. Returns ------- log : dict The log with data names as keys and ``(xs, ys, vlines)`` as values. info : dict The log plot configuration with subplot numbers as keys. """ from sfepy.base.base import as_float_or_complex as afc log = {} info = {} fd = open(filename, 'r') last_xval = None for line in fd: if line[0] == '#': ls = line.split(':') if ls[0] == '# groups': n_gr = int(ls[1]) for ig in range(n_gr): next(fd) line_info = next(fd) xlabel, ylabel, yscales = line_info.split(',') line_names = next(fd) names = line_names.split(':')[1] line_plot_kwargs = next(fd) info[ig] = (xlabel.split(':')[1].strip().strip('"'), ylabel.split(':')[1].strip().strip('"'), yscales.split(':')[1].strip().strip('"'), [ name.strip().strip('"') for name in names.split(',') ], eval(line_plot_kwargs[19:].strip().strip('"') + ',')) continue ls = line.split(':') key = ls[0] xs, ys, vlines = log.setdefault(key, ([], [], [])) if (len(ls) == 2) and (last_xval is not None): vlines.append(last_xval) else: try: xval = afc(ls[1]) yval = afc(ls[2]) except ValueError: continue xs.append(xval) ys.append(yval) last_xval = xval fd.close() for key, (xs, ys, vlines) in six.iteritems(log): log[key] = (nm.array(xs), nm.array(ys), nm.array(vlines)) return log, info
def read_log(filename): """ Read data saved by :class:`Log` into a text file. Parameters ---------- filename : str The name of a text log file. Returns ------- log : dict The log with data names as keys and ``(xs, ys, vlines)`` as values. info : dict The log plot configuration with subplot numbers as keys. """ from sfepy.base.base import as_float_or_complex as afc log = {} info = {} name2key = {} fd = open(filename, 'r') for line in fd: if line[0] == '#': ls = line.split(':') if ls[0] == '# groups': n_gr = int(ls[1]) offset = 0 for ig in range(n_gr): next(fd) line_info = next(fd) xlabel, ylabel, yscales = line_info.split(',') line_names = next(fd) names = line_names.split(':')[1] names = [ name.strip().strip('"') for name in names.split(',') ] if len(names[0]) == 0: names = [] line_plot_kwargs = next(fd) aux = line_plot_kwargs[19:].strip().strip('"') plot_kwargs = eval(aux + ',') if len(aux) else ({}, ) info[ig] = (xlabel.split(':')[1].strip().strip('"'), ylabel.split(':')[1].strip().strip('"'), yscales.split(':')[1].strip().strip('"'), names, plot_kwargs) name2key.update({ name: ik + offset for ik, name in enumerate(info[ig][3]) }) offset += len(info[ig][3]) continue ls = line.split(':') try: key = int(ls[0]) except ValueError: key = name2key[ls[0]] # Old style log. xs, ys, vlines = log.setdefault(key, ([], [], [])) if (len(ls) == 2) and len(log[key][0]): vlines.append(log[key][0][-1]) else: try: xval = afc(ls[1]) yval = afc(ls[2]) except ValueError: continue xs.append(xval) ys.append(yval) fd.close() for key, (xs, ys, vlines) in six.iteritems(log): log[key] = (nm.array(xs), nm.array(ys), nm.array(vlines)) return log, info