From e6b736c54c40f5b0636d4307afcb5d2a3bef7ca3 Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 17:08:14 -0700 Subject: [PATCH 1/9] Add test for reading time-history from file --- pyked/tests/test_validation.py | 2 +- pyked/tests/testfile_rcm3.yaml | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 pyked/tests/testfile_rcm3.yaml diff --git a/pyked/tests/test_validation.py b/pyked/tests/test_validation.py index 50c46f0..e9d2c1b 100644 --- a/pyked/tests/test_validation.py +++ b/pyked/tests/test_validation.py @@ -363,7 +363,7 @@ def properties(self, request): @pytest.mark.parametrize("properties", [ 'testfile_st.yaml', 'testfile_st2.yaml', 'testfile_rcm.yaml', 'testfile_required.yaml', - 'testfile_uncertainty.yaml', 'testfile_rcm2.yaml', + 'testfile_uncertainty.yaml', 'testfile_rcm2.yaml', 'testfile_rcm3.yaml' ], indirect=['properties']) def test_valid_yaml(self, properties): """Ensure ChemKED YAML is validated diff --git a/pyked/tests/testfile_rcm3.yaml b/pyked/tests/testfile_rcm3.yaml new file mode 100644 index 0000000..b3ed39b --- /dev/null +++ b/pyked/tests/testfile_rcm3.yaml @@ -0,0 +1,66 @@ +--- +file-authors: + - name: Kyle E Niemeyer + ORCID: 0000-0003-4425-7097 +file-version: 0 +chemked-version: 0.0.1 +reference: + doi: 10.1002/kin.20180 + authors: + - name: Gaurav Mittal + - name: Chih-Jen Sung + ORCID: 0000-0003-2046-8076 + - name: Richard A Yetter + journal: International Journal of Chemical Kinetics + year: 2006 + volume: 38 + pages: 516-529 + detail: Fig. 6, open circle +experiment-type: ignition delay +apparatus: + kind: rapid compression machine + institution: Case Western Reserve University + facility: CWRU RCM +datapoints: + - temperature: + - 297.4 kelvin + ignition-delay: + - 1.0 ms + pressure: + - 958.0 torr + composition: + kind: mole fraction + species: + - species-name: H2 + InChI: 1S/H2/h1H + amount: + - 0.12500 + - species-name: O2 + InChI: 1S/O2/c1-2 + amount: + - 0.06250 + - species-name: N2 + InChI: 1S/N2/c1-2 + amount: + - 0.18125 + - species-name: Ar + InChI: 1S/Ar + amount: + - 0.63125 + ignition-type: + target: pressure + type: d/dt max + rcm-data: + compression-time: + - 38.0 ms + time-histories: + - type: volume + time: + units: s + column: 0 + quantity: + units: cm3 + column: 1 + values: + filename: rcm_history.csv +... From dfa207e64aac6907815817b21dfcb8d6563308ad Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 17:13:55 -0700 Subject: [PATCH 2/9] force travis test --- pyked/tests/testfile_rcm3.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyked/tests/testfile_rcm3.yaml b/pyked/tests/testfile_rcm3.yaml index b3ed39b..e5dfefb 100644 --- a/pyked/tests/testfile_rcm3.yaml +++ b/pyked/tests/testfile_rcm3.yaml @@ -62,5 +62,5 @@ datapoints: units: cm3 column: 1 values: - filename: rcm_history.csv + filename: rcm_history.csv ... From 4f2a5998112019c91ffbb4c79c2ce8d0808e829f Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 17:35:21 -0700 Subject: [PATCH 3/9] Revert "force travis test" This reverts commit dfa207e64aac6907815817b21dfcb8d6563308ad. --- pyked/tests/testfile_rcm3.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyked/tests/testfile_rcm3.yaml b/pyked/tests/testfile_rcm3.yaml index e5dfefb..b3ed39b 100644 --- a/pyked/tests/testfile_rcm3.yaml +++ b/pyked/tests/testfile_rcm3.yaml @@ -62,5 +62,5 @@ datapoints: units: cm3 column: 1 values: - filename: rcm_history.csv + filename: rcm_history.csv ... From 2d19cfe77cce2cf0833cfad56708cb376c72a7fb Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 17:35:25 -0700 Subject: [PATCH 4/9] Revert "Add test for reading time-history from file" This reverts commit e6b736c54c40f5b0636d4307afcb5d2a3bef7ca3. --- pyked/tests/test_validation.py | 2 +- pyked/tests/testfile_rcm3.yaml | 66 ---------------------------------- 2 files changed, 1 insertion(+), 67 deletions(-) delete mode 100644 pyked/tests/testfile_rcm3.yaml diff --git a/pyked/tests/test_validation.py b/pyked/tests/test_validation.py index e9d2c1b..50c46f0 100644 --- a/pyked/tests/test_validation.py +++ b/pyked/tests/test_validation.py @@ -363,7 +363,7 @@ def properties(self, request): @pytest.mark.parametrize("properties", [ 'testfile_st.yaml', 'testfile_st2.yaml', 'testfile_rcm.yaml', 'testfile_required.yaml', - 'testfile_uncertainty.yaml', 'testfile_rcm2.yaml', 'testfile_rcm3.yaml' + 'testfile_uncertainty.yaml', 'testfile_rcm2.yaml', ], indirect=['properties']) def test_valid_yaml(self, properties): """Ensure ChemKED YAML is validated diff --git a/pyked/tests/testfile_rcm3.yaml b/pyked/tests/testfile_rcm3.yaml deleted file mode 100644 index b3ed39b..0000000 --- a/pyked/tests/testfile_rcm3.yaml +++ /dev/null @@ -1,66 +0,0 @@ ---- -file-authors: - - name: Kyle E Niemeyer - ORCID: 0000-0003-4425-7097 -file-version: 0 -chemked-version: 0.0.1 -reference: - doi: 10.1002/kin.20180 - authors: - - name: Gaurav Mittal - - name: Chih-Jen Sung - ORCID: 0000-0003-2046-8076 - - name: Richard A Yetter - journal: International Journal of Chemical Kinetics - year: 2006 - volume: 38 - pages: 516-529 - detail: Fig. 6, open circle -experiment-type: ignition delay -apparatus: - kind: rapid compression machine - institution: Case Western Reserve University - facility: CWRU RCM -datapoints: - - temperature: - - 297.4 kelvin - ignition-delay: - - 1.0 ms - pressure: - - 958.0 torr - composition: - kind: mole fraction - species: - - species-name: H2 - InChI: 1S/H2/h1H - amount: - - 0.12500 - - species-name: O2 - InChI: 1S/O2/c1-2 - amount: - - 0.06250 - - species-name: N2 - InChI: 1S/N2/c1-2 - amount: - - 0.18125 - - species-name: Ar - InChI: 1S/Ar - amount: - - 0.63125 - ignition-type: - target: pressure - type: d/dt max - rcm-data: - compression-time: - - 38.0 ms - time-histories: - - type: volume - time: - units: s - column: 0 - quantity: - units: cm3 - column: 1 - values: - filename: rcm_history.csv -... From 13d685ef606ec3b293a4e3a276104012b5b06918 Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 17:39:17 -0700 Subject: [PATCH 5/9] Correctly read Celsius temperatures Previously, code would interpret a value in Celsius, such as `50 degC` as `50 * 1 degC`. However, relative quantities like Celcius and Fahrenheit cannot be multiplied. This commit fixes the problem. --- pyked/validation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyked/validation.py b/pyked/validation.py index 4814201..7d85d5c 100644 --- a/pyked/validation.py +++ b/pyked/validation.py @@ -273,7 +273,11 @@ def _validate_isvalid_quantity(self, isvalid_quantity, field, value): {'isvalid_quantity': {'type': 'bool'}, 'field': {'type': 'str'}, 'value': {'type': 'list'}} """ - quantity = Q_(value[0]) + if type(value[0]) is str: + values = value[0].split() + quantity = Q_(*[float(values[0])] + values[1:]) + else: + quantity = Q_(value[0]) low_lim = 0.0 * units(property_units[field]) try: From 10fc65e53b684ad0f2458ddccaa89242310a767a Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 17:42:50 -0700 Subject: [PATCH 6/9] Add test with temperature in Celsius --- pyked/tests/test_validation.py | 2 +- pyked/tests/testfile_rcm3.yaml | 178 +++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 pyked/tests/testfile_rcm3.yaml diff --git a/pyked/tests/test_validation.py b/pyked/tests/test_validation.py index 50c46f0..e9d2c1b 100644 --- a/pyked/tests/test_validation.py +++ b/pyked/tests/test_validation.py @@ -363,7 +363,7 @@ def properties(self, request): @pytest.mark.parametrize("properties", [ 'testfile_st.yaml', 'testfile_st2.yaml', 'testfile_rcm.yaml', 'testfile_required.yaml', - 'testfile_uncertainty.yaml', 'testfile_rcm2.yaml', + 'testfile_uncertainty.yaml', 'testfile_rcm2.yaml', 'testfile_rcm3.yaml' ], indirect=['properties']) def test_valid_yaml(self, properties): """Ensure ChemKED YAML is validated diff --git a/pyked/tests/testfile_rcm3.yaml b/pyked/tests/testfile_rcm3.yaml new file mode 100644 index 0000000..c11f1a3 --- /dev/null +++ b/pyked/tests/testfile_rcm3.yaml @@ -0,0 +1,178 @@ +--- +file-authors: + - name: Kyle E Niemeyer + ORCID: 0000-0003-4425-7097 +file-version: 0 +chemked-version: 0.0.1 +reference: + doi: 10.1002/kin.20180 + authors: + - name: Gaurav Mittal + - name: Chih-Jen Sung + ORCID: 0000-0003-2046-8076 + - name: Richard A Yetter + journal: International Journal of Chemical Kinetics + year: 2006 + volume: 38 + pages: 516-529 + detail: Fig. 6, open circle +experiment-type: ignition delay +apparatus: + kind: rapid compression machine + institution: Case Western Reserve University + facility: CWRU RCM +datapoints: + - temperature: + - 24.25 degC + ignition-delay: + - 1.0 ms + first-stage-ignition-delay: + - 0.5 ms + - uncertainty-type: relative + uncertainty: 0.01 + pressure: + - 958.0 torr + rcm-data: + compressed-pressure: + - 7.1 bar + compressed-temperature: + - 765 K + - uncertainty: 0.01 + uncertainty-type: relative + compression-time: + - 38.0 ms + stroke: + - 10.0 inch + clearance: + - 2.5 cm + compression-ratio: + - 12.0 + composition: + kind: mole fraction + species: + - species-name: H2 + InChI: 1S/H2/h1H + amount: + - 0.12500 + - species-name: O2 + InChI: 1S/O2/c1-2 + amount: + - 0.06250 + - species-name: N2 + InChI: 1S/N2/c1-2 + amount: + - 0.18125 + - species-name: Ar + InChI: 1S/Ar + amount: + - 0.63125 + ignition-type: + target: pressure + type: d/dt max + time-histories: + - type: volume + time: + units: s + column: 0 + quantity: + units: cm3 + column: 1 + values: + - [0.00E+000, 5.47669375000E+002] + - [1.00E-003, 5.46608789894E+002] + - [2.00E-003, 5.43427034574E+002] + - [3.00E-003, 5.38124109043E+002] + - [4.00E-003, 5.30700013298E+002] + - [5.00E-003, 5.21154747340E+002] + - [6.00E-003, 5.09488311170E+002] + - [7.00E-003, 4.95700704787E+002] + - [8.00E-003, 4.79791928191E+002] + - [9.00E-003, 4.61761981383E+002] + - [1.00E-002, 4.41610864362E+002] + - [1.10E-002, 4.20399162234E+002] + - [1.20E-002, 3.99187460106E+002] + - [1.30E-002, 3.77975757979E+002] + - [1.40E-002, 3.56764055851E+002] + - [1.50E-002, 3.35552353723E+002] + - [1.60E-002, 3.14340651596E+002] + - [1.70E-002, 2.93128949468E+002] + - [1.80E-002, 2.71917247340E+002] + - [1.90E-002, 2.50705545213E+002] + - [2.00E-002, 2.29493843085E+002] + - [2.10E-002, 2.08282140957E+002] + - [2.20E-002, 1.87070438830E+002] + - [2.30E-002, 1.65858736702E+002] + - [2.40E-002, 1.44647034574E+002] + - [2.50E-002, 1.23435332447E+002] + - [2.60E-002, 1.02223630319E+002] + - [2.70E-002, 8.10119281915E+001] + - [2.80E-002, 6.33355097518E+001] + - [2.90E-002, 5.27296586879E+001] + - [3.00E-002, 4.91943750000E+001] + - [3.10E-002, 4.97137623933E+001] + - [3.20E-002, 5.02063762048E+001] + - [3.30E-002, 5.06454851923E+001] + - [3.40E-002, 5.10218564529E+001] + - [3.50E-002, 5.13374097598E+001] + - [3.60E-002, 5.16004693977E+001] + - [3.70E-002, 5.18223244382E+001] + - [3.80E-002, 5.20148449242E+001] + - [3.90E-002, 5.21889350372E+001] + - [4.00E-002, 5.23536351113E+001] + - [4.10E-002, 5.25157124459E+001] + - [4.20E-002, 5.26796063730E+001] + - [4.30E-002, 5.28476160610E+001] + - [4.40E-002, 5.30202402028E+001] + - [4.50E-002, 5.31965961563E+001] + - [4.60E-002, 5.33748623839E+001] + - [4.70E-002, 5.35527022996E+001] + - [4.80E-002, 5.37276399831E+001] + - [4.90E-002, 5.38973687732E+001] + - [5.00E-002, 5.40599826225E+001] + - [5.10E-002, 5.42141273988E+001] + - [5.20E-002, 5.43590751578E+001] + - [5.30E-002, 5.44947289126E+001] + - [5.40E-002, 5.46215686913E+001] + - [5.50E-002, 5.47405518236E+001] + - [5.60E-002, 5.48529815402E+001] + - [5.70E-002, 5.49603582190E+001] + - [5.80E-002, 5.50642270863E+001] + - [5.90E-002, 5.51660349836E+001] + - [6.00E-002, 5.52670070646E+001] + - [6.10E-002, 5.53680520985E+001] + - [6.20E-002, 5.54697025392E+001] + - [6.30E-002, 5.55720927915E+001] + - [6.40E-002, 5.56749762728E+001] + - [6.50E-002, 5.57777790517E+001] + - [6.60E-002, 5.58796851466E+001] + - [6.70E-002, 5.59797461155E+001] + - [6.80E-002, 5.60770054561E+001] + - [6.90E-002, 5.61706266985E+001] + - [7.00E-002, 5.62600130036E+001] + - [7.10E-002, 5.63449057053E+001] + - [7.20E-002, 5.64254496625E+001] + - [7.30E-002, 5.65022146282E+001] + - [7.40E-002, 5.65761642150E+001] + - [7.50E-002, 5.66485675508E+001] + - [7.60E-002, 5.67208534842E+001] + - [7.70E-002, 5.67944133373E+001] + - [7.80E-002, 5.68703658198E+001] + - [7.90E-002, 5.69493069272E+001] + - [8.00E-002, 5.70310785669E+001] + - [8.10E-002, 5.71146023893E+001] + - [8.20E-002, 5.71978399741E+001] + - [8.30E-002, 5.72779572372E+001] + - [8.40E-002, 5.73517897984E+001] + - [8.50E-002, 5.74167271960E+001] + - [8.60E-002, 5.74721573687E+001] + - [8.70E-002, 5.75216388520E+001] + - [8.80E-002, 5.75759967785E+001] + - [8.90E-002, 5.76575701358E+001] + - [9.00E-002, 5.78058719368E+001] + - [9.10E-002, 5.80849611077E+001] + - [9.20E-002, 5.85928651155E+001] + - [9.30E-002, 5.94734357453E+001] + - [9.40E-002, 6.09310671165E+001] + - [9.50E-002, 6.32487551103E+001] + - [9.60E-002, 6.68100309742E+001] +... From 88ee6e28ccaf58758ddfc46da1a3a37cd33b84cf Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 18:01:41 -0700 Subject: [PATCH 7/9] Minor fix in arguments --- pyked/validation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyked/validation.py b/pyked/validation.py index 7d85d5c..bb94b6d 100644 --- a/pyked/validation.py +++ b/pyked/validation.py @@ -275,7 +275,8 @@ def _validate_isvalid_quantity(self, isvalid_quantity, field, value): """ if type(value[0]) is str: values = value[0].split() - quantity = Q_(*[float(values[0])] + values[1:]) + value_alt = [float(values[0])] + values[1:] + quantity = Q_(*value_alt) else: quantity = Q_(value[0]) low_lim = 0.0 * units(property_units[field]) From c2ef04fb1e2c9a8a7979aa983888944773178052 Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 18:19:02 -0700 Subject: [PATCH 8/9] Only apply to celsius and fahrenheit --- pyked/validation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyked/validation.py b/pyked/validation.py index bb94b6d..e198ca2 100644 --- a/pyked/validation.py +++ b/pyked/validation.py @@ -275,8 +275,11 @@ def _validate_isvalid_quantity(self, isvalid_quantity, field, value): """ if type(value[0]) is str: values = value[0].split() - value_alt = [float(values[0])] + values[1:] - quantity = Q_(*value_alt) + if temp in values for temp in ['degC', 'degF', 'celsius', 'fahrenheit']: + value_alt = [float(values[0])] + values[1:] + quantity = Q_(*value_alt) + else: + quantity = Q_(value[0]) else: quantity = Q_(value[0]) low_lim = 0.0 * units(property_units[field]) From 4da3a2ae72465dfe07b6b983305a63aa0ce88fff Mon Sep 17 00:00:00 2001 From: Jeff Santner Date: Wed, 13 Jun 2018 18:23:32 -0700 Subject: [PATCH 9/9] Syntax --- pyked/validation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyked/validation.py b/pyked/validation.py index e198ca2..8bfd101 100644 --- a/pyked/validation.py +++ b/pyked/validation.py @@ -275,7 +275,8 @@ def _validate_isvalid_quantity(self, isvalid_quantity, field, value): """ if type(value[0]) is str: values = value[0].split() - if temp in values for temp in ['degC', 'degF', 'celsius', 'fahrenheit']: + if any([temp in values for temp in + ['degC', 'degF', 'celsius', 'fahrenheit']]): value_alt = [float(values[0])] + values[1:] quantity = Q_(*value_alt) else: