Changes in / [0d26e91:da3638f] in sasmodels
- Location:
- sasmodels
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
r4de14584 r4de14584 1152 1152 'rel_err' : True, 1153 1153 'explore' : False, 1154 'use_demo' : False,1154 'use_demo' : True, 1155 1155 'zero' : False, 1156 1156 'html' : False, -
sasmodels/direct_model.py
r5024a56 r5024a56 332 332 333 333 # Need to pull background out of resolution for multiple scattering 334 default_background = self._model.info.parameters.common_parameters[1].default 335 background = pars.get('background', default_background) 334 background = pars.get('background', DEFAULT_BACKGROUND) 336 335 pars = pars.copy() 337 336 pars['background'] = 0. -
sasmodels/generate.py
rcd28947 rcd28947 1006 1006 pars = model_info.parameters.kernel_parameters 1007 1007 else: 1008 pars = (model_info.parameters.common_parameters 1009 + model_info.parameters.kernel_parameters) 1008 pars = model_info.parameters.COMMON + model_info.parameters.kernel_parameters 1010 1009 partable = make_partable(pars) 1011 1010 subst = dict(id=model_info.id.replace('_', '-'), -
sasmodels/jitter.py
r7d97437 r1198f90 15 15 pass 16 16 17 import matplotlib as mpl18 17 import matplotlib.pyplot as plt 19 18 from matplotlib.widgets import Slider … … 747 746 pass 748 747 749 # CRUFT: use axisbg instead of facecolor for matplotlib<2 750 facecolor_prop = 'facecolor' if mpl.__version__ > '2' else 'axisbg' 751 props = {facecolor_prop: 'lightgoldenrodyellow'} 748 axcolor = 'lightgoldenrodyellow' 752 749 753 750 ## add control widgets to plot 754 axes_theta = plt.axes([0.1, 0.15, 0.45, 0.04], **props)755 axes_phi = plt.axes([0.1, 0.1, 0.45, 0.04], **props)756 axes_psi = plt.axes([0.1, 0.05, 0.45, 0.04], **props)751 axes_theta = plt.axes([0.1, 0.15, 0.45, 0.04], axisbg=axcolor) 752 axes_phi = plt.axes([0.1, 0.1, 0.45, 0.04], axisbg=axcolor) 753 axes_psi = plt.axes([0.1, 0.05, 0.45, 0.04], axisbg=axcolor) 757 754 stheta = Slider(axes_theta, 'Theta', -90, 90, valinit=theta) 758 755 sphi = Slider(axes_phi, 'Phi', -180, 180, valinit=phi) 759 756 spsi = Slider(axes_psi, 'Psi', -180, 180, valinit=psi) 760 757 761 axes_dtheta = plt.axes([0.75, 0.15, 0.15, 0.04], **props)762 axes_dphi = plt.axes([0.75, 0.1, 0.15, 0.04], **props)763 axes_dpsi = plt.axes([0.75, 0.05, 0.15, 0.04], **props)758 axes_dtheta = plt.axes([0.75, 0.15, 0.15, 0.04], axisbg=axcolor) 759 axes_dphi = plt.axes([0.75, 0.1, 0.15, 0.04], axisbg=axcolor) 760 axes_dpsi = plt.axes([0.75, 0.05, 0.15, 0.04], axisbg=axcolor) 764 761 # Note: using ridiculous definition of rectangle distribution, whose width 765 762 # in sasmodels is sqrt(3) times the given width. Divide by sqrt(3) to keep -
sasmodels/kernelcl.py
r3199b17 r3199b17 58 58 import time 59 59 60 try:61 from time import perf_counter as clock62 except ImportError: # CRUFT: python < 3.363 import sys64 if sys.platform.count("darwin") > 0:65 from time import time as clock66 else:67 from time import clock68 69 60 import numpy as np # type: ignore 61 70 62 71 63 # Attempt to setup OpenCL. This may fail if the pyopencl package is not … … 600 592 #call_details.show(values) 601 593 wait_for = None 602 last_nap = clock()594 last_nap = time.clock() 603 595 step = 1000000//self.q_input.nq + 1 604 596 for start in range(0, call_details.num_eval, step): … … 611 603 # Allow other processes to run. 612 604 wait_for[0].wait() 613 current_time = clock()605 current_time = time.clock() 614 606 if current_time - last_nap > 0.5: 615 607 time.sleep(0.001) -
sasmodels/modelinfo.py
r39a06c9 r39a06c9 404 404 parameters counted as n individual parameters p1, p2, ... 405 405 406 * *common_parameters* is the list of common parameters, with a unique407 copy for each model so that structure factors can have a default408 background of 0.0.409 410 406 * *call_parameters* is the complete list of parameters to the kernel, 411 407 including scale and background, with vector parameters recorded as … … 420 416 parameters don't use vector notation, and instead use p1, p2, ... 421 417 """ 418 # scale and background are implicit parameters 419 COMMON = [Parameter(*p) for p in COMMON_PARAMETERS] 420 422 421 def __init__(self, parameters): 423 422 # type: (List[Parameter]) -> None 424 425 # scale and background are implicit parameters426 # Need them to be unique to each model in case they have different427 # properties, such as default=0.0 for structure factor backgrounds.428 self.common_parameters = [Parameter(*p) for p in COMMON_PARAMETERS]429 430 423 self.kernel_parameters = parameters 431 424 self._set_vector_lengths() … … 475 468 if p.polydisperse and p.type not in ('orientation', 'magnetic')) 476 469 self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 477 478 def set_zero_background(self):479 """480 Set the default background to zero for this model. This is done for481 structure factor models.482 """483 # type: () -> None484 # Make sure background is the second common parameter.485 assert self.common_parameters[1].id == "background"486 self.common_parameters[1].default = 0.0487 self.defaults = self._get_defaults()488 470 489 471 def check_angles(self): … … 585 567 def _get_call_parameters(self): 586 568 # type: () -> List[Parameter] 587 full_list = self. common_parameters[:]569 full_list = self.COMMON[:] 588 570 for p in self.kernel_parameters: 589 571 if p.length == 1: … … 688 670 689 671 # Gather the user parameters in order 690 result = control + self. common_parameters672 result = control + self.COMMON 691 673 for p in self.kernel_parameters: 692 674 if not is2d and p.type in ('orientation', 'magnetic'): … … 788 770 789 771 info = ModelInfo() 790 791 # Build the parameter table792 772 #print("make parameter table", kernel_module.parameters) 793 773 parameters = make_parameter_table(getattr(kernel_module, 'parameters', [])) 794 795 # background defaults to zero for structure factor models796 structure_factor = getattr(kernel_module, 'structure_factor', False)797 if structure_factor:798 parameters.set_zero_background()799 800 # TODO: remove demo parameters801 # The plots in the docs are generated from the model default values.802 # Sascomp set parameters from the command line, and so doesn't need803 # demo values for testing.804 774 demo = expand_pars(parameters, getattr(kernel_module, 'demo', None)) 805 806 775 filename = abspath(kernel_module.__file__).replace('.pyc', '.py') 807 776 kernel_id = splitext(basename(filename))[0] -
sasmodels/models/hardsphere.py
r304c775 r304c775 162 162 return pars 163 163 164 demo = dict(radius_effective=200, volfraction=0.2, 165 radius_effective_pd=0.1, radius_effective_pd_n=40) 164 166 # Q=0.001 is in the Taylor series, low Q part, so add Q=0.1, 165 167 # assuming double precision sasview is correct -
sasmodels/resolution.py
rda3638f rda3638f 445 445 q = np.sort(q) 446 446 if q_min + 2*MINIMUM_RESOLUTION < q[0]: 447 n_low = int(np.ceil((q[0]-q_min) / (q[1]-q[0]))) if q[1] > q[0] else 15448 q_low = np.linspace(q_min, q[0], n_low+1)[:-1]447 n_low = np.ceil((q[0]-q_min) / (q[1]-q[0])) if q[1] > q[0] else 15 448 q_low = np.linspace(q_min, q[0], int(n_low)+1)[:-1] 449 449 else: 450 450 q_low = [] 451 451 if q_max - 2*MINIMUM_RESOLUTION > q[-1]: 452 n_high = int(np.ceil((q_max-q[-1]) / (q[-1]-q[-2]))) if q[-1] > q[-2] else 15453 q_high = np.linspace(q[-1], q_max, n_high+1)[1:]452 n_high = np.ceil((q_max-q[-1]) / (q[-1]-q[-2])) if q[-1] > q[-2] else 15 453 q_high = np.linspace(q[-1], q_max, int(n_high)+1)[1:] 454 454 else: 455 455 q_high = [] … … 498 498 if q_min < 0: 499 499 q_min = q[0]*MINIMUM_ABSOLUTE_Q 500 n_low = int(np.ceil(log_delta_q * (log(q[0])-log(q_min))))501 q_low = np.logspace(log10(q_min), log10(q[0]), n_low+1)[:-1]500 n_low = np.ceil(log_delta_q * (log(q[0])-log(q_min))) 501 q_low = np.logspace(log10(q_min), log10(q[0]), int(n_low)+1)[:-1] 502 502 else: 503 503 q_low = [] 504 504 if q_max > q[-1]: 505 n_high = int(np.ceil(log_delta_q * (log(q_max)-log(q[-1]))))506 q_high = np.logspace(log10(q[-1]), log10(q_max), n_high+1)[1:]505 n_high = np.ceil(log_delta_q * (log(q_max)-log(q[-1]))) 506 q_high = np.logspace(log10(q[-1]), log10(q_max), int(n_high)+1)[1:] 507 507 else: 508 508 q_high = [] -
sasmodels/sasview_model.py
r3a1afed r3a1afed 382 382 hidden.add('scale') 383 383 hidden.add('background') 384 self._model_info.parameters.defaults['background'] = 0. 384 385 385 386 # Update the parameter lists to exclude any hidden parameters … … 930 931 CylinderModel().evalDistribution([0.1, 0.1]) 931 932 932 def test_structure_factor_background():933 # type: () -> None934 """935 Check that sasview model and direct model match, with background=0.936 """937 from .data import empty_data1D938 from .core import load_model_info, build_model939 from .direct_model import DirectModel940 941 model_name = "hardsphere"942 q = [0.0]943 944 sasview_model = _make_standard_model(model_name)()945 sasview_value = sasview_model.evalDistribution(np.array(q))[0]946 947 data = empty_data1D(q)948 model_info = load_model_info(model_name)949 model = build_model(model_info)950 direct_model = DirectModel(data, model)951 direct_value_zero_background = direct_model(background=0.0)952 953 assert sasview_value == direct_value_zero_background954 955 # Additionally check that direct value background defaults to zero956 direct_value_default = direct_model()957 assert sasview_value == direct_value_default958 959 960 933 def magnetic_demo(): 961 934 Model = _make_standard_model('sphere') … … 978 951 #print("rpa:", test_rpa()) 979 952 #test_empty_distribution() 980 #test_structure_factor_background() -
sasmodels/weights.py
re2592f0 r3d58247 23 23 default = dict(npts=35, width=0, nsigmas=3) 24 24 def __init__(self, npts=None, width=None, nsigmas=None): 25 self.npts = self.default['npts'] if npts is None else int(npts)25 self.npts = self.default['npts'] if npts is None else npts 26 26 self.width = self.default['width'] if width is None else width 27 27 self.nsigmas = self.default['nsigmas'] if nsigmas is None else nsigmas
Note: See TracChangeset
for help on using the changeset viewer.