diff --git a/schainc/_noise.c b/schainc/_noise.c new file mode 100644 index 0000000..32100c8 --- /dev/null +++ b/schainc/_noise.c @@ -0,0 +1,82 @@ +#include +#include +#include + + +static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args) { + double navg; + PyObject *data_obj, *data_array; + + if (!PyArg_ParseTuple(args, "Od", &data_obj, &navg)) { + return NULL; + } + + data_array = PyArray_FROM_OTF(data_obj, NPY_FLOAT64, NPY_IN_ARRAY); + + if (data_array == NULL) { + Py_XDECREF(data_array); + Py_XDECREF(data_obj); + return NULL; + } + double *sortdata = (double*)PyArray_DATA(data_array); + int lenOfData = (int)PyArray_SIZE(data_array) ; + double nums_min = lenOfData*0.2; + if (nums_min <= 5) nums_min = 5; + double sump = 0; + double sumq = 0; + int j = 0; + int cont = 1; + double rtest = 0; + while ((cont == 1) && (j < lenOfData)) { + sump = sump + sortdata[j]; + sumq = sumq + pow(sortdata[j], 2); + if (j > nums_min) { + rtest = (double)j/(j-1) + 1/navg; + if ((sumq*j) > (rtest*pow(sump, 2))) { + j = j - 1; + sump = sump - sortdata[j]; + sumq = sumq - pow(sortdata[j],2); + cont = 0; + } + } + j = j + 1; + } + + double lnoise = sump / j; + + Py_DECREF(data_array); + + return PyLong_FromLong(lnoise); + //return Py_BuildValue("d", lnoise); +} + + +static PyMethodDef noiseMethods[] = { + { "hildebrand_sekhon", hildebrand_sekhon, METH_VARARGS, "Get noise with hildebrand_sekhon algorithm" }, + { NULL, NULL, 0, NULL } +}; + +#if PY_MAJOR_VERSION >= 3 + +static struct PyModuleDef noisemodule = { + PyModuleDef_HEAD_INIT, + "_noise", + "Get noise with hildebrand_sekhon algorithm", + -1, + noiseMethods +}; + +#endif + +#if PY_MAJOR_VERSION >= 3 + PyMODINIT_FUNC PyInit__noise(void) { + Py_Initialize(); + import_array(); + return PyModule_Create(&noisemodule); + } +#else + PyMODINIT_FUNC init_noise() { + Py_InitModule("_noise", noiseMethods); + import_array(); + } +#endif diff --git a/schainpy/model/data/jrodata.py b/schainpy/model/data/jrodata.py index cdd83b7..042ae22 100644 --- a/schainpy/model/data/jrodata.py +++ b/schainpy/model/data/jrodata.py @@ -12,6 +12,7 @@ import json import schainpy.admin from schainpy.utils import log from .jroheaderIO import SystemHeader, RadarControllerHeader +from schainpy.model.data import _noise def getNumpyDtype(dataTypeCode): @@ -69,6 +70,7 @@ def hildebrand_sekhon(data, navg): """ sortdata = numpy.sort(data, axis=None) + ''' lenOfData = len(sortdata) nums_min = lenOfData*0.2 @@ -98,8 +100,8 @@ def hildebrand_sekhon(data, navg): j += 1 lnoise = sump / j - - return lnoise + ''' + return _noise.hildebrand_sekhon(sortdata, navg) class Beam: diff --git a/setup.py b/setup.py index 9516c75..3f28ddf 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ Created on Jul 16, 2014 @author: Miguel Urco +@author: Juan C. Espinoza ''' import os @@ -17,47 +18,51 @@ class build_ext(_build_ext): import numpy self.include_dirs.append(numpy.get_include()) -setup(name = "schainpy", - version = __version__, - description = "Python tools to read, write and process Jicamarca data", - author = "Miguel Urco", - author_email = "miguel.urco@jro.igp.gob.pe", - url = "http://jro.igp.gob.pe", - packages = {'schainpy', - 'schainpy.model', - 'schainpy.model.data', - 'schainpy.model.graphics', - 'schainpy.model.io', - 'schainpy.model.proc', - 'schainpy.model.serializer', - 'schainpy.model.utils', - 'schainpy.utils', - 'schainpy.gui', - 'schainpy.gui.figures', - 'schainpy.gui.viewcontroller', - 'schainpy.gui.viewer', - 'schainpy.gui.viewer.windows', - 'schainpy.cli'}, - ext_package = 'schainpy', - package_data = {'': ['schain.conf.template'], - 'schainpy.gui.figures': ['*.png', '*.jpg'], - 'schainpy.files': ['*.oga'] - }, - include_package_data = False, - scripts = ['schainpy/gui/schainGUI'], - entry_points = { - 'console_scripts': [ - 'schain = schainpy.cli.cli:main', - ], - }, - cmdclass = {'build_ext': build_ext}, - setup_requires = ["numpy >= 1.11.2"], - install_requires = [ - "scipy", - "h5py", - "matplotlib", - "pyzmq", - "fuzzywuzzy", - "click", - ], +setup( + name = "schainpy", + version = __version__, + description = "Python tools to read, write and process Jicamarca data", + author = "Miguel Urco, Juan C. Espinoza", + author_email = "juan.espinoza@jro.igp.gob.pe", + url = "http://jro-dev.igp.gob.pe/rhodecode/schain", + packages = { + 'schainpy', + 'schainpy.model', + 'schainpy.model.data', + 'schainpy.model.graphics', + 'schainpy.model.io', + 'schainpy.model.proc', + 'schainpy.model.utils', + 'schainpy.utils', + 'schainpy.gui', + 'schainpy.gui.figures', + 'schainpy.gui.viewcontroller', + 'schainpy.gui.viewer', + 'schainpy.gui.viewer.windows', + 'schainpy.cli', + }, + package_data = {'': ['schain.conf.template'], + 'schainpy.gui.figures': ['*.png', '*.jpg'], + 'schainpy.files': ['*.oga'] + }, + include_package_data = False, + scripts = ['schainpy/gui/schainGUI'], + entry_points = { + 'console_scripts': [ + 'schain = schainpy.cli.cli:main', + ], + }, + cmdclass = {'build_ext': build_ext}, + ext_modules=[ + Extension("schainpy.model.data._noise", ["schainc/_noise.c"]), + ], + setup_requires = ["numpy"], + install_requires = [ + "scipy", + "h5py", + "matplotlib", + "pyzmq", + "fuzzywuzzy", + "click", + ], )