From b4c6f8fb1b6d78c2dab5aadccc4db6bfcef8c7e4 Mon Sep 17 00:00:00 2001 From: "Christoph.Knote" <christoph.knote@physik.uni-muenchen.de> Date: Wed, 13 Dec 2017 11:51:47 +0100 Subject: [PATCH] Stupid data fix --- boxmox/data.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/boxmox/data.py b/boxmox/data.py index 0c90e79..8327b13 100644 --- a/boxmox/data.py +++ b/boxmox/data.py @@ -108,7 +108,7 @@ class InputFile17: self.timeVar = hdr[0] self.time = [ x[0] for x in dmp ] ntime = 1 - self.anc = { hdr[i]: [ x[i] for x in dmp ] for i in range(ntime, ntime+nanc) } + self.anc = { hdr[i]: [ x[i] for x in dmp ] for i in range(ntime, ntime+nanc) } self._data = { hdr[i]: [ x[i] for x in dmp ] for i in range(ntime+nanc, len(dmp[0])) } def __str__(self): @@ -140,7 +140,12 @@ class InputFile17: line = [ xtime ] + [ self.anc[key][itime] for key in anc_names ] + [ self._data[key][itime] for key in data_names ] f.write(' '.join('{0:e}'.format(x) for x in line) + '\n') else: - data_line = ' '.join( '{0:e}'.format(float(self.anc[x])) for x in self.anc.keys() ) + ' ' + ' '.join( '{0:e}'.format(float(self._data[x])) for x in self.keys() ) + '\n' + def _data_fix(key): + if isinstance(self._data[x], list): + return self._data[x][0] + else: + return self._data[x] + data_line = ' '.join( '{0:e}'.format( float(self.anc[x])) for x in self.anc.keys() ) + ' ' + ' '.join( '{0:e}'.format( float(_data_fix(x))) for x in self.keys() ) + '\n' if not self.time is None: data_line = '{0:e}'.format(float(self.time)) + ' ' + data_line f.write(data_line) @@ -227,7 +232,12 @@ class InputFileOrig: f.write(' '.join('{0:e}'.format(x) for x in line) + '\n') else: f.write('{0:s}' .format(' '.join( column_names)) +'\n') - f.write(' '.join( '{0:e}'.format(float(self._data[x])) for x in self.keys() ) + '\n') + def _data_fix(key): + if isinstance(self._data[x], list): + return self._data[x][0] + else: + return self._data[x] + f.write(' '.join( '{0:e}'.format(float(_data_fix(x))) for x in self.keys() ) + '\n') def __init__(self, fpath=None): #: Time format (0: constant, 1: seconds since start, 2: hour of diurnal cycle) -- GitLab