예제 #1
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     xArrNew = array([1, 2, 3, 4, 5, 6], dtype=double)
     yArrNew = array([10, 5.49, 0.89, -.14, -1.07, 0.84], dtype=double)
     self.myclass = DataSet(xArrNew,
                            yArrNew,
                            xName='xxx',
                            yName='yyy',
                            xUnits='sec',
                            yUnits='ft',
                            timeStamp=123.45)
예제 #2
0
    def PcentError_Button_Click(self, event):
        self.evaluate_float_entries()
        if len(self.Listbox_1.curselection()):
            self.new_message('Showing Percent Error of:\n')

            i = int(self.Listbox_1.curselection()[0])
            obj = self.equationL[i]

            self.add_to_messages(obj.get_full_description())

            XY = self.guiObj.XYjob

            if XY.dataset:

                yeqnArr = obj.eval_xrange(XY.dataset.xArr)
                pcerrArr = -100.0 * (yeqnArr - XY.dataset.yArr
                                     ) / numpy.absolute(XY.dataset.yArr)

                errDS = DataSet(XY.dataset.xArr,
                                pcerrArr,
                                xName=XY.dataset.xName,
                                yName=XY.dataset.yName +
                                ' [100*(data - eqn)/data]',
                                xUnits=XY.dataset.xUnits,
                                yUnits=XY.dataset.yUnits)

                xArr = [XY.dataset.xmin, XY.dataset.xmax]
                yArr = [obj.pcent_std, obj.pcent_std]
                textLabelCurveL = [(xArr, yArr, 'red', 1, '--', '1 PcntStdDev')
                                   ]
                textLabelCurveL.append(
                    (xArr, [-obj.pcent_std,
                            -obj.pcent_std], 'red', 1, '--', ''))
                textLabelCurveL.append((xArr, [0., 0.], 'red', 1, '-', ''))

                self.guiObj.PlotWin.make_new_plot(
                    dataset=errDS,
                    textLabelCurveL=textLabelCurveL,
                    title_str=XY.dataset.yName + ' Percent Error\n in eqn: ' +
                    str(self.equationL[i].name),
                    specialPtL=None,
                    dataLabel='Percent Error',
                    force_linear_y=True)

        else:
            self.new_message('No Selection for Percent  Error.\n')
예제 #3
0
    -1524, -1372, -1219, -1067, -914, -762, -610, -457, -305, -152, 0, 152,
    305, 457, 610, 762, 914, 1067, 1219, 1372, 1524, 1829, 2134, 2438, 2743,
    3048, 4572, 6096, 7620, 9144, 10668, 12192, 13716, 15240
],
                 dtype=double)

PaArr = 1000.0 * array([
    121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99.5, 97.7, 96,
    94.2, 92.5, 90.8, 89.1, 87.5, 85.9, 84.3, 81.2, 78.2, 75.3, 72.4, 69.7,
    57.2, 46.6, 37.6, 30.1, 23.8, 18.7, 14.5, 11.1
],
                       dtype=double)

DS = DataSet(alt_mArr,
             PaArr,
             xName='altitude',
             yName='pressure',
             xUnits='m',
             yUnits='Pa')

guessD = {'A': 101325, 'c': 1, 'd': 2.25577E-5, 'n': 5.25588}
print('guessD Before', guessD)
CFit_toterr = NonLinCurveFit(DS,
                             rhs_eqnStr='A*(c - d*x)**n',
                             constDinp=guessD,
                             fit_best_pcent=0)  # 0=fit best total error
print('guessD After', guessD)

print('=' * 55)
print('..........Total Error............')
print(CFit_toterr.get_full_description())
print('=' * 55)
예제 #4
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.myds = DataSet(xArr, yArr)
예제 #5
0
            Percent Standard Deviation = 4.11221905227%
        y = 0.8315625 + 6.22254971591*x + 3.19353693182*x**2

