31#define PYROPOGENERATOR_MODULE
35#include "pyrave_debug.h"
36#include "rave_alloc.h"
46#define raiseException_gotoTag(tag, type, msg) \
47{PyErr_SetString(type, msg); goto tag;}
52#define raiseException_returnNULL(type, msg) \
53{PyErr_SetString(type, msg); return NULL;}
58static PyObject *ErrorObject;
72 RAVE_ASSERT((ropogenerator != NULL),
"ropogenerator == NULL");
73 return RAVE_OBJECT_COPY(ropogenerator->
generator);
92 RAVE_CRITICAL0(
"Failed to allocate memory for ropo generator.");
100 cp = RAVE_OBJECT_COPY(p);
101 result = RAVE_OBJECT_GETBINDING(p);
102 if (result != NULL) {
107 if (result == NULL) {
109 if (result != NULL) {
110 PYRAVE_DEBUG_OBJECT_CREATED;
111 result->
generator = RAVE_OBJECT_COPY(cp);
112 RAVE_OBJECT_BIND(result->
generator, result);
114 RAVE_CRITICAL0(
"Failed to create PyRopoGenerator instance");
120 RAVE_OBJECT_RELEASE(cp);
134 PYRAVE_DEBUG_OBJECT_DESTROYED;
146static PyObject* _pyropogenerator_new(PyObject* self, PyObject* args)
148 PyObject* inptr = NULL;
150 if (!PyArg_ParseTuple(args,
"|O", &inptr)) {
169static PyObject* _pyropogenerator_getImage(
PyRopoGenerator* self, PyObject* args)
172 PyObject* result = NULL;
173 if (!PyArg_ParseTuple(args,
"")) {
180 RAVE_OBJECT_RELEASE(image);
182 if (result != NULL) {
195static PyObject* _pyropogenerator_setImage(
PyRopoGenerator* self, PyObject* args)
197 PyObject* inptr = NULL;
198 if (!PyArg_ParseTuple(args,
"O", &inptr)) {
214static PyObject* _pyropogenerator_threshold(
PyRopoGenerator* self, PyObject* args)
217 if (!PyArg_ParseTuple(args,
"i", &threshold)) {
230static PyObject* _pyropogenerator_speck(
PyRopoGenerator* self, PyObject* args)
232 int minDbz = 0, maxA = 0;
233 if (!PyArg_ParseTuple(args,
"ii", &minDbz, &maxA)) {
248static PyObject* _pyropogenerator_speckNormOld(
PyRopoGenerator* self, PyObject* args)
250 int minDbz = 0, maxA = 0, maxN = 0;
251 if (!PyArg_ParseTuple(args,
"iii", &minDbz, &maxA, &maxN)) {
266static PyObject* _pyropogenerator_emitter(
PyRopoGenerator* self, PyObject* args)
268 int minDbz = 0, length = 0;
269 if (!PyArg_ParseTuple(args,
"ii", &minDbz, &length)) {
284static PyObject* _pyropogenerator_emitter2(
PyRopoGenerator* self, PyObject* args)
286 int minDbz = 0, length = 0, width = 0;
287 if (!PyArg_ParseTuple(args,
"iii", &minDbz, &length, &width)) {
302static PyObject* _pyropogenerator_clutter(
PyRopoGenerator* self, PyObject* args)
304 int minDbz = 0, maxCompactness = 0;
305 if (!PyArg_ParseTuple(args,
"ii", &minDbz, &maxCompactness)) {
320static PyObject* _pyropogenerator_clutter2(
PyRopoGenerator* self, PyObject* args)
322 int minDbz = 0, maxSmoothness = 0;
323 if (!PyArg_ParseTuple(args,
"ii", &minDbz, &maxSmoothness)) {
338static PyObject* _pyropogenerator_softcut(
PyRopoGenerator* self, PyObject* args)
340 int maxDbz = 0, r = 0, r2 = 0;
341 if (!PyArg_ParseTuple(args,
"iii", &maxDbz, &r, &r2)) {
356static PyObject* _pyropogenerator_biomet(
PyRopoGenerator* self, PyObject* args)
358 int maxDbz = 0, dbzDelta = 0, maxAlt = 0, altDelta;
359 if (!PyArg_ParseTuple(args,
"iiii", &maxDbz, &dbzDelta, &maxAlt, &altDelta)) {
374static PyObject* _pyropogenerator_ship(
PyRopoGenerator* self, PyObject* args)
376 int minRelDbz = 0, minA = 0;
377 if (!PyArg_ParseTuple(args,
"ii", &minRelDbz, &minA)) {
392static PyObject* _pyropogenerator_sun(
PyRopoGenerator* self, PyObject* args)
394 int minDbz = 0, minLength = 0, maxThickness = 0;
395 if (!PyArg_ParseTuple(args,
"iii", &minDbz, &minLength, &maxThickness)) {
410static PyObject* _pyropogenerator_sun2(
PyRopoGenerator* self, PyObject* args)
412 int minDbz = 0, minLength = 0, maxThickness = 0, azimuth = 0, elevation = 0;
413 if (!PyArg_ParseTuple(args,
"iiiii", &minDbz, &minLength, &maxThickness, &azimuth, &elevation)) {
428static PyObject* _pyropogenerator_classify(
PyRopoGenerator* self, PyObject* args)
430 if (!PyArg_ParseTuple(args,
"")) {
445static PyObject* _pyropogenerator_declassify(
PyRopoGenerator* self, PyObject* args)
447 if (!PyArg_ParseTuple(args,
"")) {
460static PyObject* _pyropogenerator_restore(
PyRopoGenerator* self, PyObject* args)
463 PyObject* result = NULL;
465 if (!PyArg_ParseTuple(args,
"i", &threshold)) {
473 RAVE_OBJECT_RELEASE(image);
483static PyObject* _pyropogenerator_restore2(
PyRopoGenerator* self, PyObject* args)
486 PyObject* result = NULL;
488 if (!PyArg_ParseTuple(args,
"i", &threshold)) {
496 RAVE_OBJECT_RELEASE(image);
506static PyObject* _pyropogenerator_restoreSelf(
PyRopoGenerator* self, PyObject* args)
509 if (!PyArg_ParseTuple(args,
"i", &threshold)) {
524static PyObject* _pyropogenerator_getProbabilityFieldCount(
PyRopoGenerator* self, PyObject* args)
526 if (!PyArg_ParseTuple(args,
"")) {
538static PyObject* _pyropogenerator_getProbabilityField(
PyRopoGenerator* self, PyObject* args)
541 PyObject* result = NULL;
544 if (!PyArg_ParseTuple(args,
"i", &index)) {
552 RAVE_OBJECT_RELEASE(image);
559static struct PyMethodDef _pyropogenerator_methods[] =
561 {
"classification", NULL, METH_VARARGS},
562 {
"markers", NULL, METH_VARARGS},
563 {
"getImage", (PyCFunction)_pyropogenerator_getImage, 1},
564 {
"setImage", (PyCFunction)_pyropogenerator_setImage, 1},
565 {
"threshold", (PyCFunction)_pyropogenerator_threshold, 1},
566 {
"speck", (PyCFunction)_pyropogenerator_speck, 1},
567 {
"speckNormOld", (PyCFunction)_pyropogenerator_speckNormOld, 1},
568 {
"emitter", (PyCFunction)_pyropogenerator_emitter, 1},
569 {
"emitter2", (PyCFunction)_pyropogenerator_emitter2, 1},
570 {
"clutter", (PyCFunction)_pyropogenerator_clutter, 1},
571 {
"clutter2", (PyCFunction)_pyropogenerator_clutter2, 1},
572 {
"softcut", (PyCFunction)_pyropogenerator_softcut, 1},
573 {
"biomet", (PyCFunction)_pyropogenerator_biomet, 1},
574 {
"ship", (PyCFunction)_pyropogenerator_ship, 1},
575 {
"sun", (PyCFunction)_pyropogenerator_sun, 1},
576 {
"sun2", (PyCFunction)_pyropogenerator_sun2, 1},
577 {
"classify", (PyCFunction)_pyropogenerator_classify, 1},
578 {
"declassify", (PyCFunction)_pyropogenerator_declassify, 1},
579 {
"restore", (PyCFunction)_pyropogenerator_restore, 1},
580 {
"restore2", (PyCFunction)_pyropogenerator_restore2, 1},
581 {
"restoreSelf", (PyCFunction)_pyropogenerator_restoreSelf, 1},
582 {
"getProbabilityFieldCount", (PyCFunction)_pyropogenerator_getProbabilityFieldCount, 1},
583 {
"getProbabilityField", (PyCFunction)_pyropogenerator_getProbabilityField, 1},
590static PyObject* _pyropogenerator_getattro(
PyRopoGenerator* self, PyObject* name)
592 PyObject* res = NULL;
594 if (PY_COMPARE_STRING_WITH_ATTRO_NAME(
"classification", name) == 0) {
601 RAVE_OBJECT_RELEASE(image);
603 }
else if (PY_COMPARE_STRING_WITH_ATTRO_NAME(
"markers", name) == 0) {
610 RAVE_OBJECT_RELEASE(image);
613 return PyObject_GenericGetAttr((PyObject*)self, name);
619static int _pyropogenerator_setattro(
PyRopoGenerator* self, PyObject* name, PyObject* val)
641 PyVarObject_HEAD_INIT(NULL, 0)
646 (destructor)_pyropogenerator_dealloc,
658 (getattrofunc)_pyropogenerator_getattro,
659 (setattrofunc)_pyropogenerator_setattro,
669 _pyropogenerator_methods,
690 for (i = 0; i < prob->volume;i++) {
691 if (prob->array[i] >= master_prob->array[i]) {
693 mark->array[i]=marker;
695 master_prob->array[i]=prob->array[i];
700static PyObject* _pyropo_speck(PyObject* self, PyObject* args)
702 PyObject* inptr = NULL;
703 PyObject* result = NULL;
710 int intensity = 0, sz = 0;
711 if (!PyArg_ParseTuple(args,
"Oii|i", &inptr, &intensity, &sz, &sweep)) {
719 sourceSweep = RaveFmiImage_getSweep(image->
image, sweep);
720 if (sourceSweep == NULL) {
728 probSweep = RaveFmiImage_getSweep(prob, 0);
729 detect_specks(sourceSweep, probSweep, intensity, histogram_area);
730 semisigmoid_image(probSweep, sz);
731 invert_image(probSweep);
732 translate_intensity(probSweep, 255, 0);
735 RAVE_OBJECT_RELEASE(prob);
739static PyObject* _pyropo_emitter(PyObject* self, PyObject* args)
741 PyObject* inptr = NULL;
742 PyObject* result = NULL;
749 int intensity = 0, sz = 0;
750 if (!PyArg_ParseTuple(args,
"Oii|i", &inptr, &intensity, &sz, &sweep)) {
758 sourceSweep = RaveFmiImage_getSweep(image->
image, sweep);
759 if (sourceSweep == NULL) {
767 probSweep = RaveFmiImage_getSweep(prob, 0);
768 detect_emitters(sourceSweep, probSweep, intensity, sz);
771 RAVE_OBJECT_RELEASE(prob);
775static PyObject* _pyropo_restore(PyObject* self, PyObject* args)
777 PyObject* sweepptr = NULL;
778 PyObject* inprobabilityptr = NULL;
782 PyObject* result = NULL;
788 if (!PyArg_ParseTuple(args,
"OOi|i", &sweepptr, &inprobabilityptr, &threshold, &sweepnr)) {
798 sourceSweep = RaveFmiImage_getSweep(sweep->
image, sweepnr);
799 if (sourceSweep == NULL) {
802 probabilitySweep = RaveFmiImage_getSweep(probability->
image, 0);
803 if (probabilitySweep == NULL) {
808 if (resultimage == NULL) {
812 restore_image(sourceSweep, RaveFmiImage_getSweep(resultimage, 0), probabilitySweep, threshold);
815 RAVE_OBJECT_RELEASE(resultimage);
819static PyObject* _pyropo_restore2(PyObject* self, PyObject* args)
821 PyObject* sweepptr = NULL;
822 PyObject* inprobabilityptr = NULL;
826 PyObject* result = NULL;
832 if (!PyArg_ParseTuple(args,
"OOi|i", &sweepptr, &inprobabilityptr, &threshold, &sweepnr)) {
842 sourceSweep = RaveFmiImage_getSweep(sweep->
image, sweepnr);
843 if (sourceSweep == NULL) {
846 probabilitySweep = RaveFmiImage_getSweep(probability->
image, 0);
847 if (probabilitySweep == NULL) {
852 if (resultimage == NULL) {
856 restore_image2(sourceSweep, RaveFmiImage_getSweep(resultimage, 0), probabilitySweep, threshold);
859 RAVE_OBJECT_RELEASE(resultimage);
863static PyObject* _pyropo_update_classification(PyObject* self, PyObject* args)
865 PyObject *classificationptr = NULL, *probabilityptr = NULL, *targetprobabilityptr = NULL;
866 PyFmiImage *classification = NULL, *probability = NULL, *targetprobability = NULL;
867 FmiImage *cSweep = NULL, *pSweep = NULL, *tSweep = NULL;
869 FmiRadarPGMCode marker = CLEAR;
871 if (!PyArg_ParseTuple(args,
"OOi|O", &probabilityptr, &targetprobabilityptr, &marker, &classificationptr)) {
876 raiseException_returnNULL(PyExc_TypeError,
"Input types must be either OOi|O with probfield, targetprobfield, marker, classification field");
879 raiseException_returnNULL(PyExc_TypeError,
"Input types must be either OOi|O with probfield, targetprobfield, marker, classification field");
881 classification = (
PyFmiImage*)classificationptr;
883 targetprobability = (
PyFmiImage*)targetprobabilityptr;
885 if (RaveFmiImage_getSweepCount(probability->image) != 1 ||
886 RaveFmiImage_getSweepCount(targetprobability->image) != 1 ||
887 (classification != NULL && RaveFmiImage_getSweepCount(targetprobability->image) != 1)) {
888 raiseException_returnNULL(PyExc_TypeError,
"Input types must be either OOi|O with probfield, targetprobfield, marker, classification field with sweep count 1");
890 if (classification != NULL) {
891 cSweep = RaveFmiImage_getSweep(classification->
image, 0);
893 pSweep = RaveFmiImage_getSweep(probability->image, 0);
894 tSweep = RaveFmiImage_getSweep(targetprobability->image, 0);
896 canonize_image(pSweep, cSweep);
897 canonize_image(pSweep, tSweep);
899 _pyropointernal_update_classification(pSweep, tSweep, cSweep, marker);
908static PyMethodDef functions[] = {
909 {
"new", (PyCFunction)_pyropogenerator_new, 1},
913MOD_INIT(_ropogenerator)
915 PyObject *module=NULL,*dictionary=NULL;
917 PyObject *c_api_object = NULL;
923 MOD_INIT_DEF(module,
"_ropogenerator", NULL, functions);
924 if (module == NULL) {
925 return MOD_INIT_ERROR;
933 c_api_object = PyCapsule_New(PyRopoGenerator_API, PyRopoGenerator_CAPSULE_NAME, NULL);
934 dictionary = PyModule_GetDict(module);
935 PyDict_SetItemString(dictionary,
"_C_API", c_api_object);
937 ErrorObject = PyErr_NewException(
"_ropogenerator.error", NULL, NULL);
938 if (ErrorObject == NULL || PyDict_SetItemString(dictionary,
"error", ErrorObject) != 0) {
939 Py_FatalError(
"Can't define _ropogenerator.error");
940 return MOD_INIT_ERROR;
944 PYRAVE_DEBUG_INITIALIZE;
945 return MOD_INIT_SUCCESS(module);
#define import_fmiimage()
#define PyFmiImage_Check(op)
PyTypeObject PyRopoGenerator_Type
#define raiseException_gotoTag(tag, type, msg)
#define raiseException_returnNULL(type, msg)
PYRAVE_DEBUG_MODULE("_ropogenerator")
#define PyRopoGenerator_GetNative
#define PyRopoGenerator_GetNative_NUM
#define PyRopoGenerator_Type_NUM
#define PyRopoGenerator_New_NUM
#define PyRopoGenerator_API_pointers
#define PyRopoGenerator_New
RaveFmiImage_t * RaveFmiImage_new(int width, int height)
RaveCoreObjectType RaveRopoGenerator_TYPE
int RaveRopoGenerator_getProbabilityFieldCount(RaveRopoGenerator_t *self)
RaveFmiImage_t * RaveRopoGenerator_restore(RaveRopoGenerator_t *self, int threshold)
int RaveRopoGenerator_speckNormOld(RaveRopoGenerator_t *self, int minDbz, int maxA, int maxN)
int RaveRopoGenerator_clutter2(RaveRopoGenerator_t *self, int minDbz, int maxSmoothness)
void RaveRopoGenerator_threshold(RaveRopoGenerator_t *self, int threshold)
RaveFmiImage_t * RaveRopoGenerator_restore2(RaveRopoGenerator_t *self, int threshold)
RaveFmiImage_t * RaveRopoGenerator_getMarkers(RaveRopoGenerator_t *self)
int RaveRopoGenerator_sun2(RaveRopoGenerator_t *self, int minDbz, int minLength, int maxThickness, int azimuth, int elevation)
void RaveRopoGenerator_setImage(RaveRopoGenerator_t *self, RaveFmiImage_t *image)
void RaveRopoGenerator_declassify(RaveRopoGenerator_t *self)
int RaveRopoGenerator_sun(RaveRopoGenerator_t *self, int minDbz, int minLength, int maxThickness)
int RaveRopoGenerator_restoreSelf(RaveRopoGenerator_t *self, int threshold)
RaveFmiImage_t * RaveRopoGenerator_getClassification(RaveRopoGenerator_t *self)
int RaveRopoGenerator_clutter(RaveRopoGenerator_t *self, int minDbz, int maxCompactness)
int RaveRopoGenerator_speck(RaveRopoGenerator_t *self, int minDbz, int maxA)
int RaveRopoGenerator_classify(RaveRopoGenerator_t *self)
RaveFmiImage_t * RaveRopoGenerator_getImage(RaveRopoGenerator_t *self)
int RaveRopoGenerator_ship(RaveRopoGenerator_t *self, int minRelDbz, int minA)
int RaveRopoGenerator_biomet(RaveRopoGenerator_t *self, int maxDbz, int dbzDelta, int maxAlt, int altDelta)
int RaveRopoGenerator_emitter(RaveRopoGenerator_t *self, int minDbz, int length)
int RaveRopoGenerator_emitter2(RaveRopoGenerator_t *self, int minDbz, int length, int width)
int RaveRopoGenerator_softcut(RaveRopoGenerator_t *self, int maxDbz, int r, int r2)
RaveFmiImage_t * RaveRopoGenerator_getProbabilityField(RaveRopoGenerator_t *self, int index)
PyObject_HEAD RaveFmiImage_t * image
PyObject_HEAD RaveRopoGenerator_t * generator
RAVE_OBJECT_HEAD RaveFmiImage_t * image