Changeset 68e7f9d in sasmodels
- Timestamp:
- Apr 4, 2016 12:18:02 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:
- 9d96649
- Parents:
- 5b0335b
- Location:
- sasmodels
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/core.py
r5b0335b r68e7f9d 9 9 from os.path import basename, dirname, join as joinpath, splitext 10 10 from glob import glob 11 import imp12 11 13 12 import numpy as np … … 29 28 30 29 try: 31 # Python 3.5 and up32 from importlib.util import spec_from_file_location, module_from_spec33 def load_module(fullname, path):34 spec = spec_from_file_location(fullname, path)35 module = module_from_spec(spec)36 spec.loader.exec_module(module)37 return module38 except ImportError:39 # CRUFT: python 240 import imp41 def load_module(fullname, path):42 module = imp.load_source(fullname, path)43 return module44 45 try:46 30 np.meshgrid([]) 47 31 meshgrid = np.meshgrid … … 98 82 return product.make_product_info(P_info, Q_info) 99 83 100 kernel_module = load_kernel_module(model_name)84 kernel_module = generate.load_kernel_module(model_name) 101 85 return generate.make_model_info(kernel_module) 102 103 104 def load_kernel_module(model_name):105 if model_name.endswith('.py'):106 path = model_name107 # Pull off the last .ext if it exists; there may be others108 name = basename(splitext(path)[0])109 # Placing the model in the 'sasmodels.custom' name space.110 from sasmodels import custom111 kernel_module = load_module('sasmodels.custom.'+name, path)112 else:113 from sasmodels import models114 __import__('sasmodels.models.'+model_name)115 kernel_module = getattr(models, model_name, None)116 #import sys; print "\n".join(sys.path)117 __import__('sasmodels.models.'+model_name)118 kernel_module = getattr(models, model_name, None)119 return kernel_module120 86 121 87 -
sasmodels/direct_model.py
raaf75b6 r68e7f9d 25 25 import numpy as np 26 26 27 from .core import make_kernel28 27 from .core import call_kernel, call_ER_VR 29 28 from . import sesans … … 171 170 def _calc_theory(self, pars, cutoff=0.0): 172 171 if self._kernel is None: 173 self._kernel = make_kernel(self._model, self._kernel_inputs) # pylint: disable=attribute-dedata_type174 self._kernel_mono = ( make_kernel(self._model,self._kernel_mono_inputs)172 self._kernel = self._model.make_kernel(self._kernel_inputs) 173 self._kernel_mono = (self._model.make_kernel(self._kernel_mono_inputs) 175 174 if self._kernel_mono_inputs else None) 176 175 -
sasmodels/generate.py
rce896fd r68e7f9d 193 193 194 194 from .modelinfo import ModelInfo, Parameter, make_parameter_table, set_demo 195 from .custom import load_custom_kernel_module 195 196 196 197 # TODO: identify model files which have changed since loading and reload them. … … 662 663 return Iq(np.sqrt(qx**2 + qy**2), **kw) 663 664 model_info['Iqxy'] = Iqxy 665 666 667 def load_kernel_module(model_name): 668 if model_name.endswith('.py'): 669 kernel_module = load_custom_kernel_module(model_name) 670 else: 671 from sasmodels import models 672 __import__('sasmodels.models.'+model_name) 673 kernel_module = getattr(models, model_name, None) 674 return kernel_module 664 675 665 676 … … 811 822 """ 812 823 import sys 813 from sasmodels.core import make_model_by_name814 824 if len(sys.argv) <= 1: 815 825 print("usage: python -m sasmodels.generate modelname") 816 826 else: 817 827 name = sys.argv[1] 818 model_info = make_model_by_name(name) 828 kernel_module = load_kernel_module(name) 829 model_info = make_model_info(kernel_module) 819 830 source = make_source(model_info) 820 831 print(source)
Note: See TracChangeset
for help on using the changeset viewer.