"""
try:
    from matplotlib import pyplot as plt
    got_plt = True
except:
    got_plt = False
    
from xymath.dataset import DataSet
from xymath.linfit import LinCurveFit

concL = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
readingL = [1.54,2.03,3.17,3.67,4.89,6.73,6.74,7.87,8.86,10.35]
DS = DataSet(concL, readingL, xName='Concentration', yName='Instrument Reading')

print('\n\n')
print('='*55)
print(".... First show author's answer ....")
Fit_ref = LinCurveFit(DS, xtranL=['const', 'x'] , ytran='y', cArrInp=[0.199, 9.7926],
                  fit_best_pcent=0)   # 0=fit best total error
print(Fit_ref.get_full_description())

print('='*55)
print('.... Then show XYmath answer ....')
Fit_linear = LinCurveFit(DS, xtranL=['const', 'x'] , ytran='y', 
                  fit_best_pcent=0)   # 0=fit best total error
print(Fit_linear.get_full_description())

print('='*55)
예제 #6
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     xArrNew = array( [1,2,3,4,5,6], dtype=double)
     yArrNew = array( [10,5.49,0.89,-.14,-1.07,0.84], dtype=double)
     self.myclass = DataSet(xArrNew, yArrNew,
         xName='xxx', yName='yyy', xUnits='sec', yUnits='ft', timeStamp=123.45)
예제 #7
0
class MyTest(unittest.TestCase):

    def setUp(self):
        unittest.TestCase.setUp(self)
        xArrNew = array( [1,2,3,4,5,6], dtype=double)
        yArrNew = array( [10,5.49,0.89,-.14,-1.07,0.84], dtype=double)
        self.myclass = DataSet(xArrNew, yArrNew,
            xName='xxx', yName='yyy', xUnits='sec', yUnits='ft', timeStamp=123.45)

    def tearDown(self):
        unittest.TestCase.tearDown(self)
        del( self.myclass )

    def test_should_always_pass_cleanly(self):
        """Should always pass cleanly."""
        pass
        
    def test_myclass_existence(self):
        """Check that myclass exists"""
        result = self.myclass
        # See if the self.myclass object exists
        self.assertTrue(result)
        
    def test_get_x_transform_for_constant(self):
        """get x transform for constant"""
        val = self.myclass.getTransXArr(name='const')
        self.assertTrue((val==ones(6, dtype=double)).all())

    def test_get_x_transform_for_x(self):
        """get x transform for x"""
        val = self.myclass.getTransXArr(name='x')
        self.assertTrue((val==xArr).all())

    def test_get_x_transform_for_1_over_x(self):
        """get x transform for x"""
        val = self.myclass.getTransXArr(name='1/x')
        self.assertTrue((val==1.0/xArr).all())

    def test_get_x_transform_for_x2(self):
        """get x transform for x"""
        val = self.myclass.getTransXArr(name='x**2')
        self.assertTrue((val==xArr**2).all())

    def test_get_x_transform_for_y(self):
        """get y transform for y"""
        val = self.myclass.getTransYArr(name='y')
        self.assertTrue((val==yArr).all())

    def test_data_append(self):
        """append a row of data"""
        self.myclass.append_xy( 7.0, 0.7 )
        xnewArr = array( [1,2,3,4,5,6,7], dtype=double)
        self.assertTrue((self.myclass.xArr==xnewArr).all())
        
        ynewArr = array( [10,5.49,0.89,-.14,-1.07,0.84, 0.7], dtype=double)
        self.assertTrue((self.myclass.yArr==ynewArr).all())

    def test_data_append_list(self):
        """append new rows of data"""
        self.myclass.append_xy_list( [7.0,8.0], [0.7,0.8] )
        xnewArr = array( [1,2,3,4,5,6,7,8], dtype=double)
        self.assertTrue((self.myclass.xArr==xnewArr).all())
        
        ynewArr = array( [10,5.49,0.89,-.14,-1.07,0.84, 0.7,0.8], dtype=double)
        self.assertTrue((self.myclass.yArr==ynewArr).all())

    def test_data_append_with_wts(self):
        """append a row of data"""
        self.myclass.set_all_weights_to_one()
        self.myclass.append_xy( 7.0, 0.7 )
        wnewArr = ones( 7, dtype=double)
        self.assertTrue((self.myclass.wtArr==wnewArr).all())

    def test_data_append_list_with_wts(self):
        """append new rows of data"""
        self.myclass.set_all_weights_to_one()
        self.myclass.append_xy_list( [7.0,8.0], [0.7,0.8] )
        wnewArr = ones( 8, dtype=double)
        self.assertTrue((self.myclass.wtArr==wnewArr).all())

    def test_data_set_xy(self):
        """set an xy pair"""
        self.myclass.set_an_xy_pair( 2, 3.33, 3.89)
        xnewArr = array( [1,2,3.33,4,5,6], dtype=double)
        self.assertTrue((self.myclass.xArr==xnewArr).all())
        
        ynewArr = array( [10,5.49,3.89,-.14,-1.07,0.84], dtype=double)
        self.assertTrue((self.myclass.yArr==ynewArr).all())

    def test_replace_all_xy_data(self):
        """set all xy data"""
        self.myclass.replace_all_xy_data(xArr=array([1.,2.]), yArr=array([3.,4.]))
        xnewArr = array( [1,2], dtype=double)
        self.assertTrue((self.myclass.xArr==xnewArr).all())
        
        ynewArr = array( [3,4], dtype=double)
        self.assertTrue((self.myclass.yArr==ynewArr).all())

    def test_swap_x_and_y_data(self):
        """swap xArr and yArr data"""
        self.myclass.summary_print()
        print( '#'*66 )
        self.myclass.swap_x_and_y()
        self.myclass.summary_print()
        ynewArr = array( [1,2,3,4,5,6], dtype=double)
        xnewArr = array( [10,5.49,0.89,-.14,-1.07,0.84], dtype=double)
        
        self.assertTrue((self.myclass.xArr==xnewArr).all())
        self.assertTrue((self.myclass.yArr==ynewArr).all())


    def test_sort_data(self):
        """sort xArr and yArr data by xArr"""
        self.myclass.replace_all_xy_data( xArr=array([2,7,1,4]), yArr=array([22.2,0.7,11.1,4.4]), wtArr=None)
        self.myclass.summary_print()
        print( '#'*66 )
        self.myclass.sort_by_x()
        self.myclass.summary_print()
        xnewArr = array( [1,2,4,7], dtype=double)
        ynewArr = array( [11.1,22.2,4.4,0.7], dtype=double)
        
        self.assertTrue((self.myclass.xArr==xnewArr).all())
        self.assertTrue((self.myclass.yArr==ynewArr).all())
예제 #8
0
"""
try:
    from matplotlib import pyplot as plt
    got_plt = True
