Changeset 43c0a8e in sasview for pr_inversion/c_extensions
- Timestamp:
- May 23, 2008 10:55:39 AM (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:
- dfb58f8
- Parents:
- eb06cbe
- Location:
- pr_inversion/c_extensions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pr_inversion/c_extensions/Cinvertor.c
rf71287f4 r43c0a8e 492 492 PyObject *err_obj; 493 493 Py_ssize_t npars2; 494 494 int i; 495 495 496 if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 496 OUTVECTOR(data_obj,pars,npars); 497 OUTVECTOR(data_obj,pars,npars); 497 498 OUTVECTOR(err_obj,pars_err,npars2); 498 499 499 500 pr_err(pars, pars_err, self->params.d_max, npars, r, &pr_value, &pr_err_value); 500 501 return Py_BuildValue("ff", pr_value, pr_err_value); … … 537 538 538 539 return Py_BuildValue("i", count ); 540 541 } 542 543 static PyObject * get_positive(Cinvertor *self, PyObject *args) { 544 double *pars; 545 PyObject *data_obj; 546 Py_ssize_t npars; 547 double fraction; 548 549 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 550 OUTVECTOR(data_obj,pars,npars); 551 552 fraction = positive_integral(pars, self->params.d_max, npars, 100); 553 554 return Py_BuildValue("f", fraction ); 555 556 } 557 558 static PyObject * get_pos_err(Cinvertor *self, PyObject *args) { 559 double *pars; 560 double *pars_err; 561 PyObject *data_obj; 562 PyObject *err_obj; 563 Py_ssize_t npars; 564 Py_ssize_t npars2; 565 double fraction; 566 567 if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL; 568 OUTVECTOR(data_obj,pars,npars); 569 OUTVECTOR(err_obj,pars_err,npars2); 570 571 fraction = positive_errors(pars, pars_err, self->params.d_max, npars, 51); 572 573 return Py_BuildValue("f", fraction ); 539 574 540 575 } … … 567 602 {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""}, 568 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, ""}, 569 606 570 607 {NULL} -
pr_inversion/c_extensions/invertor.c
rf71287f4 r43c0a8e 100 100 func_value = ortho(d_max, i+1, r); 101 101 sum += pars[i] * func_value; 102 sum_err += err[i]*err[i]*func_value*func_value; 102 //sum_err += err[i]*err[i]*func_value*func_value; 103 sum_err += err[i*n_c+i]*func_value*func_value; 103 104 } 104 105 *pr_value = sum; … … 115 116 double dprdr(double *pars, double d_max, int n_c, double r) { 116 117 double sum = 0.0; 117 int i; 118 int i; 118 119 for (i=0; i<n_c; i++) { 119 120 sum += pars[i] * 2.0*(sin(pi*(i+1)*r/d_max) + pi*(i+1)*r/d_max * cos(pi*(i+1)*r/d_max)); … … 180 181 } 181 182 183 /** 184 * Get the fraction of the integral of P(r) over the whole range 185 * of r that is above zero. 186 * A valid P(r) is define as being positive for all r. 187 */ 188 double positive_integral(double *pars, double d_max, int n_c, int nslice) { 189 double r; 190 double value; 191 int i; 192 double sum_pos = 0.0; 193 double sum = 0.0; 194 195 for (i=0; i<nslice; i++) { 196 r = d_max/(1.0*nslice)*i; 197 value = pr(pars, d_max, n_c, r); 198 if (value>0.0) sum_pos += value; 199 sum += value; 200 } 201 return sum_pos/sum; 202 } 203 204 /** 205 * Get the fraction of the integral of P(r) over the whole range 206 * of r that is at least one sigma above zero. 207 */ 208 double positive_errors(double *pars, double *err, double d_max, int n_c, int nslice) { 209 double r; 210 double value; 211 int i; 212 double sum_pos = 0.0; 213 double sum = 0.0; 214 double pr_val; 215 double pr_val_err; 216 217 for (i=0; i<nslice; i++) { 218 r = d_max/(1.0*nslice)*i; 219 pr_err(pars, err, d_max, n_c, r, &pr_val, &pr_val_err); 220 if (pr_val>pr_val_err) sum_pos += pr_val; 221 sum += pr_val; 222 223 224 } 225 return sum_pos/sum; 226 } -
pr_inversion/c_extensions/invertor.h
rf71287f4 r43c0a8e 33 33 double r, double *pr_value, double *pr_value_err); 34 34 int npeaks(double *pars, double d_max, int n_c, int nslice); 35 double positive_integral(double *pars, double d_max, int n_c, int nslice); 36 double positive_errors(double *pars, double *err, double d_max, int n_c, int nslice); 35 37 36 38 #endif
Note: See TracChangeset
for help on using the changeset viewer.