Changeset 17bbadd in sasmodels for sasmodels/convert.py
- Timestamp:
- Mar 15, 2016 12:47:12 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 754e27b
- Parents:
- 5ceb7d0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/convert.py
r0d0aee1 r17bbadd 4 4 import warnings 5 5 6 STRUCTURE_FACTORS = [ 7 'hardsphere', 8 'stickyhardsphere', 9 'squarewell', 10 'HayterMSAsq' 11 ] 6 12 # List of models which SasView versions don't contain the explicit 'scale' argument. 7 13 # When converting such a model, please update this list. 8 MODELS_WITHOUT_SCALE = [14 MODELS_WITHOUT_SCALE = STRUCTURE_FACTORS + [ 9 15 'teubner_strey', 10 16 'broad_peak', … … 15 21 'be_polyelectrolyte', 16 22 'correlation_length', 23 'fractal_core_shell' 17 24 'binary_hard_sphere', 18 'fractal_core_shell'19 25 ] 20 26 21 27 # List of models which SasView versions don't contain the explicit 'background' argument. 22 28 # When converting such a model, please update this list. 23 MODELS_WITHOUT_BACKGROUND = [29 MODELS_WITHOUT_BACKGROUND = STRUCTURE_FACTORS + [ 24 30 'guinier', 25 31 ] … … 52 58 new model definition end with sld. 53 59 """ 54 return dict((p, (v*1e6 if p.endswith('sld') else v*1e-15 if 'ndensity' in p else v)) 60 return dict((p, (v*1e6 if p.endswith('sld') 61 else v*1e-15 if 'ndensity' in p 62 else v)) 55 63 for p, v in pars.items()) 56 64 … … 70 78 new model definition end with sld. 71 79 """ 72 return dict((p, (v*1e-6 if p.endswith('sld') else v*1e15 if 'ndensity' in p else v)) 80 return dict((p, (v*1e-6 if p.endswith('sld') 81 else v*1e15 if 'ndensity' in p 82 else v)) 73 83 for p, v in pars.items()) 74 84 … … 109 119 return newpars 110 120 111 def revert_ model(model_definition, pars):121 def revert_pars(model_info, pars): 112 122 """ 113 123 Convert model from new style parameter names to old style. 114 124 """ 115 mapping = model_definition.oldpars 116 oldname = model_definition.oldname 125 mapping = model_info['oldpars'] 117 126 oldpars = _revert_pars(_unscale_sld(pars), mapping) 118 127 119 128 # Note: update compare.constrain_pars to match 120 name = model_ definition.name129 name = model_info['id'] 121 130 if name in MODELS_WITHOUT_SCALE: 122 131 if oldpars.pop('scale', 1.0) != 1.0: 123 132 warnings.warn("parameter scale not used in sasview %s"%name) 124 elif name in MODELS_WITHOUT_BACKGROUND:133 if name in MODELS_WITHOUT_BACKGROUND: 125 134 if oldpars.pop('background', 0.0) != 0.0: 126 135 warnings.warn("parameter background not used in sasview %s"%name) 127 elif getattr(model_definition, 'category', None) == 'structure-factor':128 if oldpars.pop('scale', 1.0) != 1.0:129 warnings.warn("parameter scale not used in sasview %s"%name)130 if oldpars.pop('background', 0.0) != 0.0:131 warnings.warn("parameter background not used in sasview %s"%name)132 elif name == 'pearl_necklace':133 _remove_pd(oldpars, 'num_pearls', name)134 _remove_pd(oldpars, 'thick_string', name)135 elif name == 'core_shell_parallelepiped':136 _remove_pd(oldpars, 'rimA', name)137 _remove_pd(oldpars, 'rimB', name)138 _remove_pd(oldpars, 'rimC', name)139 elif name == 'rpa':140 # convert scattering lengths from femtometers to centimeters141 for p in "La", "Lb", "Lc", "Ld":142 if p in oldpars: oldpars[p] *= 1e-13143 136 144 return oldname, oldpars 137 # If it is a product model P*S, then check the individual forms for special 138 # cases. Note: despite the structure factor alone not having scale or 139 # background, the product model does, so this is below the test for 140 # models without scale or background. 141 namelist = name.split('*') if '*' in name else [name] 142 for name in namelist: 143 if name == 'pearl_necklace': 144 _remove_pd(oldpars, 'num_pearls', name) 145 _remove_pd(oldpars, 'thick_string', name) 146 elif name == 'core_shell_parallelepiped': 147 _remove_pd(oldpars, 'rimA', name) 148 _remove_pd(oldpars, 'rimB', name) 149 _remove_pd(oldpars, 'rimC', name) 150 elif name == 'rpa': 151 # convert scattering lengths from femtometers to centimeters 152 for p in "La", "Lb", "Lc", "Ld": 153 if p in oldpars: oldpars[p] *= 1e-13 145 154 146 def constrain_new_to_old(model_definition, pars): 155 return oldpars 156 157 def constrain_new_to_old(model_info, pars): 147 158 """ 148 159 Restrict parameter values to those that will match sasview. 149 160 """ 161 name = model_info['id'] 150 162 # Note: update convert.revert_model to match 151 name = model_definition.name152 163 if name in MODELS_WITHOUT_SCALE: 153 164 pars['scale'] = 1 154 elif name in MODELS_WITHOUT_BACKGROUND:165 if name in MODELS_WITHOUT_BACKGROUND: 155 166 pars['background'] = 0 156 elif name == 'pearl_necklace':157 pars['string_thickness_pd_n'] = 0158 pars['number_of_pearls_pd_n'] = 0159 elif name == 'line':160 pars['scale'] = 1161 pars['background'] = 0162 elif name == 'rpa':163 pars['case_num'] = int(pars['case_num'])164 elif getattr(model_definition, 'category', None) == 'structure-factor':165 pars['scale'], pars['background'] = 1, 0166 167 168 # If it is a product model P*S, then check the individual forms for special 169 # cases. Note: despite the structure factor alone not having scale or 170 # background, the product model does, so this is below the test for 171 # models without scale or background. 172 namelist = name.split('*') if '*' in name else [name] 173 for name in namelist: 174 if name == 'pearl_necklace': 175 pars['string_thickness_pd_n'] = 0 176 pars['number_of_pearls_pd_n'] = 0 177 elif name == 'line': 178 pars['scale'] = 1 179 pars['background'] = 0 180 elif name == 'rpa': 181 pars['case_num'] = int(pars['case_num'])
Note: See TracChangeset
for help on using the changeset viewer.