Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jet Stirred Reactor (JSR) #126

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
72d3d12
Included species profile schema
anthonymstohr May 15, 2019
50edfc0
Added example JSR file as test case. Incomplete
anthonymstohr May 17, 2019
1a51a63
Fixed test file errors and made schemas more compatiable with desired…
anthonymstohr May 23, 2019
956a7fc
Updated JSR test file after autoscience meeting
anthonymstohr May 24, 2019
7c42f17
Fixed temperature JSR schema to match test file
anthonymstohr May 29, 2019
0d5a473
cleaned up anthony's test jsr yaml
Jun 21, 2019
6f55f8d
added a csv file for test jsr yaml
Jul 5, 2019
6220857
Undo removing part of chemked_schema.yaml
Jun 21, 2019
ced3ea8
Changed Datapoint to IgnitionDatapoint
Jul 5, 2019
4ff9c58
deleted broken jsr schemas so pytests works
Jul 5, 2019
a0cda57
Move process_quantity method to superclass DataPoint
rwest Jul 5, 2019
f87edef
Tweak docstrings
rwest Jul 5, 2019
1902bfe
Putting uncertainties on a pressure
rwest Jul 5, 2019
78a41a7
Hopefully, a way to read data from CSV files
rwest Jul 5, 2019
97879a9
ChemKED class now successfully readstemperature column from jsr yaml
Jul 5, 2019
4231b2d
updated ChemKED class to read inlet and outlet compositions
Jul 5, 2019
ddc8cd5
fix PEP8 and indenting
sevyharris Feb 24, 2022
65da379
set SpeciesProfileDataPoint to a single reaction setting
sevyharris Feb 24, 2022
09bd13a
process one row at a time instead of the whole column for every datap…
sevyharris Feb 25, 2022
a523973
updated class docstrings
sevyharris Feb 28, 2022
463bb41
added JSR to changelog
sevyharris Feb 28, 2022
b6da445
updated old tests so they pass again
sevyharris Feb 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hopefully, a way to read data from CSV files
  • Loading branch information
rwest authored and sevyharris committed Feb 24, 2022
commit 78a41a724fb2b16751759467693c95fb68db4403
69 changes: 66 additions & 3 deletions pyked/chemked.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Main ChemKED module
"""
# Standard libraries
import os
from os.path import exists
from collections import namedtuple
from warnings import warn
Expand All @@ -11,6 +12,7 @@
from itertools import chain

import numpy as np
import pandas as pd

# Local imports
from .validation import schema, OurValidator, yaml, Q_
Expand Down Expand Up @@ -120,8 +122,16 @@ def __init__(self, yaml_file=None, dict_input=None, *, skip_validation=False):
self.validate_yaml(self._properties)

self.datapoints = []
for point in self._properties['datapoints']:
self.datapoints.append(IgnitionDataPoint(point))
if self._properties['experiment-type'] == 'ignition delay':
for point in self._properties['datapoints']:
self.datapoints.append(IgnitionDataPoint(point))
elif self._properties['experiment-type'] == 'species profile':
assert len(self._properties['datapoints']) == 1, "Only one CSV file per YAML file please"
for point in self._properties['datapoints']:
csv_file = os.path.join(os.path.split(yaml_file)[0], point['csvfile'])
csv_df= pd.read_csv(csv_file)
self.datapoints.extend(SpeciesProfileDataPoint(point, csv_df))


self.reference = Reference(
volume=self._properties['reference'].get('volume'),
Expand Down Expand Up @@ -590,6 +600,31 @@ class DataPoint(object):

Specific types of data point should inherit from this.
"""
def process_column(self, properties, csv_df):
"""
Process a column data and return as a list of units.Quantity objects
csv_df is a Pandas DataFrame.
"""
column_name = properties['column-name']
data_list = []
for value in df[column_name]:
for p in properties:
units = p.get('units', '')
if units: break
#todo: schema should enforce at most 1 units entry

value_properties = [ f'{value} {units}' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no f-strings in python 3.5, which travis includes?


for p in properties:
if p.get('uncertainty-type', False):
# this is the uncertainty data
value_properties.append(p)

quant = self.process_quantity(value_properties)
data_list.append(quant)
return data_list


def process_quantity(self, properties):
"""
Process the units and uncertainty information from a given quantity
Expand Down Expand Up @@ -629,9 +664,37 @@ def process_quantity(self, properties):
'"lower-uncertainty" need to be specified.')
else:
raise ValueError('uncertainty-type must be one of "absolute" or "relative"')

return quant


class SpeciesProfileDataPoint(DataPoint):
"""
Class for a single JSR experiment data point.

"""
value_unit_props = [
'pressure', 'reactor-volume', 'residence-time'
]

column_unit_props = [
'temperature',
]

def __init__(self, properties, csv_df):
for prop in self.value_unit_props:
if prop in properties:
quant = self.process_quantity(properties[prop])
setattr(self, prop.replace('-', '_'), quant)
else:
setattr(self, prop.replace('-', '_'), None)

for prop in self.column_unit_props:
if prop in properties:
data_list = self.process_column(properties[prop], csv_df)
setattr(self, prop.replace('-', '_'), data_list)
else:
setattr(self, prop.replace('-', '_'), None)


class IgnitionDataPoint(DataPoint):
"""Class for a single ignition delay datapoint.
Expand Down