Ignore:
Timestamp:
Oct 7, 2016 8:48:25 AM (8 years ago)
Author:
mathieu
Branches:
master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
1b1a1c1
Parents:
61780e3
Message:

Make sure we can compute models w/o data. Fixes #714

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/fitting/model_thread.py

    rca4d985 r286c757  
    179179            unsmeared_output[first_bin:last_bin+1] = self.model.evalDistribution(mask) 
    180180            output = self.smearer(unsmeared_output, first_bin, last_bin) 
    181              
     181 
    182182            # Rescale data to unsmeared model 
    183             unsmeared_data = numpy.zeros((len(self.data.x))) 
    184             unsmeared_error = numpy.zeros((len(self.data.x))) 
    185             unsmeared_data[first_bin:last_bin+1] = self.data.y[first_bin:last_bin+1]\ 
    186                                                     * unsmeared_output[first_bin:last_bin+1]\ 
    187                                                     / output[first_bin:last_bin+1] 
    188             unsmeared_error[first_bin:last_bin+1] = self.data.dy[first_bin:last_bin+1]\ 
    189                                                     * unsmeared_output[first_bin:last_bin+1]\ 
    190                                                     / output[first_bin:last_bin+1] 
    191             unsmeared_output=unsmeared_output[index] 
    192             unsmeared_data=unsmeared_data[index] 
    193             unsmeared_error=unsmeared_error 
     183            # Check that the arrays are compatible. If we only have a model but no data, 
     184            # the length of data.y will be zero. 
     185            if isinstance(self.data.y, numpy.ndarray) and output.shape == self.data.y.shape: 
     186                unsmeared_data = numpy.zeros((len(self.data.x))) 
     187                unsmeared_error = numpy.zeros((len(self.data.x))) 
     188                unsmeared_data[first_bin:last_bin+1] = self.data.y[first_bin:last_bin+1]\ 
     189                                                        * unsmeared_output[first_bin:last_bin+1]\ 
     190                                                        / output[first_bin:last_bin+1] 
     191                unsmeared_error[first_bin:last_bin+1] = self.data.dy[first_bin:last_bin+1]\ 
     192                                                        * unsmeared_output[first_bin:last_bin+1]\ 
     193                                                        / output[first_bin:last_bin+1] 
     194                unsmeared_output=unsmeared_output[index] 
     195                unsmeared_data=unsmeared_data[index] 
     196                unsmeared_error=unsmeared_error 
    194197        else: 
    195198            output[index] = self.model.evalDistribution(self.data.x[index]) 
Note: See TracChangeset for help on using the changeset viewer.