core_shell_microgelscostrafo411magnetic_modelrelease_v0.94release_v0.95ticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change
on this file since aa4946b 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:
1.7 KB
|
Rev | Line | |
---|
[ae7b97b] | 1 | import warnings |
---|
| 2 | |
---|
| 3 | import numpy as np |
---|
| 4 | |
---|
[aa4946b] | 5 | from .core import load_model_definition, load_model, make_kernel |
---|
| 6 | from .core import call_kernel, call_ER, call_VR |
---|
[ae7b97b] | 7 | |
---|
| 8 | class DirectModel: |
---|
[aa4946b] | 9 | def __init__(self, name, q_vectors=None, dtype='single'): |
---|
[ae7b97b] | 10 | self.model_definition = load_model_definition(name) |
---|
| 11 | self.model = load_model(self.model_definition, dtype=dtype) |
---|
[aa4946b] | 12 | if q_vectors is not None: |
---|
| 13 | q_vectors = [np.ascontiguousarray(q,dtype=dtype) for q in q_vectors] |
---|
| 14 | self.kernel = make_kernel(self.model, q_vectors) |
---|
[16bc3fc] | 15 | def __call__(self, **pars): |
---|
[ae7b97b] | 16 | return call_kernel(self.kernel, pars) |
---|
[aa4946b] | 17 | def ER(self, **pars): |
---|
| 18 | return call_ER(self.model.info, pars) |
---|
| 19 | def VR(self, **pars): |
---|
| 20 | return call_VR(self.model.info, pars) |
---|
[ae7b97b] | 21 | |
---|
| 22 | def demo(): |
---|
| 23 | import sys |
---|
| 24 | if len(sys.argv) < 3: |
---|
| 25 | print "usage: python -m sasmodels.direct_model modelname (q|qx,qy) par=val ..." |
---|
| 26 | sys.exit(1) |
---|
| 27 | model_name = sys.argv[1] |
---|
[aa4946b] | 28 | call = sys.argv[2].upper() |
---|
| 29 | if call in ("ER","VR"): |
---|
| 30 | q_vectors = None |
---|
[ae7b97b] | 31 | else: |
---|
[aa4946b] | 32 | values = [float(v) for v in sys.argv[2].split(',')] |
---|
| 33 | if len(values) == 1: |
---|
| 34 | q = values[0] |
---|
| 35 | q_vectors = [[q]] |
---|
| 36 | elif len(values) == 2: |
---|
| 37 | qx,qy = values |
---|
| 38 | q_vectors = [[qx],[qy]] |
---|
| 39 | else: |
---|
| 40 | print "use q or qx,qy or ER or VR" |
---|
| 41 | sys.exit(1) |
---|
[ae7b97b] | 42 | model = DirectModel(model_name, q_vectors) |
---|
| 43 | pars = dict((k,float(v)) |
---|
| 44 | for pair in sys.argv[3:] |
---|
| 45 | for k,v in [pair.split('=')]) |
---|
[aa4946b] | 46 | if call == "ER": |
---|
| 47 | print model.ER(**pars) |
---|
| 48 | elif call == "VR": |
---|
| 49 | print model.VR(**pars) |
---|
| 50 | else: |
---|
| 51 | Iq = model(**pars) |
---|
| 52 | print Iq[0] |
---|
[ae7b97b] | 53 | |
---|
| 54 | if __name__ == "__main__": |
---|
| 55 | demo() |
---|
Note: See
TracBrowser
for help on using the repository browser.