|
2 | 2 | Main ChemKED module
|
3 | 3 | """
|
4 | 4 | # Standard libraries
|
| 5 | +import os |
5 | 6 | from os.path import exists
|
6 | 7 | from collections import namedtuple
|
7 | 8 | from warnings import warn
|
|
11 | 12 | from itertools import chain
|
12 | 13 |
|
13 | 14 | import numpy as np
|
| 15 | +import pandas as pd |
14 | 16 |
|
15 | 17 | # Local imports
|
16 | 18 | from .validation import schema, OurValidator, yaml, Q_
|
@@ -120,8 +122,16 @@ def __init__(self, yaml_file=None, dict_input=None, *, skip_validation=False):
|
120 | 122 | self.validate_yaml(self._properties)
|
121 | 123 |
|
122 | 124 | self.datapoints = []
|
123 |
| - for point in self._properties['datapoints']: |
124 |
| - self.datapoints.append(IgnitionDataPoint(point)) |
| 125 | + if self._properties['experiment-type'] == 'ignition delay': |
| 126 | + for point in self._properties['datapoints']: |
| 127 | + self.datapoints.append(IgnitionDataPoint(point)) |
| 128 | + elif self._properties['experiment-type'] == 'species profile': |
| 129 | + assert len(self._properties['datapoints']) == 1, "Only one CSV file per YAML file please" |
| 130 | + for point in self._properties['datapoints']: |
| 131 | + csv_file = os.path.join(os.path.split(yaml_file)[0], point['csvfile']) |
| 132 | + csv_df= pd.read_csv(csv_file) |
| 133 | + self.datapoints.extend(SpeciesProfileDataPoint(point, csv_df)) |
| 134 | + |
125 | 135 |
|
126 | 136 | self.reference = Reference(
|
127 | 137 | volume=self._properties['reference'].get('volume'),
|
@@ -590,6 +600,31 @@ class DataPoint(object):
|
590 | 600 |
|
591 | 601 | Specific types of data point should inherit from this.
|
592 | 602 | """
|
| 603 | + def process_column(self, properties, csv_df): |
| 604 | + """ |
| 605 | + Process a column data and return as a list of units.Quantity objects |
| 606 | + csv_df is a Pandas DataFrame. |
| 607 | + """ |
| 608 | + column_name = properties['column-name'] |
| 609 | + data_list = [] |
| 610 | + for value in df[column_name]: |
| 611 | + for p in properties: |
| 612 | + units = p.get('units', '') |
| 613 | + if units: break |
| 614 | + #todo: schema should enforce at most 1 units entry |
| 615 | + |
| 616 | + value_properties = [ f'{value} {units}' ] |
| 617 | + |
| 618 | + for p in properties: |
| 619 | + if p.get('uncertainty-type', False): |
| 620 | + # this is the uncertainty data |
| 621 | + value_properties.append(p) |
| 622 | + |
| 623 | + quant = self.process_quantity(value_properties) |
| 624 | + data_list.append(quant) |
| 625 | + return data_list |
| 626 | + |
| 627 | + |
593 | 628 | def process_quantity(self, properties):
|
594 | 629 | """
|
595 | 630 | Process the units and uncertainty information from a given quantity
|
@@ -629,9 +664,37 @@ def process_quantity(self, properties):
|
629 | 664 | '"lower-uncertainty" need to be specified.')
|
630 | 665 | else:
|
631 | 666 | raise ValueError('uncertainty-type must be one of "absolute" or "relative"')
|
632 |
| - |
633 | 667 | return quant
|
634 | 668 |
|
| 669 | + |
| 670 | +class SpeciesProfileDataPoint(DataPoint): |
| 671 | + """ |
| 672 | + Class for a single JSR experiment data point. |
| 673 | +
|
| 674 | + """ |
| 675 | + value_unit_props = [ |
| 676 | + 'pressure', 'reactor-volume', 'residence-time' |
| 677 | + ] |
| 678 | + |
| 679 | + column_unit_props = [ |
| 680 | + 'temperature', |
| 681 | + ] |
| 682 | + |
| 683 | + def __init__(self, properties, csv_df): |
| 684 | + for prop in self.value_unit_props: |
| 685 | + if prop in properties: |
| 686 | + quant = self.process_quantity(properties[prop]) |
| 687 | + setattr(self, prop.replace('-', '_'), quant) |
| 688 | + else: |
| 689 | + setattr(self, prop.replace('-', '_'), None) |
| 690 | + |
| 691 | + for prop in self.column_unit_props: |
| 692 | + if prop in properties: |
| 693 | + data_list = self.process_column(properties[prop], csv_df) |
| 694 | + setattr(self, prop.replace('-', '_'), data_list) |
| 695 | + else: |
| 696 | + setattr(self, prop.replace('-', '_'), None) |
| 697 | + |
635 | 698 |
|
636 | 699 | class IgnitionDataPoint(DataPoint):
|
637 | 700 | """Class for a single ignition delay datapoint.
|
|
0 commit comments