Changeset a503bfd in sasmodels for sasmodels/convert.py
- Timestamp:
- Feb 16, 2015 7:41:55 PM (9 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:
- a1542aae, 373d1b6
- Parents:
- d547f16
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/convert.py
rf4cf580 ra503bfd 2 2 Convert models to and from sasview. 3 3 """ 4 PARAMETER_MAP = {5 'CylinderModel': dict(6 name='cylinder',7 cyl_theta='theta', cyl_phi='phi',8 sldCyl='sld', sldSolv='solvent_sld',9 ),10 'EllipsoidModel': dict(11 name='ellipsoid',12 axis_theta='theta', axis_phi='phi',13 sldEll='sld', sldSolv='solvent_sld',14 radius_a='rpolar', radius_b='requatorial',15 ),16 'CoreShellCylinderModel': dict(17 name='core_shell_cylinder',18 axis_theta='theta', axis_phi='phi',19 ),20 'TriaxialEllipsoidModel': dict(21 name='triaxial_ellipsoid',22 axis_theta='theta', axis_phi='phi', axis_psi='psi',23 sldEll='sld', sldSolv='solvent_sld',24 semi_axisA='req_minor', semi_axisB='req_major', semi_axisC='rpolar',25 ),26 'LamellarModel': dict(27 name='lamellar',28 sld_bi='sld', sld_sol='solvent_sld',29 bi_thick='thickness',30 ),31 'CappedCylinderModel': dict(32 name='capped_cylinder',33 sld_capcyl='sld', sld_solv='solvent_sld',34 len_cyl='length', rad_cyl='radius', rad_cap='cap_radius',35 ),36 'SphereModel': dict(37 name='sphere',38 sldSph='sld', sldSolv='solvent_sld',39 radius='radius', # listing identical parameters is optional40 ),41 }42 43 def _reverse_map():44 retval = {}45 for old_name,old_map in PARAMETER_MAP.items():46 new_name = old_map['name']47 new_map = dict((v,k) for k,v in old_map.items() if k != 'name')48 new_map['name'] = old_name49 retval[new_name] = new_map50 return retval51 REVERSE_MAP = _reverse_map()52 del _reverse_map53 54 4 55 5 def _rename_pars(pars, mapping): … … 85 35 Convert model from old style parameter names to new style. 86 36 """ 87 mapping = PARAMETER_MAP[name] 88 newname = mapping['name'] 89 newpars = _rescale_sld(_rename_pars(pars, mapping)) 90 return newname, newpars 37 raise NotImplementedError 38 # need to load all new models in order to determine old=>new 39 # model name mapping 91 40 92 41 def _unscale_sld(pars): … … 103 52 Convert model from new style parameter names to old style. 104 53 """ 105 mapping = REVERSE_MAP[name] 106 oldname = mapping['name'] 54 sasmodels = __import__('sasmodels.models.'+name) 55 newmodel = getattr(sasmodels.models, name, None) 56 mapping = newmodel.oldpars 57 oldname = newmodel.oldname 107 58 oldpars = _rename_pars(_unscale_sld(pars), mapping) 108 59 return oldname, oldpars
Note: See TracChangeset
for help on using the changeset viewer.