diff --git a/boxmox/__init__.py b/boxmox/__init__.py index 29c3ce12484ba9dc416482b9876a8c8d4645dc9d..d0ebe91bc36803ea1e4ff6a88e95f81b45a9ffc1 100644 --- a/boxmox/__init__.py +++ b/boxmox/__init__.py @@ -5,7 +5,7 @@ except: import _installation -from data import InputFile, Output, ConcentrationOutput, RatesOutput, AdjointOutput, JacobianOutput, HessianOutput +from data import InputFile, InputFileOrig, InputFile17, Output, ConcentrationOutput, RatesOutput, AdjointOutput, JacobianOutput, HessianOutput from fluxes import FluxParser work_path = _installation.validate() diff --git a/boxmox/data.py b/boxmox/data.py index dfcce7813a095d6c8d6f6ace39181b5388f27764..8a875f881bdcaafe1fb137598c3ded7120582d74 100644 --- a/boxmox/data.py +++ b/boxmox/data.py @@ -43,6 +43,11 @@ def _mygenfromtxt(f): return np.array(dat, dtype=[(_, float) for _ in hdr]) def InputFile(fpath=None, version=1.7): + ''' + Returns an instance of a BOXMOX input file class, either old format if + version < 1.7 (class InputFileOrig), or the current file format + (class InputFile17). + ''' if not fpath is None: # file format discovery: 3 lines with numbers ==> 1.7 with open(fpath, 'rb') as f: @@ -324,7 +329,13 @@ class ConcentrationOutput(Output): def __init__(self, fpath, vars=None): self.fpath = fpath with open(fpath, 'rb') as f: - self.data = _mygenfromtxt(f) + # not using mygenfromtxt as we know the file format and this is way faster... + spamreader = csv.reader(f, skipinitialspace = True, delimiter=" ") + hdr = spamreader.next() + dat = [] + for row in spamreader: + dat.append( tuple(map(float, row)) ) + self.data = np.array(dat, dtype=[(_, float) for _ in hdr]) self.times = self.data['time'] if not vars is None: self.data = self.data[vars] diff --git a/docs/index.rst b/docs/index.rst index 1e49be70239c6ebc1d510d32193da8c77db4e1d2..33bfede719911568a4a7b1bbfd800efe25bc6eef 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -129,7 +129,9 @@ Experiment Input/Output ^^^^^^^^^^^^ -.. autoclass:: InputFile +.. autofunction:: InputFile +.. autoclass:: InputFile17 +.. autoclass:: InputFileOrig .. autoclass:: ConcentrationOutput :inherited-members: