Changeset a42fec0 in sasmodels
- Timestamp:
- Aug 4, 2014 5:20:07 PM (10 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:
- 8cdb9f1
- Parents:
- 099e053
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
Kernel/Kernel-CapCyl.cpp
r099e053 ra42fec0 42 42 answer/=sin(alpha); 43 43 44 _ptvalue[i] = rad_cyl_weight*length_weight*rad_cap_weight*theta_weight*phi_weight*vol_i*answer;44 _ptvalue[i] += rad_cyl_weight*length_weight*rad_cap_weight*theta_weight*phi_weight*vol_i*answer; 45 45 // if (size>1) { 46 46 // _ptvalue[i] *= fabs(cos(thet*pi/180.0)); -
Kernel/Kernel-CoreShellCylinder.cpp
r099e053 ra42fec0 44 44 answer *= answer/(pi*(radius+thickness)*(radius+thickness)*(length+2.0*thickness))*1.0e8*scale; 45 45 46 _ptvalue[i] = radius_weight*length_weight*thickness_weight*theta_weight*phi_weight*answer*pow(radius+thickness,2)*(length+2.0*thickness);46 _ptvalue[i] += radius_weight*length_weight*thickness_weight*theta_weight*phi_weight*answer*pow(radius+thickness,2)*(length+2.0*thickness); 47 47 // if (size>1) { 48 48 // _ptvalue[i] *= fabs(cos(axis_theta*pi/180.0)); -
Kernel/Kernel-Cylinder.cpp
r099e053 ra42fec0 42 42 real answer = sub*sub*form*acos(-1.0)*rr*rr*h*1.0e8*scale; 43 43 44 _ptvalue[i] = radius_weight*length_weight*theta_weight*phi_weight*answer*pow(rr,2)*h; 44 _ptvalue[i] += radius_weight*length_weight*theta_weight*phi_weight*answer*pow(rr,2)*h; 45 45 46 // if (size>1) { 46 47 // _ptvalue[i] *= fabs(cos(cyl_theta*pi/180.0)); -
Kernel/Kernel-Ellipse.cpp
r099e053 ra42fec0 20 20 ret*=ret*9.0*sub*sub*4.0/3.0*acos(-1.0)*radius_b*radius_b*radius_a*scale*(1.0e8); 21 21 22 _ptvalue[i] = radius_a_weight*radius_b_weight*axis_theta_weight*radius_a*axis_phi_weight*ret*pow(radius_b, 2);22 _ptvalue[i] += radius_a_weight*radius_b_weight*axis_theta_weight*radius_a*axis_phi_weight*ret*pow(radius_b, 2); 23 23 //if(size > 1){ 24 24 // _ptvalue[i] *= fabs(cos(axis_theta*pi/180.0)); -
Kernel/Kernel-TriaxialEllipse.cpp
r099e053 ra42fec0 32 32 answer*=answer*sub*sub*4.0*pi/3.0*axisA*axisB*axisC*1.0e8*scale; 33 33 34 _ptvalue[i] = axisA_weight*axisB_weight*axisC_weight*theta_weight*phi_weight*psi_weight*answer*axisA*axisB*axisC;34 _ptvalue[i] += axisA_weight*axisB_weight*axisC_weight*theta_weight*phi_weight*psi_weight*answer*axisA*axisB*axisC; 35 35 // if (size>1) 36 36 // _ptvalue[i] *= fabs(cos(theta*pi/180.0)); -
Models/code_capcyl.py
rca6c007 ra42fec0 3 3 4 4 import numpy as np 5 from math import asin,sqrt, fabs, atan5 from math import sqrt, fabs, atan 6 6 import pyopencl as cl 7 7 8 8 from weights import GaussianDispersion 9 from sasmodel import card 9 from sasmodel import card, set_precision 10 10 11 11 12 def set_precision(src, qx, qy, dtype):13 qx = np.ascontiguousarray(qx, dtype=dtype)14 qy = np.ascontiguousarray(qy, dtype=dtype)15 if np.dtype(dtype) == np.dtype('float32'):16 header = """\17 #define real float18 """19 else:20 header = """\21 #pragma OPENCL EXTENSION cl_khr_fp64: enable22 #define real double23 """24 return header+src, qx, qy25 12 26 13 class GpuCapCylinder(object): … … 50 37 51 38 _ctx,queue = card() 39 self.res[:] = 0 40 cl.enqueue_copy(queue, self.res_b, self.res) 52 41 rad_cyl,length,rad_cap,theta,phi = \ 53 42 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 79 68 real(rad_cyl.weight[i]), real(length.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size)) 80 69 81 cl.enqueue_copy(queue, self.res, self.res_b)82 83 sum += self.res84 70 vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*vol_i 85 71 norm_vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m] 86 72 norm += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l] 87 73 88 if size > 1: 89 norm /= asin(1.0) 90 74 #if size > 1: 75 # norm /= asin(1.0) 76 cl.enqueue_copy(queue, self.res, self.res_b) 77 sum += self.res 91 78 if vol != 0.0 and norm_vol != 0.0: 92 79 sum *= norm_vol/vol -
Models/code_coreshellcyl.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 11 def set_precision(src, qx, qy, dtype): 12 qx = np.ascontiguousarray(qx, dtype=dtype) 13 qy = np.ascontiguousarray(qy, dtype=dtype) 14 if np.dtype(dtype) == np.dtype('float32'): 15 header = """\ 16 #define real float 17 """ 18 else: 19 header = """\ 20 #pragma OPENCL EXTENSION cl_khr_fp64: enable 21 #define real double 22 """ 23 return header+src, qx, qy 8 from sasmodel import card, set_precision 24 9 25 10 class GpuCoreShellCylinder(object): … … 46 31 47 32 _ctx,queue = card() 33 self.res[:] = 0 34 cl.enqueue_copy(queue, self.res_b, self.res) 48 35 radius, length, thickness, axis_phi, axis_theta = [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) 49 36 for base in GpuCoreShellCylinder.PD_PARS] … … 56 43 57 44 sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 58 59 print radius.value60 print thickness.weight61 print axis_phi.weight62 print axis_theta.weight63 print length.value64 65 45 size = len(axis_theta.weight) 66 46 … … 79 59 real(pars['shell_sld']), real(pars['solvent_sld']),np.uint32(size), 80 60 np.uint32(self.qx.size)) 81 cl.enqueue_copy(queue, self.res, self.res_b)82 83 sum += self.res84 61 vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ 85 62 *(length.value[l]+2.0*thickness.value[th]) … … 90 67 #if size>1: 91 68 # norm /= math.asin(1.0) 69 cl.enqueue_copy(queue, self.res, self.res_b) 70 sum = self.res 92 71 if vol != 0.0 and norm_vol != 0.0: 93 72 sum *= norm_vol/vol -
Models/code_cylinder.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 8 from sasmodel import card, set_precision, set_precision_1d 9 9 10 11 def set_precision(src, qx, qy, dtype):12 qx = np.ascontiguousarray(qx, dtype=dtype)13 qy = np.ascontiguousarray(qy, dtype=dtype)14 if np.dtype(dtype) == np.dtype('float32'):15 header = """\16 #define real float17 """18 else:19 header = """\20 #pragma OPENCL EXTENSION cl_khr_fp64: enable21 #define real double22 """23 return header+src, qx, qy24 25 def set_precision_1d(src, q, dtype):26 q = np.ascontiguousarray(q, dtype=dtype)27 if np.dtype(dtype) == np.dtype('float32'):28 header = """\29 #define real float30 """31 else:32 header = """\33 #pragma OPENCL EXTENSION cl_khr_fp64: enable34 #define real double35 """36 return header+src, q37 10 38 11 class GpuCylinder(object): … … 55 28 self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) 56 29 self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) 57 self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY,qx.nbytes)30 self.res_b = cl.Buffer(ctx, cl.mem_flags.READ_WRITE, self.qx.nbytes) 58 31 self.res = np.empty_like(self.qx) 59 32 … … 61 34 62 35 _ctx,queue = card() 36 self.res[:] = 0 37 cl.enqueue_copy(queue, self.res_b, self.res) 63 38 radius, length, cyl_theta, cyl_phi = \ 64 39 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 68 43 radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True) 69 44 length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True) 70 cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], - 90, 180, False)71 cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], - 90, 180, False)45 cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], -np.inf, np.inf, False) 46 cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], -np.inf, np.inf, False) 72 47 73 48 #Perform the computation, with all weight points … … 87 62 real(cyl_phi.weight[l]), real(cyl_theta.value[k]), real(cyl_phi.value[l]), 88 63 np.uint32(self.qx.size), np.uint32(size)) 89 cl.enqueue_copy(queue, self.res, self.res_b) 90 sum += self.res 64 91 65 vol += radius.weight[i]*length.weight[j]*pow(radius.value[i], 2)*length.value[j] 92 66 norm_vol += radius.weight[i]*length.weight[j] … … 95 69 # if size > 1: 96 70 # norm /= math.asin(1.0) 71 cl.enqueue_copy(queue, self.res, self.res_b) 72 sum = self.res 97 73 if vol != 0.0 and norm_vol != 0.0: 98 74 sum *= norm_vol/vol -
Models/code_ellipse.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 11 def set_precision(src, qx, qy, dtype): 12 qx = np.ascontiguousarray(qx, dtype=dtype) 13 qy = np.ascontiguousarray(qy, dtype=dtype) 14 if np.dtype(dtype) == np.dtype('float32'): 15 header = """\ 16 #define real float 17 """ 18 else: 19 header = """\ 20 #pragma OPENCL EXTENSION cl_khr_fp64: enable 21 #define real double 22 """ 23 return header+src, qx, qy 8 from sasmodel import card, set_precision 24 9 25 10 class GpuEllipse(object): … … 46 31 #b_n = radius_b # want, a_n = radius_a # want, etc 47 32 _ctx,queue = card() 33 self.res[:] = 0 34 cl.enqueue_copy(queue, self.res_b, self.res) 48 35 radius_a, radius_b, axis_theta, axis_phi = \ 49 36 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 76 63 real(axis_phi.value[l]), self.qx_b, self.qy_b, self.res_b, 77 64 np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) 78 #copy result back from buffer 79 cl.enqueue_copy(queue, self.res, self.res_b) 80 sum += self.res 65 81 66 vol += radius_a.weight[i]*radius_b.weight[j]*pow(radius_b.value[j], 2)*radius_a.value[i] 82 67 norm_vol += radius_a.weight[i]*radius_b.weight[j] … … 88 73 # if size > 1: 89 74 # norm /= math.asin(1.0) 75 cl.enqueue_copy(queue, self.res, self.res_b) 76 sum += self.res 90 77 if vol != 0.0 and norm_vol != 0.0: 91 78 sum *= norm_vol/vol -
Models/code_lamellar.py
rca6c007 ra42fec0 5 5 import pyopencl as cl 6 6 from Models.weights import GaussianDispersion 7 8 def set_precision(src, qx, qy, dtype): 9 qx = np.ascontiguousarray(qx, dtype=dtype) 10 qy = np.ascontiguousarray(qy, dtype=dtype) 11 if dtype == 'double': 12 header = """\ 13 #define real float 14 """ 15 else: 16 header = """\ 17 #pragma OPENCL EXTENSION cl_khr_fp64: enable 18 #define real double 19 """ 20 return header+src, qx, qy 7 from sasmodel import set_precision 21 8 22 9 -
Models/code_triaxialellipse.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 11 def set_precision(src, qx, qy, dtype): 12 qx = np.ascontiguousarray(qx, dtype=dtype) 13 qy = np.ascontiguousarray(qy, dtype=dtype) 14 if np.dtype(dtype) == np.dtype('float32'): 15 header = """\ 16 #define real float 17 """ 18 else: 19 header = """\ 20 #pragma OPENCL EXTENSION cl_khr_fp64: enable 21 #define real double 22 """ 23 return header+src, qx, qy 8 from sasmodel import card, set_precision 24 9 25 10 class GpuTriEllipse: … … 45 30 46 31 _ctx,queue = card() 32 self.res[:] = 0 33 cl.enqueue_copy(queue, self.res_b, self.res) 47 34 axisA, axisB, axisC, theta, phi, psi = \ 48 35 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 72 59 real(axisA.weight[a]), real(axisB.weight[b]), real(axisC.weight[c]), real(psi.weight[s]), 73 60 real(phi.weight[i]), real(theta.weight[t]), np.uint32(self.qx.size), np.uint32(size)) 74 cl.enqueue_copy(queue, self.res, self.res_b)75 sum += self.res76 61 77 62 vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*axisA.value[a]*axisB.value[b]*axisC.value[c] … … 81 66 # if size > 1: 82 67 # norm /= asin(1.0) 83 68 cl.enqueue_copy(queue, self.res, self.res_b) 69 sum = self.res 84 70 if vol != 0.0 and norm_vol != 0.0: 85 71 sum *= norm_vol/vol -
Models/weights.py
rdbb0048 ra42fec0 19 19 sigma = width * center if relative else width 20 20 if sigma == 0: 21 return np.array([center ,1.], 'd')21 return np.array([center],'d'), np.array([1.], 'd') 22 22 x = center + np.linspace(-nsigmas * sigma, +nsigmas * sigma, npts) 23 23 x = x[(x >= min) & (x <= max)] -
Testers/test.py
r099e053 ra42fec0 1 impor 2 3 4 5 1 6 import numpy as np 2 7 … … 12 17 13 18 print sum 19 -
compare.py
r473183c ra42fec0 4 4 import datetime 5 5 6 from Models.sasmodel import SasModel, load_data, set_beam_stop, plot_data6 from sasmodel import SasModel, load_data, set_beam_stop, plot_data 7 7 8 8 … … 46 46 if len(sys.argv) > 1: 47 47 N = int(sys.argv[1]) 48 data = load_data(' JUN03289.DAT')48 data = load_data('December/DEC07098.DAT') 49 49 set_beam_stop(data, 0.004) 50 50 51 dtype = "float" 51 52 pars = dict( 52 scale=1, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=0, 53 cyl_theta=0, cyl_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,length_pd=0.1, 54 length_pd_n=5, length_pd_nsigma=3, cyl_theta_pd=0.1, cyl_theta_pd_n=5, cyl_theta_pd_nsigma=3, 53 scale=.08, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=.1, 54 cyl_theta=0, cyl_phi=0, 55 radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3, 56 length_pd=0.1,length_pd_n=5, length_pd_nsigma=3, 57 cyl_theta_pd=0.1, cyl_theta_pd_n=5, cyl_theta_pd_nsigma=3, 55 58 cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3, 56 59 ) … … 62 65 cpu_time = toc()*1000./N 63 66 64 from code_cylinder import GpuCylinder 67 68 from Models.code_cylinder import GpuCylinder 65 69 model = SasModel(data, GpuCylinder, dtype='f', **pars) 66 70 tic() … … 69 73 gpu_time = toc()*1000./N 70 74 75 print "gpu/cpu", max(gpu/cpu) 76 cpu *= max(gpu/cpu) 71 77 relerr = (gpu - cpu)/cpu 72 78 print "max(|(ocl-omp)/ocl|)", max(abs(relerr)) … … 76 82 plt.subplot(131); plot_data(data, cpu); plt.title("omp t=%.1f ms"%cpu_time) 77 83 plt.subplot(132); plot_data(data, gpu); plt.title("ocl t=%.1f ms"%gpu_time) 78 plt.subplot(133); plot_data(data, 1e8*relerr); plt.title("relerr x 10^8"); plt.colorbar()84 plt.subplot(133); plot_data(data, relerr); plt.title("relerr x 10^8"); plt.colorbar() 79 85 plt.show() 80 86 … … 85 91 if len(sys.argv) > 1: 86 92 N = int(sys.argv[1]) 87 data = load_data('DEC071 33.DAT')93 data = load_data('DEC07106.DAT') 88 94 set_beam_stop(data, 0.004) 89 95 … … 99 105 cpu_time = toc()*1000./N 100 106 101 from code_ellipse import GpuEllipse107 from Models.code_ellipse import GpuEllipse 102 108 model = SasModel(data, GpuEllipse, dtype='f', **pars) 103 109 tic() … … 116 122 plt.show() 117 123 118 def coreshell(N= 4):124 def coreshell(N=1): 119 125 import sys 120 126 import matplotlib.pyplot as plt … … 122 128 if len(sys.argv) > 1: 123 129 N = int(sys.argv[1]) 124 data = load_data('D EC07133.DAT')130 data = load_data('December/DEC07098.DAT') 125 131 set_beam_stop(data, 0.004) 126 132 … … 141 147 cpu_time = toc()*1000./N 142 148 143 from code_coreshellcyl import GpuCoreShellCylinder149 from Models.code_coreshellcyl import GpuCoreShellCylinder 144 150 model = SasModel(data, GpuCoreShellCylinder, dtype='f', **pars) 145 151 tic() -
fit.py
r099e053 ra42fec0 3 3 4 4 from bumps.names import * 5 from sasmodel import SasModel, load_data, set_beam_stop 5 from sasmodel import SasModel, load_data, set_beam_stop, set_half, set_top 6 6 from Models.code_capcyl import GpuCapCylinder 7 7 from Models.code_coreshellcyl import GpuCoreShellCylinder … … 13 13 """ IMPORT THE DATA USED """ 14 14 #data = load_data('December/Tangential/Sector0/DEC07133.ABS') 15 data = load_data('December/DEC07 235.DAT')15 data = load_data('December/DEC07102.DAT') 16 16 17 17 """ SET INNER BEAM STOP, OUTER RING, AND MASK HALF OF THE DATA """ 18 set_beam_stop(data, 0.0052)#, outer=0.025) 19 #set_half(data, 'left') 18 set_beam_stop(data, 0.00669)#, outer=0.025) 19 set_top(data, -.018) 20 #set_half(data, 'right') 20 21 21 22 """ … … 26 27 length=1000, 27 28 background=21, 28 sldCyl=.291e-6,sldSolv= 5.77e-6,29 sldCyl=.291e-6,sldSolv=7.105e-6, 29 30 radius_pd=0.1,radius_pd_n=10,radius_pd_nsigma=0, 30 31 length_pd=0.1,length_pd_n=5,length_pd_nsigma=0, … … 35 36 model = SasModel(data, GpuEllipse, 36 37 scale=0.08, 37 radius_a=15, radius_b= 200,38 radius_a=15, radius_b=800, 38 39 sldEll=.291e-6, sldSolv=7.105e-6, 39 40 background=0, 40 axis_theta= 0, axis_phi=0,41 axis_theta_pd= 20, axis_theta_pd_n=10, axis_theta_pd_nsigma=3,41 axis_theta=90, axis_phi=0, 42 axis_theta_pd=15, axis_theta_pd_n=40, axis_theta_pd_nsigma=3, 42 43 43 44 radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0, … … 48 49 49 50 # SET THE FITTING PARAMETERS 50 #model.radius_a.range(15, 1000)51 #model.radius_b.range(15, 1000)52 model.axis_theta_pd.range(0, 360)51 model.radius_a.range(15, 1000) 52 model.radius_b.range(15, 1000) 53 #model.axis_theta_pd.range(0, 360) 53 54 #model.background.range(0,1000) 54 55 #model.scale.range(0, 1) 55 56 """ 57 56 58 """ 57 58 59 model = SasModel(data, GpuLamellar, 59 scale=0. 70,60 bi_thick= 5,61 sld_bi= .291e-6,sld_sol=5.77e-6,62 background= 85.23,63 bi_thick_pd= 0. 0013, bi_thick_pd_n=5, bi_thick_pd_nsigma=3,60 scale=0.08, 61 bi_thick=19.2946, 62 sld_bi=5.38e-6,sld_sol=7.105e-6, 63 background=0.003, 64 bi_thick_pd= 0.37765, bi_thick_pd_n=10, bi_thick_pd_nsigma=3, 64 65 dtype='float') 65 66 66 67 # SET THE FITTING PARAMETERS 67 model.bi_thick.range(0, 1000)68 model.scale.range(0, 1)68 #model.bi_thick.range(0, 1000) 69 #model.scale.range(0, 1) 69 70 #model.bi_thick_pd.range(0, 1000) 70 71 #model.background.range(0, 1000) 72 model.sld_bi.range(0, 1) 73 71 74 """ 72 73 model = SasModel(data, GpuCylinder, 74 scale=0.08, radius=46, length=719, 75 sldCyl=.291e-6, sldSolv=5.77e-6, background=0, 76 cyl_theta=0, cyl_phi=0, 77 cyl_theta_pd=23, cyl_theta_pd_n=10, cyl_theta_pd_nsigma=3, 75 if 1: 76 model = SasModel(data, GpuCylinder, 77 scale=0.0104, 78 radius=92.5, 79 length=798.3, 80 sldCyl=.29e-6, 81 sldSolv=7.105e-6, 82 background=5, 83 cyl_theta=0, 84 cyl_phi=0, 85 cyl_theta_pd=22.11, 86 cyl_theta_pd_n=20, 87 cyl_theta_pd_nsigma=3, 88 radius_pd=.0084, 89 radius_pd_n=10, 90 radius_pd_nsigma=3, 91 length_pd=0.493, 92 length_pd_n=10, 93 length_pd_nsigma=3, 94 cyl_phi_pd=0, 95 cyl_phi_pd_n=1, 96 cyl_phi_pd_nsigma=3, 97 dtype='float') 78 98 79 99 80 radius_pd=0.1, radius_pd_n=20, radius_pd_nsigma=0,81 length_pd=0.1, length_pd_n=20, length_pd_nsigma=0,82 cyl_phi_pd=0.1, cyl_phi_pd_n=20, cyl_phi_pd_nsigma=0,83 dtype='float')84 100 85 # SET THE FITTING PARAMETERS 86 model.radius.range(0, 25) 87 #model.length.range(0, 1000) 88 #model.cyl_theta_pd.range(0,90) 89 #model.scale.range(0, 1) 90 #model.background.range(0, 1000) 101 # SET THE FITTING PARAMETERS 102 #model.radius.range(1, 500) 103 #model.length.range(1, 4000) 104 #model.cyl_theta.range(-90,100) 105 #model.cyl_theta_pd.range(0, 90) 106 #model.cyl_theta_pd_n = model.cyl_theta_pd + 5 107 #model.radius_pd.range(0, 90) 108 #model.length_pd.range(0, 90) 109 model.scale.range(0, 1) 110 #model.background.range(0, 100) 111 #model.sldCyl.range(0, 1) 91 112 92 113 93 """ 94 model = SasModel(data, GpuCoreShellCylinder,95 scale= 0.08, radius=200, thickness=30, length=2000,96 core_sld=7e-6, shell_sld=.291e-6, solvent_sld=7.105e-6,97 background=0, axis_theta=0, axis_phi=0,114 if 0: 115 model = SasModel(data, GpuCoreShellCylinder, 116 scale= .00031, radius=19.5, thickness=30, length=22, 117 core_sld=7.105e-6, shell_sld=.291e-6, solvent_sld=7.105e-6, 118 background=0.2, axis_theta=0, axis_phi=0, 98 119 99 radius_pd=0.38, radius_pd_n=10, radius_pd_nsigma=3,100 length_pd=.9, length_pd_n=10, length_pd_nsigma=3,101 thickness_pd=0.1, thickness_pd_n=1, thickness_pd_nsigma=0,102 axis_theta_pd=10, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,103 axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=0,104 dtype='float')120 radius_pd=0.26, radius_pd_n=10, radius_pd_nsigma=3, 121 length_pd=0.26, length_pd_n=10, length_pd_nsigma=3, 122 thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=1, 123 axis_theta_pd=1, axis_theta_pd_n=10, axis_theta_pd_nsigma=3, 124 axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=1, 125 dtype='float') 105 126 106 # SET THE FITTING PARAMETERS107 model.radius.range(15, 1000)108 #model.length.range(0, 1000)109 #model.thickness.range(20, 50)110 #model.axis_phi.range(0, 90)111 #model.radius_pd.range(0, 1)112 #model.radius_b_pd.range(0, 1)113 #model.axis_theta_pd.range(0, 360)114 #model.axis_phi_pd.range(0, 360)115 #model.background.range(0,1000)116 model.scale.range(0, 1)117 """ 127 # SET THE FITTING PARAMETERS 128 #model.radius.range(115, 1000) 129 #model.length.range(0, 2500) 130 #model.thickness.range(18, 38) 131 #model.thickness_pd.range(0, 1) 132 #model.axis_phi.range(0, 90) 133 #model.radius_pd.range(0, 1) 134 #model.length_pd.range(0, 1) 135 #model.axis_theta_pd.range(0, 360) 136 #model.background.range(0,5) 137 model.scale.range(0, 1) 138 118 139 119 140 … … 135 156 """ 136 157 model = SasModel(data, GpuTriEllipse, 137 scale=0.0 036, axisA=118, axisB=70, axisC=800,158 scale=0.08, axisA=15, axisB=20, axisC=500, 138 159 sldEll=7.105e-6, sldSolv=.291e-6, 139 background= 15, theta=90, phi=0, psi=0,140 theta_pd=2 2, theta_pd_n=40, theta_pd_nsigma=3,160 background=5, theta=0, phi=0, psi=0, 161 theta_pd=20, theta_pd_n=40, theta_pd_nsigma=3, 141 162 phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0, 142 163 psi_pd=30, psi_pd_n=1, psi_pd_nsigma=0, … … 150 171 #model.axisC.range(15, 1000) 151 172 #model.background.range(0,1000) 152 model.scale.range(0, 1)153 173 #model.theta_pd.range(0, 360) 154 174 #model.phi_pd.range(0, 360) -
fit2.py
r473183c ra42fec0 3 3 4 4 from bumps.names import * 5 from cylcode import GpuCylinder6 from Models.sasmodel import SasModel, load_data, set_beam_stop5 from Models.code_coreshellcyl import GpuCoreShellCylinder 6 from sasmodel import SasModel, load_data, set_beam_stop, set_top 7 7 8 8 9 radial_data = load_data('JUN03289.DAT') 10 set_beam_stop(radial_data, 0.004) 11 trans_data = load_data('JUN03305.DAT') 12 set_beam_stop(trans_data, 0.004) 9 radial_data = load_data('December/DEC07267.DAT') 10 set_beam_stop(radial_data, 0.00669, outer=0.025) 11 set_top(radial_data, -.0185) 12 13 tan_data = load_data('December/DEC07266.DAT') 14 set_beam_stop(tan_data, 0.00669, outer=0.025) 15 set_top(tan_data, -.0185) 13 16 14 17 … … 17 20 dtype='float32' 18 21 radial = SasModel(radial_data, 19 GpuCylinder, dtype=dtype, 20 scale=1, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=0, 21 cyl_theta=0, cyl_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,length_pd=0.1, 22 length_pd_n=5, length_pd_nsigma=3, cyl_theta_pd=0.1, cyl_theta_pd_n=5, cyl_theta_pd_nsigma=3, 23 cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3) 24 trans = SasModel(trans_data, 25 GpuCylinder, dtype=dtype, 22 GpuCoreShellCylinder, 23 scale= 3.75e-7, radius=378, thickness=30, length=1806, 24 core_sld=7.105e-6, shell_sld=.291e-6, solvent_sld=7.105e-6, 25 background=0.2, axis_theta=0, axis_phi=90, 26 27 radius_pd=0.26, radius_pd_n=20, radius_pd_nsigma=3, 28 length_pd=0.26, length_pd_n=20, length_pd_nsigma=3, 29 thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=0, 30 axis_theta_pd=1, axis_theta_pd_n=10, axis_theta_pd_nsigma=3, 31 axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=0, 32 dtype='float') 33 tan = SasModel(tan_data, 34 GpuCoreShellCylinder, dtype=dtype, 26 35 **radial.parameters()) 27 36 28 radial.radius.range(0,100) 29 radial.length.range(0, 1000) 30 radial.cyl_theta.range(0,90) 31 radial.cyl_phi.range(0,90) 32 radial.scale.range(0,10) 33 trans.cyl_theta = radial.cyl_theta + 90. 37 radial.radius.range(15, 1000) 38 radial.length.range(0, 2500) 39 #radial.thickness.range(18, 38) 40 #radial.thickness_pd.range(0, 1) 41 #radial.axis_phi.range(0, 90) 42 #radial.radius_pd.range(0, 1) 43 #radial.length_pd.range(0, 1) 44 #radial.axis_theta_pd.range(0, 360) 45 #radial.background.range(0,5) 46 #radial.scale.range(0, 1) 47 radial.axis_phi = tan.axis_phi + 90 34 48 35 49 36 problem = FitProblem([radial,t rans])50 problem = FitProblem([radial,tan]) 37 51 38 52 -
multi-fit.py
rd772f5d ra42fec0 3 3 4 4 from bumps.names import * 5 from code_lamellar import GpuLamellar 6 from code_ellipse import GpuEllipse 5 from Models.code_lamellar import GpuLamellar 6 from Models.code_ellipse import GpuEllipse 7 from Models.code_cylinder import GpuCylinder 7 8 from multisasmodels import SasModel, load_data, set_beam_stop, set_half 8 9 import numpy as np 9 10 10 data = load_data('D EC07282.DAT')11 data = load_data('December/DEC07238.DAT') 11 12 set_beam_stop(data, 0.0052)#, outer=0.025) 12 13 #set_half(data, 'left') 13 14 14 truth = SasModel(data, GpuEllipse, 15 scale=.0011, radius_a=45.265, radius_b=600.8, sldEll=.291e-6, sldSolv=7.105e-6, 16 background=8.30161, axis_theta=0, axis_phi=0, 17 radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0, 18 radius_b_pd=.000128, radius_b_pd_n=1, radius_b_pd_nsigma=0, 19 axis_theta_pd=20, axis_theta_pd_n=40, axis_theta_pd_nsigma=3, 20 axis_phi_pd=2.63698e-05, axis_phi_pd_n=20, axis_phi_pd_nsigma=0, 21 dtype='float') 15 truth = SasModel(data, GpuCylinder, 16 scale=0.08, radius=46, length=719, 17 sldCyl=.291e-6, sldSolv=5.77e-6, background=0, 18 cyl_theta=90, cyl_phi=0, 19 cyl_theta_pd=23, cyl_theta_pd_n=40, cyl_theta_pd_nsigma=3, 20 radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3, 21 length_pd=0.1, length_pd_n=10, length_pd_nsigma=3, 22 cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3, 23 dtype='float') 24 22 25 23 26 #model.radius_a.range(15, 1000) … … 30 33 31 34 32 lies = SasModel(data, GpuLamellar, scale=0, bi_thick=5, sld_bi=.291e-6, sld_sol=5.77e-6, background=85.23, 33 bi_thick_pd= 0.0013, bi_thick_pd_n=5, bi_thick_pd_nsigma=3, dtype='float') 35 lies = SasModel(data, GpuCylinder, 36 scale=0.08, radius=46, length=719, 37 sldCyl=.291e-6, sldSolv=5.77e-6, background=0, 38 cyl_theta=90, cyl_phi=0, 39 cyl_theta_pd=23, cyl_theta_pd_n=40, cyl_theta_pd_nsigma=3, 40 radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3, 41 length_pd=0.1, length_pd_n=10, length_pd_nsigma=3, 42 cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3, 43 dtype='float') 44 34 45 35 46 … … 43 54 44 55 45 a = np.add(np.multiply(arrayone, . 5), np.multiply(arraytwo, 0))56 a = np.add(np.multiply(arrayone, .08), np.multiply(arraytwo, .08)) 46 57 truth.set_result(a) 47 58 -
sasmodel.py
r099e053 ra42fec0 16 16 return data 17 17 18 def set_precision(src, qx, qy, dtype): 19 qx = np.ascontiguousarray(qx, dtype=dtype) 20 qy = np.ascontiguousarray(qy, dtype=dtype) 21 if np.dtype(dtype) == np.dtype('float32'): 22 header = """\ 23 #define real float 24 """ 25 else: 26 header = """\ 27 #pragma OPENCL EXTENSION cl_khr_fp64: enable 28 #define real double 29 """ 30 return header+src, qx, qy 31 32 def set_precision_1d(src, q, dtype): 33 q = np.ascontiguousarray(q, dtype=dtype) 34 if np.dtype(dtype) == np.dtype('float32'): 35 header = """\ 36 #define real float 37 """ 38 else: 39 header = """\ 40 #pragma OPENCL EXTENSION cl_khr_fp64: enable 41 #define real double 42 """ 43 return header+src, q 18 44 19 45 def set_beam_stop(data, radius, outer=None): … … 28 54 29 55 def set_half(data, half): 56 if half == 'right': 57 data.mask += Boxcut(x_min=-np.inf, x_max=0.0, y_min=-np.inf, y_max=np.inf)(data) 30 58 if half == 'left': 31 data.mask += Boxcut(x_min=-np.inf, x_max=0.0, y_min=-np.inf, y_max=np.inf)(data)32 if half == 'right':33 59 data.mask += Boxcut(x_min=0.0, x_max=np.inf, y_min=-np.inf, y_max=np.inf)(data) 34 60 35 61 def set_top(data, max): 62 data.mask += Boxcut(x_min=-np.inf, x_max=np.inf, y_min=-np.inf, y_max=max)(data) 36 63 37 64 def plot_data(data, iq, vmin=None, vmax=None): … … 69 96 plt.colorbar() 70 97 plt.subplot(1, 3, 3) 98 print abs(mresid).max() 71 99 plot_data(data, mresid) 72 100 plt.colorbar() … … 110 138 def __init__(self, data, model, dtype='float32', **kw): 111 139 self.__dict__['_parameters'] = {} 140 #self.name = data.filename 112 141 self.is2D = hasattr(data,'qx_data') 113 142 self.data = data … … 135 164 pars.update((base+'_pd_nsigma', 3) for base in model.PD_PARS) 136 165 pars.update(kw) 137 self._parameters = dict((k, Parameter.default(v, name=k)) for k, v in pars.items()) 166 for k,v in pars.items(): 167 setattr(self, k, Parameter.default(v, name=k)) 168 self._parameter_names = set(pars.keys()) 169 self.update() 170 171 def update(self): 172 self._cache = {} 138 173 139 174 def numpoints(self): … … 141 176 142 177 def parameters(self): 143 return self._parameters 144 145 def __getattr__(self, par): 146 return self._parameters[par] 147 148 def __setattr__(self, par, val): 149 if par in self._parameters: 150 self._parameters[par] = val 151 else: 152 self.__dict__[par] = val 178 return dict((k,getattr(self,k)) for k in self._parameter_names) 153 179 154 180 def theory(self): 155 pars = dict((k,v.value) for k,v in self._parameters.items()) 156 result = self.gpu.eval(pars) 157 return result 181 if 'theory' not in self._cache: 182 pars = dict((k,getattr(self,k).value) for k in self._parameter_names) 183 #print pars 184 self._cache['theory'] = self.gpu.eval(pars) 185 return self._cache['theory'] 158 186 159 187 def residuals(self): … … 178 206 pass 179 207 180 def update(self):181 pass182 183 184 208 def demo(): 185 209 data = load_data('DEC07086.DAT')
Note: See TracChangeset
for help on using the changeset viewer.