Ticket 782: Changed so that classification is returned as 8-bit uchar jenkins-bRopo-62
authorAnders Henja <anders@baltrad.eu>
Fri, 5 Jul 2019 16:54:13 +0000 (18:54 +0200)
committerAnders Henja <anders@baltrad.eu>
Fri, 5 Jul 2019 16:54:13 +0000 (18:54 +0200)
ropo/rave_ropo_generator.c
test/pytest/PyRopoGeneratorTest.py

index 31766f0..02f76e8 100644 (file)
@@ -861,6 +861,9 @@ int RaveRopoGenerator_classify(RaveRopoGenerator_t* self)
     goto done;
   }
 
+  RaveFmiImage_getImage(probability)->original_type = RaveDataType_UCHAR; /* We want the probability and markers field to be of UCHAR type */
+  RaveFmiImage_getImage(markers)->original_type = RaveDataType_UCHAR;
+
   RaveFmiImage_fill(probability, CLEAR);
   RaveFmiImage_fill(markers, CLEAR);
 
@@ -869,11 +872,13 @@ int RaveRopoGenerator_classify(RaveRopoGenerator_t* self)
   fmiProbImage = RaveFmiImage_getImage(probability);
   fmiMarkersImage = RaveFmiImage_getImage(markers);
 
+
   for (i = 0; i < probCount; i++) {
     int j = 0;
     RaveFmiImage_t* image = (RaveFmiImage_t*)RaveObjectList_get(self->probabilities, i);
     FmiImage* probImage = RaveFmiImage_getImage(image);
     FmiRadarPGMCode pgmCode = RaveRopoGeneratorInternal_getPgmCode(image);
+
     for (j = 0; j < fmiProbImage->volume; j++) {
       if (probImage->array[j] >= fmiProbImage->array[j]) {
         fmiMarkersImage->array[j]=pgmCode;
index 4e47260..b059d0c 100644 (file)
@@ -356,7 +356,24 @@ class PyRopoGeneratorTest(unittest.TestCase):
     result32bit=result32bit.astype(numpy.uint8)
     
     self.assertTrue(numpy.array_equal(result8bit.astype(numpy.int32),result32bit.astype(numpy.int32)))
+  
+  def testCompare_8bit_and_16bit_Classification(self):
+    a = _raveio.open(self.PVOL_RIX_TESTFILE).object.getScan(0)
+    b = _ropogenerator.new(_fmiimage.fromRave(a, "DBZH"))
+    result8bit = b.speckNormOld(-20,24,8).classify().classification.toRaveField().getData()
+    
+    self.assertEqual(numpy.uint8, result8bit.dtype)
+    
+    a = _raveio.open(self.PVOL_RIX_TESTFILE).object.getScan(0)
+    # Adjust the 8 bit data to be 16 bit instead
+    p = a.getParameter("DBZH")
+    p.setData(p.getData().astype(numpy.int16))
+    c = _ropogenerator.new(_fmiimage.fromRave(a, "DBZH"))
+
+    result16bit = c.speckNormOld(-20,24,8).classify().classification.toRaveField().getData()
+    self.assertEqual(numpy.uint8, result16bit.dtype)
 
+    self.assertTrue(numpy.array_equal(result8bit,result16bit))
   
   # Simple way to ensure that a file is exported properly
   #