Ticket 735: Add beamb as a rave quality plugin hudson-beamb-22-SUCCESS
authorAnders Henja <anders@baltrad.eu>
Tue, 3 Jan 2012 09:50:31 +0000 (10:50 +0100)
committerAnders Henja <anders@baltrad.eu>
Tue, 3 Jan 2012 09:50:31 +0000 (10:50 +0100)
pybeamb/beamb_quality_plugin.py [new file with mode: 0644]
test/pytest/BeambTestSuite.py
test/pytest/beamb_quality_plugin_test.py [new file with mode: 0644]
test/pytest/fixtures/pvol_seosu_20090501T120000Z.h5 [new file with mode: 0644]

diff --git a/pybeamb/beamb_quality_plugin.py b/pybeamb/beamb_quality_plugin.py
new file mode 100644 (file)
index 0000000..72354c3
--- /dev/null
@@ -0,0 +1,99 @@
+'''
+Copyright (C) 2011- Swedish Meteorological and Hydrological Institute (SMHI)
+
+This file is part of the BEAMB extension to RAVE.
+
+BEAMB is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+BEAMB is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+See the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with BEAMB.  If not, see <http://www.gnu.org/licenses/>.
+'''
+##
+# A quality plugin for enabling the beamb support 
+
+## 
+# @file
+# @author Anders Henja, SMHI
+# @date 2012-01-03
+
+from rave_quality_plugin import rave_quality_plugin
+import _polarscan
+import _polarvolume
+import _beamblockage
+
+##
+# The limit of the Gaussian approximation of main lobe
+#
+BEAMBLOCKAGE_DBLIMIT=-20
+
+##
+# The beam blockage quality plugin
+#
+class beamb_quality_plugin(rave_quality_plugin):
+  ##
+  # The gtopo30 directory. If not set, then default values
+  # will be used.
+  #
+  _topodir = None
+  
+  ##
+  # The cachedir. If not set, then default values
+  # will be used.
+  #
+  _cachedir = None
+  
+  ##
+  # The default beamblockage gaussian approximation main lobe. Defaults to BEAMBLOCKAGE_DBLIMIT
+  #
+  _dblimit = BEAMBLOCKAGE_DBLIMIT
+  
+  ##
+  # Default constructor
+  def __init__(self):
+    super(beamb_quality_plugin, self).__init__()
+  
+  ##
+  # @return a list containing the string se.smhi.detector.beamblockage
+  def getQualityFields(self):
+    return ["se.smhi.detector.beamblockage"]
+  
+  ##
+  # @param obj: A rave object that should be processed.
+  # @return: The modified object if this quality plugin has performed changes 
+  # to the object.
+  def process(self, obj):
+    if obj != None:
+      try:
+        if _polarscan.isPolarScan(obj):
+          bb = self._create_bb()
+          result = bb.getBlockage(obj, self._dblimit)
+          obj.addQualityField(result)
+        elif _polarvolume.isPolarVolume(obj):
+          for i in range(obj.getNumberOfScans()):
+            bb = self._create_bb()
+            scan = obj.getScan(i)
+            result = bb.getBlockage(scan, self._dblimit)
+            scan.addQualityField(result)
+      except Exception,e:
+        pass
+
+    return obj
+
+  ##
+  # Creates a beam blockage instance
+  #
+  def _create_bb(self):
+    bb = _beamblockage.new()
+    if self._topodir != None:
+      bb.topo30dir = self._topodir
+    if self._cachedir != None:
+      bb.cachedir = self._cachedir
+    return bb
index 4b83135..b4b324e 100644 (file)
@@ -28,6 +28,8 @@ import unittest
 from PyBeamBlockageTest import *
 from PyBeamBlockageMapTest import *
 from PyBBTopographyTest import *
+from beamb_quality_plugin_test import *
+
 
 if __name__ == "__main__":
   unittest.main()
