Changeset f247314 in sasmodels
- Timestamp:
- Apr 4, 2016 3:23:23 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:
- ec45c4f
- Parents:
- 204fd9b
- Location:
- sasmodels
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rea75043 rf247314 41 41 from .data import plot_theory, empty_data1D, empty_data2D 42 42 from .direct_model import DirectModel 43 from .convert import revert_ pars, constrain_new_to_old43 from .convert import revert_name, revert_pars, constrain_new_to_old 44 44 45 45 USAGE = """ … … 347 347 def eval_sasview(model_info, data): 348 348 """ 349 Return a model calculator using the SasView fitting engine.349 Return a model calculator using the pre-4.0 SasView models. 350 350 """ 351 351 # importing sas here so that the error message will be that sas failed to … … 366 366 composition_type, parts = model_info['composition'] 367 367 if composition_type == 'product': 368 from sas. sascalc.fit.MultiplicationModel import MultiplicationModel369 P, S = [get_model( p) for p in model_info['oldname']]368 from sas.models.MultiplicationModel import MultiplicationModel 369 P, S = [get_model(revert_name(p)) for p in parts] 370 370 model = MultiplicationModel(P, S) 371 371 else: 372 372 raise ValueError("sasview mixture models not supported by compare") 373 373 else: 374 model = get_model( model_info['oldname'])374 model = get_model(revert_name(model_info)) 375 375 376 376 # build a smearer with which to call the model, if necessary -
sasmodels/convert.py
r2a3e1f5 rf247314 2 2 Convert models to and from sasview. 3 3 """ 4 from os.path import join as joinpath, abspath, dirname 4 5 import warnings 6 import json 5 7 6 8 # List of models which SasView versions don't contain the explicit 'scale' argument. … … 26 28 ] 27 29 30 # Convert new style names for polydispersity info to old style names 28 31 PD_DOT = [ 29 32 ("", ""), … … 33 36 ("_pd_type", ".type"), 34 37 ] 38 39 CONVERSION_TABLE = None 40 41 def _read_conversion_table(): 42 global CONVERSION_TABLE 43 if CONVERSION_TABLE is None: 44 path = joinpath(dirname(abspath(__file__)), "convert.json") 45 with open(path) as fid: 46 CONVERSION_TABLE = json_load_byteified(fid) 47 48 def json_load_byteified(file_handle): 49 return _byteify( 50 json.load(file_handle, object_hook=_byteify), 51 ignore_dicts=True 52 ) 53 54 def _byteify(data, ignore_dicts = False): 55 # if this is a unicode string, return its string representation 56 if isinstance(data, unicode): 57 return data.encode('utf-8') 58 # if this is a list of values, return list of byteified values 59 if isinstance(data, list): 60 return [ _byteify(item, ignore_dicts=True) for item in data ] 61 # if this is a dictionary, return dictionary of byteified keys and values 62 # but only if we haven't already byteified it 63 if isinstance(data, dict) and not ignore_dicts: 64 return { 65 _byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True) 66 for key, value in data.iteritems() 67 } 68 # if it's anything else, return it in its original form 69 return data 70 71 35 72 def _convert_pars(pars, mapping): 36 73 """ … … 114 151 return newpars 115 152 153 def revert_name(model_info): 154 _read_conversion_table() 155 oldname, oldpars = CONVERSION_TABLE.get(model_info['id'], [None, {}]) 156 return oldname 157 158 def _get_old_pars(model_info): 159 _read_conversion_table() 160 oldname, oldpars = CONVERSION_TABLE.get(model_info['id'], [None, {}]) 161 return oldpars 162 116 163 def revert_pars(model_info, pars): 117 164 """ 118 165 Convert model from new style parameter names to old style. 119 166 """ 120 mapping = model_info['oldpars'] 121 oldpars = _revert_pars(_unscale_sld(pars), mapping) 167 if model_info['composition'] is not None: 168 composition_type, parts = model_info['composition'] 169 if composition_type == 'product': 170 P, S = parts 171 oldpars = {'scale':'scale_factor'} 172 oldpars.update(_get_old_pars(P)) 173 oldpars.update(_get_old_pars(S)) 174 else: 175 raise NotImplementedError("cannot convert to sasview sum") 176 else: 177 oldpars = _get_old_pars(model_info) 178 oldpars = _revert_pars(_unscale_sld(pars), oldpars) 179 122 180 123 181 # Note: update compare.constrain_pars to match -
sasmodels/generate.py
r9ef9dd9 rf247314 153 153 parameter list. *demo* is mostly needed to set the default 154 154 polydispersity values for tests. 155 156 *oldname* is the name of the model in sasview before sasmodels157 was split into its own package, and *oldpars* is a dictionary158 of *parameter: old_parameter* pairs defining the new names for159 the parameters. This is used by *compare* to check the values160 of the new model against the values of the old model before161 you are ready to add the new model to sasmodels.162 163 155 164 156 An *model_info* dictionary is constructed from the kernel meta data and … … 692 684 implementing the kernel for the module, or None if they are not 693 685 defined in python 694 * *oldname* is the model name in pre-4.0 Sasview695 * *oldpars* is the *{new: old}* parameter translation table696 from pre-4.0 Sasview697 686 * *composition* is None if the model is independent, otherwise it is a 698 687 tuple with composition type ('product' or 'mixture') and a list of … … 723 712 demo=getattr(kernel_module, 'demo', None), 724 713 source=getattr(kernel_module, 'source', []), 725 oldname=getattr(kernel_module, 'oldname', None),726 oldpars=getattr(kernel_module, 'oldpars', {}),727 714 tests=getattr(kernel_module, 'tests', []), 728 715 ) -
sasmodels/models/cylinder.py
r6ef4293 rf247314 138 138 phi_pd=10, phi_pd_n=5) 139 139 140 # For testing against the old sasview models, include the converted parameter141 # names and the target sasview model name.142 oldname = 'CylinderModel'143 oldpars = dict(theta='cyl_theta', phi='cyl_phi', sld='sldCyl', sld_solvent='sldSolv')144 145 146 140 qx, qy = 0.2 * np.cos(2.5), 0.2 * np.sin(2.5) 147 141 tests = [[{}, 0.2, 0.042761386790780453], -
sasmodels/product.py
r3c6d5bc rf247314 42 42 if len(set(p.name for p in pars)) != len(pars): 43 43 raise ValueError("Duplicate parameters in %s and %s"%(p_id)) 44 # For comparison with sasview, determine the old parameters.45 oldname = [p_info['oldname'], s_info['oldname']]46 oldpars = {'scale':'scale_factor'}47 oldpars.update(p_info['oldpars'])48 oldpars.update(s_info['oldpars'])49 50 44 model_info = {} 51 45 model_info['id'] = '*'.join((p_id, s_id)) … … 63 57 #model_info['source'] = [] 64 58 # Iq, Iqxy, form_volume, ER, VR and sesans 65 model_info['oldname'] = oldname66 model_info['oldpars'] = oldpars67 59 model_info['composition'] = ('product', [p_info, s_info]) 68 60 process_parameters(model_info) -
sasmodels/sasview_model.py
r787be86 rf247314 32 32 33 33 Returns a class that can be used directly as a sasview model.t 34 35 Defaults to using the new name for a model. Setting36 *namestyle='oldname'* will produce a class with a name37 compatible with SasView.38 34 """ 39 35 model_info = core.load_model_info(model_name) … … 60 56 61 57 self.name = model_info['name'] 62 self.oldname = model_info['oldname']63 58 self.description = model_info['description'] 64 59 self.category = None
Note: See TracChangeset
for help on using the changeset viewer.