Ignore:
Timestamp:
Mar 28, 2017 6:53:29 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
0268aed
Parents:
a9b568c
Message:

Chi2 display + minor refactoring

Location:
src/sas/qtgui/Perspectives/Fitting/UnitTesting
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingLogicTest.py

    r351b53e r6fd4e36  
    104104                        data, False, None) 
    105105 
    106         self.logic.new1DPlot(return_data=return_data) 
     106        new_plot = self.logic.new1DPlot(return_data=return_data) 
    107107 
    108         self.assertIsInstance(self.logic.data, Data1D) 
    109         self.assertFalse(self.logic.data.is_data) 
    110         self.assertEqual(self.logic.data.dy.size, 3) 
    111         self.assertEqual(self.logic.data.title, "boop") 
    112         self.assertEqual(self.logic.data.name, "boop [boop]") 
     108        self.assertIsInstance(new_plot, Data1D) 
     109        self.assertFalse(new_plot.is_data) 
     110        self.assertEqual(new_plot.dy.size, 3) 
     111        self.assertEqual(new_plot.title, "boop") 
     112        self.assertEqual(new_plot.name, "boop [boop]") 
    113113 
    114114    def testNew2DPlot(self): 
     
    142142                        0.1, False, None) 
    143143 
    144         self.logic.new2DPlot(return_data=return_data) 
     144        new_plot = self.logic.new2DPlot(return_data=return_data) 
    145145 
    146         self.assertIsInstance(self.logic.data, Data2D) 
    147         self.assertFalse(self.logic.data.is_data) 
    148         self.assertEqual(self.logic.data.title, "Analytical model 2D ") 
    149         self.assertEqual(self.logic.data.name, "boop [boop]") 
     146        self.assertIsInstance(new_plot, Data2D) 
     147        self.assertFalse(new_plot.is_data) 
     148        self.assertEqual(new_plot.title, "Analytical model 2D ") 
     149        self.assertEqual(new_plot.name, "boop [boop]") 
    150150 
    151151 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingUtilitiesTest.py

    rb1e36a3 r6fd4e36  
    33from PyQt4 import QtGui 
    44 
     5from sas.sasgui.guiframe.dataFitting import Data1D 
     6from sas.sasgui.guiframe.dataFitting import Data2D 
     7 
    58from UnitTesting.TestUtils import WarningTestNotImplemented 
    6 #from sasmodels.sasview_model import load_standard_models 
     9 
    710from sasmodels import generate 
    811from sasmodels import modelinfo 
     
    180183        self.assertEqual(model.item(1).child(0).child(0,1).text(), "40.0") 
    181184 
     185    def testCalculate1DChi2(self): 
     186        """ 
     187        Test the chi2 calculator for Data1D 
     188        """ 
     189        reference_data = Data1D(x=[0.1, 0.2], y=[0.0, 0.0]) 
     190 
     191        # 1. identical data 
     192        current_data = Data1D(x=[0.1, 0.2], y=[0.0, 0.0]) 
     193 
     194        chi = FittingUtilities.calculateChi2(reference_data, current_data) 
     195 
     196        # Should be zero 
     197        self.assertAlmostEqual(chi, 0.0, 8) 
     198 
     199        # 2. far data 
     200        current_data = Data1D(x=[0.1, 0.2], y=[200.0, 150.0]) 
     201 
     202        chi = FittingUtilities.calculateChi2(reference_data, current_data) 
     203 
     204        # Should not be zero 
     205        self.assertAlmostEqual(chi, 31250.0, 8) 
     206 
     207        # 3. Wrong data 
     208        current_data = Data1D(x=[0.1, 0.2], y=[200.0, 150.0, 200.0]) 
     209        chi = FittingUtilities.calculateChi2(reference_data, current_data) 
     210        # Should be None 
     211        self.assertIsNone(chi) 
     212 
     213    def testCalculate2DChi2(self): 
     214        """ 
     215        Test the chi2 calculator for Data2D 
     216        """ 
     217        reference_data = Data2D(image=[1.0, 2.0, 3.0], 
     218                      err_image=[0.01, 0.02, 0.03], 
     219                      qx_data=[0.1, 0.2, 0.3], 
     220                      qy_data=[0.1, 0.2, 0.3]) 
     221 
     222        # 1. identical data 
     223        current_data = Data2D(image=[1.0, 2.0, 3.0], 
     224                      err_image=[0.01, 0.02, 0.03], 
     225                      qx_data=[0.1, 0.2, 0.3], 
     226                      qy_data=[0.1, 0.2, 0.3]) 
     227 
     228        chi = FittingUtilities.calculateChi2(reference_data, current_data) 
     229 
     230        # Should be zero 
     231        self.assertAlmostEqual(chi, 0.0, 8) 
     232 
     233        # 2. far data 
     234        current_data = Data2D(image=[100.0, 200.0, 300.0], 
     235                      err_image=[1.01, 2.02, 3.03], 
     236                      qx_data=[0.1, 0.2, 0.3], 
     237                      qy_data=[100.0, 200., 300.]) 
     238 
     239        chi = FittingUtilities.calculateChi2(reference_data, current_data) 
     240 
     241        # Should not be zero 
     242        self.assertAlmostEqual(chi, 9607.88, 2) 
     243 
     244        # 3. Wrong data 
     245        current_data = Data2D(image=[1.0, 2.0, 3.0], 
     246                      err_image=[0.01, 0.02], 
     247                      qx_data=[0.1, 0.2], 
     248                      qy_data=[0.1, 0.2, 0.3]) 
     249        # Should throw 
     250        with self.assertRaises(ValueError): 
     251            chi = FittingUtilities.calculateChi2(reference_data, current_data) 
     252 
    182253if __name__ == "__main__": 
    183254    unittest.main() 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r9934e48 r6fd4e36  
    215215        self.assertFalse(self.widget.calculateQGridForModel.called) 
    216216 
    217         # Let's set a dummy index on widget 
    218         self.widget._index = QtGui.QStandardItem() 
     217        # Let's tell the widget that data has been loaded 
     218        self.widget.data_is_loaded = True 
    219219        # Reset the sasmodel index 
    220220        self.widget.cbModel.setCurrentIndex(1) 
Note: See TracChangeset for help on using the changeset viewer.