Skip to content
Snippets Groups Projects
Commit 3705b2a3 authored by Christoph.Knote's avatar Christoph.Knote
Browse files

Updated ConcentrationOutput reading routine (faster). Exposing

InputFileOrig, InputFile17 for documentation.
parent 843a9471
Branches
Tags
No related merge requests found
...@@ -5,7 +5,7 @@ except: ...@@ -5,7 +5,7 @@ except:
import _installation 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 from fluxes import FluxParser
work_path = _installation.validate() work_path = _installation.validate()
......
...@@ -43,6 +43,11 @@ def _mygenfromtxt(f): ...@@ -43,6 +43,11 @@ def _mygenfromtxt(f):
return np.array(dat, dtype=[(_, float) for _ in hdr]) return np.array(dat, dtype=[(_, float) for _ in hdr])
def InputFile(fpath=None, version=1.7): 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: if not fpath is None:
# file format discovery: 3 lines with numbers ==> 1.7 # file format discovery: 3 lines with numbers ==> 1.7
with open(fpath, 'rb') as f: with open(fpath, 'rb') as f:
...@@ -324,7 +329,13 @@ class ConcentrationOutput(Output): ...@@ -324,7 +329,13 @@ class ConcentrationOutput(Output):
def __init__(self, fpath, vars=None): def __init__(self, fpath, vars=None):
self.fpath = fpath self.fpath = fpath
with open(fpath, 'rb') as f: 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'] self.times = self.data['time']
if not vars is None: if not vars is None:
self.data = self.data[vars] self.data = self.data[vars]
......
...@@ -129,7 +129,9 @@ Experiment ...@@ -129,7 +129,9 @@ Experiment
Input/Output Input/Output
^^^^^^^^^^^^ ^^^^^^^^^^^^
.. autoclass:: InputFile .. autofunction:: InputFile
.. autoclass:: InputFile17
.. autoclass:: InputFileOrig
.. autoclass:: ConcentrationOutput .. autoclass:: ConcentrationOutput
:inherited-members: :inherited-members:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment