Ticket 425: Add possibility for quality plugins to identify if reprocessing should... jenkins-beamb-55
authorAnders Henja <anders@henjab.se>
Sun, 16 Nov 2014 15:29:16 +0000 (16:29 +0100)
committerAnders Henja <anders@henjab.se>
Sun, 16 Nov 2014 15:29:16 +0000 (16:29 +0100)
pybeamb/beamb_quality_plugin.py
test/pytest/BeambTestSuite.py
test/pytest/beamb_quality_plugin_test.py

index 86111e8..fc54d37 100644 (file)
@@ -74,25 +74,32 @@ class beamb_quality_plugin(rave_quality_plugin):
   
   ##
   # @param obj: A rave object that should be processed.
+  # @param reprocess_quality_flag: If the quality fields should be reprocessed or not.
   # @return: The modified object if this quality plugin has performed changes 
   # to the object.
-  def process(self, obj):
+  def process(self, obj, reprocess_quality_flag=True):
     if obj != None:
       try:
         if _polarscan.isPolarScan(obj):
+          if reprocess_quality_flag == False and obj.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None:
+            return obj
           bb = self._create_bb()
           result = bb.getBlockage(obj, self._dblimit)
           restored = _beamblockage.restore(obj, result, "DBZH", self._bblimit)
-          obj.addQualityField(result)
+          obj.addOrReplaceQualityField(result)
+          
         elif _polarvolume.isPolarVolume(obj):
           for i in range(obj.getNumberOfScans()):
-            bb = self._create_bb()
             scan = obj.getScan(i)
+            if reprocess_quality_flag == False and scan.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None:
+              continue
+            bb = self._create_bb()
             result = bb.getBlockage(scan, self._dblimit)
             restored = _beamblockage.restore(scan, result, "DBZH", self._bblimit)
-            scan.addQualityField(result)
+            scan.addOrReplaceQualityField(result)
       except Exception,e:
-        pass
+        import traceback
+        traceback.print_exc()
 
     return obj
 
index b4b324e..53074e8 100644 (file)
@@ -24,7 +24,6 @@ Test suite for beamb
 @date 2011-11-15
 '''
 import unittest
-
 from PyBeamBlockageTest import *
 from PyBeamBlockageMapTest import *
 from PyBBTopographyTest import *
index 7427326..1dcc8d5 100644 (file)
@@ -119,6 +119,36 @@ class beamb_quality_plugin_test(unittest.TestCase):
     
     self.assertTrue(result == scan) # Return original scan with added field
     self.assertTrue(result.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None)
+
+  def test_process_scan_reprocess_true(self):
+    classUnderTest = beamb_quality_plugin.beamb_quality_plugin()
+    classUnderTest._cachedir="/tmp"
+    classUnderTest._topodir="../../data/gtopo30"
+    
+    scan = _raveio.open(self.SCAN_FIXTURE).object
+    
+    result = classUnderTest.process(scan)
+    field1 = result.getQualityFieldByHowTask("se.smhi.detector.beamblockage")
+
+    result = classUnderTest.process(scan, reprocess_quality_flag=True)
+    field2 = result.getQualityFieldByHowTask("se.smhi.detector.beamblockage")
+    
+    self.assertTrue(field1 != field2)
+
+  def test_process_scan_reprocess_false(self):
+    classUnderTest = beamb_quality_plugin.beamb_quality_plugin()
+    classUnderTest._cachedir="/tmp"
+    classUnderTest._topodir="../../data/gtopo30"
+    
+    scan = _raveio.open(self.SCAN_FIXTURE).object
+    
+    result = classUnderTest.process(scan)
+    field1 = result.getQualityFieldByHowTask("se.smhi.detector.beamblockage")
+
+    result = classUnderTest.process(scan, reprocess_quality_flag=False)
+    field2 = result.getQualityFieldByHowTask("se.smhi.detector.beamblockage")
+    
+    self.assertTrue(field1 == field2)
     
   def test_process_volume(self):
     classUnderTest = beamb_quality_plugin.beamb_quality_plugin()
@@ -137,6 +167,53 @@ class beamb_quality_plugin_test(unittest.TestCase):
       scan = volume.getScan(i)
       self.assertTrue(scan.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None)
 
+  def test_process_volume_reprocess_true(self):
+    classUnderTest = beamb_quality_plugin.beamb_quality_plugin()
+    classUnderTest._cachedir="/tmp"
+    classUnderTest._topodir="../../data/gtopo30"
+    
+    volume = _raveio.open(self.VOLUME_FIXTURE).object
+    
+    result = classUnderTest.process(volume)
+    
+    fields=[]
+    for i in range(volume.getNumberOfScans()):
+      scan = volume.getScan(i)
+      fields.append(scan.getQualityFieldByHowTask("se.smhi.detector.beamblockage"))
+    
+    result = classUnderTest.process(volume, reprocess_quality_flag=True)
+    fields2=[]
+    for i in range(volume.getNumberOfScans()):
+      scan = volume.getScan(i)
+      fields2.append(scan.getQualityFieldByHowTask("se.smhi.detector.beamblockage"))
+    
+    self.assertEquals(len(fields), len(fields2))
+    for i in range(len(fields)):
+      self.assertTrue(fields[i] != fields2[i])
+
+  def test_process_volume_reprocess_false(self):
+    classUnderTest = beamb_quality_plugin.beamb_quality_plugin()
+    classUnderTest._cachedir="/tmp"
+    classUnderTest._topodir="../../data/gtopo30"
+    
+    volume = _raveio.open(self.VOLUME_FIXTURE).object
+    
+    result = classUnderTest.process(volume)
+    
+    fields=[]
+    for i in range(volume.getNumberOfScans()):
+      scan = volume.getScan(i)
+      fields.append(scan.getQualityFieldByHowTask("se.smhi.detector.beamblockage"))
+    
+    result = classUnderTest.process(volume, reprocess_quality_flag=False)
+    fields2=[]
+    for i in range(volume.getNumberOfScans()):
+      scan = volume.getScan(i)
+      fields2.append(scan.getQualityFieldByHowTask("se.smhi.detector.beamblockage"))
+    
+    self.assertEquals(len(fields), len(fields2))
+    for i in range(len(fields)):
+      self.assertTrue(fields[i] == fields2[i])
     
 if __name__ == "__main__":
   #import sys;sys.argv = ['', 'Test.testName']