Changeset 4f63160 in sasview


Ignore:
Timestamp:
May 8, 2008 7:13:59 PM (17 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
32dffae4
Parents:
34ab06d
Message:

number of peaks as figure of merit

Location:
pr_inversion/c_extensions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pr_inversion/c_extensions/Cinvertor.c

    rabad620 r4f63160  
    484484        norm   = int_p2(pars, self->params.d_max, npars, 100); 
    485485        return Py_BuildValue("f", sqrt(oscill/norm)/acos(-1.0)*self->params.d_max );     
     486         
     487} 
     488 
     489static PyObject * get_peaks(Cinvertor *self, PyObject *args) { 
     490        double *pars; 
     491        PyObject *data_obj; 
     492        Py_ssize_t npars; 
     493        int count; 
     494         
     495        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
     496        OUTVECTOR(data_obj,pars,npars); 
     497         
     498        count = npeaks(pars, self->params.d_max, npars, 100); 
     499 
     500        return Py_BuildValue("i", count );       
    486501         
    487502} 
     
    509524                   {"basefunc_ft", (PyCFunction)basefunc_ft, METH_VARARGS, ""}, 
    510525                   {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""}, 
     526                   {"get_peaks", (PyCFunction)get_peaks, METH_VARARGS, ""}, 
    511527    
    512528   {NULL} 
  • pr_inversion/c_extensions/invertor.c

    rabad620 r4f63160  
    152152} 
    153153 
     154/** 
     155 * Get the number of P(r) peaks. 
     156 */ 
     157int npeaks(double *pars, double d_max, int n_c, int nslice) { 
     158    double r;  
     159    double value; 
     160        int i; 
     161        double previous = 0.0; 
     162        double slope    = 0.0; 
     163        int count = 0; 
     164    for (i=0; i<nslice; i++) { 
     165        r = d_max/(1.0*nslice)*i; 
     166        value = pr(pars, d_max, n_c, r); 
     167        if (previous<=value){ 
     168                //if (slope<0) count += 1; 
     169                slope = 1; 
     170        } else { 
     171                //printf("slope -1"); 
     172                if (slope>0) count += 1; 
     173                slope = -1; 
     174        } 
     175        previous = value; 
     176    } 
     177    return count; 
     178} 
     179 
  • pr_inversion/c_extensions/invertor.h

    rabad620 r4f63160  
    3030void pr_err(double *pars, double *err, double d_max, int n_c,  
    3131                double r, double *pr_value, double *pr_value_err); 
     32int npeaks(double *pars, double d_max, int n_c, int nslice); 
     33 
    3234#endif 
Note: See TracChangeset for help on using the changeset viewer.