Changeset 112f54c in sasview for realSpaceModeling/pointsmodelpy


Ignore:
Timestamp:
Dec 31, 2009 6:22:55 PM (15 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:
7e8601f
Parents:
adbb821
Message:

real_space_modeling: added method to return P(r) as two lists

Location:
realSpaceModeling/pointsmodelpy/pointsmodelpymodule
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • realSpaceModeling/pointsmodelpy/pointsmodelpymodule/bindings.cc

    r41e8114 r112f54c  
    129129     METH_VARARGS, pypointsmodelpy_get_complex_iq__doc__}, 
    130130 
    131     //outputPR 
    132     {pypointsmodelpy_outputPR__name__, pypointsmodelpy_outputPR, 
    133      METH_VARARGS, pypointsmodelpy_outputPR__doc__}, 
     131     //outputPR 
     132     {pypointsmodelpy_outputPR__name__, pypointsmodelpy_outputPR, 
     133      METH_VARARGS, pypointsmodelpy_outputPR__doc__}, 
     134 
     135    //getPR 
     136    {pypointsmodelpy_getPR__name__, pypointsmodelpy_getPR, 
     137     METH_VARARGS, pypointsmodelpy_getPR__doc__}, 
    134138 
    135139    //outputPR_xy 
  • realSpaceModeling/pointsmodelpy/pointsmodelpymodule/misc.cc

    rbbfad0a r112f54c  
    673673} 
    674674 
     675 
     676//method get_pr() 
     677char pypointsmodelpy_getPR__name__[] = "get_pr"; 
     678char pypointsmodelpy_getPR__doc__[] = "Return P(r) as a list of points"; 
     679 
     680PyObject * pypointsmodelpy_getPR(PyObject *, PyObject *args) 
     681{ 
     682  PyObject *pymodel = 0; 
     683  char *outfile; 
     684  int ok = PyArg_ParseTuple(args, "O", &pymodel); 
     685  if(!ok) return NULL; 
     686 
     687  void *temp = PyCObject_AsVoidPtr(pymodel); 
     688 
     689  LORESModel * thislores = static_cast<LORESModel *>(temp); 
     690 
     691  // Get the P(r) array 
     692  Array2D<double> pr_ = thislores->GetPr(); 
     693 
     694  // Create two lists to store the r and P(r) values 
     695  PyObject* r_list  = PyList_New(0); 
     696  PyObject* pr_list = PyList_New(0); 
     697 
     698  double sum = 0.0; 
     699  double r_stepsize = 1.0; 
     700  if (pr_.dim1()>2) r_stepsize = pr_[1][0] - pr_[0][0]; 
     701 
     702  for (int i = 0;  i < pr_.dim1(); ++i){ 
     703          sum += pr_[i][1]*r_stepsize; 
     704  } 
     705 
     706  for (int i = 0;  i < pr_.dim1(); ++i){ 
     707          if (pr_[i][1]==0) continue; 
     708          int r_append  = PyList_Append(r_list, Py_BuildValue("d", pr_[i][0])); 
     709          int pr_append = PyList_Append(pr_list, Py_BuildValue("d", pr_[i][1]/sum)); 
     710          if (r_append+pr_append<0) return NULL; 
     711  } 
     712 
     713  return Py_BuildValue("OO", r_list, pr_list); 
     714} 
     715 
     716 
     717 
    675718//method outputPR_xy(string filename) 
    676719char pypointsmodelpy_outputPR_xy__name__[] = "outputPR_xy"; 
  • realSpaceModeling/pointsmodelpy/pointsmodelpymodule/misc.h

    r41e8114 r112f54c  
    200200PyObject * pypointsmodelpy_outputPR(PyObject *, PyObject *); 
    201201 
     202//method get_pr() 
     203extern char pypointsmodelpy_getPR__name__[]; 
     204extern char pypointsmodelpy_getPR__doc__[]; 
     205extern "C" 
     206PyObject * pypointsmodelpy_getPR(PyObject *, PyObject *); 
     207 
     208 
    202209// method outputPR_xy 
    203210extern char pypointsmodelpy_outputPR_xy__name__[]; 
Note: See TracChangeset for help on using the changeset viewer.