@@ -0,0 +1,82 | |||
|
1 | #include <Python.h> | |
|
2 | #include <numpy/arrayobject.h> | |
|
3 | #include <math.h> | |
|
4 | ||
|
5 | ||
|
6 | static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args) { | |
|
7 | double navg; | |
|
8 | PyObject *data_obj, *data_array; | |
|
9 | ||
|
10 | if (!PyArg_ParseTuple(args, "Od", &data_obj, &navg)) { | |
|
11 | return NULL; | |
|
12 | } | |
|
13 | ||
|
14 | data_array = PyArray_FROM_OTF(data_obj, NPY_FLOAT64, NPY_IN_ARRAY); | |
|
15 | ||
|
16 | if (data_array == NULL) { | |
|
17 | Py_XDECREF(data_array); | |
|
18 | Py_XDECREF(data_obj); | |
|
19 | return NULL; | |
|
20 | } | |
|
21 | double *sortdata = (double*)PyArray_DATA(data_array); | |
|
22 | int lenOfData = (int)PyArray_SIZE(data_array) ; | |
|
23 | double nums_min = lenOfData*0.2; | |
|
24 | if (nums_min <= 5) nums_min = 5; | |
|
25 | double sump = 0; | |
|
26 | double sumq = 0; | |
|
27 | int j = 0; | |
|
28 | int cont = 1; | |
|
29 | double rtest = 0; | |
|
30 | while ((cont == 1) && (j < lenOfData)) { | |
|
31 | sump = sump + sortdata[j]; | |
|
32 | sumq = sumq + pow(sortdata[j], 2); | |
|
33 | if (j > nums_min) { | |
|
34 | rtest = (double)j/(j-1) + 1/navg; | |
|
35 | if ((sumq*j) > (rtest*pow(sump, 2))) { | |
|
36 | j = j - 1; | |
|
37 | sump = sump - sortdata[j]; | |
|
38 | sumq = sumq - pow(sortdata[j],2); | |
|
39 | cont = 0; | |
|
40 | } | |
|
41 | } | |
|
42 | j = j + 1; | |
|
43 | } | |
|
44 | ||
|
45 | double lnoise = sump / j; | |
|
46 | ||
|
47 | Py_DECREF(data_array); | |
|
48 | ||
|
49 | return PyLong_FromLong(lnoise); | |
|
50 | //return Py_BuildValue("d", lnoise); | |
|
51 | } | |
|
52 | ||
|
53 | ||
|
54 | static PyMethodDef noiseMethods[] = { | |
|
55 | { "hildebrand_sekhon", hildebrand_sekhon, METH_VARARGS, "Get noise with hildebrand_sekhon algorithm" }, | |
|
56 | { NULL, NULL, 0, NULL } | |
|
57 | }; | |
|
58 | ||
|
59 | #if PY_MAJOR_VERSION >= 3 | |
|
60 | ||
|
61 | static struct PyModuleDef noisemodule = { | |
|
62 | PyModuleDef_HEAD_INIT, | |
|
63 | "_noise", | |
|
64 | "Get noise with hildebrand_sekhon algorithm", | |
|
65 | -1, | |
|
66 | noiseMethods | |
|
67 | }; | |
|
68 | ||
|
69 | #endif | |
|
70 | ||
|
71 | #if PY_MAJOR_VERSION >= 3 | |
|
72 | PyMODINIT_FUNC PyInit__noise(void) { | |
|
73 | Py_Initialize(); | |
|
74 | import_array(); | |
|
75 | return PyModule_Create(&noisemodule); | |
|
76 | } | |
|
77 | #else | |
|
78 | PyMODINIT_FUNC init_noise() { | |
|
79 | Py_InitModule("_noise", noiseMethods); | |
|
80 | import_array(); | |
|
81 | } | |
|
82 | #endif |
@@ -12,6 +12,7 import json | |||
|
12 | 12 | import schainpy.admin |
|
13 | 13 | from schainpy.utils import log |
|
14 | 14 | from .jroheaderIO import SystemHeader, RadarControllerHeader |
|
15 | from schainpy.model.data import _noise | |
|
15 | 16 | |
|
16 | 17 | |
|
17 | 18 | def getNumpyDtype(dataTypeCode): |
@@ -69,6 +70,7 def hildebrand_sekhon(data, navg): | |||
|
69 | 70 | """ |
|
70 | 71 | |
|
71 | 72 | sortdata = numpy.sort(data, axis=None) |
|
73 | ''' | |
|
72 | 74 | lenOfData = len(sortdata) |
|
73 | 75 | nums_min = lenOfData*0.2 |
|
74 | 76 |
|
@@ -98,8 +100,8 def hildebrand_sekhon(data, navg): | |||
|
98 | 100 | j += 1 |
|
99 | 101 |
|
|
100 | 102 | lnoise = sump / j |
|
101 | ||
|
102 | return lnoise | |
|
103 | ''' | |
|
104 | return _noise.hildebrand_sekhon(sortdata, navg) | |
|
103 | 105 | |
|
104 | 106 | |
|
105 | 107 | class Beam: |
@@ -2,6 +2,7 | |||
|
2 | 2 | Created on Jul 16, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: Miguel Urco |
|
5 | @author: Juan C. Espinoza | |
|
5 | 6 | ''' |
|
6 | 7 | |
|
7 | 8 | import os |
@@ -17,47 +18,51 class build_ext(_build_ext): | |||
|
17 | 18 | import numpy |
|
18 | 19 | self.include_dirs.append(numpy.get_include()) |
|
19 | 20 | |
|
20 | setup(name = "schainpy", | |
|
21 | version = __version__, | |
|
22 | description = "Python tools to read, write and process Jicamarca data", | |
|
23 | author = "Miguel Urco", | |
|
24 | author_email = "miguel.urco@jro.igp.gob.pe", | |
|
25 |
|
|
|
26 | packages = {'schainpy', | |
|
27 | 'schainpy.model', | |
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 | 'schainpy.cli'}, | |
|
41 |
|
|
|
42 | package_data = {'': ['schain.conf.template'], | |
|
43 | 'schainpy.gui.figures': ['*.png', '*.jpg'], | |
|
44 |
|
|
|
45 |
|
|
|
46 | include_package_data = False, | |
|
47 | scripts = ['schainpy/gui/schainGUI'], | |
|
48 | entry_points = { | |
|
49 | 'console_scripts': [ | |
|
50 | 'schain = schainpy.cli.cli:main', | |
|
51 | ], | |
|
52 |
|
|
|
53 | cmdclass = {'build_ext': build_ext}, | |
|
54 | setup_requires = ["numpy >= 1.11.2"], | |
|
55 | install_requires = [ | |
|
56 | "scipy", | |
|
57 |
|
|
|
58 | "matplotlib", | |
|
59 | "pyzmq", | |
|
60 |
|
|
|
61 |
|
|
|
62 | ], | |
|
21 | setup( | |
|
22 | name = "schainpy", | |
|
23 | version = __version__, | |
|
24 | description = "Python tools to read, write and process Jicamarca data", | |
|
25 | author = "Miguel Urco, Juan C. Espinoza", | |
|
26 | author_email = "juan.espinoza@jro.igp.gob.pe", | |
|
27 | url = "http://jro-dev.igp.gob.pe/rhodecode/schain", | |
|
28 | packages = { | |
|
29 | 'schainpy', | |
|
30 | 'schainpy.model', | |
|
31 | 'schainpy.model.data', | |
|
32 | 'schainpy.model.graphics', | |
|
33 | 'schainpy.model.io', | |
|
34 | 'schainpy.model.proc', | |
|
35 | 'schainpy.model.utils', | |
|
36 | 'schainpy.utils', | |
|
37 | 'schainpy.gui', | |
|
38 | 'schainpy.gui.figures', | |
|
39 | 'schainpy.gui.viewcontroller', | |
|
40 | 'schainpy.gui.viewer', | |
|
41 | 'schainpy.gui.viewer.windows', | |
|
42 | 'schainpy.cli', | |
|
43 | }, | |
|
44 | package_data = {'': ['schain.conf.template'], | |
|
45 | 'schainpy.gui.figures': ['*.png', '*.jpg'], | |
|
46 | 'schainpy.files': ['*.oga'] | |
|
47 | }, | |
|
48 | include_package_data = False, | |
|
49 | scripts = ['schainpy/gui/schainGUI'], | |
|
50 | entry_points = { | |
|
51 | 'console_scripts': [ | |
|
52 | 'schain = schainpy.cli.cli:main', | |
|
53 | ], | |
|
54 | }, | |
|
55 | cmdclass = {'build_ext': build_ext}, | |
|
56 | ext_modules=[ | |
|
57 | Extension("schainpy.model.data._noise", ["schainc/_noise.c"]), | |
|
58 | ], | |
|
59 | setup_requires = ["numpy"], | |
|
60 | install_requires = [ | |
|
61 | "scipy", | |
|
62 | "h5py", | |
|
63 | "matplotlib", | |
|
64 | "pyzmq", | |
|
65 | "fuzzywuzzy", | |
|
66 | "click", | |
|
67 | ], | |
|
63 | 68 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now