Changeset fa79f5c in sasmodels
- Timestamp:
- Nov 29, 2017 6:43:12 AM (7 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- a839b22
- Parents:
- 32398dc
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
example/sesans_parameters_sphere.py
r9217ef8 rfa79f5c 46 46 # DO NOT MODIFY THIS LINE 47 47 problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 48 -
example/sesans_sphere_2micron.py
r3330bb4 rfa79f5c 1 1 """ 2 This is a data file 2 This is a data file used to load in sesans data and fit it using the bumps engine 3 3 """ 4 4 from bumps.names import * … … 38 38 # Constraints 39 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 is41 # a custom parameter40 # EXAMPLE: model.scale = model.radius*model.radius*(1 - phi) - where radius 41 # and scale are model functions and phi is a custom parameter 42 42 model.scale = phi*(1-phi) 43 43 … … 45 45 # DO NOT MODIFY THIS LINE 46 46 problem = sesansfit.sesans_fit(sesans_file, model, initial_vals, custom_params, param_range) 47 -
example/sesansfit.py
r9217ef8 rfa79f5c 1 import logging 2 1 3 from bumps.names import * 2 4 from sasmodels import core, bumps_model, sesans … … 8 10 return model 9 11 10 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[], acceptance_angle=None): 12 def sesans_fit(file, model, initial_vals={}, custom_params={}, param_range=[], 13 acceptance_angle=None): 11 14 """ 12 15 … … 19 22 @return: FitProblem for Bumps usage 20 23 """ 24 logging.basicConfig() 25 21 26 initial_vals['background'] = 0.0 22 27 try: 23 28 loader = Loader() 24 data = loader.load(file) 25 if data is None: raise IOError("Could not load file %r"%(file)) 29 data = loader.load(file)[0] 30 if data is None: 31 raise IOError("Could not load file %r"%(file)) 26 32 27 except: 33 except Exception: 34 raise 28 35 # If no loadable data file, generate random data 29 36 SElength = np.linspace(0, 2400, 61) # [A] … … 50 57 data.Rmax = 30*radius # [A] 51 58 52 if isinstance(model, basestring):59 if isinstance(model, str): 53 60 model = get_bumps_model(model) 54 61 -
example/spheres2micron.ses
r6abf703 rfa79f5c 1 DataFileTitle Polystyrene of Markus Strobl, Full Sine, ++ only 2 Sample Polystyrene 2 um in 53% H2O, 47% D2O 3 Settings D1=D2=20x8 mm,Ds = 16x10 mm (WxH), GF1 =scanning, GF2 = 2.5 A. 2 um polystyrene in 53% H2O, 47% D2O; 8.55% contrast 4 Operator CPD 5 Date ma 7 jul 2014 18:54:43 6 ScanType sine one element scan 7 Thickness [mm] 2 8 Q_zmax [\AA^-1] 0.05 9 Q_ymax [\AA^-1] 0.05 10 11 spin echo length [nm] error SEL wavelength [nm] error wavelength polarisation error pol 12 49.778 2.4889 0.211 0.01055 0.99782 0.0044367 13 63.041 3.152 0.211 0.01055 1.0026 0.0047862 14 76.487 3.8244 0.211 0.01055 0.99601 0.0060598 15 89.847 4.4924 0.211 0.01055 0.99175 0.0058257 16 103.41 5.1705 0.211 0.01055 0.99543 0.0060966 17 116.95 5.8475 0.211 0.01055 0.99512 0.0048106 18 130.61 6.5303 0.211 0.01055 0.9975 0.0062594 19 144.37 7.2184 0.211 0.01055 0.99473 0.005293 20 158.2 7.9102 0.211 0.01055 0.9927 0.0053389 21 172.12 8.6062 0.211 0.01055 0.99453 0.0064548 22 186.17 9.3087 0.211 0.01055 0.98641 0.0073259 23 200.28 10.014 0.211 0.01055 0.98879 0.0078682 24 214.46 10.723 0.211 0.01055 0.9895 0.0068058 25 228.73 11.436 0.211 0.01055 0.99204 0.0082509 26 243.12 12.156 0.211 0.01055 0.99406 0.0051381 27 257.55 12.878 0.211 0.01055 0.97965 0.0055447 28 272.22 13.611 0.211 0.01055 0.97982 0.0065843 29 286.9 14.345 0.211 0.01055 0.97793 0.0071814 30 301.73 15.087 0.211 0.01055 0.97835 0.0066197 31 316.75 15.838 0.211 0.01055 0.98125 0.0069484 32 331.82 16.591 0.211 0.01055 0.97828 0.0068737 33 347.16 17.358 0.211 0.01055 0.97682 0.006744 34 362.45 18.122 0.211 0.01055 0.98155 0.0059865 35 378.09 18.904 0.211 0.01055 0.96446 0.0066788 36 393.74 19.687 0.211 0.01055 0.97276 0.0073781 37 409.61 20.481 0.211 0.01055 0.97101 0.0071053 38 425.55 21.278 0.211 0.01055 0.97501 0.0068244 39 441.91 22.096 0.211 0.01055 0.96958 0.0072272 40 458.12 22.906 0.211 0.01055 0.95991 0.0064035 41 474.77 23.739 0.211 0.01055 0.96219 0.0059227 42 491.52 24.576 0.211 0.01055 0.96016 0.0058606 43 508.51 25.426 0.211 0.01055 0.9509 0.0049836 44 525.68 26.284 0.211 0.01055 0.95558 0.0055218 45 543.08 27.154 0.211 0.01055 0.95079 0.0058258 46 560.74 28.037 0.211 0.01055 0.9514 0.0043921 47 578.69 28.935 0.211 0.01055 0.94562 0.0046962 48 596.75 29.838 0.211 0.01055 0.94588 0.0047341 49 615.17 30.758 0.211 0.01055 0.93958 0.0045821 50 633.77 31.688 0.211 0.01055 0.93731 0.0043108 51 652.82 32.641 0.211 0.01055 0.93664 0.0052044 52 672.04 33.602 0.211 0.01055 0.93209 0.0035563 53 691.57 34.578 0.211 0.01055 0.93385 0.0046002 54 711.48 35.574 0.211 0.01055 0.93028 0.0051136 55 731.67 36.583 0.211 0.01055 0.93012 0.0035279 56 752.17 37.608 0.211 0.01055 0.92594 0.0039458 57 773.1 38.655 0.211 0.01055 0.92352 0.0027613 58 794.42 39.721 0.211 0.01055 0.91823 0.0034587 59 816.14 40.807 0.211 0.01055 0.90862 0.0034262 60 838.19 41.91 0.211 0.01055 0.91909 0.003498 61 860.69 43.034 0.211 0.01055 0.91013 0.0030537 62 883.74 44.187 0.211 0.01055 0.90449 0.0035391 63 907.04 45.352 0.211 0.01055 0.90057 0.0029672 64 930.95 46.547 0.211 0.01055 0.90316 0.0031245 65 955.38 47.769 0.211 0.01055 0.89492 0.0030981 66 980.25 49.013 0.211 0.01055 0.89636 0.0036625 67 1005.7 50.284 0.211 0.01055 0.88808 0.0022652 68 1031.7 51.586 0.211 0.01055 0.88665 0.0044622 69 1058.3 52.914 0.211 0.01055 0.88205 0.0030275 70 1085.5 54.276 0.211 0.01055 0.88257 0.0028637 71 1113.4 55.669 0.211 0.01055 0.87629 0.0030312 72 1141.9 57.093 0.211 0.01055 0.87732 0.0026539 73 1171 58.55 0.211 0.01055 0.87361 0.0034591 74 1201 60.052 0.211 0.01055 0.86595 0.0028129 75 1231.6 61.582 0.211 0.01055 0.86804 0.0043311 76 1263 63.151 0.211 0.01055 0.86676 0.0028806 77 1295.2 64.762 0.211 0.01055 0.85655 0.0028657 78 1328.4 66.419 0.211 0.01055 0.85794 0.0034773 79 1362.3 68.113 0.211 0.01055 0.85521 0.0032798 80 1397.1 69.854 0.211 0.01055 0.84974 0.0044537 81 1432.9 71.644 0.211 0.01055 0.84149 0.0032738 82 1469.7 73.487 0.211 0.01055 0.84801 0.0037874 83 1507.5 75.376 0.211 0.01055 0.84334 0.003206 84 1546.4 77.318 0.211 0.01055 0.83749 0.0040707 85 1586.4 79.322 0.211 0.01055 0.83921 0.0049938 86 1627.6 81.381 0.211 0.01055 0.83434 0.0057337 87 1669.9 83.497 0.211 0.01055 0.82878 0.0062417 88 1713.6 85.678 0.211 0.01055 0.82309 0.0080179 89 1758.5 87.927 0.211 0.01055 0.82433 0.0074191 90 1804.8 90.239 0.211 0.01055 0.82023 0.0076431 91 1852.5 92.627 0.211 0.01055 0.82756 0.0063064 92 1901.7 95.087 0.211 0.01055 0.82584 0.0052944 93 1952.4 97.622 0.211 0.01055 0.82799 0.0050662 94 2004.8 100.24 0.211 0.01055 0.82345 0.0043127 95 2058.8 102.94 0.211 0.01055 0.82296 0.0038 96 2114.5 105.72 0.211 0.01055 0.81987 0.0034072 97 2172 108.6 0.211 0.01055 0.82021 0.0036752 98 2231.4 111.57 0.211 0.01055 0.82765 0.0028851 99 2292.8 114.64 0.211 0.01055 0.82664 0.0038942 100 2356.2 117.81 0.211 0.01055 0.82702 0.0047371 101 2421.8 121.09 0.211 0.01055 0.81593 0.0043772 102 2489.6 124.48 0.211 0.01055 0.8251 0.0028026 103 2559.5 127.98 0.211 0.01055 0.8292 0.0024574 104 2631.9 131.59 0.211 0.01055 0.82626 0.0036198 105 2706.8 135.34 0.211 0.01055 0.8208 0.0032314 106 2784.3 139.22 0.211 0.01055 0.81959 0.0042731 107 2864.5 143.23 0.211 0.01055 0.82653 0.002699 108 2947.5 147.38 0.211 0.01055 0.82401 0.0036726 109 3033.5 151.67 0.211 0.01055 0.82361 0.0048224 110 3122.4 156.12 0.211 0.01055 0.82358 0.0041221 111 3214.5 160.73 0.211 0.01055 0.82187 0.0028807 112 3310.1 165.5 0.211 0.01055 0.82644 0.003516 113 3409 170.45 0.211 0.01055 0.82355 0.0021166 114 3511.4 175.57 0.211 0.01055 0.82513 0.0033911 115 3617.6 180.88 0.211 0.01055 0.82802 0.0015342 116 3727.6 186.38 0.211 0.01055 0.82663 0.0029222 117 3841.7 192.08 0.211 0.01055 0.82026 0.0020755 118 3960 198 0.211 0.01055 0.83079 0.0026394 119 4082.7 204.13 0.211 0.01055 0.82665 0.0027466 120 4209.9 210.5 0.211 0.01055 0.82774 0.0025199 121 4341.9 217.09 0.211 0.01055 0.83489 0.0030619 122 4478.7 223.94 0.211 0.01055 0.81987 0.0020988 123 4620.8 231.04 0.211 0.01055 0.8253 0.0023899 124 4768.2 238.41 0.211 0.01055 0.82653 0.0022851 125 4921.1 246.06 0.211 0.01055 0.82442 0.003383 126 5079.8 253.99 0.211 0.01055 0.82827 0.0015979 127 5244.7 262.23 0.211 0.01055 0.82494 0.0031129 128 5415.7 270.79 0.211 0.01055 0.82183 0.0030149 129 5593.3 279.67 0.211 0.01055 0.83217 0.0046976 130 5777.8 288.89 0.211 0.01055 0.82227 0.005574 131 5969.3 298.46 0.211 0.01055 0.82338 0.0025569 1 FileFormatVersion 1.0 2 DataFileTitle Polystyrene of Markus Strobl, Full Sine, ++ only 3 Sample Polystyrene 2 um in 53% H2O, 47% D2O 4 Settings D1=D2=20x8 mm,Ds = 16x10 mm (WxH), GF1 =scanning, GF2 = 2.5 A. 2 um polystyrene in 53% H2O, 47% D2O; 8.55% contrast 5 Operator CPD 6 Date do 10 jul 2014 16:37:30 7 ScanType sine one element scan 8 Thickness 2.00E-01 9 Thickness_unit cm 10 Theta_zmax 0.0168 11 Theta_zmax_unit radians 12 Theta_ymax 0.0168 13 Theta_ymax_unit radians 14 Orientation Z 15 SpinEchoLength_unit A 16 Depolarisation_unit A-2 cm-1 17 Wavelength_unit A 18 19 BEGIN_DATA 20 SpinEchoLength Depolarisation Depolarisation_error SpinEchoLength_error Wavelength Wavelength_error Polarisation Polarisation_error 21 391.56 0.0041929 0.0036894 19.578 2.11 0.1055 1.0037 0.0032974 22 1564 -0.0046571 0.0038185 78.2 2.11 0.1055 0.99586 0.003386 23 2735.6 -0.017007 0.0038132 136.78 2.11 0.1055 0.98497 0.0033444 24 3907.9 -0.033462 0.0035068 195.39 2.11 0.1055 0.97064 0.0030309 25 5080.2 -0.047483 0.0038208 254.01 2.11 0.1055 0.9586 0.0032613 26 6251.8 -0.070375 0.00376 312.59 2.11 0.1055 0.93926 0.0031446 27 7423.2 -0.092217 0.0037927 371.16 2.11 0.1055 0.92117 0.0031108 28 8595.5 -0.10238 0.004006 429.77 2.11 0.1055 0.91287 0.0032562 29 9767.7 -0.12672 0.0038534 488.39 2.11 0.1055 0.8933 0.0030651 30 10940 -0.1374 0.004243 546.98 2.11 0.1055 0.88484 0.003343 31 12112 -0.16072 0.0045837 605.58 2.11 0.1055 0.86666 0.0035372 32 13284 -0.16623 0.0045613 664.2 2.11 0.1055 0.86242 0.0035027 33 14456 -0.18468 0.0044918 722.79 2.11 0.1055 0.84837 0.0033931 34 15628 -0.19143 0.0048967 781.38 2.11 0.1055 0.84328 0.0036768 35 16800 -0.20029 0.0045421 840.02 2.11 0.1055 0.83666 0.0033837 36 17971 -0.19798 0.0046642 898.56 2.11 0.1055 0.83838 0.0034819 37 19143 -0.21442 0.0047052 957.17 2.11 0.1055 0.82619 0.0034614 38 20316 -0.20885 0.0044931 1015.8 2.11 0.1055 0.8303 0.0033218 39 21488 -0.21393 0.0049186 1074.4 2.11 0.1055 0.82655 0.00362 40 22660 -0.20685 0.004423 1133 2.11 0.1055 0.83179 0.0032758 41 23832 -0.20802 0.0046979 1191.6 2.11 0.1055 0.83092 0.0034758 42 25003 -0.19848 0.0045953 1250.2 2.11 0.1055 0.838 0.0034289 43 26175 -0.21117 0.0044567 1308.8 2.11 0.1055 0.82859 0.0032881 44 27347 -0.21283 0.004137 1367.4 2.11 0.1055 0.82736 0.0030477 45 28520 -0.2042 0.0044587 1426 2.11 0.1055 0.83375 0.0033101 46 29692 -0.2112 0.0042852 1484.6 2.11 0.1055 0.82857 0.0031615 47 30864 -0.20319 0.0043483 1543.2 2.11 0.1055 0.8345 0.003231 48 32036 -0.20752 0.0044297 1601.8 2.11 0.1055 0.83129 0.0032788 49 33207 -0.20654 0.0043188 1660.4 2.11 0.1055 0.83201 0.0031995 50 34380 -0.20126 0.0046375 1719 2.11 0.1055 0.83593 0.0034518 51 35551 -0.20924 0.0042871 1777.6 2.11 0.1055 0.83001 0.0031684 52 36724 -0.21323 0.0045471 1836.2 2.11 0.1055 0.82707 0.0033487 53 37895 -0.21324 0.0045354 1894.7 2.11 0.1055 0.82706 0.00334 54 39067 -0.19905 0.0044141 1953.4 2.11 0.1055 0.83758 0.003292 55 40239 -0.1991 0.0047441 2012 2.11 0.1055 0.83754 0.003538 56 41411 -0.20359 0.0050136 2070.5 2.11 0.1055 0.8342 0.003724 57 42583 -0.21032 0.0049474 2129.1 2.11 0.1055 0.82922 0.0036529 58 43755 -0.20689 0.0048203 2187.8 2.11 0.1055 0.83176 0.00357 59 44927 -0.21075 0.0052337 2246.4 2.11 0.1055 0.8289 0.0038628 60 46099 -0.19956 0.0047827 2304.9 2.11 0.1055 0.8372 0.0035653 -
sasmodels/data.py
re65c3ba rfa79f5c 527 527 528 528 if use_data or use_theory: 529 is_tof = (data.lam != data.lam[0]).any()529 is_tof = data.lam is not None and (data.lam != data.lam[0]).any() 530 530 if num_plots > 1: 531 531 plt.subplot(1, num_plots, 1) -
sasmodels/direct_model.py
r9e771a3 rfa79f5c 177 177 178 178 179 def _make_sesans_transform(data): 180 from sas.sascalc.data_util.nxsunit import Converter 181 182 # Pre-compute the Hankel matrix (H) 183 SElength = Converter(data._xunit)(data.x, "A") 184 185 theta_max = Converter("radians")(data.sample.zacceptance)[0] 186 q_max = 2 * np.pi / np.max(data.source.wavelength) * np.sin(theta_max) 187 zaccept = Converter("1/A")(q_max, "1/" + data.source.wavelength_unit), 188 189 Rmax = 10000000 190 hankel = sesans.SesansTransform(data.x, SElength, 191 data.source.wavelength, 192 zaccept, Rmax) 193 return hankel 194 195 179 196 class DataMixin(object): 180 197 """ … … 216 233 217 234 if self.data_type == 'sesans': 218 q = sesans.make_q(data.sample.zacceptance, data.Rmax)235 res = _make_sesans_transform(data) 219 236 index = slice(None, None) 220 res = None221 237 if data.y is not None: 222 238 Iq, dIq = data.y, data.dy … … 224 240 Iq, dIq = None, None 225 241 #self._theory = np.zeros_like(q) 226 q_vectors = [q] 227 q_mono = sesans.make_all_q(data) 242 q_vectors = [res.q_calc] 228 243 elif self.data_type == 'Iqxy': 229 244 #if not model.info.parameters.has_2d: … … 244 259 #self._theory = np.zeros_like(self.Iq) 245 260 q_vectors = res.q_calc 246 q_mono = []247 261 elif self.data_type == 'Iq': 248 262 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 269 283 #self._theory = np.zeros_like(self.Iq) 270 284 q_vectors = [res.q_calc] 271 q_mono = []272 285 elif self.data_type == 'Iq-oriented': 273 286 index = (data.x >= data.qmin) & (data.x <= data.qmax) … … 286 299 qy_width=data.dxl[index]) 287 300 q_vectors = res.q_calc 288 q_mono = []289 301 else: 290 302 raise ValueError("Unknown data type") # never gets here … … 293 305 # so we can save/restore state 294 306 self._kernel_inputs = q_vectors 295 self._kernel_mono_inputs = q_mono296 307 self._kernel = None 297 308 self.Iq, self.dIq, self.index = Iq, dIq, index … … 331 342 if self._kernel is None: 332 343 self._kernel = self._model.make_kernel(self._kernel_inputs) 333 self._kernel_mono = (334 self._model.make_kernel(self._kernel_mono_inputs)335 if self._kernel_mono_inputs else None)336 344 337 345 Iq_calc = call_kernel(self._kernel, pars, cutoff=cutoff) … … 341 349 # TODO: refactor so we don't store the result in the model 342 350 self.Iq_calc = Iq_calc 343 if self.data_type == 'sesans': 344 Iq_mono = (call_kernel(self._kernel_mono, pars, mono=True) 345 if self._kernel_mono_inputs else None) 346 result = sesans.transform(self._data, 347 self._kernel_inputs[0], Iq_calc, 348 self._kernel_mono_inputs, Iq_mono) 349 else: 350 result = self.resolution.apply(Iq_calc) 351 if hasattr(self.resolution, 'nx'): 352 self.Iq_calc = ( 353 self.resolution.qx_calc, self.resolution.qy_calc, 354 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 355 ) 351 result = self.resolution.apply(Iq_calc) 352 if hasattr(self.resolution, 'nx'): 353 self.Iq_calc = ( 354 self.resolution.qx_calc, self.resolution.qy_calc, 355 np.reshape(Iq_calc, (self.resolution.ny, self.resolution.nx)) 356 ) 356 357 return result 357 358 -
sasmodels/sesans.py
r9f91afe rfa79f5c 13 13 14 14 import numpy as np # type: ignore 15 from numpy import pi , exp# type: ignore15 from numpy import pi # type: ignore 16 16 from scipy.special import j0 17 17
Note: See TracChangeset
for help on using the changeset viewer.