diff --git a/test/pytest/beamb_quality_plugin_test.py b/test/pytest/beamb_quality_plugin_test.py
new file mode 100644 (file)
index 0000000..7427326
--- /dev/null
@@ -0,0 +1,143 @@
+'''
+Copyright (C) 2011 Swedish Meteorological and Hydrological Institute, SMHI,
+
+This file is part of beamb.
+
+beamb is free software: you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+beamb is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with beamb.  If not, see <http://www.gnu.org/licenses/>.
+------------------------------------------------------------------------*/
+
+BeamBlockage tests
+
+@file
+@author Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
+@date 2012-01-03
+'''
+import unittest
+
+import _raveio
+import _beamblockage
+import beamb_quality_plugin
+import rave_quality_plugin
+import os, string
+import _rave
+import numpy
+
+class beamb_quality_plugin_test(unittest.TestCase):
+  SCAN_FIXTURE = "fixtures/sevil_0.5_20111223T0000Z.h5"
+  VOLUME_FIXTURE = "fixtures/pvol_seosu_20090501T120000Z.h5"
+  
+  CACHEFILES = ["/tmp/15.94_58.11_223_0.50_420_120_2000.00_0.00_0.90_-20.00.h5",
+                "/tmp/15.94_58.11_223_1.00_420_120_2000.00_0.00_0.90_-20.00.h5",
+                "/tmp/14.76_63.30_465_0.50_420_120_2000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_1.00_420_120_2000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_14.00_420_120_1000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_1.50_420_120_2000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_2.00_420_120_2000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_24.00_420_120_1000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_2.50_420_120_1000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_40.00_420_120_1000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_4.00_420_120_1000.00_0.00_1.00_-20.00.h5",
+                "/tmp/14.76_63.30_465_8.00_420_120_1000.00_0.00_1.00_-20.00.h5"]
+
+  def setUp(self):
+    for file in self.CACHEFILES:
+      if os.path.isfile(file):
+        try:
+          os.unlink(file)
+        except:
+          pass
+      
+  def tearDown(self):
+    for file in self.CACHEFILES:
+      if os.path.isfile(file):
+        try:
+          os.unlink(file)
+        except:
+          pass
+
+  def testNew(self):
+    a = beamb_quality_plugin.beamb_quality_plugin()
+    self.assertTrue(isinstance(a, rave_quality_plugin.rave_quality_plugin))
+    self.assertEquals(None, a._cachedir)
+    self.assertEquals(None, a._topodir)
+    self.assertEquals(beamb_quality_plugin.BEAMBLOCKAGE_DBLIMIT, a._dblimit)
+    
+  def test_getQualityFields(self):
+    a = beamb_quality_plugin.beamb_quality_plugin()
+    result = a.getQualityFields()
+    self.assertEquals(1, len(result))
+    self.assertEquals("se.smhi.detector.beamblockage", result[0])
+
+  def test_create_bb_default(self):
+    a = beamb_quality_plugin.beamb_quality_plugin()
+    result = a._create_bb()
+    self.assertTrue(None != result.cachedir)
+    self.assertTrue(None != result.topo30dir)
+    
+  def test_create_bb_modified_cache(self):
+    a = beamb_quality_plugin.beamb_quality_plugin()
+    a._cachedir="/tmp"
+    result = a._create_bb()
+    self.assertEquals("/tmp", result.cachedir)
+
+  def test_create_bb_modified_topo(self):
+    a = beamb_quality_plugin.beamb_quality_plugin()
+    a._topodir="../../data/gtopo30"
+    result = a._create_bb()
+    self.assertEquals("../../data/gtopo30", result.topo30dir)
+
+  def test_create_bb_modified_dirs(self):
+    a = beamb_quality_plugin.beamb_quality_plugin()
+    a._cachedir="/tmp"
+    a._topodir="../../data/gtopo30"
+    result = a._create_bb()
+    self.assertEquals("/tmp", result.cachedir)
+    self.assertEquals("../../data/gtopo30", result.topo30dir)
+
+
+  def test_process_scan(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)
+
+    result = classUnderTest.process(scan)
+    
+    self.assertTrue(result == scan) # Return original 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()
+    classUnderTest._cachedir="/tmp"
+    classUnderTest._topodir="../../data/gtopo30"
+    
+    volume = _raveio.open(self.VOLUME_FIXTURE).object
+    for i in range(volume.getNumberOfScans()):
+      scan = volume.getScan(i)
+      self.assertTrue(scan.findQualityFieldByHowTask("se.smhi.detector.beamblockage") == None)
+    
+    result = classUnderTest.process(volume)
+    
+    self.assertTrue(result == volume)
+    for i in range(volume.getNumberOfScans()):
+      scan = volume.getScan(i)
+      self.assertTrue(scan.findQualityFieldByHowTask("se.smhi.detector.beamblockage") != None)
+
+    
+if __name__ == "__main__":
+  #import sys;sys.argv = ['', 'Test.testName']
+  unittest.main()
\ No newline at end of file
diff --git a/test/pytest/fixtures/pvol_seosu_20090501T120000Z.h5 b/test/pytest/fixtures/pvol_seosu_20090501T120000Z.h5
new file mode 100644 (file)
index 0000000..62c88bb
Binary files /dev/null and b/test/pytest/fixtures/pvol_seosu_20090501T120000Z.h5 differ