except:
    got_plt = False
    
from numpy import array
from xymath.dataset import DataSet
from xymath.nonlinfit import NonLinCurveFit

xdata = array([-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9])
ydata = array([0.699369,0.700462,0.695354,1.03905,1.97389,2.41143,
               1.91091,0.919576,-0.730975,-1.42001])
DS = DataSet(xdata, ydata, xName='x', yName='y')

guessD = {'p1':1.0, 'p2':0.2}
CFit = NonLinCurveFit(DS, rhs_eqnStr='p1*cos(p2*x) + p2*sin(p1*x)', 
                      constDinp=guessD, fit_best_pcent=0)   # 0=fit best total error

print( 'residuals from XYmath = %g'%sum( (CFit.eval_xrange( xdata ) - ydata)**2 ) )
print( 'residuals from author = 0.053812696547933969' )
print('')
print(CFit.get_full_description())

if got_plt:
    plt.plot( xdata, ydata, 'o', markersize=10  )
    xPlotArr, yPlotArr = CFit.get_xy_plot_arrays( Npoints=100, logScale=False)
    plt.plot( xPlotArr, yPlotArr )
    plt.title('Trig Function: p1*cos(p2*x) + p2*sin(p1*x)')
예제 #9
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.myds = DataSet(xArr, yArr)
     self.myspline = Spline(self.myds, order=2, smoothing=0.0)
     self.mylinterp = Spline(self.myds, order=1, smoothing=0.0)
