@@ -584,8 +584,54 @@ def convert_to_ReSpecTh(self, filename):
584
584
585
585
print ('Converted to ' + filename )
586
586
587
+ class DataPoint (object ):
588
+ """
589
+ A base class for a single datapoint.
590
+
591
+ Specific types of data point should inherit from this.
592
+ """
593
+ def process_quantity (self , properties ):
594
+ """Process the uncertainty information from a given quantity and return it
595
+ """
596
+ quant = Q_ (properties [0 ])
597
+ if len (properties ) > 1 :
598
+ unc = properties [1 ]
599
+ uncertainty = unc .get ('uncertainty' , False )
600
+ upper_uncertainty = unc .get ('upper-uncertainty' , False )
601
+ lower_uncertainty = unc .get ('lower-uncertainty' , False )
602
+ uncertainty_type = unc .get ('uncertainty-type' )
603
+ if uncertainty_type == 'relative' :
604
+ if uncertainty :
605
+ quant = quant .plus_minus (float (uncertainty ), relative = True )
606
+ elif upper_uncertainty and lower_uncertainty :
607
+ warn ('Asymmetric uncertainties are not supported. The '
608
+ 'maximum of lower-uncertainty and upper-uncertainty '
609
+ 'has been used as the symmetric uncertainty.' )
610
+ uncertainty = max (float (upper_uncertainty ), float (lower_uncertainty ))
611
+ quant = quant .plus_minus (uncertainty , relative = True )
612
+ else :
613
+ raise ValueError ('Either "uncertainty" or "upper-uncertainty" and '
614
+ '"lower-uncertainty" need to be specified.' )
615
+ elif uncertainty_type == 'absolute' :
616
+ if uncertainty :
617
+ uncertainty = Q_ (uncertainty )
618
+ quant = quant .plus_minus (uncertainty .to (quant .units ).magnitude )
619
+ elif upper_uncertainty and lower_uncertainty :
620
+ warn ('Asymmetric uncertainties are not supported. The '
621
+ 'maximum of lower-uncertainty and upper-uncertainty '
622
+ 'has been used as the symmetric uncertainty.' )
623
+ uncertainty = max (Q_ (upper_uncertainty ), Q_ (lower_uncertainty ))
624
+ quant = quant .plus_minus (uncertainty .to (quant .units ).magnitude )
625
+ else :
626
+ raise ValueError ('Either "uncertainty" or "upper-uncertainty" and '
627
+ '"lower-uncertainty" need to be specified.' )
628
+ else :
629
+ raise ValueError ('uncertainty-type must be one of "absolute" or "relative"' )
587
630
588
- class IgnitionDataPoint (object ):
631
+ return quant
632
+
633
+
634
+ class IgnitionDataPoint (DataPoint ):
589
635
"""Class for a single datapoint.
590
636
591
637
The `DataPoint` class stores the information associated with a single data point in the dataset
@@ -719,45 +765,7 @@ def __init__(self, properties):
719
765
if not hasattr (self , '{}_history' .format (h )):
720
766
setattr (self , '{}_history' .format (h ), None )
721
767
722
- def process_quantity (self , properties ):
723
- """Process the uncertainty information from a given quantity and return it
724
- """
725
- quant = Q_ (properties [0 ])
726
- if len (properties ) > 1 :
727
- unc = properties [1 ]
728
- uncertainty = unc .get ('uncertainty' , False )
729
- upper_uncertainty = unc .get ('upper-uncertainty' , False )
730
- lower_uncertainty = unc .get ('lower-uncertainty' , False )
731
- uncertainty_type = unc .get ('uncertainty-type' )
732
- if uncertainty_type == 'relative' :
733
- if uncertainty :
734
- quant = quant .plus_minus (float (uncertainty ), relative = True )
735
- elif upper_uncertainty and lower_uncertainty :
736
- warn ('Asymmetric uncertainties are not supported. The '
737
- 'maximum of lower-uncertainty and upper-uncertainty '
738
- 'has been used as the symmetric uncertainty.' )
739
- uncertainty = max (float (upper_uncertainty ), float (lower_uncertainty ))
740
- quant = quant .plus_minus (uncertainty , relative = True )
741
- else :
742
- raise ValueError ('Either "uncertainty" or "upper-uncertainty" and '
743
- '"lower-uncertainty" need to be specified.' )
744
- elif uncertainty_type == 'absolute' :
745
- if uncertainty :
746
- uncertainty = Q_ (uncertainty )
747
- quant = quant .plus_minus (uncertainty .to (quant .units ).magnitude )
748
- elif upper_uncertainty and lower_uncertainty :
749
- warn ('Asymmetric uncertainties are not supported. The '
750
- 'maximum of lower-uncertainty and upper-uncertainty '
751
- 'has been used as the symmetric uncertainty.' )
752
- uncertainty = max (Q_ (upper_uncertainty ), Q_ (lower_uncertainty ))
753
- quant = quant .plus_minus (uncertainty .to (quant .units ).magnitude )
754
- else :
755
- raise ValueError ('Either "uncertainty" or "upper-uncertainty" and '
756
- '"lower-uncertainty" need to be specified.' )
757
- else :
758
- raise ValueError ('uncertainty-type must be one of "absolute" or "relative"' )
759
768
760
- return quant
761
769
762
770
def get_cantera_composition_string (self , species_conversion = None ):
763
771
"""Get the composition in a string format suitable for input to Cantera.
0 commit comments