##// END OF EJS Templates
Add C extension for hildebrand_sekhon noise estimation and update requirements versions in setup
Juan C. Valdez -
r878:0ef791f9f681
parent child
Show More
@@ -0,0 +1,55
1 #include <Python.h>
2 #include <numpy/arrayobject.h>
3 #include <math.h>
4
5 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args);
6
7 static PyMethodDef extensionsMethods[] = {
8 { "hildebrand_sekhon", (PyCFunction)hildebrand_sekhon, METH_VARARGS, "get noise with" },
9 { NULL, NULL, 0, NULL }
10 };
11
12 PyMODINIT_FUNC initcSchain() {
13 Py_InitModule("cSchain", extensionsMethods);
14 import_array();
15 }
16
17 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args) {
18 /* Do your stuff here. */
19 double navg;
20 PyObject *data_obj, *data_array;
21
22 if (!PyArg_ParseTuple(args, "Od", &data_obj, &navg)) return NULL;
23 data_array = PyArray_FROM_OTF(data_obj, NPY_FLOAT64, NPY_IN_ARRAY);
24 if (data_array == NULL) {
25 Py_XDECREF(data_array);
26 Py_XDECREF(data_obj);
27 return NULL;
28 }
29 double *sortdata = (double*)PyArray_DATA(data_array);
30 int lenOfData = (int)PyArray_SIZE(data_array) ;
31 double nums_min = lenOfData*0.2;
32 if (nums_min <= 5) nums_min = 5;
33 double sump = 0;
34 double sumq = 0;
35 int j = 0;
36 int cont = 1;
37 double rtest = 0;
38 while ((cont == 1) && (j < lenOfData)) {
39 sump = sump + sortdata[j];
40 sumq = sumq + pow(sortdata[j], 2);
41 if (j > nums_min) {
42 rtest = (double)j/(j-1) + 1/navg;
43 if ((sumq*j) > (rtest*pow(sump, 2))) {
44 j = j - 1;
45 sump = sump - sortdata[j];
46 sumq = sumq - pow(sortdata[j],2);
47 cont = 0;
48 }
49 }
50 j = j + 1;
51 }
52
53 double lnoise = sump / j;
54 return Py_BuildValue("d", lnoise);
55 }
@@ -9,6 +9,8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from schainpy import cSchain
13
12
14
13 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
14
16
@@ -64,41 +66,45 def hildebrand_sekhon(data, navg):
64 """
66 """
65
67
66 sortdata = numpy.sort(data,axis=None)
68 sortdata = numpy.sort(data,axis=None)
67 lenOfData = len(sortdata)
69 # lenOfData = len(sortdata)
68 nums_min = lenOfData*0.2
70 # nums_min = lenOfData*0.2
69
71 #
70 if nums_min <= 5:
72 # if nums_min <= 5:
71 nums_min = 5
73 # nums_min = 5
74 #
75 # sump = 0.
76 #
77 # sumq = 0.
78 #
79 # j = 0
80 #
81 # cont = 1
82 #
83 # while((cont==1)and(j<lenOfData)):
84 #
85 # sump += sortdata[j]
86 #
87 # sumq += sortdata[j]**2
88 #
89 # if j > nums_min:
90 # rtest = float(j)/(j-1) + 1.0/navg
91 # if ((sumq*j) > (rtest*sump**2)):
92 # j = j - 1
93 # sump = sump - sortdata[j]
94 # sumq = sumq - sortdata[j]**2
95 # cont = 0
96 #
97 # j += 1
98 #
99 # lnoise = sump /j
100 #
101 # return lnoise
102
103 return cSchain.hildebrand_sekhon(sortdata, navg)
72
104
73 sump = 0.
74
75 sumq = 0.
76
77 j = 0
78
79 cont = 1
80
81 while((cont==1)and(j<lenOfData)):
82
83 sump += sortdata[j]
84
85 sumq += sortdata[j]**2
86
87 if j > nums_min:
88 rtest = float(j)/(j-1) + 1.0/navg
89 if ((sumq*j) > (rtest*sump**2)):
90 j = j - 1
91 sump = sump - sortdata[j]
92 sumq = sumq - sortdata[j]**2
93 cont = 0
94
95 j += 1
96
97 lnoise = sump /j
98 # stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
99 return lnoise
100
105
101 class Beam:
106 class Beam:
107
102 def __init__(self):
108 def __init__(self):
103 self.codeList = []
109 self.codeList = []
104 self.azimuthList = []
110 self.azimuthList = []
@@ -1,7 +1,7
1 '''
1 '''
2 Created on Jul 16, 2014
2 Created on Jul 16, 2014
3
3
4 @author: @author: Miguel Urco
4 @author: Miguel Urco
5 '''
5 '''
6
6
7 from schainpy import __version__
7 from schainpy import __version__
@@ -26,6 +26,7 setup(name="schainpy",
26 'schainpy.gui.viewcontroller',
26 'schainpy.gui.viewcontroller',
27 'schainpy.gui.viewer',
27 'schainpy.gui.viewer',
28 'schainpy.gui.viewer.windows'},
28 'schainpy.gui.viewer.windows'},
29 ext_package='schainpy',
29 py_modules=[''],
30 py_modules=[''],
30 package_data={'': ['schain.conf.template'],
31 package_data={'': ['schain.conf.template'],
31 'schainpy.gui.figures': ['*.png','*.jpg'],
32 'schainpy.gui.figures': ['*.png','*.jpg'],
@@ -33,13 +34,15 setup(name="schainpy",
33 include_package_data=False,
34 include_package_data=False,
34 scripts =['schainpy/gui/schainGUI',
35 scripts =['schainpy/gui/schainGUI',
35 'schainpy/scripts/schain'],
36 'schainpy/scripts/schain'],
37 ext_modules=[Extension("cSchain", ["schainpy/model/proc/extensions.c"])],
36 install_requires=[
38 install_requires=[
37 "scipy >= 0.9.0",
39 "scipy >= 0.14.0",
38 "h5py >= 2.0.1",
40 "h5py >= 2.2.1",
39 "matplotlib >= 1.0.0",
41 "matplotlib >= 1.4.2",
40 "pyfits >= 2.0.0",
42 "pyfits >= 3.4",
41 "numpy >= 1.6.0",
43 "numpy >= 1.11.2",
42 "paramiko",
44 "paramiko >= 2.1.2",
43 "paho-mqtt"
45 "paho-mqtt >= 1.2",
46 "zmq",
44 ],
47 ],
45 ) No newline at end of file
48 )
General Comments 0
You need to be logged in to leave comments. Login now