Changeset 4b4eee1 in sasmodels
- Timestamp:
- Dec 5, 2016 3:36:01 PM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 298621b
- Parents:
- 9eb5eca
- Location:
- sasmodels
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/conversion_table.py
re1ea6b5 r4b4eee1 8 8 """ 9 9 10 # TODO: May need to version this for future versions of sasview when11 # TODO: models are reparameterized12 13 10 CONVERSION_TABLE = { 11 "4.1.0" : {}, 12 "4.0.1" : { 14 13 "adsorbed_layer": [ 15 14 "Core2ndMomentModel", … … 845 844 } 846 845 ] 846 } 847 847 } -
sasmodels/convert.py
re1ea6b5 r4b4eee1 92 92 93 93 94 def _get_translation_table(model_info ):95 _, translation = CONVERSION_TABLE.get( model_info.id, [None, {}])94 def _get_translation_table(model_info, version='4.0.1'): 95 _, translation = CONVERSION_TABLE.get(version).get(model_info.id, [None, {}]) 96 96 translation = translation.copy() 97 97 for p in model_info.parameters.kernel_parameters: … … 145 145 return newpars 146 146 147 def _conversion_target(model_name ):147 def _conversion_target(model_name, version='4.0.1'): 148 148 """ 149 149 Find the sasmodel name which translates into the sasview name. … … 153 153 two variants in sasview. 154 154 """ 155 for sasmodels_name, [sasview_name, _] in CONVERSION_TABLE. items():155 for sasmodels_name, [sasview_name, _] in CONVERSION_TABLE.get(version).items(): 156 156 if sasview_name == model_name: 157 157 return sasmodels_name … … 159 159 160 160 161 def _hand_convert(name, oldpars ):162 if name == 'core_shell_parallelepiped' :161 def _hand_convert(name, oldpars, version='4.0.1'): 162 if name == 'core_shell_parallelepiped' and version == '4.0.1': 163 163 # Make sure pd on rim parameters defaults to zero 164 164 # ... probably not necessary. … … 166 166 oldpars['rimB.width'] = 0.0 167 167 oldpars['rimC.width'] = 0.0 168 elif name == 'core_shell_ellipsoid:1' :168 elif name == 'core_shell_ellipsoid:1' and version == '4.0.1': 169 169 # Reverse translation (from new to old), from core_shell_ellipsoid.c 170 170 # equat_shell = equat_core + thick_shell … … 185 185 oldpars['polar_core'] = polar_core / equat_core 186 186 oldpars['polar_shell'] = (polar_shell-polar_core)/(equat_shell-equat_core) 187 elif name == 'hollow_cylinder' :187 elif name == 'hollow_cylinder' and version == '4.0.1': 188 188 # now uses radius and thickness 189 189 thickness = oldpars['radius'] - oldpars['core_radius'] … … 192 192 pd = oldpars['radius.width']*oldpars['radius']/thickness 193 193 oldpars['radius.width'] = pd 194 elif name == 'multilayer_vesicle' :194 elif name == 'multilayer_vesicle' and version == '4.0.1': 195 195 if 'scale' in oldpars: 196 196 oldpars['volfraction'] = oldpars['scale'] … … 206 206 if 'scale.units' in oldpars: 207 207 oldpars['volfraction.units'] = oldpars['scale.units'] 208 elif name == 'pearl_necklace' :208 elif name == 'pearl_necklace' and version == '4.0.1': 209 209 pass 210 210 #_remove_pd(oldpars, 'num_pearls', name) 211 211 #_remove_pd(oldpars, 'thick_string', name) 212 elif name == 'polymer_micelle' :212 elif name == 'polymer_micelle' and version == '4.0.1': 213 213 if 'ndensity' in oldpars: 214 214 oldpars['ndensity'] /= 1e15 … … 217 217 if 'ndensity.upper' in oldpars: 218 218 oldpars['ndensity.upper'] /= 1e15 219 elif name == 'rpa' :219 elif name == 'rpa' and version == '4.0.1': 220 220 # convert scattering lengths from femtometers to centimeters 221 221 for p in "L1", "L2", "L3", "L4": … … 226 226 if p + ".upper" in oldpars: 227 227 oldpars[p + ".upper"] /= 1e-13 228 elif name == 'spherical_sld' :228 elif name == 'spherical_sld' and version == '4.0.1': 229 229 oldpars["CONTROL"] = 0 230 230 i = 0 … … 232 232 oldpars["CONTROL"] += 1 233 233 i += 1 234 elif name == 'teubner_strey' :234 elif name == 'teubner_strey' and version == '4.0.1': 235 235 # basically undoing the entire Teubner-Strey calculations here. 236 236 # drho = (sld_a - sld_b) … … 280 280 Convert model from old style parameter names to new style. 281 281 """ 282 newname = _conversion_target(name) 283 if newname is None: 284 return name, pars 285 if ':' in newname: # core_shell_ellipsoid:1 286 model_info = load_model_info(newname[:-2]) 287 # Know that the table exists and isn't multiplicity so grab it directly 288 # Can't use _get_translation_table since that will return the 'bare' 289 # version. 290 translation = CONVERSION_TABLE[newname][1] 291 else: 292 model_info = load_model_info(newname) 293 translation = _get_translation_table(model_info) 294 newpars = _hand_convert(newname, pars.copy()) 295 newpars = _convert_pars(newpars, translation) 296 if not model_info.structure_factor: 297 newpars = _rescale_sld(model_info, newpars, 1e6) 298 newpars.setdefault('scale', 1.0) 299 newpars.setdefault('background', 0.0) 300 if use_underscore: 301 newpars = _pd_to_underscores(newpars) 282 newpars = pars 283 for version, _ in sorted(CONVERSION_TABLE.iteritems()): 284 newname = _conversion_target(name, version) 285 if newname is None: 286 newname = name 287 continue 288 if ':' in newname: # core_shell_ellipsoid:1 289 model_info = load_model_info(newname[:-2]) 290 # Know that the table exists and isn't multiplicity so grab it directly 291 # Can't use _get_translation_table since that will return the 'bare' 292 # version. 293 translation = CONVERSION_TABLE.get(version)[newname][1] 294 else: 295 model_info = load_model_info(newname) 296 translation = _get_translation_table(model_info, version) 297 newpars = _hand_convert(newname, newpars, version) 298 newpars = _convert_pars(newpars, translation) 299 if not model_info.structure_factor: 300 newpars = _rescale_sld(model_info, newpars, 1e6) 301 newpars.setdefault('scale', 1.0) 302 newpars.setdefault('background', 0.0) 303 if use_underscore: 304 newpars = _pd_to_underscores(newpars) 305 name = newname 302 306 return newname, newpars 303 307 -
sasmodels/sasview_model.py
r8977226 r4b4eee1 57 57 import sas.models 58 58 from sasmodels.conversion_table import CONVERSION_TABLE 59 for new_name, conversion in CONVERSION_TABLE. items():59 for new_name, conversion in CONVERSION_TABLE.get('4.0.1').items(): 60 60 # CoreShellEllipsoidModel => core_shell_ellipsoid:1 61 61 new_name = new_name.split(':')[0]
Note: See TracChangeset
for help on using the changeset viewer.