source: sasmodels/sasmodels/convert.py @ 5d316e9

core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 5d316e9 was aa4946b, checked in by Paul Kienzle <pkienzle@…>, 9 years ago

refactor so kernels are loaded via core.load_model

  • Property mode set to 100644
File size: 2.0 KB
Line 
1"""
2Convert models to and from sasview.
3"""
4
5def _rename_pars(pars, mapping):
6    """
7    Rename the parameters and any associated polydispersity attributes.
8    """
9    newpars = pars.copy()
10    for old,new in mapping.items():
11        if old == new: continue
12        # Bumps style parameter names
13        for variant in ("", "_pd", "_pd_n", "_pd_nsigma", "_pd_type"):
14            if old+variant in newpars:
15                if new is not None:
16                    newpars[new+variant] = pars[old+variant]
17                del newpars[old+variant]
18        # Sasview style parameter names
19        for variant in (".width", ".nsigmas", ".type", ".npts"):
20            if old+variant in newpars:
21                if new is not None:
22                    newpars[new+variant] = pars[old+variant]
23                del newpars[old+variant]
24    return newpars
25
26def _rescale_sld(pars):
27    """
28    rescale all sld parameters in the new model definition by 1e6 so the
29    numbers are nicer.  Relies on the fact that all sld parameters in the
30    new model definition end with sld.
31    """
32    return dict((p, (v*1e6 if p.endswith('sld') else v))
33                for p,v in pars.items())
34
35def convert_model(name, pars):
36    """
37    Convert model from old style parameter names to new style.
38    """
39    _,_ = name,pars # lint
40    raise NotImplementedError
41    # need to load all new models in order to determine old=>new
42    # model name mapping
43
44def _unscale_sld(pars):
45    """
46    rescale all sld parameters in the new model definition by 1e6 so the
47    numbers are nicer.  Relies on the fact that all sld parameters in the
48    new model definition end with sld.
49    """
50    return dict((p, (v*1e-6 if p.endswith('sld') else v))
51                for p,v in pars.items())
52
53def revert_model(model_definition, pars):
54    """
55    Convert model from new style parameter names to old style.
56    """
57    mapping = model_definition.oldpars
58    oldname = model_definition.oldname
59    oldpars = _rename_pars(_unscale_sld(pars), mapping)
60    return oldname, oldpars
61
Note: See TracBrowser for help on using the repository browser.