예제 #10
0
class MyTest(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)
        xArrNew = array([1, 2, 3, 4, 5, 6], dtype=double)
        yArrNew = array([10, 5.49, 0.89, -.14, -1.07, 0.84], dtype=double)
        self.myclass = DataSet(xArrNew,
                               yArrNew,
                               xName='xxx',
                               yName='yyy',
                               xUnits='sec',
                               yUnits='ft',
                               timeStamp=123.45)

    def tearDown(self):
        unittest.TestCase.tearDown(self)
        del (self.myclass)

    def test_should_always_pass_cleanly(self):
        """Should always pass cleanly."""
        pass

    def test_myclass_existence(self):
        """Check that myclass exists"""
        result = self.myclass
        # See if the self.myclass object exists
        self.assertTrue(result)

    def test_get_x_transform_for_constant(self):
        """get x transform for constant"""
        val = self.myclass.getTransXArr(name='const')
        self.assertTrue((val == ones(6, dtype=double)).all())

    def test_get_x_transform_for_x(self):
        """get x transform for x"""
        val = self.myclass.getTransXArr(name='x')
        self.assertTrue((val == xArr).all())

    def test_get_x_transform_for_1_over_x(self):
        """get x transform for x"""
        val = self.myclass.getTransXArr(name='1/x')
        self.assertTrue((val == 1.0 / xArr).all())

    def test_get_x_transform_for_x2(self):
        """get x transform for x"""
        val = self.myclass.getTransXArr(name='x**2')
        self.assertTrue((val == xArr**2).all())

    def test_get_x_transform_for_y(self):
        """get y transform for y"""
        val = self.myclass.getTransYArr(name='y')
        self.assertTrue((val == yArr).all())

    def test_data_append(self):
        """append a row of data"""
        self.myclass.append_xy(7.0, 0.7)
        xnewArr = array([1, 2, 3, 4, 5, 6, 7], dtype=double)
        self.assertTrue((self.myclass.xArr == xnewArr).all())

        ynewArr = array([10, 5.49, 0.89, -.14, -1.07, 0.84, 0.7], dtype=double)
        self.assertTrue((self.myclass.yArr == ynewArr).all())

    def test_data_append_list(self):
        """append new rows of data"""
        self.myclass.append_xy_list([7.0, 8.0], [0.7, 0.8])
        xnewArr = array([1, 2, 3, 4, 5, 6, 7, 8], dtype=double)
        self.assertTrue((self.myclass.xArr == xnewArr).all())

        ynewArr = array([10, 5.49, 0.89, -.14, -1.07, 0.84, 0.7, 0.8],
                        dtype=double)
        self.assertTrue((self.myclass.yArr == ynewArr).all())

    def test_data_append_with_wts(self):
        """append a row of data"""
        self.myclass.set_all_weights_to_one()
        self.myclass.append_xy(7.0, 0.7)
        wnewArr = ones(7, dtype=double)
        self.assertTrue((self.myclass.wtArr == wnewArr).all())

    def test_data_append_list_with_wts(self):
        """append new rows of data"""
        self.myclass.set_all_weights_to_one()
        self.myclass.append_xy_list([7.0, 8.0], [0.7, 0.8])
        wnewArr = ones(8, dtype=double)
        self.assertTrue((self.myclass.wtArr == wnewArr).all())

    def test_data_set_xy(self):
        """set an xy pair"""
        self.myclass.set_an_xy_pair(2, 3.33, 3.89)
        xnewArr = array([1, 2, 3.33, 4, 5, 6], dtype=double)
        self.assertTrue((self.myclass.xArr == xnewArr).all())

        ynewArr = array([10, 5.49, 3.89, -.14, -1.07, 0.84], dtype=double)
        self.assertTrue((self.myclass.yArr == ynewArr).all())

    def test_replace_all_xy_data(self):
        """set all xy data"""
        self.myclass.replace_all_xy_data(xArr=array([1., 2.]),
                                         yArr=array([3., 4.]))
        xnewArr = array([1, 2], dtype=double)
        self.assertTrue((self.myclass.xArr == xnewArr).all())

        ynewArr = array([3, 4], dtype=double)
        self.assertTrue((self.myclass.yArr == ynewArr).all())

    def test_swap_x_and_y_data(self):
        """swap xArr and yArr data"""
        self.myclass.summary_print()
        print('#' * 66)
        self.myclass.swap_x_and_y()
        self.myclass.summary_print()
        ynewArr = array([1, 2, 3, 4, 5, 6], dtype=double)
        xnewArr = array([10, 5.49, 0.89, -.14, -1.07, 0.84], dtype=double)

        self.assertTrue((self.myclass.xArr == xnewArr).all())
        self.assertTrue((self.myclass.yArr == ynewArr).all())

    def test_sort_data(self):
        """sort xArr and yArr data by xArr"""
        self.myclass.replace_all_xy_data(xArr=array([2, 7, 1, 4]),
                                         yArr=array([22.2, 0.7, 11.1, 4.4]),
                                         wtArr=None)
        self.myclass.summary_print()
        print('#' * 66)
        self.myclass.sort_by_x()
        self.myclass.summary_print()
        xnewArr = array([1, 2, 4, 7], dtype=double)
        ynewArr = array([11.1, 22.2, 4.4, 0.7], dtype=double)

        self.assertTrue((self.myclass.xArr == xnewArr).all())
        self.assertTrue((self.myclass.yArr == ynewArr).all())