Changeset c080c943 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Mar 31, 2019 1:29:02 PM (6 years ago)
Author:
GitHub <noreply@…>
Parents:
fa307dd (diff), e66f9c1 (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.
git-author:
Paul Kienzle <pkienzle@…> (03/31/19 13:29:02)
git-committer:
GitHub <noreply@…> (03/31/19 13:29:02)
Message:

Merge e66f9c1f0e64eb3f2bd4e989067361257af0d83a into fa307ddb8d25a41b44c02bd525f9727d5b4b7e5b

Location:
src/sas/sascalc
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r8c9e65c rf0b9bce  
    493493                self.current_datainfo.errors.add(error) 
    494494            self.data_cleanup() 
    495             self.sort_one_d_data() 
    496             self.sort_two_d_data() 
     495            self.sort_data() 
    497496            self.reset_data_list() 
    498497            return self.output[0], None 
  • src/sas/sascalc/fit/BumpsFitting.py

    r1386b2f r0aeba4e  
    22BumpsFitting module runs the bumps optimizer. 
    33""" 
     4from __future__ import print_function 
     5 
    46import os 
    57from datetime import timedelta, datetime 
     
    911 
    1012from bumps import fitters 
     13 
    1114try: 
    1215    from bumps.options import FIT_CONFIG 
     16    # Preserve bumps default fitter in case someone wants it later 
     17    BUMPS_DEFAULT_FITTER = FIT_CONFIG.selected_id 
    1318    # Default bumps to use the Levenberg-Marquardt optimizer 
    1419    FIT_CONFIG.selected_id = fitters.LevenbergMarquardtFit.id 
     
    1722except ImportError: 
    1823    # CRUFT: Bumps changed its handling of fit options around 0.7.5.6 
     24    # Preserve bumps default fitter in case someone wants it later 
     25    BUMPS_DEFAULT_FITTER = fitters.FIT_DEFAULT 
    1926    # Default bumps to use the Levenberg-Marquardt optimizer 
    2027    fitters.FIT_DEFAULT = 'lm' 
     
    126133        if initial_values is not None: 
    127134            self._reset_pars(fitted, initial_values) 
     135        #print("constraints", constraints) 
    128136        self.constraints = dict(constraints) 
    129137        self.set_fitted(fitted) 
     
    222230    def _setup(self): 
    223231        exprs = {} 
    224         for M in self.models: 
    225             exprs.update((".".join((M.name, k)), v) for k, v in M.constraints.items()) 
     232        for model in self.models: 
     233            exprs.update((".".join((model.name, k)), v) 
     234                         for k, v in model.constraints.items()) 
    226235        if exprs: 
    227             symtab = dict((".".join((M.name, k)), p) 
    228                           for M in self.models 
    229                           for k, p in M.parameters().items()) 
     236            symtab = dict((".".join((model.name, k)), p) 
     237                          for model in self.models 
     238                          for k, p in model.parameters().items()) 
    230239            self.update = compile_constraints(symtab, exprs) 
    231240        else: 
  • src/sas/sascalc/fit/pagestate.py

    re090ba90 rcb44d66  
    11""" 
    22Class that holds a fit page state 
     3 
     4Pagestate fields reflect the names of the gui controls from the sasview 3.x 
     5fit page, so they are somewhat difficult to interpret. 
     6 
     7Pagestate attributes are as follows: 
     8 
     9    # =>name: desc       indicates the attribute is derived 
     10    # name(xml): desc    indicates the attribute name differs from the xml tag 
     11 
     12    # SasView version which saved the file 
     13    version: (4, 1, 2) from <fitting_plug_in version="major.minor.point"> 
     14 
     15    # Session information 
     16    group_id: unique id for fit page in running system (int) 
     17    => data_group_id: unique id for data item in running system (None) 
     18 
     19    # Data file 
     20    data: contents of <SASdata> (Data1D or Data2D) 
     21    data_name: filename + [num] (latex_smeared.xml [1]) 
     22    data_id: filename + [num] + timestamp (latex_smeared.xml [1]1523303027.73) 
     23    file: filename + [date time] (latex_smeared.xml [Apr 09 15:45]) 
     24    name: ?? (None) 
     25    npts: number of points (float) 
     26    enable2D: True if data is 2D (or if model is 2D and no data) 
     27    is_data: True (pagestate will not save if there is no data attached) 
     28 
     29    # Data weighting 
     30    dI_didata: True if dy = data.dy 
     31    dI_idata: True if dy = data.y 
     32    dI_noweight: True if dy = 1 
     33    dI_sqrdata: True if dy = sqrt(data.y) 
     34 
     35    # Data selection 
     36    qmax: maximum q (float) 
     37    qmin: minimum q (float) 
     38    => qmax_x: ?? (None) 
     39    => qmin_x: ?? (None) 
     40 
     41    # Resolution smearing 
     42    enable_smearer: True if use data.dx 
     43    disable_smearer: True if no smearing 
     44    pinhole_smearer: True if custom pinhole smear 
     45    slit_smearer: True if custom slit smear 
     46    dq_l: 2D resolution <dQp> 
     47    dq_r: 2D resolution <dQs> 
     48    dx_old: True for 3.x version of custom pinhole, which used dx_min rather 
     49        than dx_percent, with dx_percent interpreted as 100 * dx_percent/q[0] 
     50    dx_percent: custom pinhole resolution percentage 
     51    dxl: slit height for custom slit resolution 
     52    dxw: slit width for custom slit resolution 
     53    smearer: repr() for active smearer (None on load) 
     54    smear_type: None (None on load) 
     55 
     56    # Model selection 
     57    categorycombobox: model category 
     58    formfactorcombobox: model name (could be "[plug-in] name") 
     59    structurecombobox: structure factor model name (string or None or "None") 
     60    multi_factor: multiplicity (integer or None) 
     61    magnetic_on: True if model is magnetic (only for 2D data for now) 
     62    => model: active model object (None on load) 
     63 
     64    # Model parameters 
     65    # Parameter is a tuple with the following structure.  The parentheses 
     66    # indicate xml attribute for the <parameter .../> tag: 
     67    #    fitted(selected_to_fit): True if parameter is fitted 
     68    #    name(name): display name for the parameter (string) 
     69    #    value(value): displayed parameter value (string) 
     70    #    => plusminus: '+/-' (constant string) 
     71    #    => uncertainty: tuple 
     72    #        (uncertainty_displayed): True if there is an uncertainty 
     73    #        (uncertainty_value): displayed uncertainty (string) 
     74    #    => lower: tuple 
     75    #        (minimum_displayed): True if there is a lower bound 
     76    #        (minimum_value): displayed lower bound (string) 
     77    #    => upper: tuple 
     78    #        (maximum_displayed): True if there is a upper bound 
     79    #        (maximum_value): displayed upper bound (string) 
     80    #    units(unit): displayed units 
     81    parameters: list of normal parameters 
     82    fixed_param: list of non-fitting parameters (nsigma, npts in dispersity) 
     83    fittable_param: list of fittable dispersity parameters (distribution width) 
     84    str_parameters: list of selection parameters (e.g, shell forms in spherical_sld) 
     85    orientation_params(orientation_parameters): list of orientation and 
     86        magnetic parameters (already included in parameters, so safe to ignore) 
     87    orientation_params_disp(dispersity_parameters): list of orientation 
     88        disperisty parameters (already included in fixed_param and 
     89        fittable_param so safe to ignore) 
     90 
     91    # Dispersity controls 
     92    enable_disp: True if dispersity parameters 
     93    disable_disp: True if no dispersity parameters 
     94    disp_obj_dict(disp_obj): {'parameter.width': 'dispersity distribution'} 
     95    values: {'parameter.width': [array distribution parameter values] } 
     96    weights: {'parameter.width': [array distribution parameter weights] } 
     97    => disp_box 0 
     98    => disp_cb_dict {} 
     99    => disp_list [] 
     100 
     101    # Simultaneous fitting 
     102 
     103    => images: None (initialized but unused?) 
     104    => reset: False (initialized but unused?) 
     105    => event_owner None 
     106    => m_name None 
     107    => manager None 
     108    => page_name 
     109    => param_toFit: [] 
     110    => process: list of process done on object [] (maybe managed by guiframe?) 
     111    => saved_states {} 
     112    => cb1: False (simfit cb1 is now stored in select_all) 
     113 
     114    tcChi 1.3463 
     115    theory_data None 
     116    timestamp 1523303103.74 
     117 
     118Constraint attributes are as follows: 
     119 
     120    constraint_dict {} 
     121    constraints_list 
     122        {'model_cbox': 'M2', 'param_cbox': 'scale', 'egal_txt': ' = ', 'constraint': 'M1.scale'} 
     123        {'model_cbox': 'M2', 'param_cbox': 'radius', 'egal_txt': ' = ', 'constraint': 'M1.radius'} 
     124        {'model_cbox': 'M2', 'param_cbox': 'radius.width', 'egal_txt': ' = ', 'constraint': 'M1.radius.width'} 
     125    fit_page_no None 
     126    model_list 
     127        {'fit_number': '393', 'checked': 'True', 'fit_page_source': 'M2', 'name': 'latex_smeared.xml   [1]1523535051.03', 'model_name': 'sphere'} 
     128        {'fit_number': '335', 'checked': 'True', 'fit_page_source': 'M1', 'name': 'latex_smeared.xml  1523535050.03', 'model_name': 'sphere'} 
     129    model_to_fit 
     130    no_constraint 0 
     131    select_all True 
     132 
     133 
    3134""" 
    4135# TODO: Refactor code so we don't need to use getattr/setattr 
     
    162293        self.theory_data = None 
    163294        # Is 2D 
    164         self.is_2D = False 
    165295        self.images = None 
    166296 
     
    557687        temp_parameters = [] 
    558688        temp_fittable_param = [] 
    559         if self.data.__class__.__name__ == "Data2D": 
    560             self.is_2D = True 
    561         else: 
    562             self.is_2D = False 
    563689        if self.data is not None: 
    564             if not self.is_2D: 
     690            is_2D = (self.data.__class__.__name__ == "Data2D") 
     691            if not is_2D: 
    565692                for item in self.parameters: 
    566693                    if item not in self.orientation_params: 
  • src/sas/sascalc/fit/expression.py

    re090ba90 r3c680c1  
    188188 
    189189    # Initialize dictionary with available functions 
    190     globals = {} 
    191     globals.update(math.__dict__) 
    192     globals.update(dict(arcsin=math.asin,arccos=math.acos, 
    193                         arctan=math.atan,arctan2=math.atan2)) 
    194     globals.update(context) 
    195     globals.update(parameters) 
    196     globals['id'] = id 
    197     locals = {} 
     190    global_context = {} 
     191    global_context.update(math.__dict__) 
     192    global_context.update(dict(arcsin=math.asin,arccos=math.acos, 
     193                               arctan=math.atan,arctan2=math.atan2)) 
     194    global_context.update(context) 
     195    global_context.update(parameters) 
     196    global_context['id'] = id 
     197    local_context = {} 
    198198 
    199199    # Define the constraints function 
     
    210210 
    211211    #print("Function: "+functiondef) 
    212     exec(functiondef, globals, locals) 
    213     retfn = locals['eval_expressions'] 
     212    # CRUFT: python < 3.0;  doc builder isn't allowing the following exec 
     213    # https://stackoverflow.com/questions/4484872/why-doesnt-exec-work-in-a-function-with-a-subfunction/41368813#comment73790496_41368813 
     214    #exec(functiondef, global_context, local_context) 
     215    eval(compile(functiondef, '<string>', 'exec'), global_context, local_context) 
     216    retfn = local_context['eval_expressions'] 
    214217 
    215218    # Remove garbage added to globals by exec 
    216     globals.pop('__doc__',None) 
    217     globals.pop('__name__',None) 
    218     globals.pop('__file__',None) 
    219     globals.pop('__builtins__') 
     219    global_context.pop('__doc__', None) 
     220    global_context.pop('__name__', None) 
     221    global_context.pop('__file__', None) 
     222    global_context.pop('__builtins__') 
    220223    #print globals.keys() 
    221224 
     
    232235 
    233236    # Break pairs into left set and right set 
    234     left,right = [set(s) for s in zip(*pairs)] if pairs != [] else ([],[]) 
    235     while pairs != []: 
     237    # Note: pairs is array or list, so use "len(pairs) > 0" to check for empty. 
     238    left,right = [set(s) for s in zip(*pairs)] if len(pairs) > 0 else ([],[]) 
     239    while len(pairs) > 0: 
    236240        #print "within",pairs 
    237241        # Find which items only occur on the right 
     
    261265    satisfies the partial ordering given by the pairs in partial order. 
    262266    """ 
    263     left,right = zip(*pairs) if pairs != [] else ([],[]) 
     267    # Note: pairs is array or list, so use "len(pairs) > 0" to check for empty. 
     268    left,right = zip(*pairs) if len(pairs) > 0 else ([],[]) 
    264269    items = set(left) 
    265270    n = order_dependencies(pairs) 
Note: See TracChangeset for help on using the changeset viewer.