Changes in sasmodels/sasview_model.py [d533590:bd547d0] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/sasview_model.py
rd533590 rbd547d0 62 62 #: set of defined models (standard and custom) 63 63 MODELS = {} # type: Dict[str, SasviewModelType] 64 # TODO: remove unused MODEL_BY_PATH cache once sasview no longer references it 64 65 #: custom model {path: model} mapping so we can check timestamps 65 66 MODEL_BY_PATH = {} # type: Dict[str, SasviewModelType] 67 #: Track modules that we have loaded so we can determine whether the model 68 #: has changed since we last reloaded. 69 _CACHED_MODULE = {} # type: Dict[str, "module"] 66 70 67 71 def find_model(modelname): … … 106 110 Load a custom model given the model path. 107 111 """ 108 model = MODEL_BY_PATH.get(path, None)109 if model is not None and model.timestamp == getmtime(path):110 #logger.info("Model already loaded %s", path)111 return model112 113 112 #logger.info("Loading model %s", path) 113 114 # Load the kernel module. This may already be cached by the loader, so 115 # only requires checking the timestamps of the dependents. 114 116 kernel_module = custom.load_custom_kernel_module(path) 115 if hasattr(kernel_module, 'Model'): 116 model = kernel_module.Model 117 118 # Check if the module has changed since we last looked. 119 reloaded = kernel_module != _CACHED_MODULE.get(path, None) 120 _CACHED_MODULE[path] = kernel_module 121 122 # Turn the module into a model. We need to do this in even if the 123 # model has already been loaded so that we can determine the model 124 # name and retrieve it from the MODELS cache. 125 model = getattr(kernel_module, 'Model', None) 126 if model is not None: 117 127 # Old style models do not set the name in the class attributes, so 118 128 # set it here; this name will be overridden when the object is created … … 127 137 model_info = modelinfo.make_model_info(kernel_module) 128 138 model = make_model_from_info(model_info) 129 model.timestamp = getmtime(path)130 139 131 140 # If a model name already exists and we are loading a different model, … … 143 152 _previous_name, model.name, model.filename) 144 153 145 MODELS[model.name] = model 146 MODEL_BY_PATH[path] = model 147 return model 154 # Only update the model if the module has changed 155 if reloaded or model.name not in MODELS: 156 MODELS[model.name] = model 157 158 return MODELS[model.name] 148 159 149 160 … … 372 383 hidden.add('background') 373 384 self._model_info.parameters.defaults['background'] = 0. 385 386 # Update the parameter lists to exclude any hidden parameters 387 self.magnetic_params = tuple(pname for pname in self.magnetic_params 388 if pname not in hidden) 389 self.orientation_params = tuple(pname for pname in self.orientation_params 390 if pname not in hidden) 374 391 375 392 self._persistency_dict = {} … … 873 890 Model = _make_standard_model('sphere') 874 891 model = Model() 875 model.setParam(' M0:sld', 8)892 model.setParam('sld_M0', 8) 876 893 q = np.linspace(-0.35, 0.35, 500) 877 894 qx, qy = np.meshgrid(q, q)
Note: See TracChangeset
for help on using the changeset viewer.