Changeset 98e3f24 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Jun 23, 2017 4:31:13 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
65f3930
Parents:
ba8d326
Message:

code cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/realspace/VolumeCanvas.py

    r235f514 r98e3f24  
    44    Simulation canvas for real-space simulation of SAS scattering intensity. 
    55    The user can create an arrangement of basic shapes and estimate I(q) and 
    6     I(q_x, q_y). Error estimates on the simulation are also available.  
    7      
     6    I(q_x, q_y). Error estimates on the simulation are also available. 
     7 
    88    Example: 
    9      
     9 
    1010    import sas.sascalc.realspace.VolumeCanvas as VolumeCanvas 
    1111    canvas = VolumeCanvas.VolumeCanvas() 
    1212    canvas.setParam('lores_density', 0.01) 
    13      
     13 
    1414    sphere = SphereDescriptor() 
    1515    handle = canvas.addObject(sphere) 
     
    1717    output, error = canvas.getIqError(q=0.1) 
    1818    output, error = canvas.getIq2DError(0.1, 0.1) 
    19      
     19 
    2020    or alternatively: 
    2121    iq = canvas.run(0.1) 
    2222    i2_2D = canvas.run([0.1, 1.57]) 
    23      
     23 
    2424""" 
    2525 
    26 from sas.models.BaseComponent import BaseComponent 
     26from sas.sascalc.calculator.BaseComponent import BaseComponent 
    2727from sas.sascalc.simulation.pointsmodelpy import pointsmodelpy 
    2828from sas.sascalc.simulation.geoshapespy import geoshapespy 
     
    3131import os.path, math 
    3232 
    33 class ShapeDescriptor: 
     33class ShapeDescriptor(object): 
    3434    """ 
    3535        Class to hold the information about a shape 
    3636        The descriptor holds a dictionary of parameters. 
    37          
     37 
    3838        Note: if shape parameters are accessed directly 
    3939        from outside VolumeCanvas. The getPr method 
    4040        should be called before evaluating I(q). 
    41                  
     41 
    4242    """ 
    4343    def __init__(self): 
     
    5555        self.params['is_lores'] = True 
    5656        self.params['order'] = 0 
    57              
     57 
    5858    def create(self): 
    5959        """ 
     
    6565        z0 = self.params["center"][2] 
    6666        geoshapespy.set_center(self.shapeObject, x0, y0, z0) 
    67          
     67 
    6868        # Set orientation 
    6969        x0 = self.params["orientation"][0] 
     
    7171        z0 = self.params["orientation"][2] 
    7272        geoshapespy.set_orientation(self.shapeObject, x0, y0, z0) 
    73                 
     73 
    7474class SphereDescriptor(ShapeDescriptor): 
    7575    """ 
    7676        Descriptor for a sphere 
    77          
     77 
    7878        The parameters are: 
    7979            - radius [Angstroem] [default = 20 A] 
    8080            - Contrast [A-2] [default = 1 A-2] 
    81              
     81 
    8282    """ 
    8383    def __init__(self): 
    8484        """ 
    8585            Initialization 
    86         """  
     86        """ 
    8787        ShapeDescriptor.__init__(self) 
    8888        # Default parameters 
    89         self.params["type"]   = "sphere" 
     89        self.params["type"] = "sphere" 
    9090        # Radius of the sphere 
    9191        self.params["radius"] = 20.0 
     
    100100        self.shapeObject = geoshapespy.new_sphere(\ 
    101101            self.params["radius"]) 
    102          
    103         ShapeDescriptor.create(self)    
     102 
     103        ShapeDescriptor.create(self) 
    104104        return self.shapeObject 
    105      
     105 
    106106class CylinderDescriptor(ShapeDescriptor): 
    107107    """ 
    108108        Descriptor for a cylinder 
    109109        Orientation: Default cylinder is along Y 
    110          
     110 
    111111        Parameters: 
    112112            - Length [default = 40 A] 
     
    117117        """ 
    118118            Initialization 
    119         """  
     119        """ 
    120120        ShapeDescriptor.__init__(self) 
    121121        # Default parameters 
    122         self.params["type"]   = "cylinder" 
     122        self.params["type"] = "cylinder" 
    123123        # Length of the cylinder 
    124124        self.params["length"] = 40.0 
     
    127127        # Constrast parameter 
    128128        self.params["contrast"] = 1.0 
    129          
     129 
    130130    def create(self): 
    131131        """ 
     
    138138        ShapeDescriptor.create(self) 
    139139        return self.shapeObject 
    140          
     140 
    141141 
    142142class EllipsoidDescriptor(ShapeDescriptor): 
    143143    """ 
    144144        Descriptor for an ellipsoid 
    145          
     145 
    146146        Parameters: 
    147147            - Radius_x along the x-axis [default = 30 A] 
     
    153153        """ 
    154154            Initialization 
    155         """  
     155        """ 
    156156        ShapeDescriptor.__init__(self) 
    157157        # Default parameters 
    158         self.params["type"]   = "ellipsoid" 
     158        self.params["type"] = "ellipsoid" 
    159159        self.params["radius_x"] = 30.0 
    160160        self.params["radius_y"] = 20.0 
    161161        self.params["radius_z"] = 10.0 
    162162        self.params["contrast"] = 1.0 
    163          
     163 
    164164    def create(self): 
    165165        """ 
     
    168168        """ 
    169169        self.shapeObject = geoshapespy.new_ellipsoid(\ 
    170             self.params["radius_x"], self.params["radius_y"],  
     170            self.params["radius_x"], self.params["radius_y"], 
    171171            self.params["radius_z"]) 
    172          
    173         ShapeDescriptor.create(self)    
     172 
     173        ShapeDescriptor.create(self) 
    174174        return self.shapeObject 
    175          
     175 
    176176class HelixDescriptor(ShapeDescriptor): 
    177177    """ 
    178178        Descriptor for an helix 
    179          
     179 
    180180        Parameters: 
    181181            -radius_helix: the radius of the helix [default = 10 A] 
     
    188188        """ 
    189189            Initialization 
    190         """  
     190        """ 
    191191        ShapeDescriptor.__init__(self) 
    192192        # Default parameters 
    193         self.params["type"]   = "singlehelix" 
     193        self.params["type"] = "singlehelix" 
    194194        self.params["radius_helix"] = 10.0 
    195195        self.params["radius_tube"] = 3.0 
     
    204204        """ 
    205205        self.shapeObject = geoshapespy.new_singlehelix(\ 
    206             self.params["radius_helix"], self.params["radius_tube"],  
     206            self.params["radius_helix"], self.params["radius_tube"], 
    207207            self.params["pitch"], self.params["turns"]) 
    208          
    209         ShapeDescriptor.create(self)    
     208 
     209        ShapeDescriptor.create(self) 
    210210        return self.shapeObject 
    211          
     211 
    212212class PDBDescriptor(ShapeDescriptor): 
    213213    """ 
    214214        Descriptor for a PDB set of points 
    215          
     215 
    216216        Parameter: 
    217217            - file = name of the PDB file 
     
    221221            Initialization 
    222222            @param filename: name of the PDB file to load 
    223         """  
     223        """ 
    224224        ShapeDescriptor.__init__(self) 
    225225        # Default parameters 
    226         self.params["type"]   = "pdb" 
     226        self.params["type"] = "pdb" 
    227227        self.params["file"] = filename 
    228228        self.params['is_lores'] = False 
     
    234234        """ 
    235235        self.shapeObject = pointsmodelpy.new_pdbmodel() 
    236         pointsmodelpy.pdbmodel_add(self.shapeObject, self.params['file'])        
    237          
    238         #ShapeDescriptor.create(self)    
     236        pointsmodelpy.pdbmodel_add(self.shapeObject, self.params['file']) 
     237 
     238        #ShapeDescriptor.create(self) 
    239239        return self.shapeObject 
    240          
     240 
    241241# Define a dictionary for the shape until we find 
    242242# a better way to create them 
     
    245245              'ellipsoid':EllipsoidDescriptor, 
    246246              'singlehelix':HelixDescriptor} 
    247          
     247 
    248248class VolumeCanvas(BaseComponent): 
    249249    """ 
    250         Class representing an empty space volume to add  
     250        Class representing an empty space volume to add 
    251251        geometrical object to. 
    252          
     252 
    253253        For 1D I(q) simulation, getPr() is called internally for the 
    254254        first call to getIq(). 
    255          
    256     """ 
    257      
     255 
     256    """ 
     257 
    258258    def __init__(self): 
    259259        """ 
     
    261261        """ 
    262262        BaseComponent.__init__(self) 
    263          
     263 
    264264        ## Maximum value of q reachable 
    265265        self.params['q_max'] = 0.1 
     
    267267        self.params['scale'] = 1.0 
    268268        self.params['background'] = 0.0 
    269          
     269 
    270270        self.lores_model = pointsmodelpy.new_loresmodel(self.params['lores_density']) 
    271271        self.complex_model = pointsmodelpy.new_complexmodel() 
    272272        self.shapes = {} 
    273         self.shapecount = 0         
     273        self.shapecount = 0 
    274274        self.points = None 
    275275        self.npts = 0 
    276         self.hasPr = False         
    277          
     276        self.hasPr = False 
     277 
    278278    def _model_changed(self): 
    279279        """ 
    280             Reset internal data members to reflect the fact that the  
     280            Reset internal data members to reflect the fact that the 
    281281            real-space model has changed 
    282282        """ 
    283         self.hasPr  = False 
     283        self.hasPr = False 
    284284        self.points = None 
    285          
    286     def addObject(self, shapeDesc, id = None): 
     285 
     286    def addObject(self, shapeDesc, id=None): 
    287287        """ 
    288288            Adds a real-space object to the canvas. 
    289          
     289 
    290290            @param shapeDesc: object to add to the canvas [ShapeDescriptor] 
    291291            @param id: string handle for the object [string] [optional] 
     
    295295        if id is None: 
    296296            id = shapeDesc.params["type"]+str(self.shapecount) 
    297           
     297 
    298298        # Self the order number 
    299299        shapeDesc.params['order'] = self.shapecount 
     
    307307 
    308308        return id 
    309              
    310      
    311     def add(self, shape, id = None): 
     309 
     310 
     311    def add(self, shape, id=None): 
    312312        """ 
    313313            The intend of this method is to eventually be able to use it 
     
    315315            analytical solutions. For instance, if one adds a cylinder and 
    316316            it is the only shape on the canvas, the analytical solution 
    317             could be called. If multiple shapes are involved, then  
     317            could be called. If multiple shapes are involved, then 
    318318            simulation has to be performed. 
    319              
     319 
    320320            This function is deprecated, use addObject(). 
    321          
     321 
    322322            @param shape: name of the object to add to the canvas [string] 
    323323            @param id: string handle for the object [string] [optional] 
     
    327327        if id is None: 
    328328            id = "shape"+str(self.shapecount) 
    329   
     329 
    330330        # shapeDesc = ShapeDescriptor(shape.lower()) 
    331331        if shape.lower() in shape_dict: 
     
    336336        else: 
    337337            raise ValueError("VolumeCanvas.add: Unknown shape %s" % shape) 
    338          
     338 
    339339        return self.addObject(shapeDesc, id) 
    340340 
     
    354354 
    355355 
    356     def setParam(self, name, value):     
    357         """ 
    358             Function to set the value of a parameter.  
     356    def setParam(self, name, value): 
     357        """ 
     358            Function to set the value of a parameter. 
    359359            Both VolumeCanvas parameters and shape parameters 
    360             are accessible.  
    361              
     360            are accessible. 
     361 
    362362            Note: if shape parameters are accessed directly 
    363363            from outside VolumeCanvas. The getPr method 
    364364            should be called before evaluating I(q). 
    365          
     365 
    366366            TODO: implemented a check method to protect 
    367367            against that. 
    368          
     368 
    369369            @param name: name of the parameter to change 
    370370            @param value: value to give the parameter 
    371371        """ 
    372          
     372 
    373373        # Lowercase for case insensitivity 
    374374        name = name.lower() 
    375          
     375 
    376376        # Look for shape access 
    377377        toks = name.split('.') 
    378          
     378 
    379379        # If a shape identifier was given, look the shape up 
    380380        # in the dictionary 
     
    390390            else: 
    391391                raise ValueError("Could not find shape %s" % toks[0]) 
    392          
     392 
    393393        else: 
    394             # If we are not accessing the parameters of a  
     394            # If we are not accessing the parameters of a 
    395395            # shape, see if the parameter is part of this object 
    396396            BaseComponent.setParam(self, name, value) 
    397397            self._model_changed() 
    398398 
    399     def getParam(self, name):     
     399    def getParam(self, name): 
    400400        """ 
    401401            @param name: name of the parameter to change 
    402402        """ 
    403403        #TODO: clean this up 
    404          
     404 
    405405        # Lowercase for case insensitivity 
    406406        name = name.lower() 
    407          
     407 
    408408        # Look for sub-model access 
    409409        toks = name.split('.') 
     
    435435        else: 
    436436            raise ValueError("VolumeCanvas.getParam: Could not find %s" % name) 
    437              
     437 
    438438    def getParamList(self, shapeid=None): 
    439439        """ 
    440                return a full list of all available parameters from  
     440               return a full list of all available parameters from 
    441441           self.params.keys(). If a key in self.params is a instance 
    442            of ShapeDescriptor, extend the return list to:  
     442           of ShapeDescriptor, extend the return list to: 
    443443           [param1,param2,shapeid.param1,shapeid.param2.......] 
    444444 
     
    456456                header = key2 + '.' 
    457457                for key3 in value2.params: 
    458                     fullname = header + key3                  
     458                    fullname = header + key3 
    459459                    param_list.append(fullname) 
    460       
     460 
    461461        else: 
    462462            if not shapeid in self.shapes: 
     
    470470    def getShapeList(self): 
    471471        """ 
    472             Return a list of the shapes  
     472            Return a list of the shapes 
    473473        """ 
    474474        return self.shapes.keys() 
     
    481481        # Create the object model 
    482482        shapeDesc.create() 
    483                      
     483 
    484484        if shapeDesc.params['is_lores']: 
    485485            # Add the shape to the lores_model 
    486             pointsmodelpy.lores_add(self.lores_model,  
    487                 shapeDesc.shapeObject, shapeDesc.params['contrast'])   
     486            pointsmodelpy.lores_add(self.lores_model, 
     487                                    shapeDesc.shapeObject, 
     488                                    shapeDesc.params['contrast']) 
    488489 
    489490    def _createVolumeFromList(self): 
     
    492493            Whenever we change a parameter of a shape, we have to re-create 
    493494            the whole thing. 
    494              
     495 
    495496            Items with higher 'order' number take precedence for regions 
    496             of space that are shared with other objects. Points in the  
     497            of space that are shared with other objects. Points in the 
    497498            overlapping region belonging to objects with lower 'order' 
    498499            will be ignored. 
    499              
     500 
    500501            Items are added in decreasing 'order' number. 
    501502            The item with the highest 'order' will be added *first*. 
    502503            [That conventions is prescribed by the realSpaceModeling module] 
    503504        """ 
    504          
     505 
    505506        # Create empty model 
    506507        self.lores_model = \ 
     
    509510        # Create empty complex model 
    510511        self.complex_model = pointsmodelpy.new_complexmodel() 
    511         
     512 
    512513        # Order the object first 
    513514        obj_list = [] 
    514      
     515 
    515516        for shape in self.shapes: 
    516517            order = self.shapes[shape].params['order'] 
    517518            # find where to place it in the list 
    518519            stored = False 
    519              
     520 
    520521            for i in range(len(obj_list)): 
    521522                if obj_list[i][0] > order: 
     
    523524                    stored = True 
    524525                    break 
    525              
     526 
    526527            if not stored: 
    527528                obj_list.append([order, shape]) 
    528                  
     529 
    529530        # Add each shape 
    530531        len_list = len(obj_list) 
     
    533534            self._addSingleShape(shapedesc) 
    534535 
    535         return 0      
    536      
     536        return 0 
     537 
    537538    def getPr(self): 
    538539        """ 
     
    540541            This method should always be called after the shapes 
    541542            on the VolumeCanvas have changed. 
    542              
    543             @return: calculation output flag  
     543 
     544            @return: calculation output flag 
    544545        """ 
    545546        # To find a complete example of the correct call order: 
    546547        # In LORES2, in actionclass.py, method CalculateAction._get_iq() 
    547          
     548 
    548549        # If there are not shapes, do nothing 
    549550        if len(self.shapes) == 0: 
    550551            self._model_changed() 
    551552            return 0 
    552          
     553 
    553554        # generate space filling points from shape list 
    554555        self._createVolumeFromList() 
     
    556557        self.points = pointsmodelpy.new_point3dvec() 
    557558 
    558         pointsmodelpy.complexmodel_add(self.complex_model,  
    559                                         self.lores_model, "LORES") 
     559        pointsmodelpy.complexmodel_add(self.complex_model, 
     560                                       self.lores_model, "LORES") 
    560561        for shape in self.shapes: 
    561             if self.shapes[shape].params['is_lores'] == False: 
    562                 pointsmodelpy.complexmodel_add(self.complex_model,  
     562            if not self.shapes[shape].params['is_lores']: 
     563                pointsmodelpy.complexmodel_add(self.complex_model, 
    563564                    self.shapes[shape].shapeObject, "PDB") 
    564          
     565 
    565566        #pointsmodelpy.get_lorespoints(self.lores_model, self.points) 
    566567        self.npts = pointsmodelpy.get_complexpoints(self.complex_model, self.points) 
    567          
     568 
    568569        # expecting the rmax is a positive float or 0. The maximum distance. 
    569         #rmax = pointsmodelpy.get_lores_pr(self.lores_model, self.points)    
    570           
    571         rmax = pointsmodelpy.get_complex_pr(self.complex_model, self.points)  
    572         self.hasPr = True    
     570        #rmax = pointsmodelpy.get_lores_pr(self.lores_model, self.points) 
     571 
     572        rmax = pointsmodelpy.get_complex_pr(self.complex_model, self.points) 
     573        self.hasPr = True 
    573574 
    574575        return rmax 
    575          
    576     def run(self, q = 0): 
     576 
     577    def run(self, q=0): 
    577578        """ 
    578579            Returns the value of I(q) for a given q-value 
     
    595596        else: 
    596597            raise ValueError("run(q): bad type for q") 
    597      
    598     def runXY(self, q = 0): 
     598 
     599    def runXY(self, q=0): 
    599600        """ 
    600601            Standard run command for the canvas. 
    601             Redirects to the correct method  
     602            Redirects to the correct method 
    602603            according to the input type. 
    603604            @param q: q-value [float] or [list] [A-1] 
     
    615616        else: 
    616617            raise ValueError("runXY(q): bad type for q") 
    617      
     618 
    618619    def _create_modelObject(self): 
    619620        """ 
    620621            Create the simulation model obejct from the list 
    621622            of shapes. 
    622              
     623 
    623624            This method needs to be called each time a parameter 
    624625            changes because of the way the underlying library 
    625             was (badly) written. It is impossible to change a  
    626             parameter, or remove a shape without having to  
     626            was (badly) written. It is impossible to change a 
     627            parameter, or remove a shape without having to 
    627628            refill the space points. 
    628              
     629 
    629630            TODO: improve that. 
    630631        """ 
    631632        # To find a complete example of the correct call order: 
    632633        # In LORES2, in actionclass.py, method CalculateAction._get_iq() 
    633          
     634 
    634635        # If there are not shapes, do nothing 
    635636        if len(self.shapes) == 0: 
    636637            self._model_changed() 
    637638            return 0 
    638          
     639 
    639640        # generate space filling points from shape list 
    640641        self._createVolumeFromList() 
     
    642643        self.points = pointsmodelpy.new_point3dvec() 
    643644 
    644         pointsmodelpy.complexmodel_add(self.complex_model,  
    645                                         self.lores_model, "LORES") 
     645        pointsmodelpy.complexmodel_add(self.complex_model, 
     646                                       self.lores_model, "LORES") 
    646647        for shape in self.shapes: 
    647             if self.shapes[shape].params['is_lores'] == False: 
    648                 pointsmodelpy.complexmodel_add(self.complex_model,  
     648            if not self.shapes[shape].params['is_lores']: 
     649                pointsmodelpy.complexmodel_add(self.complex_model, 
    649650                    self.shapes[shape].shapeObject, "PDB") 
    650          
     651 
    651652        #pointsmodelpy.get_lorespoints(self.lores_model, self.points) 
    652653        self.npts = pointsmodelpy.get_complexpoints(self.complex_model, self.points) 
    653          
    654          
     654 
     655 
    655656    def getIq2D(self, qx, qy): 
    656657        """ 
     
    660661            @return: I(q) [cm-1] 
    661662        """ 
    662          
     663 
    663664        # If this is the first simulation call, we need to generate the 
    664665        # space points 
    665666        if self.points is None: 
    666667            self._create_modelObject() 
    667              
     668 
    668669            # Protect against empty model 
    669670            if self.points is None: 
    670671                return 0 
    671                 
    672         # Evalute I(q)  
    673         norm =  1.0e8/self.params['lores_density']*self.params['scale'] 
     672 
     673        # Evalute I(q) 
     674        norm = 1.0e8/self.params['lores_density']*self.params['scale'] 
    674675        return norm*pointsmodelpy.get_complex_iq_2D(self.complex_model, self.points, qx, qy)\ 
    675676            + self.params['background'] 
    676                  
     677 
    677678    def write_pr(self, filename): 
    678679        """ 
    679680            Write P(r) to an output file 
    680681            @param filename: file name for P(r) output 
    681         """    
    682         if self.hasPr == False: 
     682        """ 
     683        if not self.hasPr: 
    683684            self.getPr() 
    684       
     685 
    685686        pointsmodelpy.outputPR(self.complex_model, filename) 
    686       
     687 
    687688    def getPrData(self): 
    688689        """ 
    689690            Write P(r) to an output file 
    690691            @param filename: file name for P(r) output 
    691         """    
    692         if self.hasPr == False: 
     692        """ 
     693        if not self.hasPr: 
    693694            self.getPr() 
    694       
     695 
    695696        return pointsmodelpy.get_pr(self.complex_model) 
    696       
     697 
    697698    def getIq(self, q): 
    698699        """ 
    699700            Returns the value of I(q) for a given q-value 
    700              
     701 
    701702            This method should remain internal to the class 
    702703            and the run() method should be used instead. 
    703              
     704 
    704705            @param q: q-value [float] 
    705706            @return: I(q) [float] 
    706707        """ 
    707          
    708         if self.hasPr == False: 
     708 
     709        if not self.hasPr: 
    709710            self.getPr() 
    710711 
    711         # By dividing by the density instead of the actuall V/N,  
    712         # we have an uncertainty of +-1 on N because the number  
     712        # By dividing by the density instead of the actuall V/N, 
     713        # we have an uncertainty of +-1 on N because the number 
    713714        # of points chosen for the simulation is int(density*volume). 
    714715        # Propagation of error gives: 
     
    716717        # where N is stored in self.npts 
    717718 
    718         norm =  1.0e8/self.params['lores_density']*self.params['scale'] 
     719        norm = 1.0e8/self.params['lores_density']*self.params['scale'] 
    719720        #return norm*pointsmodelpy.get_lores_i(self.lores_model, q) 
    720721        return norm*pointsmodelpy.get_complex_i(self.complex_model, q)\ 
    721722            + self.params['background'] 
    722      
     723 
    723724    def getError(self, q): 
    724725        """ 
     
    727728            @return: I(q) [float] 
    728729        """ 
    729          
    730         if self.hasPr == False: 
     730 
     731        if not self.hasPr: 
    731732            self.getPr() 
    732733 
    733         # By dividing by the density instead of the actual V/N,  
    734         # we have an uncertainty of +-1 on N because the number  
     734        # By dividing by the density instead of the actual V/N, 
     735        # we have an uncertainty of +-1 on N because the number 
    735736        # of points chosen for the simulation is int(density*volume). 
    736737        # Propagation of error gives: 
     
    738739        # where N is stored in self.npts 
    739740 
    740         norm =  1.0e8/self.params['lores_density']*self.params['scale'] 
     741        norm = 1.0e8/self.params['lores_density']*self.params['scale'] 
    741742        #return norm*pointsmodelpy.get_lores_i(self.lores_model, q) 
    742743        return norm*pointsmodelpy.get_complex_i_error(self.complex_model, q)\ 
    743744            + self.params['background'] 
    744      
     745 
    745746    def getIqError(self, q): 
    746747        """ 
    747748            Return the simulated value along with its estimated 
    748749            error for a given q-value 
    749              
     750 
    750751            Propagation of errors is used to evaluate the 
    751752            uncertainty. 
    752              
     753 
    753754            @param q: q-value [float] 
    754755            @return: mean, error [float, float] 
     
    765766            Return the simulated value along with its estimated 
    766767            error for a given q-value 
    767              
     768 
    768769            Propagation of errors is used to evaluate the 
    769770            uncertainty. 
    770              
     771 
    771772            @param qx: qx-value [float] 
    772773            @param qy: qy-value [float] 
     
    774775        """ 
    775776        self._create_modelObject() 
    776                  
    777         norm =  1.0e8/self.params['lores_density']*self.params['scale'] 
     777 
     778        norm = 1.0e8/self.params['lores_density']*self.params['scale'] 
    778779        val = norm*pointsmodelpy.get_complex_iq_2D(self.complex_model, self.points, qx, qy)\ 
    779780            + self.params['background'] 
    780          
     781 
    781782        # Simulation error (statistical) 
    782         norm =  1.0e8/self.params['lores_density']*self.params['scale'] \ 
    783                 * math.pow(self.npts/self.params['lores_density'], 1.0/3.0)/self.npts 
     783        norm = 1.0e8/self.params['lores_density']*self.params['scale'] \ 
     784               * math.pow(self.npts/self.params['lores_density'], 1.0/3.0)/self.npts 
    784785        err = norm*pointsmodelpy.get_complex_iq_2D_err(self.complex_model, self.points, qx, qy) 
    785786        # Error on V/N 
    786787        simerr = 2*val/self.npts 
    787          
     788 
    788789        # The error used for the position is over-simplified. 
    789790        # The actual error was empirically found to be about 
    790791        # an order of magnitude larger. 
    791792        return val, 10.0*err+simerr 
    792          
Note: See TracChangeset for help on using the changeset viewer.