ROPO
Loading...
Searching...
No Matches
pyropogenerator.c
Go to the documentation of this file.
1/* --------------------------------------------------------------------
2Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
3
4This file is part of bRopo.
5
6bRopo is free software: you can redistribute it and/or modify
7it under the terms of the GNU Lesser General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11bRopo is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU Lesser General Public License for more details.
15
16You should have received a copy of the GNU Lesser General Public License
17along with bRopo. If not, see <http://www.gnu.org/licenses/>.
18------------------------------------------------------------------------*/
25#include "pyropo_compat.h"
26#include "Python.h"
27#include <math.h>
28#include <stdio.h>
29#include <string.h>
30
31#define PYROPOGENERATOR_MODULE
32#include "pyropogenerator.h"
33
34#include "pyfmiimage.h"
35#include "pyrave_debug.h"
36#include "rave_alloc.h"
37
41PYRAVE_DEBUG_MODULE("_ropogenerator");
42
46#define raiseException_gotoTag(tag, type, msg) \
47{PyErr_SetString(type, msg); goto tag;}
48
52#define raiseException_returnNULL(type, msg) \
53{PyErr_SetString(type, msg); return NULL;}
54
58static PyObject *ErrorObject;
59
63
71{
72 RAVE_ASSERT((ropogenerator != NULL), "ropogenerator == NULL");
73 return RAVE_OBJECT_COPY(ropogenerator->generator);
74}
75
83static PyRopoGenerator*
85{
86 PyRopoGenerator* result = NULL;
87 RaveRopoGenerator_t* cp = NULL;
88
89 if (p == NULL) {
90 cp = RAVE_OBJECT_NEW(&RaveRopoGenerator_TYPE);
91 if (cp == NULL) {
92 RAVE_CRITICAL0("Failed to allocate memory for ropo generator.");
93 raiseException_returnNULL(PyExc_MemoryError, "Failed to allocate memory for ropo generator.");
94 }
95
96 if (image != NULL) {
98 }
99 } else {
100 cp = RAVE_OBJECT_COPY(p);
101 result = RAVE_OBJECT_GETBINDING(p); // If p already have a binding, then this should only be increfed.
102 if (result != NULL) {
103 Py_INCREF(result);
104 }
105 }
106
107 if (result == NULL) {
108 result = PyObject_NEW(PyRopoGenerator, &PyRopoGenerator_Type);
109 if (result != NULL) {
110 PYRAVE_DEBUG_OBJECT_CREATED;
111 result->generator = RAVE_OBJECT_COPY(cp);
112 RAVE_OBJECT_BIND(result->generator, result);
113 } else {
114 RAVE_CRITICAL0("Failed to create PyRopoGenerator instance");
115 raiseException_gotoTag(done, PyExc_MemoryError, "Failed to allocate memory for ropo generator.");
116 }
117 }
118
119done:
120 RAVE_OBJECT_RELEASE(cp);
121 return result;
122}
123
128static void _pyropogenerator_dealloc(PyRopoGenerator* obj)
129{
130 /*Nothing yet*/
131 if (obj == NULL) {
132 return;
133 }
134 PYRAVE_DEBUG_OBJECT_DESTROYED;
135 RAVE_OBJECT_UNBIND(obj->generator, obj);
136 RAVE_OBJECT_RELEASE(obj->generator);
137 PyObject_Del(obj);
138}
139
146static PyObject* _pyropogenerator_new(PyObject* self, PyObject* args)
147{
148 PyObject* inptr = NULL;
149
150 if (!PyArg_ParseTuple(args, "|O", &inptr)) {
151 return NULL;
152 }
153 if (inptr != NULL && !PyFmiImage_Check(inptr)) {
154 raiseException_returnNULL(PyExc_TypeError, "Generator only takes FmiImageCore instances");
155 }
156 if (inptr != NULL) {
157 return (PyObject*)PyRopoGenerator_New(NULL, ((PyFmiImage*)inptr)->image);
158 } else {
159 return (PyObject*)PyRopoGenerator_New(NULL, NULL);
160 }
161}
162
169static PyObject* _pyropogenerator_getImage(PyRopoGenerator* self, PyObject* args)
170{
171 RaveFmiImage_t* image = NULL;
172 PyObject* result = NULL;
173 if (!PyArg_ParseTuple(args, "")) {
174 return NULL;
175 }
177 if (image != NULL) {
178 result = (PyObject*)PyFmiImage_New(image,0,0);
179 }
180 RAVE_OBJECT_RELEASE(image);
181
182 if (result != NULL) {
183 return result;
184 }
185
186 Py_RETURN_NONE;
187}
188
195static PyObject* _pyropogenerator_setImage(PyRopoGenerator* self, PyObject* args)
196{
197 PyObject* inptr = NULL;
198 if (!PyArg_ParseTuple(args, "O", &inptr)) {
199 return NULL;
200 }
201 if (!PyFmiImage_Check(inptr)) {
202 raiseException_returnNULL(PyExc_TypeError, "Generator can only be set with fmi images");
203 }
205 Py_RETURN_NONE;
206}
207
214static PyObject* _pyropogenerator_threshold(PyRopoGenerator* self, PyObject* args)
215{
216 int threshold = 0;
217 if (!PyArg_ParseTuple(args, "i", &threshold)) {
218 return NULL;
219 }
220 RaveRopoGenerator_threshold(self->generator, threshold);
221 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
222}
223
230static PyObject* _pyropogenerator_speck(PyRopoGenerator* self, PyObject* args)
231{
232 int minDbz = 0, maxA = 0;
233 if (!PyArg_ParseTuple(args, "ii", &minDbz, &maxA)) {
234 return NULL;
235 }
236 if (!RaveRopoGenerator_speck(self->generator, minDbz, maxA)) {
237 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run speck");
238 }
239 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
240}
241
248static PyObject* _pyropogenerator_speckNormOld(PyRopoGenerator* self, PyObject* args)
249{
250 int minDbz = 0, maxA = 0, maxN = 0;
251 if (!PyArg_ParseTuple(args, "iii", &minDbz, &maxA, &maxN)) {
252 return NULL;
253 }
254 if (!RaveRopoGenerator_speckNormOld(self->generator, minDbz, maxA, maxN)) {
255 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run speckNormOld");
256 }
257 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
258}
259
266static PyObject* _pyropogenerator_emitter(PyRopoGenerator* self, PyObject* args)
267{
268 int minDbz = 0, length = 0;
269 if (!PyArg_ParseTuple(args, "ii", &minDbz, &length)) {
270 return NULL;
271 }
272 if (!RaveRopoGenerator_emitter(self->generator, minDbz, length)) {
273 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run emitter");
274 }
275 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
276}
277
284static PyObject* _pyropogenerator_emitter2(PyRopoGenerator* self, PyObject* args)
285{
286 int minDbz = 0, length = 0, width = 0;
287 if (!PyArg_ParseTuple(args, "iii", &minDbz, &length, &width)) {
288 return NULL;
289 }
290 if (!RaveRopoGenerator_emitter2(self->generator, minDbz, length, width)) {
291 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run emitter2");
292 }
293 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
294}
295
302static PyObject* _pyropogenerator_clutter(PyRopoGenerator* self, PyObject* args)
303{
304 int minDbz = 0, maxCompactness = 0;
305 if (!PyArg_ParseTuple(args, "ii", &minDbz, &maxCompactness)) {
306 return NULL;
307 }
308 if (!RaveRopoGenerator_clutter(self->generator, minDbz, maxCompactness)) {
309 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run clutter");
310 }
311 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
312}
313
320static PyObject* _pyropogenerator_clutter2(PyRopoGenerator* self, PyObject* args)
321{
322 int minDbz = 0, maxSmoothness = 0;
323 if (!PyArg_ParseTuple(args, "ii", &minDbz, &maxSmoothness)) {
324 return NULL;
325 }
326 if (!RaveRopoGenerator_clutter2(self->generator, minDbz, maxSmoothness)) {
327 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run clutter2");
328 }
329 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
330}
331
338static PyObject* _pyropogenerator_softcut(PyRopoGenerator* self, PyObject* args)
339{
340 int maxDbz = 0, r = 0, r2 = 0;
341 if (!PyArg_ParseTuple(args, "iii", &maxDbz, &r, &r2)) {
342 return NULL;
343 }
344 if (!RaveRopoGenerator_softcut(self->generator, maxDbz, r, r2)) {
345 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run softcut");
346 }
347 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
348}
349
356static PyObject* _pyropogenerator_biomet(PyRopoGenerator* self, PyObject* args)
357{
358 int maxDbz = 0, dbzDelta = 0, maxAlt = 0, altDelta;
359 if (!PyArg_ParseTuple(args, "iiii", &maxDbz, &dbzDelta, &maxAlt, &altDelta)) {
360 return NULL;
361 }
362 if (!RaveRopoGenerator_biomet(self->generator, maxDbz, dbzDelta, maxAlt, altDelta)) {
363 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run biomet");
364 }
365 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
366}
367
374static PyObject* _pyropogenerator_ship(PyRopoGenerator* self, PyObject* args)
375{
376 int minRelDbz = 0, minA = 0;
377 if (!PyArg_ParseTuple(args, "ii", &minRelDbz, &minA)) {
378 return NULL;
379 }
380 if (!RaveRopoGenerator_ship(self->generator, minRelDbz, minA)) {
381 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run ship");
382 }
383 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
384}
385
392static PyObject* _pyropogenerator_sun(PyRopoGenerator* self, PyObject* args)
393{
394 int minDbz = 0, minLength = 0, maxThickness = 0;
395 if (!PyArg_ParseTuple(args, "iii", &minDbz, &minLength, &maxThickness)) {
396 return NULL;
397 }
398 if (!RaveRopoGenerator_sun(self->generator, minDbz, minLength, maxThickness)) {
399 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run sun");
400 }
401 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
402}
403
410static PyObject* _pyropogenerator_sun2(PyRopoGenerator* self, PyObject* args)
411{
412 int minDbz = 0, minLength = 0, maxThickness = 0, azimuth = 0, elevation = 0;
413 if (!PyArg_ParseTuple(args, "iiiii", &minDbz, &minLength, &maxThickness, &azimuth, &elevation)) {
414 return NULL;
415 }
416 if (!RaveRopoGenerator_sun2(self->generator, minDbz, minLength, maxThickness, azimuth, elevation)) {
417 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to run sun2");
418 }
419 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
420}
421
428static PyObject* _pyropogenerator_classify(PyRopoGenerator* self, PyObject* args)
429{
430 if (!PyArg_ParseTuple(args, "")) {
431 return NULL;
432 }
434 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to classify detector sequence");
435 }
436 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
437}
438
445static PyObject* _pyropogenerator_declassify(PyRopoGenerator* self, PyObject* args)
446{
447 if (!PyArg_ParseTuple(args, "")) {
448 return NULL;
449 }
451 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
452}
453
460static PyObject* _pyropogenerator_restore(PyRopoGenerator* self, PyObject* args)
461{
462 RaveFmiImage_t* image = NULL;
463 PyObject* result = NULL;
464 int threshold = 0;
465 if (!PyArg_ParseTuple(args, "i", &threshold)) {
466 return NULL;
467 }
468 image = RaveRopoGenerator_restore(self->generator, threshold);
469 if (image == NULL) {
470 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to classify detector sequence");
471 }
472 result = (PyObject*)PyFmiImage_New(image, 0, 0);
473 RAVE_OBJECT_RELEASE(image);
474 return result;
475}
476
483static PyObject* _pyropogenerator_restore2(PyRopoGenerator* self, PyObject* args)
484{
485 RaveFmiImage_t* image = NULL;
486 PyObject* result = NULL;
487 int threshold = 0;
488 if (!PyArg_ParseTuple(args, "i", &threshold)) {
489 return NULL;
490 }
491 image = RaveRopoGenerator_restore2(self->generator, threshold);
492 if (image == NULL) {
493 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to classify detector sequence");
494 }
495 result = (PyObject*)PyFmiImage_New(image, 0, 0);
496 RAVE_OBJECT_RELEASE(image);
497 return result;
498}
499
506static PyObject* _pyropogenerator_restoreSelf(PyRopoGenerator* self, PyObject* args)
507{
508 int threshold = 0;
509 if (!PyArg_ParseTuple(args, "i", &threshold)) {
510 return NULL;
511 }
512 if (!RaveRopoGenerator_restoreSelf(self->generator, threshold)) {
513 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to restore self");
514 }
515 return (PyObject*)PyRopoGenerator_New(self->generator, NULL);
516}
517
524static PyObject* _pyropogenerator_getProbabilityFieldCount(PyRopoGenerator* self, PyObject* args)
525{
526 if (!PyArg_ParseTuple(args, "")) {
527 return NULL;
528 }
529 return PyLong_FromLong((int)RaveRopoGenerator_getProbabilityFieldCount(self->generator));
530}
531
538static PyObject* _pyropogenerator_getProbabilityField(PyRopoGenerator* self, PyObject* args)
539{
540 RaveFmiImage_t* image = NULL;
541 PyObject* result = NULL;
542
543 int index = 0;
544 if (!PyArg_ParseTuple(args, "i", &index)) {
545 return NULL;
546 }
548 if (image == NULL) {
549 raiseException_returnNULL(PyExc_IndexError, "Failed to return probability field at specified index");
550 }
551 result = (PyObject*)PyFmiImage_New(image, 0, 0);
552 RAVE_OBJECT_RELEASE(image);
553 return result;
554}
555
559static struct PyMethodDef _pyropogenerator_methods[] =
560{
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},
584 {NULL, NULL} /* sentinel */
585};
586
590static PyObject* _pyropogenerator_getattro(PyRopoGenerator* self, PyObject* name)
591{
592 PyObject* res = NULL;
593
594 if (PY_COMPARE_STRING_WITH_ATTRO_NAME("classification", name) == 0) {
595 RaveFmiImage_t* image = NULL;
597 if (image == NULL) {
598 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to get classification");
599 }
600 res = (PyObject*)PyFmiImage_New(image,0,0);
601 RAVE_OBJECT_RELEASE(image);
602 return res;
603 } else if (PY_COMPARE_STRING_WITH_ATTRO_NAME("markers", name) == 0) {
604 RaveFmiImage_t* image = NULL;
606 if (image == NULL) {
607 raiseException_returnNULL(PyExc_RuntimeWarning, "Failed to get classification");
608 }
609 res = (PyObject*)PyFmiImage_New(image,0,0);
610 RAVE_OBJECT_RELEASE(image);
611 return res;
612 }
613 return PyObject_GenericGetAttr((PyObject*)self, name);
614}
615
619static int _pyropogenerator_setattro(PyRopoGenerator* self, PyObject* name, PyObject* val)
620{
621 int result = -1;
622 if (name == NULL) {
623 goto done;
624 }
625
626 raiseException_gotoTag(done, PyExc_AttributeError, PY_RAVE_ATTRO_NAME_TO_STRING(name));
627
628 result = 0;
629done:
630 return result;
631}
632
638
640{
641 PyVarObject_HEAD_INIT(NULL, 0) /*ob_size*/
642 "RopoGeneratorCore", /*tp_name*/
643 sizeof(PyRopoGenerator), /*tp_size*/
644 0, /*tp_itemsize*/
645 /* methods */
646 (destructor)_pyropogenerator_dealloc, /*tp_dealloc*/
647 0, /*tp_print*/
648 (getattrfunc)0, /*tp_getattr*/
649 (setattrfunc)0, /*tp_setattr*/
650 0, /*tp_compare*/
651 0, /*tp_repr*/
652 0, /*tp_as_number */
653 0,
654 0, /*tp_as_mapping */
655 0, /*tp_hash*/
656 (ternaryfunc)0, /*tp_call*/
657 (reprfunc)0, /*tp_str*/
658 (getattrofunc)_pyropogenerator_getattro, /*tp_getattro*/
659 (setattrofunc)_pyropogenerator_setattro, /*tp_setattro*/
660 0, /*tp_as_buffer*/
661 Py_TPFLAGS_DEFAULT, /*tp_flags*/
662 0, /*tp_doc*/
663 (traverseproc)0, /*tp_traverse*/
664 (inquiry)0, /*tp_clear*/
665 0, /*tp_richcompare*/
666 0, /*tp_weaklistoffset*/
667 0, /*tp_iter*/
668 0, /*tp_iternext*/
669 _pyropogenerator_methods, /*tp_methods*/
670 0, /*tp_members*/
671 0, /*tp_getset*/
672 0, /*tp_base*/
673 0, /*tp_dict*/
674 0, /*tp_descr_get*/
675 0, /*tp_descr_set*/
676 0, /*tp_dictoffset*/
677 0, /*tp_init*/
678 0, /*tp_alloc*/
679 0, /*tp_new*/
680 0, /*tp_free*/
681 0, /*tp_is_gc*/
682};
685#ifdef KALLE
687static void _pyropointernal_update_classification(FmiImage *prob,FmiImage *master_prob,FmiImage *mark,Byte marker)
688{
689 register int i;
690 for (i = 0; i < prob->volume;i++) {
691 if (prob->array[i] >= master_prob->array[i]) {
692 if (mark != NULL) {
693 mark->array[i]=marker;
694 }
695 master_prob->array[i]=prob->array[i];
696 }
697 }
698}
699
700static PyObject* _pyropo_speck(PyObject* self, PyObject* args)
701{
702 PyObject* inptr = NULL;
703 PyObject* result = NULL;
704 PyFmiImage* image = NULL;
705 RaveFmiImage_t* prob = NULL;
706 FmiImage* sourceSweep = NULL; /* Do not release, internal memory */
707 FmiImage* probSweep = NULL; /* Do not release, internal memory */
708
709 int sweep = 0;
710 int intensity = 0, sz = 0; /* min DBZ, max area */
711 if (!PyArg_ParseTuple(args, "Oii|i", &inptr, &intensity, &sz, &sweep)) {
712 return NULL;
713 }
714
715 if (!PyFmiImage_Check(inptr)) {
716 raiseException_returnNULL(PyExc_TypeError, "speck takes FmiImages as input");
717 }
718 image = (PyFmiImage*)inptr;
719 sourceSweep = RaveFmiImage_getSweep(image->image, sweep);
720 if (sourceSweep == NULL) {
721 raiseException_returnNULL(PyExc_TypeError, "Input fmi image does not contain that sweep");
722 }
723
724 prob = RaveFmiImage_new(1);
725 if (prob == NULL) {
726 return NULL;
727 }
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);
733
734 result = (PyObject*)PyFmiImage_New(prob, 0);
735 RAVE_OBJECT_RELEASE(prob);
736 return result;
737}
738
739static PyObject* _pyropo_emitter(PyObject* self, PyObject* args)
740{
741 PyObject* inptr = NULL;
742 PyObject* result = NULL;
743 PyFmiImage* image = NULL;
744 RaveFmiImage_t* prob = NULL;
745 FmiImage* sourceSweep = NULL; /* Do not release, internal memory */
746 FmiImage* probSweep = NULL; /* Do not release, internal memory */
747
748 int sweep = 0;
749 int intensity = 0, sz = 0; /* min DBZ, max area */
750 if (!PyArg_ParseTuple(args, "Oii|i", &inptr, &intensity, &sz, &sweep)) {
751 return NULL;
752 }
753
754 if (!PyFmiImage_Check(inptr)) {
755 raiseException_returnNULL(PyExc_TypeError, "speck takes FmiImages as input");
756 }
757 image = (PyFmiImage*)inptr;
758 sourceSweep = RaveFmiImage_getSweep(image->image, sweep);
759 if (sourceSweep == NULL) {
760 raiseException_returnNULL(PyExc_TypeError, "Input fmi image does not contain that sweep");
761 }
762
763 prob = RaveFmiImage_new(1);
764 if (prob == NULL) {
765 return NULL;
766 }
767 probSweep = RaveFmiImage_getSweep(prob, 0);
768 detect_emitters(sourceSweep, probSweep, intensity, sz);
769
770 result = (PyObject*)PyFmiImage_New(prob, 0);
771 RAVE_OBJECT_RELEASE(prob);
772 return result;
773}
774
775static PyObject* _pyropo_restore(PyObject* self, PyObject* args)
776{
777 PyObject* sweepptr = NULL;
778 PyObject* inprobabilityptr = NULL;
779 PyFmiImage* sweep = NULL;
780 PyFmiImage* probability = NULL;
781 RaveFmiImage_t* resultimage = NULL;
782 PyObject* result = NULL;
783 FmiImage* sourceSweep = NULL; /* Do not release, internal memory */
784 FmiImage* probabilitySweep = NULL; /* Do not release, internal memory */
785 int threshold = 255;
786 int sweepnr = 0;
787
788 if (!PyArg_ParseTuple(args, "OOi|i", &sweepptr, &inprobabilityptr, &threshold, &sweepnr)) {
789 return NULL;
790 }
791
792 if (!PyFmiImage_Check(sweepptr) || !PyFmiImage_Check(inprobabilityptr)) {
793 raiseException_returnNULL(PyExc_TypeError, "restore takes sweep, probability field and threshold as input");
794 }
795 sweep = (PyFmiImage*)sweepptr;
796 probability = (PyFmiImage*)inprobabilityptr;
797
798 sourceSweep = RaveFmiImage_getSweep(sweep->image, sweepnr);
799 if (sourceSweep == NULL) {
800 raiseException_returnNULL(PyExc_TypeError, "Input fmi image does not contain that sweep");
801 }
802 probabilitySweep = RaveFmiImage_getSweep(probability->image, 0);
803 if (probabilitySweep == NULL) {
804 raiseException_returnNULL(PyExc_TypeError, "Probability field is empty");
805 }
806
807 resultimage = RaveFmiImage_new(1);
808 if (resultimage == NULL) {
809 return NULL;
810 }
811
812 restore_image(sourceSweep, RaveFmiImage_getSweep(resultimage, 0), probabilitySweep, threshold);
813
814 result = (PyObject*)PyFmiImage_New(resultimage, 0);
815 RAVE_OBJECT_RELEASE(resultimage);
816 return result;
817}
818
819static PyObject* _pyropo_restore2(PyObject* self, PyObject* args)
820{
821 PyObject* sweepptr = NULL;
822 PyObject* inprobabilityptr = NULL;
823 PyFmiImage* sweep = NULL;
824 PyFmiImage* probability = NULL;
825 RaveFmiImage_t* resultimage = NULL;
826 PyObject* result = NULL;
827 FmiImage* sourceSweep = NULL; /* Do not release, internal memory */
828 FmiImage* probabilitySweep = NULL; /* Do not release, internal memory */
829 int threshold = 255;
830 int sweepnr = 0;
831
832 if (!PyArg_ParseTuple(args, "OOi|i", &sweepptr, &inprobabilityptr, &threshold, &sweepnr)) {
833 return NULL;
834 }
835
836 if (!PyFmiImage_Check(sweepptr) || !PyFmiImage_Check(inprobabilityptr)) {
837 raiseException_returnNULL(PyExc_TypeError, "restore2 takes sweep, probability field and threshold as input");
838 }
839 sweep = (PyFmiImage*)sweepptr;
840 probability = (PyFmiImage*)inprobabilityptr;
841
842 sourceSweep = RaveFmiImage_getSweep(sweep->image, sweepnr);
843 if (sourceSweep == NULL) {
844 raiseException_returnNULL(PyExc_TypeError, "Input fmi image does not contain that sweep");
845 }
846 probabilitySweep = RaveFmiImage_getSweep(probability->image, 0);
847 if (probabilitySweep == NULL) {
848 raiseException_returnNULL(PyExc_TypeError, "Probability field is empty");
849 }
850
851 resultimage = RaveFmiImage_new(1);
852 if (resultimage == NULL) {
853 return NULL;
854 }
855
856 restore_image2(sourceSweep, RaveFmiImage_getSweep(resultimage, 0), probabilitySweep, threshold);
857
858 result = (PyObject*)PyFmiImage_New(resultimage, 0);
859 RAVE_OBJECT_RELEASE(resultimage);
860 return result;
861}
862
863static PyObject* _pyropo_update_classification(PyObject* self, PyObject* args)
864{
865 PyObject *classificationptr = NULL, *probabilityptr = NULL, *targetprobabilityptr = NULL;
866 PyFmiImage *classification = NULL, *probability = NULL, *targetprobability = NULL;
867 FmiImage *cSweep = NULL, *pSweep = NULL, *tSweep = NULL;
868
869 FmiRadarPGMCode marker = CLEAR;
870
871 if (!PyArg_ParseTuple(args, "OOi|O", &probabilityptr, &targetprobabilityptr, &marker, &classificationptr)) {
872 return NULL;
873 }
874
875 if (!PyFmiImage_Check(probabilityptr) || !PyFmiImage_Check(targetprobabilityptr)) {
876 raiseException_returnNULL(PyExc_TypeError, "Input types must be either OOi|O with probfield, targetprobfield, marker, classification field");
877 }
878 if (classificationptr != NULL && !PyFmiImage_Check(classificationptr)) {
879 raiseException_returnNULL(PyExc_TypeError, "Input types must be either OOi|O with probfield, targetprobfield, marker, classification field");
880 }
881 classification = (PyFmiImage*)classificationptr;
882 probability = (PyFmiImage*)probabilityptr;
883 targetprobability = (PyFmiImage*)targetprobabilityptr;
884
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");
889 }
890 if (classification != NULL) {
891 cSweep = RaveFmiImage_getSweep(classification->image, 0);
892 }
893 pSweep = RaveFmiImage_getSweep(probability->image, 0);
894 tSweep = RaveFmiImage_getSweep(targetprobability->image, 0);
895
896 canonize_image(pSweep, cSweep);
897 canonize_image(pSweep, tSweep);
898
899 _pyropointernal_update_classification(pSweep, tSweep, cSweep, marker);
900
901 Py_RETURN_NONE;
902}
903#endif
904
908static PyMethodDef functions[] = {
909 {"new", (PyCFunction)_pyropogenerator_new, 1},
910 {NULL,NULL} /*Sentinel*/
911};
912
913MOD_INIT(_ropogenerator)
914{
915 PyObject *module=NULL,*dictionary=NULL;
916 static void *PyRopoGenerator_API[PyRopoGenerator_API_pointers];
917 PyObject *c_api_object = NULL;
918
919 MOD_INIT_SETUP_TYPE(PyRopoGenerator_Type, &PyType_Type);
920
921 MOD_INIT_VERIFY_TYPE_READY(&PyRopoGenerator_Type);
922
923 MOD_INIT_DEF(module, "_ropogenerator", NULL/*doc*/, functions);
924 if (module == NULL) {
925 return MOD_INIT_ERROR;
926 }
927
928 PyRopoGenerator_API[PyRopoGenerator_Type_NUM] = (void*)&PyRopoGenerator_Type;
929 PyRopoGenerator_API[PyRopoGenerator_GetNative_NUM] = (void *)PyRopoGenerator_GetNative;
930 PyRopoGenerator_API[PyRopoGenerator_New_NUM] = (void*)PyRopoGenerator_New;
931
932
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);
936
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;
941 }
942
944 PYRAVE_DEBUG_INITIALIZE;
945 return MOD_INIT_SUCCESS(module);
946}
#define import_fmiimage()
Definition pyfmiimage.h:101
#define PyFmiImage_New
Definition pyfmiimage.h:86
#define PyFmiImage_Check(op)
Definition pyfmiimage.h:92
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
Definition pyfmiimage.h:35
PyObject_HEAD RaveRopoGenerator_t * generator
RAVE_OBJECT_HEAD RaveFmiImage_t * image