Changeset 896abb3 in sasview for pr_inversion
- Timestamp:
- May 23, 2008 2:31:50 PM (17 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ffca8f2
- Parents:
- a1718df
- Location:
- pr_inversion
- Files:
-
- 2 added
- 2 deleted
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
pr_inversion/__init__.py
r9a11937 r896abb3 15 15 # 16 16 # [1] P.B. Moore, J.Appl. Cryst (1980) 13, 168-175. 17 # 17 18 # [2] O. Glatter, J.Appl. Cryst (1977) 10, 415-421. 19 # 18 20 # [3] D.I. Svergun, J.Appl. Cryst (1991) 24, 485-492. 21 # 19 22 # [4] D.I. Svergun, J.Appl. Cryst (1992) 25, 495-503. 23 # 20 24 # [5] S. Hansen and J. Skov Pedersen, J.Appl. Cryst (1991) 24, 541-548. 21 25 # … … 41 45 # 42 46 # 47 # \subsection Tutorial 48 # To create an inversion object: 49 # \verbatim 50 #from sans.pr.invertor import Invertor 51 # invertor = Invertor() 52 # \endverbatim 53 # 54 # To set the maximum distance between any two points: 55 # \verbatim 56 # invertor.d_max = 160.0 57 # \endverbatim 58 # 59 # To set the regularization constant: 60 # \verbatim 61 # invertor.alpha = 0.0007 62 # \endverbatim 63 # 64 # To set the q, I(q) and error on I(q): 65 # \verbatim 66 # invertor.x = q_vector 67 # invertor.y = Iq_vector 68 # invertor.err = dIq_vector 69 # \endverbatim 70 # 71 # To perform the inversion. In this example, we choose 72 # a P(r) expension wit 10 base functions. 73 # \verbatim 74 # c_out, c_cov = invertor.invert(10) 75 # \endverbatim 76 # The c_out and c_cov are the set of coefficients and the covariance 77 # matrix for those coefficients, respectively. 78 # 43 79 # Examples are available as unit tests under sans.pr_inversion.test. 44 80 # -
pr_inversion/c_extensions/Cinvertor.c
r43c0a8e r896abb3 1 1 /** 2 * C implementation of the P(r) inversion 3 * Cinvertor is the base class for the Invertor class 4 * and provides the underlying computations. 5 * 6 */ 2 7 #include <Python.h> 3 8 #include "structmember.h" … … 29 34 30 35 // Class definition 36 /** 37 * C implementation of the P(r) inversion 38 * Cinvertor is the base class for the Invertor class 39 * and provides the underlying computations. 40 * 41 */ 31 42 typedef struct { 32 43 PyObject_HEAD 44 /// Internal data structure 33 45 Invertor_params params; 34 46 } Cinvertor; … … 70 82 }; 71 83 84 const char set_x_doc[] = 85 "Function to set the x data\n" 86 "Takes an array of doubles as input.\n" 87 " @return: number of entries found"; 72 88 73 89 /** … … 102 118 return Py_BuildValue("i", self->params.npoints); 103 119 } 120 121 const char get_x_doc[] = 122 "Function to get the x data\n" 123 "Takes an array of doubles as input.\n" 124 " @return: number of entries found"; 104 125 105 126 static PyObject * get_x(Cinvertor *self, PyObject *args) { … … 126 147 } 127 148 149 const char set_y_doc[] = 150 "Function to set the y data\n" 151 "Takes an array of doubles as input.\n" 152 " @return: number of entries found"; 153 128 154 /** 129 155 * Function to set the y data … … 157 183 return Py_BuildValue("i", self->params.ny); 158 184 } 185 186 const char get_y_doc[] = 187 "Function to get the y data\n" 188 "Takes an array of doubles as input.\n" 189 " @return: number of entries found"; 159 190 160 191 static PyObject * get_y(Cinvertor *self, PyObject *args) { … … 181 212 } 182 213 214 const char set_err_doc[] = 215 "Function to set the err data\n" 216 "Takes an array of doubles as input.\n" 217 " @return: number of entries found"; 218 183 219 /** 184 220 * Function to set the x data … … 212 248 return Py_BuildValue("i", self->params.nerr); 213 249 } 250 251 const char get_err_doc[] = 252 "Function to get the err data\n" 253 "Takes an array of doubles as input.\n" 254 " @return: number of entries found"; 214 255 215 256 static PyObject * get_err(Cinvertor *self, PyObject *args) { … … 235 276 return Py_BuildValue("i", self->params.npoints); 236 277 } 278 279 const char is_valid_doc[] = 280 "Check the validity of the stored data\n" 281 " @return: Returns the number of points if it's all good, -1 otherwise"; 237 282 238 283 /** … … 249 294 } 250 295 296 const char set_dmax_doc[] = 297 "Sets the maximum distance\n"; 298 251 299 /** 252 300 * Sets the maximum distance … … 260 308 } 261 309 310 const char get_dmax_doc[] = 311 "Gets the maximum distance\n"; 312 262 313 /** 263 314 * Gets the maximum distance … … 266 317 return Py_BuildValue("d", self->params.d_max); 267 318 } 319 320 const char set_qmin_doc[] = 321 "Sets the minimum q\n"; 268 322 269 323 /** … … 278 332 } 279 333 334 const char get_qmin_doc[] = 335 "Gets the minimum q\n"; 336 280 337 /** 281 338 * Gets the minimum q … … 285 342 } 286 343 344 const char set_qmax_doc[] = 345 "Sets the maximum q\n"; 287 346 288 347 /** … … 297 356 } 298 357 358 const char get_qmax_doc[] = 359 "Gets the maximum q\n"; 360 299 361 /** 300 362 * Gets the maximum q … … 304 366 } 305 367 368 const char set_alpha_doc[] = 369 "Sets the alpha parameter\n"; 306 370 307 371 static PyObject * set_alpha(Cinvertor *self, PyObject *args) { … … 313 377 } 314 378 379 const char get_alpha_doc[] = 380 "Gets the alpha parameter\n"; 381 315 382 /** 316 383 * Gets the maximum distance … … 320 387 } 321 388 389 const char get_nx_doc[] = 390 "Gets the number of x points\n"; 391 322 392 /** 323 393 * Gets the number of x points … … 327 397 } 328 398 399 const char get_ny_doc[] = 400 "Gets the number of y points\n"; 401 329 402 /** 330 403 * Gets the number of y points … … 334 407 } 335 408 409 const char get_nerr_doc[] = 410 "Gets the number of err points\n"; 411 336 412 /** 337 413 * Gets the number of error points … … 341 417 } 342 418 419 420 const char residuals_doc[] = 421 "Function to call to evaluate the residuals\n" 422 "for P(r) inversion\n" 423 " @param args: input parameters\n" 424 " @return: list of residuals"; 343 425 344 426 /** … … 391 473 return residuals; 392 474 } 475 476 const char pr_residuals_doc[] = 477 "Function to call to evaluate the residuals\n" 478 "for P(r) minimization (for testing purposes)\n" 479 " @param args: input parameters\n" 480 " @return: list of residuals"; 481 393 482 /** 394 483 * Function to call to evaluate the residuals … … 442 531 } 443 532 533 const char get_iq_doc[] = 534 "Function to call to evaluate the scattering intensity\n" 535 " @param args: c-parameters, and q\n" 536 " @return: I(q)"; 537 444 538 /** 445 539 * Function to call to evaluate the scattering intensity … … 460 554 } 461 555 556 const char get_pr_doc[] = 557 "Function to call to evaluate P(r)\n" 558 " @param args: c-parameters and r\n" 559 " @return: P(r)"; 560 462 561 /** 463 562 * Function to call to evaluate P(r) … … 478 577 } 479 578 579 const char get_pr_err_doc[] = 580 "Function to call to evaluate P(r) with errors\n" 581 " @param args: c-parameters and r\n" 582 " @return: (P(r),dP(r))"; 583 480 584 /** 481 585 * Function to call to evaluate P(r) with errors … … 502 606 } 503 607 608 const char basefunc_ft_doc[] = 609 "Returns the value of the nth Fourier transofrmed base function\n" 610 " @param args: c-parameters, n and q\n" 611 " @return: nth Fourier transformed base function, evaluated at q"; 612 504 613 static PyObject * basefunc_ft(Cinvertor *self, PyObject *args) { 505 614 double d_max, q; … … 511 620 } 512 621 622 const char oscillations_doc[] = 623 "Returns the value of the oscillation figure of merit for\n" 624 "the given set of coefficients. For a sphere, the oscillation\n" 625 "figure of merit is 1.1.\n" 626 " @param args: c-parameters\n" 627 " @return: oscillation figure of merit"; 628 513 629 static PyObject * oscillations(Cinvertor *self, PyObject *args) { 514 630 double *pars; … … 526 642 } 527 643 644 const char get_peaks_doc[] = 645 "Returns the number of peaks in the output P(r) distrubution\n" 646 "for the given set of coefficients.\n" 647 " @param args: c-parameters\n" 648 " @return: number of P(r) peaks"; 649 528 650 static PyObject * get_peaks(Cinvertor *self, PyObject *args) { 529 651 double *pars; … … 540 662 541 663 } 664 665 const char get_positive_doc[] = 666 "Returns the fraction of P(r) that is positive over\n" 667 "the full range of r for the given set of coefficients.\n" 668 " @param args: c-parameters\n" 669 " @return: fraction of P(r) that is positive"; 542 670 543 671 static PyObject * get_positive(Cinvertor *self, PyObject *args) { … … 555 683 556 684 } 685 686 const char get_pos_err_doc[] = 687 "Returns the fraction of P(r) that is 1 standard deviation\n" 688 "above zero over the full range of r for the given set of coefficients.\n" 689 " @param args: c-parameters\n" 690 " @return: fraction of P(r) that is positive"; 557 691 558 692 static PyObject * get_pos_err(Cinvertor *self, PyObject *args) { … … 575 709 } 576 710 711 712 const char eeeget_qmin_doc[] = "\ 713 This is a multiline doc string.\n\ 714 \n\ 715 This is the second line."; 716 const char eeeset_qmin_doc[] = 717 "This is a multiline doc string.\n" 718 "\n" 719 "This is the second line."; 720 577 721 static PyMethodDef Cinvertor_methods[] = { 578 {"residuals", (PyCFunction)residuals, METH_VARARGS, "Get the list of residuals"},579 {"pr_residuals", (PyCFunction)pr_residuals, METH_VARARGS, "Get the list of residuals"},580 {"set_x", (PyCFunction)set_x, METH_VARARGS, ""},581 {"get_x", (PyCFunction)get_x, METH_VARARGS, ""},582 {"set_y", (PyCFunction)set_y, METH_VARARGS, ""},583 {"get_y", (PyCFunction)get_y, METH_VARARGS, ""},584 {"set_err", (PyCFunction)set_err, METH_VARARGS, ""},585 {"get_err", (PyCFunction)get_err, METH_VARARGS, ""},586 {"set_dmax", (PyCFunction)set_dmax, METH_VARARGS, ""},587 {"get_dmax", (PyCFunction)get_dmax, METH_VARARGS, ""},588 {"set_qmin", (PyCFunction)set_qmin, METH_VARARGS, ""},589 {"get_qmin", (PyCFunction)get_qmin, METH_VARARGS, ""},590 {"set_qmax", (PyCFunction)set_qmax, METH_VARARGS, ""},591 {"get_qmax", (PyCFunction)get_qmax, METH_VARARGS, ""},592 {"set_alpha", (PyCFunction)set_alpha, METH_VARARGS, ""},593 {"get_alpha", (PyCFunction)get_alpha, METH_VARARGS, ""},594 {"get_nx", (PyCFunction)get_nx, METH_VARARGS, ""},595 {"get_ny", (PyCFunction)get_ny, METH_VARARGS, ""},596 {"get_nerr", (PyCFunction)get_nerr, METH_VARARGS, ""},597 {"iq", (PyCFunction)get_iq, METH_VARARGS, ""},598 {"pr", (PyCFunction)get_pr, METH_VARARGS, ""},599 {"get_pr_err", (PyCFunction)get_pr_err, METH_VARARGS, ""},600 {"is_valid", (PyCFunction)is_valid, METH_VARARGS, ""},601 {"basefunc_ft", (PyCFunction)basefunc_ft, METH_VARARGS, ""},602 {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""},603 {"get_peaks", (PyCFunction)get_peaks, METH_VARARGS, ""},604 {"get_positive", (PyCFunction)get_positive, METH_VARARGS, ""},605 {"get_pos_err", (PyCFunction)get_pos_err, METH_VARARGS, ""},722 {"residuals", (PyCFunction)residuals, METH_VARARGS, residuals_doc}, 723 {"pr_residuals", (PyCFunction)pr_residuals, METH_VARARGS, pr_residuals_doc}, 724 {"set_x", (PyCFunction)set_x, METH_VARARGS, set_x_doc}, 725 {"get_x", (PyCFunction)get_x, METH_VARARGS, get_x_doc}, 726 {"set_y", (PyCFunction)set_y, METH_VARARGS, set_y_doc}, 727 {"get_y", (PyCFunction)get_y, METH_VARARGS, get_y_doc}, 728 {"set_err", (PyCFunction)set_err, METH_VARARGS, set_err_doc}, 729 {"get_err", (PyCFunction)get_err, METH_VARARGS, get_err_doc}, 730 {"set_dmax", (PyCFunction)set_dmax, METH_VARARGS, set_dmax_doc}, 731 {"get_dmax", (PyCFunction)get_dmax, METH_VARARGS, get_dmax_doc}, 732 {"set_qmin", (PyCFunction)set_qmin, METH_VARARGS, set_qmin_doc}, 733 {"get_qmin", (PyCFunction)get_qmin, METH_VARARGS, get_qmin_doc}, 734 {"set_qmax", (PyCFunction)set_qmax, METH_VARARGS, set_qmax_doc}, 735 {"get_qmax", (PyCFunction)get_qmax, METH_VARARGS, get_qmax_doc}, 736 {"set_alpha", (PyCFunction)set_alpha, METH_VARARGS, set_alpha_doc}, 737 {"get_alpha", (PyCFunction)get_alpha, METH_VARARGS, get_alpha_doc}, 738 {"get_nx", (PyCFunction)get_nx, METH_VARARGS, get_nx_doc}, 739 {"get_ny", (PyCFunction)get_ny, METH_VARARGS, get_ny_doc}, 740 {"get_nerr", (PyCFunction)get_nerr, METH_VARARGS, get_nerr_doc}, 741 {"iq", (PyCFunction)get_iq, METH_VARARGS, get_iq_doc}, 742 {"pr", (PyCFunction)get_pr, METH_VARARGS, get_pr_doc}, 743 {"get_pr_err", (PyCFunction)get_pr_err, METH_VARARGS, get_pr_err_doc}, 744 {"is_valid", (PyCFunction)is_valid, METH_VARARGS, is_valid_doc}, 745 {"basefunc_ft", (PyCFunction)basefunc_ft, METH_VARARGS, basefunc_ft_doc}, 746 {"oscillations", (PyCFunction)oscillations, METH_VARARGS, oscillations_doc}, 747 {"get_peaks", (PyCFunction)get_peaks, METH_VARARGS, get_peaks_doc}, 748 {"get_positive", (PyCFunction)get_positive, METH_VARARGS, get_positive_doc}, 749 {"get_pos_err", (PyCFunction)get_pos_err, METH_VARARGS, get_pos_err_doc}, 606 750 607 751 {NULL} -
pr_inversion/c_extensions/__init__.py
r9e8dc22 r896abb3 1 """ 2 C extensions to provide the P(r) inversion computations. 3 """ -
pr_inversion/c_extensions/invertor.h
r43c0a8e r896abb3 2 2 #define invertor_h 3 3 4 4 /** 5 * Internal data structure for P(r) inversion 6 */ 5 7 typedef struct { 8 /// Maximum distance between any two points in the system 6 9 double d_max; 10 /// q data 7 11 double *x; 12 /// I(q) data 8 13 double *y; 14 /// dI(q) data 9 15 double *err; 16 /// Number of q points 10 17 int npoints; 18 /// Number of I(q) points 11 19 int ny; 20 /// Number of dI(q) points 12 21 int nerr; 22 /// Alpha value 13 23 double alpha; 24 /// Minimum q to include in inversion 14 25 double q_min; 26 /// Maximum q to include in inversion 15 27 double q_max; 16 28 } Invertor_params; -
pr_inversion/invertor.py
r43c0a8e r896abb3 1 """ 2 Module to perform P(r) inversion. 3 The module contains the Invertor class. 4 """ 1 5 from sans.pr.core.pr_inversion import Cinvertor 2 6 import numpy … … 35 39 36 40 Methods inherited from Cinvertor: 37 - get_peaks: returns the number of P(r) peaks 41 - get_peaks(pars): returns the number of P(r) peaks 42 - oscillations(pars): returns the oscillation parameters for the output P(r) 43 - get_positive(pars): returns the fraction of P(r) that is above zero 44 - get_pos_err(pars): returns the fraction of P(r) that is 1-sigma above zero 38 45 """ 39 46 ## Chisqr of the last computation … … 57 64 Set the value of an attribute. 58 65 Access the parent class methods for 59 x, y, err and d_max.66 x, y, err, d_max, q_min, q_max and alpha 60 67 """ 61 68 if name=='x': … … 194 201 195 202 def pr_err(self, c, c_cov, r): 196 #import math 197 #c_err = numpy.zeros(len(c)) 198 #for i in range(len(c)): 199 # try: 200 # c_err[i] = math.sqrt(math.fabs(c_cov[i][i])) 201 # except: 202 # import sys 203 # print sys.exc_value 204 # print "oups", c_cov[i][i] 205 # c_err[i] = c[i] 206 203 """ 204 Returns the value of P(r) for a given r, and base function 205 coefficients, with error. 206 207 @param c: base function coefficients 208 @param c_cov: covariance matrice of the base function coefficients 209 @param r: r-value to evaluate P(r) at 210 @return: P(r) 211 212 """ 207 213 return self.get_pr_err(c, c_cov, r) 208 214 -
pr_inversion/setup.py
r9e8dc22 r896abb3 1 """ 2 Setup script for the P(r) inversion module 3 """ 1 4 import sys, os 2 5
Note: See TracChangeset
for help on using the changeset viewer.