Skip to content

Commit

Permalink
When loading a csv file, tell DataPoint which directory to look in
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantner committed Jun 14, 2018
1 parent c35b681 commit 5d851fd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pyked/chemked.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Main ChemKED module
"""
# Standard libraries
from os.path import exists
from os.path import exists, isabs, dirname, join
from collections import namedtuple
from warnings import warn
from copy import deepcopy
Expand Down Expand Up @@ -121,7 +121,7 @@ def __init__(self, yaml_file=None, dict_input=None, *, skip_validation=False):

self.datapoints = []
for point in self._properties['datapoints']:
self.datapoints.append(DataPoint(point))
self.datapoints.append(DataPoint(point, dirname(yaml_file)))

self.reference = Reference(
volume=self._properties['reference'].get('volume'),
Expand Down Expand Up @@ -589,6 +589,7 @@ class DataPoint(object):
Arguments:
properties (`dict`): Dictionary adhering to the ChemKED format for ``datapoints``
directory (`str`, optional): Directory to look for auxiliary files
Attributes:
composition (`list`): List of dictionaries representing the species and their quantities
Expand Down Expand Up @@ -631,7 +632,7 @@ class DataPoint(object):
'compression-ratio'
]

def __init__(self, properties):
def __init__(self, properties, directory=None):
for prop in self.value_unit_props:
if prop in properties:
quant = self.process_quantity(properties[prop])
Expand Down Expand Up @@ -685,7 +686,10 @@ def __init__(self, properties):
values = np.array(hist['values'])
else:
# Load the values from a file
values = np.genfromtxt(hist['values']['filename'], delimiter=',')
filename = hist['values']['filename']
if not isabs(filename):
filename = join(directory, filename)
values = np.genfromtxt(filename, delimiter=',')

time_history = TimeHistory(
time=Q_(values[:, time_col], time_units),
Expand Down

0 comments on commit 5d851fd

Please sign in to comment.