Changeset e7724f5 in sasmodels
- Timestamp:
- Mar 26, 2015 2:45:00 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:
- 6ee9d39
- Parents:
- 2c801fe (diff), 42ade62 (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:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kerneldll.py
raa4946b r2c801fe 17 17 from . import generate 18 18 from .kernelpy import PyInput, PyModel 19 from .exception import annotate_exception 19 20 20 21 # Compiler platform details … … 145 146 146 147 #print "dll",self.dllpath 147 self.dll = ct.CDLL(self.dllpath) 148 try: 149 self.dll = ct.CDLL(self.dllpath) 150 except Exception, exc: 151 annotate_exception("while loading "+self.dllpath) 152 raise 148 153 149 154 fp = c_float if self.dtype == generate.F32 else c_double -
sasmodels/model_test.py
rdb8756e r9e430d0 51 51 from .core import list_models, load_model_definition, load_model, HAVE_OPENCL 52 52 from .core import make_kernel, call_kernel, call_ER, call_VR 53 54 55 def annotate_exception(exc, msg): 56 """ 57 Add an annotation to the current exception, which can then be forwarded 58 to the caller using a bare "raise" statement to reraise the annotated 59 exception. 60 Example:: 61 >>> D = {} 62 >>> try: 63 ... print D['hello'] 64 ... except Exception,exc: 65 ... annotate_exception(exc, "while accessing 'D'") 66 ... raise 67 Traceback (most recent call last): 68 ... 69 KeyError: "hello while accessing 'D'" 70 """ 71 args = exc.args 72 if not args: 73 exc.args = (msg,) 74 else: 75 try: 76 arg0 = " ".join((args[0],msg)) 77 exc.args = tuple([arg0] + list(args[1:])) 78 except: 79 exc.args = (" ".join((str(exc),msg)),) 53 from .exception import annotate_exception 80 54 81 55 -
sasmodels/resolution.py
r6871c9e rf1b8c90 56 56 be estimated from the *q* and *q_width*. 57 57 """ 58 def __init__(self, q, q_width, q_calc=None ):58 def __init__(self, q, q_width, q_calc=None, nsigma=3): 59 59 #*min_step* is the minimum point spacing to use when computing the 60 60 #underlying model. It should be on the order of … … 68 68 # default to Perfect1D if the pinhole geometry is not defined. 69 69 self.q, self.q_width = q, q_width 70 self.q_calc = pinhole_extend_q(q, q_width ) \70 self.q_calc = pinhole_extend_q(q, q_width, nsigma=nsigma) \ 71 71 if q_calc is None else np.sort(q_calc) 72 72 self.weight_matrix = pinhole_resolution(self.q_calc, … … 203 203 """ 204 204 q_min, q_max = np.min(q - nsigma*q_width), np.max(q + nsigma*q_width) 205 return geometric_extrapolation(q, q_min, q_max)205 return linear_extrapolation(q, q_min, q_max) 206 206 207 207 … … 267 267 """ 268 268 Extrapolate *q* out to [*q_min*, *q_max*] using the step size in *q* as 269 a guide. Extrapolation below uses stepsthe same size as the first270 interval. Extrapolation above uses stepsthe same size as the final269 a guide. Extrapolation below uses about the same size as the first 270 interval. Extrapolation above uses about the same size as the final 271 271 interval. 272 272 … … 276 276 if q_min < q[0]: 277 277 if q_min <= 0: q_min = q[0]/10 278 delta = q[1] - q[0]279 q_low = np. arange(q_min, q[0], delta)278 n_low = np.ceil((q[0]-q_min) / (q[1]-q[0])) if q[1]>q[0] else 15 279 q_low = np.linspace(q_min, q[0], n_low+1)[:-1] 280 280 else: 281 281 q_low = [] 282 282 if q_max > q[-1]: 283 delta = q[-1] - q[-2]284 q_high = np. arange(q[-1]+delta, q_max, delta)283 n_high = np.ceil((q_max-q[-1]) / (q[-1]-q[-2])) if q[-1]>q[-2] else 15 284 q_high = np.linspace(q[-1], q_max, n_high+1)[1:] 285 285 else: 286 286 q_high = [] … … 288 288 289 289 290 def geometric_extrapolation(q, q_min, q_max ):290 def geometric_extrapolation(q, q_min, q_max, points_per_decade=None): 291 291 r""" 292 292 Extrapolate *q* to [*q_min*, *q_max*] using geometric steps, with the … … 295 295 if *q_min* is zero or less then *q[0]/10* is used instead. 296 296 297 Starting at $q_1$ and stepping geometrically by $\Delta q$ 298 to $q_n$ in $n$ points gives a geometric average of: 297 *points_per_decade* sets the ratio between consecutive steps such 298 that there will be $n$ points used for every factor of 10 increase 299 in *q*. 300 301 If *points_per_decade* is not given, it will be estimated as follows. 302 Starting at $q_1$ and stepping geometrically by $\Delta q$ to $q_n$ 303 in $n$ points gives a geometric average of: 299 304 300 305 .. math:: … … 315 320 """ 316 321 q = np.sort(q) 317 delta_q = (len(q)-1)/(log(q[-1]) - log(q[0])) 322 if points_per_decade is None: 323 log_delta_q = (len(q) - 1) / (log(q[-1]) - log(q[0])) 324 else: 325 log_delta_q = log(10.) / points_per_decade 318 326 if q_min < q[0]: 319 327 if q_min < 0: q_min = q[0]/10 320 n_low = delta_q * (log(q[0])-log(q_min))328 n_low = log_delta_q * (log(q[0])-log(q_min)) 321 329 q_low = np.logspace(log10(q_min), log10(q[0]), np.ceil(n_low)+1)[:-1] 322 330 else: 323 331 q_low = [] 324 332 if q_max > q[-1]: 325 n_high = delta_q * (log(q_max)-log(q[-1]))333 n_high = log_delta_q * (log(q_max)-log(q[-1])) 326 334 q_high = np.logspace(log10(q[-1]), log10(q_max), np.ceil(n_high)+1)[1:] 327 335 else: … … 372 380 373 381 374 def romberg_pinhole_1d(q, q_width, form, pars ):382 def romberg_pinhole_1d(q, q_width, form, pars, nsigma=5): 375 383 """ 376 384 Romberg integration for pinhole resolution. … … 388 396 389 397 _fn = lambda q, q0, dq: eval_form(q, form, pars)*gaussian(q, q0, dq) 390 r = [romberg(_fn, max(qi- 5*dqi,0.01*q[0]), qi+5*dqi, args=(qi, dqi),398 r = [romberg(_fn, max(qi-nsigma*dqi,1e-10*q[0]), qi+nsigma*dqi, args=(qi, dqi), 391 399 divmax=100, vec_func=True, tol=0, rtol=1e-8) 392 400 for qi,dqi in zip(q,q_width)] … … 640 648 output = self.Iq_sphere(pars, resolution) 641 649 self.compare(q, output, answer, 1e-6) 642 643 650 644 651
Note: See TracChangeset
for help on using the changeset viewer.