Changeset 9687d58 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Apr 10, 2017 4:01:46 AM (8 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:
6c8fb2c
Parents:
9208346 (diff), c6f3aec (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ESS_GUI

Location:
src/sas/sascalc
Files:
12 added
11 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/data_util/qsmearing.py

    rf8aa738 rd3911e3  
    4141        elif data.dqx_data == None or data.dqy_data == None: 
    4242            return None 
    43         return Pinhole2D(data) 
     43        return PySmear2D(data, model) 
    4444 
    4545    if  not hasattr(data, "dx") and not hasattr(data, "dxl")\ 
     
    142142    width = data.dx if data.dx is not None else 0 
    143143    return PySmear(Pinhole1D(q, width), model) 
     144 
     145 
     146class PySmear2D(object): 
     147    """ 
     148    Q smearing class for SAS 2d pinhole data 
     149    """ 
     150 
     151    def __init__(self, data=None, model=None): 
     152        self.data = data 
     153        self.model = model 
     154        self.accuracy = 'Low' 
     155        self.limit = 3.0 
     156        self.index = None 
     157        self.coords = 'polar' 
     158        self.smearer = True 
     159 
     160    def set_accuracy(self, accuracy='Low'): 
     161        """ 
     162        Set accuracy. 
     163 
     164        :param accuracy:  string 
     165        """ 
     166        self.accuracy = accuracy 
     167 
     168    def set_smearer(self, smearer=True): 
     169        """ 
     170        Set whether or not smearer will be used 
     171 
     172        :param smearer: smear object 
     173 
     174        """ 
     175        self.smearer = smearer 
     176 
     177    def set_data(self, data=None): 
     178        """ 
     179        Set data. 
     180 
     181        :param data: DataLoader.Data_info type 
     182        """ 
     183        self.data = data 
     184 
     185    def set_model(self, model=None): 
     186        """ 
     187        Set model. 
     188 
     189        :param model: sas.models instance 
     190        """ 
     191        self.model = model 
     192 
     193    def set_index(self, index=None): 
     194        """ 
     195        Set index. 
     196 
     197        :param index: 1d arrays 
     198        """ 
     199        self.index = index 
     200 
     201    def get_value(self): 
     202        """ 
     203        Over sampling of r_nbins times phi_nbins, calculate Gaussian weights, 
     204        then find smeared intensity 
     205        """ 
     206        if self.smearer: 
     207            res = Pinhole2D(data=self.data, index=self.index, 
     208                            nsigma=3.0, accuracy=self.accuracy, 
     209                            coords=self.coords) 
     210            val = self.model.evalDistribution(res.q_calc) 
     211            return res.apply(val) 
     212        else: 
     213            index = self.index if self.index is not None else slice(None) 
     214            qx_data = self.data.qx_data[index] 
     215            qy_data = self.data.qy_data[index] 
     216            q_calc = [qx_data, qy_data] 
     217            val = self.model.evalDistribution(q_calc) 
     218            return val 
     219 
  • src/sas/sascalc/dataloader/data_info.py

    r20ac508 r345e7e4  
    881881                raise ValueError, msg 
    882882            # Here we could also extrapolate between data points 
    883             ZERO = 1.0e-12 
     883            TOLERANCE = 0.01 
    884884            for i in range(len(self.x)): 
    885                 if math.fabs(self.x[i] - other.x[i]) > ZERO: 
     885                if math.fabs((self.x[i] - other.x[i])/self.x[i]) > TOLERANCE: 
    886886                    msg = "Incompatible data sets: x-values do not match" 
    887887                    raise ValueError, msg 
     
    10931093        """ 
    10941094        err_other = None 
     1095        TOLERANCE = 0.01 
    10951096        if isinstance(other, Data2D): 
    10961097            # Check that data lengths are the same 
     
    11011102                raise ValueError, msg 
    11021103            for ind in range(len(self.data)): 
    1103                 if self.qx_data[ind] != other.qx_data[ind]: 
    1104                     msg = "Incompatible data sets: qx-values do not match" 
     1104                if math.fabs((self.qx_data[ind] - other.qx_data[ind])/self.qx_data[ind]) > TOLERANCE: 
     1105                    msg = "Incompatible data sets: qx-values do not match: %s %s" % (self.qx_data[ind], other.qx_data[ind]) 
    11051106                    raise ValueError, msg 
    1106                 if self.qy_data[ind] != other.qy_data[ind]: 
    1107                     msg = "Incompatible data sets: qy-values do not match" 
     1107                if math.fabs((self.qy_data[ind] - other.qy_data[ind])/self.qy_data[ind]) > TOLERANCE: 
     1108                    msg = "Incompatible data sets: qy-values do not match: %s %s" % (self.qy_data[ind], other.qy_data[ind]) 
    11081109                    raise ValueError, msg 
    11091110 
  • src/sas/sascalc/dataloader/manipulations.py

    rb699768 rb2b36932  
    143143        :return: Data1D object 
    144144        """ 
    145         if len(data2D.detector) != 1: 
     145        if len(data2D.detector) > 1: 
    146146            msg = "_Slab._avg: invalid number of " 
    147147            msg += " detectors: %g" % len(data2D.detector) 
     
    299299            error on number of counts, number of entries summed 
    300300        """ 
    301         if len(data2D.detector) != 1: 
     301        if len(data2D.detector) > 1: 
    302302            msg = "Circular averaging: invalid number " 
    303303            msg += "of detectors: %g" % len(data2D.detector) 
  • src/sas/sascalc/dataloader/readers/anton_paar_saxs_reader.py

    r80c5d46 ra235f715  
    4545    output = None 
    4646 
    47     def __init__(self): 
     47    def reset_state(self): 
    4848        self.current_dataset = Data1D(np.empty(0), np.empty(0), 
    4949                                            np.empty(0), np.empty(0)) 
     
    7272 
    7373        ## Reinitialize the class when loading a new data file to reset all class variables 
    74         self.__init__() 
     74        self.reset_state() 
    7575        ## Check that the file exists 
    7676        if os.path.isfile(filename): 
     
    8484                self.raw_data = buff.splitlines() 
    8585                self.read_data() 
    86                 xml_intermediate = self.raw_data[self.upper:] 
    87                 xml = ''.join(xml_intermediate) 
    88                 self.set_xml_file(xml) 
    8986        return self.output 
    9087 
     
    10097        self.lower = 5 
    10198        self.upper = self.lower + self.data_points 
    102         self.detector.distance = float(line4[1]) 
     99        self.source.radiation = 'x-ray' 
     100        normal = float(line4[3]) 
    103101        self.current_dataset.source.radiation = "x-ray" 
    104102        self.current_dataset.source.name = "Anton Paar SAXSess Instrument" 
    105103        self.current_dataset.source.wavelength = float(line4[4]) 
    106         normal = line4[3] 
     104        xvals = [] 
     105        yvals = [] 
     106        dyvals = [] 
    107107        for i in range(self.lower, self.upper): 
     108            index = i - self.lower 
    108109            data = self.raw_data[i].split() 
    109             x_val = [float(data[0])] 
    110             y_val = [float(data[1])] 
    111             dy_val = [float(data[2])] 
    112             self.current_dataset.x = np.append(self.current_dataset.x, x_val) 
    113             self.current_dataset.y = np.append(self.current_dataset.y, y_val) 
    114             self.current_dataset.dy = np.append(self.current_dataset.dy, dy_val) 
    115         self.current_dataset.xaxis("Q (%s)" % (q_unit), q_unit) 
    116         self.current_dataset.yaxis("Intensity (%s)" % (i_unit), i_unit) 
    117         self.current_dataset.detector.append(self.detector) 
     110            xvals.insert(index, normal * float(data[0])) 
     111            yvals.insert(index, normal * float(data[1])) 
     112            dyvals.insert(index, normal * float(data[2])) 
     113        self.current_dataset.x = np.append(self.current_dataset.x, xvals) 
     114        self.current_dataset.y = np.append(self.current_dataset.y, yvals) 
     115        self.current_dataset.dy = np.append(self.current_dataset.dy, dyvals) 
     116        if self.data_points != self.current_dataset.x.size: 
     117            self.errors.add("Not all data was loaded properly.") 
     118        if self.current_dataset.dx.size != self.current_dataset.x.size: 
     119            dxvals = np.zeros(self.current_dataset.x.size) 
     120            self.current_dataset.dx = dxvals 
     121        if self.current_dataset.x.size != self.current_dataset.y.size: 
     122            self.errors.add("The x and y data sets are not the same size.") 
     123        if self.current_dataset.y.size != self.current_dataset.dy.size: 
     124            self.errors.add("The y and dy datasets are not the same size.") 
     125        self.current_dataset.errors = self.errors 
     126        self.current_dataset.xaxis("Q", q_unit) 
     127        self.current_dataset.yaxis("Intensity", i_unit) 
     128        xml_intermediate = self.raw_data[self.upper:] 
     129        xml = ''.join(xml_intermediate) 
     130        self.set_xml_string(xml) 
     131        dom = self.xmlroot.xpath('/fileinfo') 
     132        self._parse_child(dom) 
    118133        self.output.append(self.current_dataset) 
     134 
     135    def _parse_child(self, dom, parent=''): 
     136        """ 
     137        Recursive method for stepping through the embedded XML 
     138        :param dom: XML node with or without children 
     139        """ 
     140        for node in dom: 
     141            tagname = node.tag 
     142            value = node.text 
     143            attr = node.attrib 
     144            key = attr.get("key", '') 
     145            if len(node.getchildren()) > 1: 
     146                self._parse_child(node, key) 
     147                if key == "SampleDetector": 
     148                    self.current_dataset.detector.append(self.detector) 
     149                    self.detector = Detector() 
     150            else: 
     151                if key == "value": 
     152                    if parent == "Wavelength": 
     153                        self.current_dataset.source.wavelength = value 
     154                    elif parent == "SampleDetector": 
     155                        self.detector.distance = value 
     156                    elif parent == "Temperature": 
     157                        self.current_dataset.sample.temperature = value 
     158                    elif parent == "CounterSlitLength": 
     159                        self.detector.slit_length = value 
     160                elif key == "unit": 
     161                    value = value.replace("_", "") 
     162                    if parent == "Wavelength": 
     163                        self.current_dataset.source.wavelength_unit = value 
     164                    elif parent == "SampleDetector": 
     165                        self.detector.distance_unit = value 
     166                    elif parent == "X": 
     167                        self.current_dataset.xaxis(self.current_dataset._xaxis, value) 
     168                    elif parent == "Y": 
     169                        self.current_dataset.yaxis(self.current_dataset._yaxis, value) 
     170                    elif parent == "Temperature": 
     171                        self.current_dataset.sample.temperature_unit = value 
     172                    elif parent == "CounterSlitLength": 
     173                        self.detector.slit_length_unit = value 
     174                elif key == "quantity": 
     175                    if parent == "X": 
     176                        self.current_dataset.xaxis(value, self.current_dataset._xunit) 
     177                    elif parent == "Y": 
     178                        self.current_dataset.yaxis(value, self.current_dataset._yunit) 
  • src/sas/sascalc/dataloader/readers/ascii_reader.py

    rd0ccd80f rd2471870  
    172172                input_f.close() 
    173173                if not is_data: 
    174                     return None 
     174                    msg = "ascii_reader: x has no data" 
     175                    raise RuntimeError, msg 
    175176                # Sanity check 
    176177                if has_error_dy == True and not len(ty) == len(tdy): 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    rca3f89b r0639476  
    11771177            written = written | self.write_node(pix, "z", item.pixel_size.z, 
    11781178                                                {"unit": item.pixel_size_unit}) 
    1179             written = written | self.write_node(det, "slit_length", 
    1180                                                 item.slit_length, 
    1181                                                 {"unit": item.slit_length_unit}) 
    11821179            if written == True: 
    11831180                self.append(pix, det) 
     1181            self.write_node(det, "slit_length", item.slit_length, 
     1182                {"unit": item.slit_length_unit}) 
     1183 
    11841184 
    11851185    def _write_process_notes(self, datainfo, entry_node): 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    r1b06e13a r9687d58  
    2323 
    2424    Any number of SASdata sets may be present in a SASentry and the data within can be either 1D I(Q) or 2D I(Qx, Qy). 
     25<<<<<<< HEAD 
     26======= 
     27 
     28    Also supports reading NXcanSAS formatted HDF5 files 
     29>>>>>>> master 
    2530 
    2631    :Dependencies: 
     
    7681                ## Add the last data set to the list of outputs 
    7782                self.add_data_set() 
     83                ## Close the data file 
     84                self.raw_data.close() 
    7885        ## Return data set(s) 
    7986        return self.output 
     
    189196 
    190197                    ## Sample Information 
    191                     elif key == u'Title' and self.parent_class == u'SASsample': 
     198                    elif key == u'Title' and self.parent_class == u'SASsample': # CanSAS 2.0 format 
     199                        self.current_datainfo.sample.name = data_point 
     200                    elif key == u'ID' and self.parent_class == u'SASsample': # NXcanSAS format 
    192201                        self.current_datainfo.sample.name = data_point 
    193202                    elif key == u'thickness' and self.parent_class == u'SASsample': 
     
    213222                    elif key == u'name' and self.parent_class == u'SASprocess': 
    214223                        self.process.name = data_point 
    215                     elif key == u'Title' and self.parent_class == u'SASprocess': 
    216                         self.process.name = data_point 
    217224                    elif key == u'description' and self.parent_class == u'SASprocess': 
    218225                        self.process.description = data_point 
     
    230237                        self.trans_spectrum.wavelength.append(data_point) 
    231238 
    232                     ## Other Information 
     239                    ## Source 
    233240                    elif key == u'wavelength' and self.parent_class == u'SASdata': 
    234241                        self.current_datainfo.source.wavelength = data_point 
    235                         self.current_datainfo.source.wavelength.unit = unit 
     242                        self.current_datainfo.source.wavelength_unit = unit 
     243                    elif key == u'incident_wavelength' and self.parent_class == u'SASsource': 
     244                        self.current_datainfo.source.wavelength = data_point 
     245                        self.current_datainfo.source.wavelength_unit = unit 
     246                    elif key == u'wavelength_max' and self.parent_class == u'SASsource': 
     247                        self.current_datainfo.source.wavelength_max = data_point 
     248                        self.current_datainfo.source.wavelength_max_unit = unit 
     249                    elif key == u'wavelength_min' and self.parent_class == u'SASsource': 
     250                        self.current_datainfo.source.wavelength_min = data_point 
     251                        self.current_datainfo.source.wavelength_min_unit = unit 
     252                    elif key == u'wavelength_spread' and self.parent_class == u'SASsource': 
     253                        self.current_datainfo.source.wavelength_spread = data_point 
     254                        self.current_datainfo.source.wavelength_spread_unit = unit 
     255                    elif key == u'beam_size_x' and self.parent_class == u'SASsource': 
     256                        self.current_datainfo.source.beam_size.x = data_point 
     257                        self.current_datainfo.source.beam_size_unit = unit 
     258                    elif key == u'beam_size_y' and self.parent_class == u'SASsource': 
     259                        self.current_datainfo.source.beam_size.y = data_point 
     260                        self.current_datainfo.source.beam_size_unit = unit 
     261                    elif key == u'beam_shape' and self.parent_class == u'SASsource': 
     262                        self.current_datainfo.source.beam_shape = data_point 
    236263                    elif key == u'radiation' and self.parent_class == u'SASsource': 
    237264                        self.current_datainfo.source.radiation = data_point 
  • src/sas/sascalc/dataloader/readers/xml_reader.py

    rb699768 ra235f715  
    7070            self.xmldoc = etree.parse(self.xml, parser=PARSER) 
    7171            self.xmlroot = self.xmldoc.getroot() 
     72        except etree.XMLSyntaxError as xml_error: 
     73            logging.info(xml_error) 
     74        except Exception: 
     75            self.xml = None 
     76            self.xmldoc = None 
     77            self.xmlroot = None 
     78 
     79    def set_xml_string(self, tag_soup): 
     80        """ 
     81        Set an XML string as the working XML. 
     82 
     83        :param tag_soup: XML formatted string 
     84        """ 
     85        try: 
     86            self.xml = tag_soup 
     87            self.xmldoc = tag_soup 
     88            self.xmlroot = etree.fromstring(tag_soup) 
    7289        except etree.XMLSyntaxError as xml_error: 
    7390            logging.info(xml_error) 
  • src/sas/sascalc/fit/AbstractFitEngine.py

    rfc18690 rd3911e3  
    359359        if self.smearer != None: 
    360360            fn.set_index(self.idx) 
    361             # Get necessary data from self.data and set the data for smearing 
    362             fn.get_data() 
    363  
    364361            gn = fn.get_value() 
    365362        else: 
  • src/sas/sascalc/fit/BumpsFitting.py

    rb699768 r345e7e4  
    44import os 
    55from datetime import timedelta, datetime 
     6import traceback 
    67 
    78import numpy 
     
    293294            R.success = result['success'] 
    294295            if R.success: 
    295                 R.stderr = numpy.hstack((result['stderr'][fitted_index], 
    296                                          numpy.NaN*numpy.ones(len(fitness.computed_pars)))) 
     296                if result['stderr'] is None: 
     297                    R.stderr = numpy.NaN*numpy.ones(len(param_list)) 
     298                else: 
     299                    R.stderr = numpy.hstack((result['stderr'][fitted_index], 
     300                                             numpy.NaN*numpy.ones(len(fitness.computed_pars)))) 
    297301                R.pvec = numpy.hstack((result['value'][fitted_index], 
    298302                                      [p.value for p in fitness.computed_pars])) 
     
    306310                R.uncertainty_state = result['uncertainty'] 
    307311            all_results.append(R) 
     312        all_results[0].mesg = result['errors'] 
    308313 
    309314        if q is not None: 
     
    344349    try: 
    345350        best, fbest = fitdriver.fit() 
    346     except: 
    347         import traceback; traceback.print_exc() 
    348         raise 
     351        errors = [] 
     352    except Exception as exc: 
     353        best, fbest = None, numpy.NaN 
     354        errors = [str(exc), traceback.traceback.format_exc()] 
    349355    finally: 
    350356        mapper.stop_mapper(fitdriver.mapper) 
     
    356362 
    357363    success = best is not None 
     364    try: 
     365        stderr = fitdriver.stderr() if success else None 
     366    except Exception as exc: 
     367        errors.append(str(exc)) 
     368        errors.append(traceback.format_exc()) 
     369        stderr = None 
    358370    return { 
    359371        'value': best if success else None, 
    360         'stderr': fitdriver.stderr() if success else None, 
     372        'stderr': stderr, 
    361373        'success': success, 
    362374        'convergence': convergence, 
    363375        'uncertainty': getattr(fitdriver.fitter, 'state', None), 
     376        'errors': '\n'.join(errors), 
    364377        } 
    365378 
  • src/sas/sascalc/fit/MultiplicationModel.py

    rcb4ef58 r68669da  
    88    r""" 
    99        Use for P(Q)\*S(Q); function call must be in the order of P(Q) and then S(Q): 
    10         The model parameters are combined from both models, P(Q) and S(Q), except 1) 'effect_radius' of S(Q) 
    11         which will be calculated from P(Q) via calculate_ER(),  
    12         and 2) 'scale' in P model which is synchronized w/ volfraction in S  
     10        The model parameters are combined from both models, P(Q) and S(Q), except 1) 'radius_effective' of S(Q) 
     11        which will be calculated from P(Q) via calculate_ER(), 
     12        and 2) 'scale' in P model which is synchronized w/ volfraction in S 
    1313        then P*S is multiplied by a new parameter, 'scale_factor'. 
    1414        The polydispersion is applicable only to P(Q), not to S(Q). 
     
    3434        ## Parameter details [units, min, max] 
    3535        self.details = {} 
    36          
    37         ##models  
     36 
     37        ## Define parameters to exclude from multiplication model 
     38        self.excluded_params={'radius_effective','scale','background'} 
     39 
     40        ##models 
    3841        self.p_model = p_model 
    39         self.s_model = s_model         
     42        self.s_model = s_model 
    4043        self.magnetic_params = [] 
    4144        ## dispersion 
     
    4548        ## New parameter:Scaling factor 
    4649        self.params['scale_factor'] = 1 
    47          
     50        self.params['background']  = 0 
     51 
    4852        ## Parameter details [units, min, max] 
    4953        self._set_details() 
    5054        self.details['scale_factor'] = ['', 0.0, numpy.inf] 
    51          
     55        self.details['background'] = ['',-numpy.inf,numpy.inf] 
     56 
    5257        #list of parameter that can be fitted 
    53         self._set_fixed_params()   
     58        self._set_fixed_params() 
    5459        ## parameters with orientation 
    5560        for item in self.p_model.orientation_params: 
    5661            self.orientation_params.append(item) 
    57         for item in self.p_model.magnetic_params:   
    58             self.magnetic_params.append(item)  
     62        for item in self.p_model.magnetic_params: 
     63            self.magnetic_params.append(item) 
    5964        for item in self.s_model.orientation_params: 
    6065            if not item in self.orientation_params: 
     
    6671            multiplicity = 1 
    6772        ## functional multiplicity of the model 
    68         self.multiplicity = multiplicity     
    69            
     73        self.multiplicity = multiplicity 
     74 
    7075        # non-fittable parameters 
    71         self.non_fittable = p_model.non_fittable   
    72         self.multiplicity_info = []  
     76        self.non_fittable = p_model.non_fittable 
     77        self.multiplicity_info = [] 
    7378        self.fun_list = {} 
    7479        if self.non_fittable > 1: 
    7580            try: 
    76                 self.multiplicity_info = p_model.multiplicity_info  
     81                self.multiplicity_info = p_model.multiplicity_info 
    7782                self.fun_list = p_model.fun_list 
    7883                self.is_multiplicity_model = True 
     
    8287            self.is_multiplicity_model = False 
    8388            self.multiplicity_info = [0] 
    84              
     89 
    8590    def _clone(self, obj): 
    8691        """ 
     
    96101        #obj = copy.deepcopy(self) 
    97102        return obj 
    98      
    99      
     103 
     104 
    100105    def _set_dispersion(self): 
    101106        """ 
     
    103108        applied to s_model 
    104109        """ 
    105         ##set dispersion only from p_model  
     110        ##set dispersion only from p_model 
    106111        for name , value in self.p_model.dispersion.iteritems(): 
    107             self.dispersion[name] = value  
    108                                        
     112            self.dispersion[name] = value 
     113 
    109114    def getProfile(self): 
    110115        """ 
    111116        Get SLD profile of p_model if exists 
    112          
     117 
    113118        :return: (r, beta) where r is a list of radius of the transition points\ 
    114119                beta is a list of the corresponding SLD values 
     
    121126            x = None 
    122127            y = None 
    123              
     128 
    124129        return x, y 
    125      
     130 
    126131    def _set_params(self): 
    127132        """ 
    128133        Concatenate the parameters of the two models to create 
    129         these model parameters  
     134        these model parameters 
    130135        """ 
    131136 
    132137        for name , value in self.p_model.params.iteritems(): 
    133             if not name in self.params.keys() and name != 'scale': 
     138            if not name in self.params.keys() and name not in self.excluded_params: 
    134139                self.params[name] = value 
    135              
     140 
    136141        for name , value in self.s_model.params.iteritems(): 
    137             #Remove the effect_radius from the (P*S) model parameters. 
    138             if not name in self.params.keys() and name != 'effect_radius': 
     142            #Remove the radius_effective from the (P*S) model parameters. 
     143            if not name in self.params.keys() and name not in self.excluded_params: 
    139144                self.params[name] = value 
    140                  
     145 
    141146        # Set "scale and effec_radius to P and S model as initializing 
    142147        # since run P*S comes from P and S separately. 
     148        self._set_backgrounds() 
    143149        self._set_scale_factor() 
    144         self._set_effect_radius()        
    145              
     150        self._set_radius_effective() 
     151 
    146152    def _set_details(self): 
    147153        """ 
    148154        Concatenate details of the two models to create 
    149         this model's details  
     155        this model's details 
    150156        """ 
    151157        for name, detail in self.p_model.details.iteritems(): 
    152             if name != 'scale': 
     158            if name not in self.excluded_params: 
    153159                self.details[name] = detail 
    154              
     160 
    155161        for name , detail in self.s_model.details.iteritems(): 
    156             if not name in self.details.keys() or name != 'effect_radius': 
     162            if not name in self.details.keys() or name not in self.exluded_params: 
    157163                self.details[name] = detail 
    158      
     164 
     165    def _set_backgrounds(self): 
     166        """ 
     167        Set component backgrounds to zero 
     168        """ 
     169        if 'background' in self.p_model.params: 
     170            self.p_model.setParam('background',0) 
     171        if 'background' in self.s_model.params: 
     172            self.s_model.setParam('background',0) 
     173 
     174 
    159175    def _set_scale_factor(self): 
    160176        """ 
     
    162178        """ 
    163179        value = self.params['volfraction'] 
    164         if value != None:  
     180        if value != None: 
    165181            factor = self.p_model.calculate_VR() 
    166182            if factor == None or factor == NotImplemented or factor == 0.0: 
     
    170186            self.p_model.setParam('scale', value) 
    171187            self.s_model.setParam('volfraction', val) 
    172              
    173     def _set_effect_radius(self): 
     188 
     189    def _set_radius_effective(self): 
    174190        """ 
    175191        Set effective radius to S(Q) model 
    176192        """ 
    177         if not 'effect_radius' in self.s_model.params.keys(): 
     193        if not 'radius_effective' in self.s_model.params.keys(): 
    178194            return 
    179195        effective_radius = self.p_model.calculate_ER() 
    180196        #Reset the effective_radius of s_model just before the run 
    181197        if effective_radius != None and effective_radius != NotImplemented: 
    182             self.s_model.setParam('effect_radius', effective_radius) 
    183                  
     198            self.s_model.setParam('radius_effective', effective_radius) 
     199 
    184200    def setParam(self, name, value): 
    185         """  
     201        """ 
    186202        Set the value of a model parameter 
    187          
     203 
    188204        :param name: name of the parameter 
    189205        :param value: value of the parameter 
     
    191207        # set param to P*S model 
    192208        self._setParamHelper( name, value) 
    193          
    194         ## setParam to p model  
    195         # set 'scale' in P(Q) equal to volfraction  
     209 
     210        ## setParam to p model 
     211        # set 'scale' in P(Q) equal to volfraction 
    196212        if name == 'volfraction': 
    197213            self._set_scale_factor() 
    198         elif name in self.p_model.getParamList(): 
     214        elif name in self.p_model.getParamList() and name not in self.excluded_params: 
    199215            self.p_model.setParam( name, value) 
    200          
    201         ## setParam to s model  
    202         # This is a little bit abundant: Todo: find better way          
    203         self._set_effect_radius() 
    204         if name in self.s_model.getParamList(): 
     216 
     217        ## setParam to s model 
     218        # This is a little bit abundant: Todo: find better way 
     219        self._set_radius_effective() 
     220        if name in self.s_model.getParamList() and name not in self.excluded_params: 
    205221            if name != 'volfraction': 
    206222                self.s_model.setParam( name, value) 
    207              
     223 
    208224 
    209225        #self._setParamHelper( name, value) 
    210          
     226 
    211227    def _setParamHelper(self, name, value): 
    212228        """ 
     
    228244                    self.params[item] = value 
    229245                    return 
    230              
     246 
    231247        raise ValueError, "Model does not contain parameter %s" % name 
    232               
    233     
     248 
     249 
    234250    def _set_fixed_params(self): 
    235251        """ 
     
    240256 
    241257        self.fixed.sort() 
    242                  
    243                  
     258 
     259 
    244260    def run(self, x = 0.0): 
    245         """  
     261        """ 
    246262        Evaluate the model 
    247          
     263 
    248264        :param x: input q-value (float or [float, float] as [r, theta]) 
    249265        :return: (scattering function value) 
    250266        """ 
    251267        # set effective radius and scaling factor before run 
    252         self._set_effect_radius() 
     268        self._set_radius_effective() 
    253269        self._set_scale_factor() 
    254270        return self.params['scale_factor'] * self.p_model.run(x) * \ 
    255                             self.s_model.run(x) 
     271                            self.s_model.run(x) + self.params['background'] 
    256272 
    257273    def runXY(self, x = 0.0): 
    258         """  
     274        """ 
    259275        Evaluate the model 
    260          
     276 
    261277        :param x: input q-value (float or [float, float] as [qx, qy]) 
    262278        :return: scattering function value 
    263         """   
     279        """ 
    264280        # set effective radius and scaling factor before run 
    265         self._set_effect_radius() 
     281        self._set_radius_effective() 
    266282        self._set_scale_factor() 
    267283        out = self.params['scale_factor'] * self.p_model.runXY(x) * \ 
    268                         self.s_model.runXY(x) 
     284                        self.s_model.runXY(x) + self.params['background'] 
    269285        return out 
    270      
    271     ## Now (May27,10) directly uses the model eval function  
     286 
     287    ## Now (May27,10) directly uses the model eval function 
    272288    ## instead of the for-loop in Base Component. 
    273289    def evalDistribution(self, x = []): 
    274         """  
     290        """ 
    275291        Evaluate the model in cartesian coordinates 
    276          
     292 
    277293        :param x: input q[], or [qx[], qy[]] 
    278294        :return: scattering function P(q[]) 
    279295        """ 
    280296        # set effective radius and scaling factor before run 
    281         self._set_effect_radius() 
     297        self._set_radius_effective() 
    282298        self._set_scale_factor() 
    283299        out = self.params['scale_factor'] * self.p_model.evalDistribution(x) * \ 
    284                         self.s_model.evalDistribution(x) 
     300                        self.s_model.evalDistribution(x) + self.params['background'] 
    285301        return out 
    286302 
     
    288304        """ 
    289305        Set the dispersion object for a model parameter 
    290          
     306 
    291307        :param parameter: name of the parameter [string] 
    292308        :dispersion: dispersion object of type DispersionModel 
     
    299315            return value 
    300316        except: 
    301             raise  
     317            raise 
    302318 
    303319    def fill_description(self, p_model, s_model): 
     
    306322        """ 
    307323        description = "" 
    308         description += "Note:1) The effect_radius (effective radius) of %s \n"%\ 
     324        description += "Note:1) The radius_effective (effective radius) of %s \n"%\ 
    309325                                                                (s_model.name) 
    310326        description += "             is automatically calculated " 
     
    318334        description += "        for details of individual models." 
    319335        self.description += description 
    320      
Note: See TracChangeset for help on using the changeset viewer.