Changeset 735507b in sasmodels
- Timestamp:
- Mar 18, 2016 4:12:48 AM (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:
- 2622b3f
- Parents:
- 03e8a6e (diff), c094758 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 8 added
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/genmodel.py
r03e8a6e r735507b 10 10 # Convert ../sasmodels/models/name.py to name 11 11 model_name = os.path.basename(sys.argv[1])[:-3] 12 model_info = core.load_model_info(model_name) 13 model = core.build_model(model_info) 12 14 13 15 # Load the doc string from the module definition file and store it in rst 14 docstr = generate.make_doc(core.load_model_info(model_name)) 15 16 # Generate automatically plot of the model and add it to rst documentation 16 docstr = generate.make_doc(model_info) 17 17 18 info = core.load_model_info(model_name)19 18 20 19 # Calculate 1D curve for default parameters 21 pars = dict((p [0], p[2]) for p ininfo['parameters'])20 pars = dict((p.name, p.default) for p in model_info['parameters']) 22 21 23 22 # Plotting ranges and options 24 23 opts = { 25 'xscale' : 'log', 26 'yscale' : 'log' if not info['structure_factor'] else 'linear', 27 'xlabel' : '$Q \/(\AA^{-1})$', 28 'ylabel' : '$I(Q) \/(\mathrm{cm}^{-1})$' if not info['structure_factor'] else '$S(Q) \/(\mathrm{cm}^{-1})$', 29 'qmin' : 0.001, 30 'qmax' : 1.0, 31 'nq' : 1000, 32 'nq2d' : 100, 24 'xscale' : 'log', 25 'yscale' : 'log' if not model_info['structure_factor'] else 'linear', 26 'zscale' : 'log' if not model_info['structure_factor'] else 'linear', 27 'q_min' : 0.001, 28 'q_max' : 1.0, 29 'nq' : 1000, 30 'nq2d' : 400, 31 'vmin' : 1e-3, # floor for the 2D data results 32 'qx_max' : 0.5, 33 33 } 34 34 35 qmin, qmax, nq = opts['qmin'], opts['qmax'], opts['nq']36 qmin = math.log10(qmin)37 qmax = math.log10(qmax)38 q = np.logspace(qmin, qmax, nq)39 data = empty_data1D(q)40 model = core.load_model(model_name)41 calculator = DirectModel(data, model)42 Iq1D = calculator()43 35 44 # TO DO: Generation of 2D plots 45 # Problem in sasmodels.direct_model._calc_theory 46 # There self._kernel.q_input.nq gets a value of 0 in the 2D case 47 # and returns a 0 numpy array (it does not call the C code) 36 def plot_1d(model, opts, ax): 37 q_min, q_max, nq = opts['q_min'], opts['q_max'], opts['nq'] 38 q_min = math.log10(q_min) 39 q_max = math.log10(q_max) 40 q = np.logspace(q_min, q_max, nq) 41 data = empty_data1D(q) 42 calculator = DirectModel(data, model) 43 Iq1D = calculator() 48 44 49 # If 2D model, compute 2D image 50 #if info['has_2d'] != []: 51 # qmax, nq2d = opts['qmax'], opts['nq2d'] 52 # data2d = empty_data2D(np.linspace(-qmax, qmax, nq2d), resolution=0.0) 53 # #model = core.load_model(model_name) 54 # calculator = DirectModel(data2d, model) 55 # Iq2D = calculator() 45 ax.plot(q, Iq1D, color='blue', lw=2, label=model_info['name']) 46 ax.set_xlabel(r'$Q \/(\AA^{-1})$') 47 ax.set_ylabel(r'$I(Q) \/(\mathrm{cm}^{-1})$') 48 ax.set_xscale(opts['xscale']) 49 ax.set_yscale(opts['yscale']) 50 #ax.legend(loc='best') 56 51 57 # Generate image (comment IF for 1D/2D for the moment) and generate only 1D 58 #if info['has_2d'] == []: 59 # fig = plt.figure() 60 # ax = fig.add_subplot(1,1,1) 61 # ax.plot(q, Iq1D, color='blue', lw=2, label=model_name) 62 # ax.set_xlabel(r'$Q \/(\AA^{-1})$') 63 # ax.set_xscale(opts['xscale']) 64 # ax.set_ylabel(r'$I(Q) \/(\mathrm{cm}^{-1})$') 65 # ax.set_yscale(opts['yscale']) 66 # ax.legend() 67 #else: 68 # # need figure with 1D + 2D 69 # pass 70 fig = plt.figure() 71 ax = fig.add_subplot(1,1,1) 72 ax.plot(q, Iq1D, color='blue', lw=2, label=info['name']) 73 ax.set_xlabel(opts['xlabel']) 74 ax.set_xscale(opts['xscale']) 75 ax.set_ylabel(opts['ylabel']) 76 ax.set_yscale(opts['yscale']) 77 ax.legend() 78 52 def plot_2d(model, opts, ax): 53 qx_max, nq2d = opts['qx_max'], opts['nq2d'] 54 q = np.linspace(-qx_max, qx_max, nq2d) 55 data2d = empty_data2D(q, resolution=0.0) 56 calculator = DirectModel(data2d, model) 57 Iq2D = calculator() #background=0) 58 Iq2D = Iq2D.reshape(nq2d, nq2d) 59 if opts['zscale'] == 'log': 60 Iq2D = np.log(np.clip(Iq2D, opts['vmin'], np.inf)) 61 h = ax.imshow(Iq2D, interpolation='nearest', aspect=1, origin='upper', 62 extent=[-qx_max, qx_max, -qx_max, qx_max], cmap=ice_cm()) 63 # , vmin=vmin, vmax=vmax) 64 ax.set_xlabel(r'$Q_x \/(\AA^{-1})$') 65 ax.set_ylabel(r'$Q_y \/(\AA^{-1})$') 66 67 def ice_cm(): 68 from matplotlib._cm import _Blues_data 69 from matplotlib import colors 70 from matplotlib import rcParams 71 def from_white(segments): 72 scale = 1.0/segments[0][1] 73 return [(k, v*scale, w*scale) for k, v, w in segments] 74 ice_data = dict((k,from_white(v)) for k,v in _Blues_data.items()) 75 ice = colors.LinearSegmentedColormap("ice", ice_data, rcParams['image.lut']) 76 return ice 77 78 79 # Generate image 80 fig_height = 3.0 # in 81 fig_left = 0.6 # in 82 fig_right = 0.5 # in 83 fig_top = 0.6*0.25 # in 84 fig_bottom = 0.6*0.75 85 if model_info['has_2d']: 86 plot_height = fig_height - (fig_top+fig_bottom) 87 plot_width = plot_height 88 fig_width = 2*(plot_width + fig_left + fig_right) 89 aspect = (fig_width, fig_height) 90 ratio = aspect[0]/aspect[1] 91 ax_left = fig_left/fig_width 92 ax_bottom = fig_bottom/fig_height 93 ax_height = plot_height/fig_height 94 ax_width = ax_height/ratio # square axes 95 fig = plt.figure(figsize=aspect) 96 ax2d = fig.add_axes([0.5+ax_left, ax_bottom, ax_width, ax_height]) 97 plot_2d(model, opts, ax2d) 98 ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height]) 99 #ax.set_aspect('square') 100 else: 101 plot_height = fig_height - (fig_top+fig_bottom) 102 plot_width = (1+np.sqrt(5))/2*fig_height 103 fig_width = plot_width + fig_left + fig_right 104 ax_left = fig_left/fig_width 105 ax_bottom = fig_bottom/fig_height 106 ax_width = plot_width/fig_width 107 ax_height = plot_height/fig_height 108 aspect = (fig_width, fig_height) 109 fig = plt.figure(figsize=aspect) 110 ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height]) 111 plot_1d(model, opts, ax1d) 79 112 80 113 # Save image in model/img 81 114 figname = model_name + '_autogenfig.png' 82 115 filename = os.path.join('model', 'img', figname) 83 plt.savefig(filename) 116 plt.savefig(filename, bbox_inches='tight') 117 #print "figure saved in",filename 84 118 85 119 # Auto caption for figure 86 120 captionstr = '\n' 87 captionstr += '.. figure:: img/' + model_ name+ '_autogenfig.png\n'121 captionstr += '.. figure:: img/' + model_info['id'] + '_autogenfig.png\n' 88 122 captionstr += '\n' 89 #if info['has_2d'] == []:90 # captionstr += ' 1D plot corresponding to the default parameters of the model.\n'91 #else:92 # captionstr += ' 1D and 2D plots corresponding to the default parameters of the model.\n'93 123 captionstr += ' 1D plot corresponding to the default parameters of the model.\n' 94 124 captionstr += '\n' … … 104 134 else: 105 135 print '------------------------------------------------------------------' 106 print 'References NOT FOUND for model: ', model_ name136 print 'References NOT FOUND for model: ', model_info['id'] 107 137 print '------------------------------------------------------------------' 108 138 docstr = docstr + captionstr -
example/sesans_parameters_css-hs.py
ra98958b r84db7a5 8 8 # Enter the model name to use 9 9 model_name = "core_shell_sphere*hardsphere" 10 11 # DO NOT MODIFY THIS LINE 12 model = sesansfit.get_bumps_model(model_name) 10 13 11 14 # Enter any custom parameters … … 19 22 # Initial parameter values (if other than defaults) 20 23 initial_vals = { 21 "scale" : 0.09,22 24 "core_sld" : 1.0592, 23 25 "solvent_sld" : 2.88, 24 "shell_sld" : 2.88,25 26 "radius" : 890, 26 "thickness" : 130, 27 "volfraction" : 0.45 27 "thickness" : 130 28 28 } 29 29 … … 36 36 } 37 37 38 # Constraints 39 # model.param_name = f(other params) 40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 41 # a custom parameter 42 model.scale = phi*(1-phi) 43 model.volfraction = phi 44 model.shell_sld = pen*2.88 45 38 46 # Send to the fitting engine 39 47 problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) -
example/sesans_parameters_sphere.py
ra98958b r84db7a5 9 9 model_name = "sphere" 10 10 11 # DO NOT MODIFY THIS LINE 12 model = sesansfit.get_bumps_model(model_name) 13 11 14 # Enter any custom parameters 15 # name = Parameter(initial_value, name='name') 12 16 phi = Parameter(0.10, name='phi') 17 # Add the parameters to this list that should be displayed in the fitting window 13 18 custom_params = {"phi" : phi} 14 19 15 # SESANS data file 20 # SESANS data file name 16 21 sesans_file = "sphere.ses" 17 22 18 23 # Initial parameter values (if other than defaults) 24 # "model_parameter_name" : value 19 25 initial_vals = { 20 "scale" : phi*(1 - phi),21 26 "sld" : 7.0, 27 "radius" : 1000, 22 28 "solvent_sld" : 1.0, 23 "radius" : 1000,24 29 } 25 30 26 31 # Ranges for parameters if other than default 32 # "model_parameter_name" : [min, max] 27 33 param_range = { 28 34 "phi" : [0.001, 0.5], … … 30 36 } 31 37 38 # Constraints 39 # model.param_name = f(other params) 40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius and scale are model functions and phi is 41 # a custom parameter 42 model.scale = phi*(1-phi) 43 32 44 # Send to the fitting engine 33 problem = sesansfit.sesans_fit(sesans_file, model_name, initial_vals, custom_params, param_range) 45 # DO NOT MODIFY THIS LINE 46 problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 47 -
example/sesansfit.py
ra98958b r84db7a5 1 #TODO: Convert units properly (nm -> A)2 #TODO: Implement constraints3 4 1 from bumps.names import * 5 from sasmodels import core, bumps_model 2 from sasmodels import core, bumps_model, sesans 6 3 7 4 HAS_CONVERTER = True … … 11 8 HAS_CONVERTER = False 12 9 13 def sesans_fit(file, model_name, initial_vals={}, custom_params={}, param_range=[]): 10 def get_bumps_model(model_name): 11 kernel = core.load_model(model_name) 12 model = bumps_model.Model(kernel) 13 return model 14 15 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[]): 14 16 """ 15 16 17 @param file: SESANS file location 17 @param model _name: model name string- can be model, model_1 * model_2, and/or model_1 + model_218 @param model: Bumps model object or model name - can be model, model_1 * model_2, and/or model_1 + model_2 18 19 @param initial_vals: dictionary of {param_name : initial_value} 19 20 @param custom_params: dictionary of {custom_parameter_name : Parameter() object} 20 21 @param param_range: dictionary of {parameter_name : [minimum, maximum]} 22 @param constraints: dictionary of {parameter_name : constraint} 21 23 @return: FitProblem for Bumps usage 22 24 """ … … 29 31 default_unit = "A" 30 32 data_conv_q = Converter(data._xunit) 33 for x in data.x: 34 print x 31 35 data.x = data_conv_q(data.x, units=default_unit) 36 for x in data.x: 37 print x 32 38 data._xunit = default_unit 33 39 … … 51 57 data = SESANSData1D() 52 58 53 radius = 1000 59 if "radius" in initial_vals: 60 radius = initial_vals.get("radius") 61 else: 62 radius = 1000 54 63 data.Rmax = 3*radius # [A] 55 64 56 kernel = core.load_model(model_name)57 model = bumps_model.Model(kernel)65 if isinstance(model, basestring): 66 model = get_bumps_model(model) 58 67 59 # Load custom parameters, initial values and parameter constraints68 # Load custom parameters, initial values and parameter ranges 60 69 for k, v in custom_params.items(): 61 70 setattr(model, k, v) … … 69 78 setattr(param.bounds, "limits", v) 70 79 71 if False: # have sans data80 if False: # for future implementation 72 81 M_sesans = bumps_model.Experiment(data=data, model=model) 73 82 M_sans = bumps_model.Experiment(data=sans_data, model=model) -
example/sesansfit.sh
r15bd6e7 rbdb653c 8 8 set -x 9 9 10 python w-m bumps.cli $*10 python -m bumps.cli $* -
explore/J1c.py
r0a6da3c rcbd37a7 9 9 10 10 11 SHOW_DIFF = True # True if show diff rather than function value 11 SHOW_DIFF = True # True if show diff rather than function value 12 #SHOW_DIFF = False # True if show diff rather than function value 12 13 LINEAR_X = False # True if q is linearly spaced instead of log spaced 14 #LINEAR_X = True # True if q is linearly spaced instead of log spaced 15 FUNCTION = "2*J1(x)/x" 13 16 14 def mp_ J1c(vec, bits=500):17 def mp_fn(vec, bits=500): 15 18 """ 16 19 Direct calculation using sympy multiprecision library. 17 20 """ 18 21 with mp.workprec(bits): 19 return [_mp_ J1c(mp.mpf(x)) for x in vec]22 return [_mp_fn(mp.mpf(x)) for x in vec] 20 23 21 def _mp_ J1c(x):24 def _mp_fn(x): 22 25 """ 23 Helper funciton for mp_j1c26 Actual function that gets evaluated. The caller just vectorizes. 24 27 """ 25 28 return mp.mpf(2)*mp.j1(x)/x 26 29 27 def np_ J1c(x, dtype):30 def np_fn(x, dtype): 28 31 """ 29 32 Direct calculation using scipy. … … 33 36 return np.asarray(2, dtype)*J1(x)/x 34 37 35 def cephes_J1c(x, dtype, n):38 def sasmodels_fn(x, dtype, platform='ocl'): 36 39 """ 37 40 Calculation using pade approximant. 38 41 """ 39 f = np.float64 if np.dtype(dtype) == np.float64 else np.float32 40 x = np.asarray(x, dtype) 41 ans = np.empty_like(x) 42 ax = abs(x) 43 44 # Branch a 45 a_idx = ax < f(8.0) 46 a_xsq = x[a_idx]**2 47 a_coeff1 = list(reversed((72362614232.0, -7895059235.0, 242396853.1, -2972611.439, 15704.48260, -30.16036606))) 48 a_coeff2 = list(reversed((144725228442.0, 2300535178.0, 18583304.74, 99447.43394, 376.9991397, 1.0))) 49 a_ans1 = np.polyval(np.asarray(a_coeff1[n:], dtype), a_xsq) 50 a_ans2 = np.polyval(np.asarray(a_coeff2[n:], dtype), a_xsq) 51 ans[a_idx] = f(2.0)*a_ans1/a_ans2 52 53 # Branch b 54 b_idx = ~a_idx 55 b_ax = ax[b_idx] 56 b_x = x[b_idx] 57 58 b_y = f(64.0)/(b_ax**2) 59 b_xx = b_ax - f(2.356194491) 60 b_coeff1 = list(reversed((1.0, 0.183105e-2, -0.3516396496e-4, 0.2457520174e-5, -0.240337019e-6))) 61 b_coeff2 = list(reversed((0.04687499995, -0.2002690873e-3, 0.8449199096e-5, -0.88228987e-6, 0.105787412e-6))) 62 b_ans1 = np.polyval(np.asarray(b_coeff1[n:], dtype),b_y) 63 b_ans2 = np.polyval(np.asarray(b_coeff2[n:], dtype), b_y) 64 b_sn, b_cn = np.sin(b_xx), np.cos(b_xx) 65 ans[b_idx] = np.sign(b_x)*np.sqrt(f(0.636619772)/b_ax) * (b_cn*b_ans1 - (f(8.0)/b_ax)*b_sn*b_ans2)*f(2.0)/b_x 66 67 return ans 68 69 def div_J1c(x, dtype): 70 f = np.float64 if np.dtype(dtype) == np.float64 else np.float32 71 x = np.asarray(x, dtype) 72 return f(2.0)*np.asarray([_J1(xi, f)/xi for xi in x], dtype) 73 74 def _J1(x, f): 75 ax = abs(x) 76 if ax < f(8.0): 77 y = x*x 78 ans1 = x*(f(72362614232.0) 79 + y*(f(-7895059235.0) 80 + y*(f(242396853.1) 81 + y*(f(-2972611.439) 82 + y*(f(15704.48260) 83 + y*(f(-30.16036606))))))) 84 ans2 = (f(144725228442.0) 85 + y*(f(2300535178.0) 86 + y*(f(18583304.74) 87 + y*(f(99447.43394) 88 + y*(f(376.9991397) 89 + y))))) 90 return ans1/ans2 91 else: 92 y = f(64.0)/(ax*ax) 93 xx = ax - f(2.356194491) 94 ans1 = (f(1.0) 95 + y*(f(0.183105e-2) 96 + y*(f(-0.3516396496e-4) 97 + y*(f(0.2457520174e-5) 98 + y*f(-0.240337019e-6))))) 99 ans2 = (f(0.04687499995) 100 + y*(f(-0.2002690873e-3) 101 + y*(f(0.8449199096e-5) 102 + y*(f(-0.88228987e-6) 103 + y*f(0.105787412e-6))))) 104 sn, cn = np.sin(xx), np.cos(xx) 105 ans = np.sqrt(f(0.636619772)/ax) * (cn*ans1 - (f(8.0)/ax)*sn*ans2) 106 return -ans if (x < f(0.0)) else ans 42 from sasmodels import core, data, direct_model 43 model = core.load_model('bessel', dtype=dtype) 44 calculator = direct_model.DirectModel(data.empty_data1D(x), model) 45 return calculator(background=0) 107 46 108 47 def plotdiff(x, target, actual, label): … … 113 52 """ 114 53 if SHOW_DIFF: 115 err = np.clip(abs((target-actual)/target), 0, 1) 54 err = abs((target-actual)/target) 55 #err = np.clip(err, 0, 1) 116 56 pylab.loglog(x, err, '-', label=label) 117 57 else: … … 119 59 pylab.semilogx(x, np.clip(actual,*limits), '-', label=label) 120 60 121 def compare(x, precision ):61 def compare(x, precision, target): 122 62 r""" 123 63 Compare the different computation methods using the given precision. 124 64 """ 125 target = np.asarray(mp_J1c(x), 'double') 126 #plotdiff(x, target, mp_J1c(x, 11), 'mp 11 bits') 127 plotdiff(x, target, np_J1c(x, precision), 'direct '+precision) 128 plotdiff(x, target, cephes_J1c(x, precision, 0), 'cephes '+precision) 129 #plotdiff(x, target, cephes_J1c(x, precision, 1), 'cephes '+precision) 130 #plotdiff(x, target, div_J1c(x, precision), 'cephes 2 J1(x)/x '+precision) 65 #plotdiff(x, target, mp_fn(x, 11), 'mp 11 bits') 66 plotdiff(x, target, np_fn(x, precision), 'numpy '+precision) 67 plotdiff(x, target, sasmodels_fn(x, precision, 0), 'sasmodels '+precision) 131 68 pylab.xlabel("qr (1/Ang)") 132 69 if SHOW_DIFF: 133 70 pylab.ylabel("relative error") 134 71 else: 135 pylab.ylabel( "2 J1(x)/x")72 pylab.ylabel(FUNCTION) 136 73 pylab.semilogx(x, target, '-', label="true value") 137 74 if LINEAR_X: … … 147 84 else: 148 85 qr = np.logspace(-3,5,400) 86 target = np.asarray(mp_fn(qr), 'double') 149 87 pylab.subplot(121) 150 compare(qr, 'single' )88 compare(qr, 'single', target) 151 89 pylab.legend(loc='best') 152 90 pylab.subplot(122) 153 compare(qr, 'double' )91 compare(qr, 'double', target) 154 92 pylab.legend(loc='best') 155 pylab.suptitle( '2 J1(x)/x')93 pylab.suptitle(FUNCTION) 156 94 157 95 if __name__ == "__main__": -
sasmodels/convert.py
r228cbd3 r78d3341 72 72 new model definition end with sld. 73 73 """ 74 return dict((p, (v*1e-6 if p. endswith('sld')74 return dict((p, (v*1e-6 if p.startswith('sld') or p.endswith('sld') 75 75 else v*1e15 if 'ndensity' in p 76 76 else v)) -
sasmodels/data.py
r7824276 rc094758 178 178 self.qy_data, self.dqy_data = y, dy 179 179 self.data, self.err_data = z, dz 180 self.mask = ( ~np.isnan(z) if z is not None181 else np. ones_like(x) if x is not None180 self.mask = (np.isnan(z) if z is not None 181 else np.zeros_like(x, dtype='bool') if x is not None 182 182 else None) 183 183 self.q_data = np.sqrt(x**2 + y**2) … … 440 440 441 441 if use_data or use_theory: 442 is_tof = np.any(data.lam!=data.lam[0]) 442 443 if num_plots > 1: 443 444 plt.subplot(1, num_plots, 1) 444 445 if use_data: 445 plt.errorbar(data.x, data.y, yerr=data.dy) 446 if is_tof: 447 plt.errorbar(data.x, np.log(data.y)/(data.lam*data.lam), yerr=data.dy/data.y/(data.lam*data.lam)) 448 else: 449 plt.errorbar(data.x, data.y, yerr=data.dy) 446 450 if theory is not None: 447 plt.plot(data.x, theory, '-', hold=True) 451 if is_tof: 452 plt.plot(data.x, np.log(theory)/(data.lam*data.lam), '-', hold=True) 453 else: 454 plt.plot(data.x, theory, '-', hold=True) 448 455 if limits is not None: 449 456 plt.ylim(*limits) 450 plt.xlabel('spin echo length (nm)') 451 plt.ylabel('polarization (P/P0)') 457 458 plt.xlabel('spin echo length ({})'.format(data._xunit)) 459 if is_tof: 460 plt.ylabel('(Log (P/P$_0$))/$\lambda^2$') 461 else: 462 plt.ylabel('polarization (P/P0)') 463 452 464 453 465 if resid is not None: … … 455 467 plt.subplot(1, num_plots, (use_data or use_theory) + 1) 456 468 plt.plot(data.x, resid, 'x') 457 plt.xlabel('spin echo length ( nm)')469 plt.xlabel('spin echo length ({})'.format(data._xunit)) 458 470 plt.ylabel('residuals (P/P0)') 459 471 -
sasmodels/generate.py
rfcd7bbd r78d3341 91 91 in *Iqxy* and *Imagnetic*. "magnetic* parameters will be used in 92 92 *Imagnetic* only. If *type* is the empty string, the parameter will 93 be used in all of *Iq*, *Iqxy* and *Imagnetic*. 93 be used in all of *Iq*, *Iqxy* and *Imagnetic*. "sld" parameters 94 can automatically be promoted to magnetic parameters, each of which 95 will have a magnitude and a direction, which may be different from 96 other sld parameters. 94 97 95 98 *description* is a short description of the parameter. This will … … 216 219 import re 217 220 import string 221 import warnings 218 222 from collections import namedtuple 219 223 … … 604 608 """ 605 609 partype = { 606 'volume': [], 'orientation': [], 'magnetic': [], ' ': [],610 'volume': [], 'orientation': [], 'magnetic': [], 'sld': [], '': [], 607 611 'fixed-1d': [], 'fixed-2d': [], 'pd-1d': [], 'pd-2d': [], 608 612 'pd-rel': set(), … … 618 622 elif p.type == 'orientation': 619 623 partype['pd-2d'].append(p.name) 620 elif p.type == '':624 elif p.type in ('', 'sld'): 621 625 partype['fixed-1d'].append(p.name) 622 626 partype['fixed-2d'].append(p.name) … … 632 636 """ 633 637 # convert parameters into named tuples 638 for p in model_info['parameters']: 639 if p[4] == '' and (p[0].startswith('sld') or p[0].endswith('sld')): 640 p[4] = 'sld' 641 # TODO: make sure all models explicitly label their sld parameters 642 #raise ValueError("%s.%s needs to be explicitly set to type 'sld'" %(model_info['id'], p[0])) 643 634 644 pars = [Parameter(*p) for p in model_info['parameters']] 635 645 # Fill in the derived attributes -
sasmodels/kernelcl.py
r17bbadd rc094758 367 367 self.q_vectors = [_stretch_input(q, self.dtype, 32) for q in q_vectors] 368 368 context = env.get_context(self.dtype) 369 self.global_size = [self.q_vectors[0].size] 370 #print("creating inputs of size", self.global_size) 369 371 self.q_buffers = [ 370 372 cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=q) 371 373 for q in self.q_vectors 372 374 ] 373 self.global_size = [self.q_vectors[0].size]374 375 375 376 def release(self): -
sasmodels/models/adsorbed_layer.py
r54954e1 rf10bc52 89 89 background = 'background') 90 90 91 # these unit test values taken from SasView 3.1.2 91 92 tests = [ 92 93 [{'scale': 1.0, 'second_moment': 23.0, 'adsorbed_amount': 1.9, -
sasmodels/models/mono_gauss_coil.py
r15bd6e7 rf10bc52 86 86 background = 'background') 87 87 88 # these unit test values taken from SasView 3.1.2 88 89 tests = [ 89 [{'scale': 70.0, 'radius_gyration': 75.0, 'background': 0.0},90 [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'background': 0.0}, 90 91 [0.0106939, 0.469418], [57.1241, 0.112859]], 91 92 ] -
sasmodels/models/poly_gauss_coil.py
r15bd6e7 r09b84ed 50 50 """ 51 51 52 from numpy import inf, sqrt, power52 from numpy import inf, sqrt, exp, power 53 53 54 54 name = "poly_gauss_coil" … … 69 69 def Iq(q, i_zero, radius_gyration, polydispersity): 70 70 # pylint: disable = missing-docstring 71 # need to trap the case of the polydispersity being 1 (ie, monodispersity)72 71 u = polydispersity - 1.0 73 if polydispersity == 1:74 minusoneonu = -1.0 / u75 else:76 minusoneonu = -1.0 / u77 72 z = ((q * radius_gyration) * (q * radius_gyration)) / (1.0 + 2.0 * u) 78 73 if (q == 0).any(): 79 inten = i_zero74 inten = i_zero 80 75 else: 81 inten = i_zero * 2.0 * (power((1.0 + u * z),minusoneonu) + z - 1.0 ) / ((1.0 + u) * (z * z)) 76 # need to trap the case of the polydispersity being 1 (ie, monodispersity!) 77 if polydispersity == 1: 78 inten = i_zero * 2.0 * (exp(-z) + z - 1.0 ) / (z * z) 79 else: 80 minusoneonu = -1.0 / u 81 inten = i_zero * 2.0 * (power((1.0 + u * z),minusoneonu) + z - 1.0 ) / ((1.0 + u) * (z * z)) 82 82 return inten 83 Iq.vectorized = True # Iq accepts an array of q values83 #Iq.vectorized = True # Iq accepts an array of q values 84 84 85 85 def Iqxy(qx, qy, *args): … … 100 100 background = 'background') 101 101 102 # these unit test values taken from SasView 3.1.2 102 103 tests = [ 103 [{'scale': 70.0, 'radius_gyration': 75.0, 'polydispersity': 2.0, 'background': 0.0},104 [{'scale': 1.0, 'i_zero': 70.0, 'radius_gyration': 75.0, 'polydispersity': 2.0, 'background': 0.0}, 104 105 [0.0106939, 0.469418], [57.6405, 0.169016]], 105 106 ] -
sasmodels/product.py
rfcd7bbd r3bcd03d 18 18 SCALE=0 19 19 BACKGROUND=1 20 EFFECT_RADIUS=220 RADIUS_EFFECTIVE=2 21 21 VOLFRACTION=3 22 22 … … 31 31 assert s_pars[BACKGROUND].name == 'background' 32 32 # We require structure factors to start with effect radius and volfraction 33 assert s_pars[ EFFECT_RADIUS].name == 'effect_radius'33 assert s_pars[RADIUS_EFFECTIVE].name == 'radius_effective' 34 34 assert s_pars[VOLFRACTION].name == 'volfraction' 35 35 # Combine the parameter sets. We are skipping the first three
Note: See TracChangeset
for help on using the changeset viewer.