Changeset f168d02 in sasview
- Timestamp:
- Jul 1, 2008 2:56:32 PM (16 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:
- 2a92852
- Parents:
- a17ffdf
- Location:
- pr_inversion
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pr_inversion/c_extensions/Cinvertor.c
rbd30f4a5 rf168d02 624 624 625 625 iq_value = iq(pars, self->params.d_max, npars, q); 626 return Py_BuildValue("f", iq_value); 627 } 628 629 const char get_iq_smeared_doc[] = 630 "Function to call to evaluate the scattering intensity.\n" 631 "The scattering intensity is slit-smeared." 632 " @param args: c-parameters, and q\n" 633 " @return: I(q)"; 634 635 /** 636 * Function to call to evaluate the scattering intensity 637 * The scattering intensity is slit-smeared. 638 * @param args: c-parameters, and q 639 * @return: I(q) 640 */ 641 static PyObject * get_iq_smeared(Cinvertor *self, PyObject *args) { 642 double *pars; 643 double q, iq_value; 644 PyObject *data_obj; 645 Py_ssize_t npars; 646 647 if (!PyArg_ParseTuple(args, "Od", &data_obj, &q)) return NULL; 648 OUTVECTOR(data_obj,pars,npars); 649 650 iq_value = iq_smeared(pars, self->params.d_max, npars, 651 self->params.slit_height, self->params.slit_width, 652 q, 21); 626 653 return Py_BuildValue("f", iq_value); 627 654 } … … 875 902 a[i*nfunc+j] = 1.0/self->params.err[i]; 876 903 } else { 877 a[i*nfunc+j] = ortho_transformed(self->params.d_max, j+offset, self->params.x[i])/self->params.err[i]; 904 if (self->params.slit_width>0 || self->params.slit_height>0) { 905 a[i*nfunc+j] = ortho_transformed_smeared(self->params.d_max, 906 j+offset, self->params.slit_height, self->params.slit_width, 907 self->params.x[i], 21)/self->params.err[i]; 908 } else { 909 a[i*nfunc+j] = ortho_transformed(self->params.d_max, j+offset, self->params.x[i])/self->params.err[i]; 910 } 878 911 } 879 912 } … … 1009 1042 {"get_nerr", (PyCFunction)get_nerr, METH_VARARGS, get_nerr_doc}, 1010 1043 {"iq", (PyCFunction)get_iq, METH_VARARGS, get_iq_doc}, 1044 {"iq_smeared", (PyCFunction)get_iq_smeared, METH_VARARGS, get_iq_smeared_doc}, 1011 1045 {"pr", (PyCFunction)get_pr, METH_VARARGS, get_pr_doc}, 1012 1046 {"get_pr_err", (PyCFunction)get_pr_err, METH_VARARGS, get_pr_err_doc}, -
pr_inversion/c_extensions/invertor.c
r9a23253e rf168d02 63 63 double ortho_transformed_smeared(double d_max, int n, double height, double width, double q, int npts) { 64 64 double sum, value, y, z; 65 int i, j; 65 int i, j, n_height, n_width; 66 double count_w; 66 67 double fnpts; 67 68 sum = 0.0; 68 69 fnpts = (float)npts-1.0; 69 70 70 for(i=0; i<npts; i++) { 71 y = -width/2.0+width/fnpts*(float)i; 72 for(j=0; j<npts; j++) { 71 // Check for zero slit size 72 n_height = (height>0) ? npts : 1; 73 n_width = (width>0) ? npts : 1; 74 75 count_w = 0.0; 76 77 for(j=0; j<n_height; j++) { 78 if(height>0){ 73 79 z = height/fnpts*(float)j; 80 } else { 81 z = 0.0; 82 } 83 84 for(i=0; i<n_width; i++) { 85 if(width>0){ 86 y = -width/2.0+width/fnpts*(float)i; 87 } else { 88 y = 0.0; 89 } 90 if (((q-y)*(q-y)+z*z)<=0.0) continue; 91 count_w += 1.0; 74 92 sum += ortho_transformed(d_max, n, sqrt((q-y)*(q-y)+z*z)); 75 93 } 76 94 } 77 78 return sum/npts/npts/height/width; 95 return sum/count_w; 79 96 } 80 97 … … 95 112 for (i=0; i<n_c; i++) { 96 113 sum += pars[i] * ortho_transformed(d_max, i+1, q); 114 } 115 return sum; 116 } 117 118 /** 119 * Scattering intensity calculated from the expansion, 120 * slit-smeared. 121 */ 122 double iq_smeared(double *pars, double d_max, int n_c, double height, double width, double q, int npts) { 123 double sum = 0.0; 124 int i; 125 for (i=0; i<n_c; i++) { 126 sum += pars[i] * ortho_transformed_smeared(d_max, i+1, height, width, q, npts); 97 127 } 98 128 return sum; -
pr_inversion/c_extensions/invertor.h
r9a23253e rf168d02 55 55 double int_pr(double *pars, double d_max, int n_c, int nslice); 56 56 double ortho_transformed_smeared(double d_max, int n, double heigth, double width, double q, int npts); 57 double iq_smeared(double *pars, double d_max, int n_c, double height, double width, double q, int npts); 57 58 58 59 #endif -
pr_inversion/invertor.py
re96a852 rf168d02 73 73 suggested_alpha = 0 74 74 ## Last number of base functions used 75 nfunc = 075 nfunc = 10 76 76 ## Last output values 77 77 out = None … … 191 191 invertor.err = self.err 192 192 invertor.has_bck = self.has_bck 193 invertor.slit_height = self.slit_height 194 invertor.slit_width = self.slit_width 193 195 194 196 return invertor … … 391 393 392 394 # Construct the a matrix and b vector that represent the problem 395 t_0 = time.time() 393 396 self._get_matrix(nfunc, nq, a, b) 397 #print "elasped: ", time.time()-t_0 394 398 395 399 # Perform the inversion (least square fit) … … 531 535 from num_term import Num_terms 532 536 estimator = Num_terms(self.clone()) 533 534 return estimator.num_terms(isquit_func) 537 try: 538 return estimator.num_terms(isquit_func) 539 except: 540 # If we fail, estimate alpha and return the default 541 # number of terms 542 best_alpha, message, elapsed =self.estimate_alpha(self.nfunc) 543 return self.nfunc, best_alpha, "Could not estimate number of terms" 535 544 536 545 def estimate_alpha(self, nfunc): … … 572 581 # just return the estimate 573 582 if npeaks>1: 574 message = "Your P(r) is not smooth, please check your inversion parameters" 583 #message = "Your P(r) is not smooth, please check your inversion parameters" 584 message = None 575 585 return pr.suggested_alpha, message, elapsed 576 586 else: -
pr_inversion/test/utest_invertor.py
r9a23253e rf168d02 175 175 176 176 self.assertEqual(self.invertor.test_no_data, None) 177 178 def test_slitsettings(self): 179 self.invertor.slit_width = 1.0 180 self.assertEqual(self.invertor.slit_width, 1.0) 181 self.invertor.slit_height = 2.0 182 self.assertEqual(self.invertor.slit_height, 2.0) 183 177 184 178 185 def test_inversion(self):
Note: See TracChangeset
for help on using the changeset viewer.