Changeset f168d02 in sasview for pr_inversion/c_extensions


Ignore:
Timestamp:
Jul 1, 2008 2:56:32 PM (16 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:
2a92852
Parents:
a17ffdf
Message:

Added slit smearing (still slow)

Location:
pr_inversion/c_extensions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pr_inversion/c_extensions/Cinvertor.c

    rbd30f4a5 rf168d02  
    624624 
    625625        iq_value = iq(pars, self->params.d_max, npars, q); 
     626        return Py_BuildValue("f", iq_value); 
     627} 
     628 
     629const 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 */ 
     641static 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); 
    626653        return Py_BuildValue("f", iq_value); 
    627654} 
     
    875902                    a[i*nfunc+j] = 1.0/self->params.err[i]; 
    876903                } 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                        } 
    878911                } 
    879912            } 
     
    10091042                   {"get_nerr", (PyCFunction)get_nerr, METH_VARARGS, get_nerr_doc}, 
    10101043                   {"iq", (PyCFunction)get_iq, METH_VARARGS, get_iq_doc}, 
     1044                   {"iq_smeared", (PyCFunction)get_iq_smeared, METH_VARARGS, get_iq_smeared_doc}, 
    10111045                   {"pr", (PyCFunction)get_pr, METH_VARARGS, get_pr_doc}, 
    10121046                   {"get_pr_err", (PyCFunction)get_pr_err, METH_VARARGS, get_pr_err_doc}, 
  • pr_inversion/c_extensions/invertor.c

    r9a23253e rf168d02  
    6363double ortho_transformed_smeared(double d_max, int n, double height, double width, double q, int npts) { 
    6464        double sum, value, y, z; 
    65         int i, j; 
     65        int i, j, n_height, n_width; 
     66        double count_w; 
    6667        double fnpts; 
    6768        sum = 0.0; 
    6869        fnpts = (float)npts-1.0; 
    6970 
    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){ 
    7379                        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; 
    7492                        sum += ortho_transformed(d_max, n, sqrt((q-y)*(q-y)+z*z)); 
    7593                } 
    7694        } 
    77  
    78         return sum/npts/npts/height/width; 
     95        return sum/count_w; 
    7996} 
    8097 
     
    95112    for (i=0; i<n_c; i++) { 
    96113        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 */ 
     122double 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); 
    97127    } 
    98128    return sum; 
  • pr_inversion/c_extensions/invertor.h

    r9a23253e rf168d02  
    5555double int_pr(double *pars, double d_max, int n_c, int nslice); 
    5656double ortho_transformed_smeared(double d_max, int n, double heigth, double width, double q, int npts); 
     57double iq_smeared(double *pars, double d_max, int n_c, double height, double width, double q, int npts); 
    5758 
    5859#endif 
Note: See TracChangeset for help on using the changeset viewer.