Ticket 678: Add functionality for choosing to only perform qc or if qc also should... jenkins-beamb-59
authorAnders Henja <anders@henjab.se>
Thu, 19 Jan 2017 08:27:18 +0000 (09:27 +0100)
committerAnders Henja <anders@henjab.se>
Thu, 19 Jan 2017 08:27:18 +0000 (09:27 +0100)
pybeamb/beamb_quality_plugin.py
test/pytest/beamb_quality_plugin_test.py

index 022eb3b..c6e08e3 100644 (file)
@@ -25,10 +25,17 @@ along with BEAMB.  If not, see <http://www.gnu.org/licenses/>.
 # @date 2012-01-03
 
 from rave_quality_plugin import rave_quality_plugin
+from rave_quality_plugin import QUALITY_CONTROL_MODE_ANALYZE_AND_APPLY
+from rave_quality_plugin import QUALITY_CONTROL_MODE_ANALYZE
+
+import rave_pgf_logger
+
 import _polarscan
 import _polarvolume
 import _beamblockage
 
+logger = rave_pgf_logger.create_logger()
+
 ##
 # The limit of the Gaussian approximation of main lobe
 #
@@ -78,7 +85,7 @@ class beamb_quality_plugin(rave_quality_plugin):
   # @param arguments: Not used
   # @return: The modified object if this quality plugin has performed changes 
   # to the object.
-  def process(self, obj, reprocess_quality_flag=True, arguments=None):
+  def process(self, obj, reprocess_quality_flag=True, quality_control_mode=QUALITY_CONTROL_MODE_ANALYZE_AND_APPLY, arguments=None):
     if obj != None:
       try:
         if _polarscan.isPolarScan(obj):
@@ -86,7 +93,8 @@ class beamb_quality_plugin(rave_quality_plugin):
             return obj
           bb = self._create_bb()
           result = bb.getBlockage(obj, self._dblimit)
-          restored = _beamblockage.restore(obj, result, "DBZH", self._bblimit)
+          if quality_control_mode != QUALITY_CONTROL_MODE_ANALYZE:
+            _beamblockage.restore(obj, result, "DBZH", self._bblimit)
           obj.addOrReplaceQualityField(result)
           
         elif _polarvolume.isPolarVolume(obj):
@@ -96,11 +104,11 @@ class beamb_quality_plugin(rave_quality_plugin):
               continue
             bb = self._create_bb()
             result = bb.getBlockage(scan, self._dblimit)
-            restored = _beamblockage.restore(scan, result, "DBZH", self._bblimit)
+            if quality_control_mode != QUALITY_CONTROL_MODE_ANALYZE:
+              _beamblockage.restore(scan, result, "DBZH", self._bblimit)
             scan.addOrReplaceQualityField(result)
-      except Exception,e:
-        import traceback
-        traceback.print_exc()
+      except:
+        logger.exception("Failed to generate beam blockage field")
 
     return obj
 
index 1dcc8d5..3ff172b 100644 (file)
@@ -32,6 +32,7 @@ import rave_quality_plugin
 import os, string
 import _rave
 import numpy
+from rave_quality_plugin import QUALITY_CONTROL_MODE_ANALYZE
 
 class beamb_quality_plugin_test(unittest.TestCase):
   SCAN_FIXTURE = "fixtures/sevil_0.5_20111223T0000Z.h5"
@@ -114,10 +115,15 @@ class beamb_quality_plugin_test(unittest.TestCase):
     scan = _raveio.open(self.SCAN_FIXTURE).object
     
     self.assertTrue(scan.findQualityFieldByHowTask("se.smhi.detector.beamblockage") == None)
+    
+    oldparam = scan.getParameter("DBZH").clone()
 
     result = classUnderTest.process(scan)
     
     self.assertTrue(result == scan) # Return original scan with added field
+    
+    self.assertFalse(numpy.array_equal(oldparam.getData(), result.getParameter("DBZH").getData())) # Default behaviour is analyze&apply
+    
     self.assertTrue(result.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None)
 
   def test_process_scan_reprocess_true(self):
@@ -149,6 +155,22 @@ class beamb_quality_plugin_test(unittest.TestCase):
     field2 = result.getQualityFieldByHowTask("se.smhi.detector.beamblockage")
     
     self.assertTrue(field1 == field2)
+
+  def test_process_scan_only_analyse(self):
+    classUnderTest = beamb_quality_plugin.beamb_quality_plugin()
+    classUnderTest._cachedir="/tmp"
+    classUnderTest._topodir="../../data/gtopo30"
+    
+    scan = _raveio.open(self.SCAN_FIXTURE).object
+    
+    self.assertTrue(scan.findQualityFieldByHowTask("se.smhi.detector.beamblockage") == None)
+
+    oldparam = scan.getParameter("DBZH").clone()
+
+    result = classUnderTest.process(scan, True, QUALITY_CONTROL_MODE_ANALYZE)
+    
+    self.assertTrue(numpy.array_equal(oldparam.getData(), result.getParameter("DBZH").getData())) # Return new scan with added field
+    self.assertTrue(result.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None)
     
   def test_process_volume(self):
     classUnderTest = beamb_quality_plugin.beamb_quality_plugin()