Ticket 504: How attributes should be copied from volume to profile jenkins-wrwp-16
authorAnders Henja <anders@henjab.se>
Tue, 17 Nov 2015 12:03:40 +0000 (13:03 +0100)
committerAnders Henja <anders@henjab.se>
Tue, 17 Nov 2015 12:03:40 +0000 (13:03 +0100)
lib/wrwp.c
test/pytest/WrwpTest.py
test/pytest/fixtures/selul_pvol_20151114T1615Z.h5 [new file with mode: 0644]

index 7f831f4..c7f0c5a 100644 (file)
@@ -63,6 +63,35 @@ static void Wrwp_destructor(RaveCoreObject* obj)
 {
 }
 
+static int WrwpInternal_findAndAddAttribute(VerticalProfile_t* vp, PolarVolume_t* pvol, const char* name)
+{
+  int nscans = PolarVolume_getNumberOfScans(pvol);
+  int i = 0;
+  int found = 0;
+  for (i = 0; i < nscans && found == 0; i++) {
+    PolarScan_t* scan = PolarVolume_getScan(pvol, i);
+    if (scan != NULL && PolarScan_hasAttribute(scan, name)) {
+      RaveAttribute_t* attr = PolarScan_getAttribute(scan, name);
+      VerticalProfile_addAttribute(vp, attr);
+      found = 1;
+      RAVE_OBJECT_RELEASE(attr);
+    }
+    RAVE_OBJECT_RELEASE(scan);
+  }
+  return found;
+}
+
+static int WrwpInternal_addIntAttribute(VerticalProfile_t* vp, const char* name, int value)
+{
+  RaveAttribute_t* attr = RaveAttributeHelp_createLong(name, value);
+  int result = 0;
+  if (attr != NULL) {
+    result = VerticalProfile_addAttribute(vp, attr);
+  }
+  RAVE_OBJECT_RELEASE(attr);
+  return result;
+}
+
 /*@} End of Private functions */
 
 /*@{ Interface functions */
@@ -387,6 +416,29 @@ VerticalProfile_t* Wrwp_generate(Wrwp_t* self, PolarVolume_t* inobj) {
   VerticalProfile_setDate(result, PolarVolume_getDate(inobj));
   VerticalProfile_setTime(result, PolarVolume_getTime(inobj));
 
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/highprf");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/lowprf");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/pulsewidth");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/wavelength");
+
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/RXbandwidth");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/RXloss");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/TXloss");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/antgain");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/azmethod");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/binmethod");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/malfunc");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/nomTXpower");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/radar_msg");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/radconstH");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/radomeloss");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/rpm");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/software");
+  WrwpInternal_findAndAddAttribute(result, inobj, "how/system");
+
+  WrwpInternal_addIntAttribute(result, "how/minrange", Wrwp_getDMIN(self));
+  WrwpInternal_addIntAttribute(result, "how/maxrange", Wrwp_getDMAX(self));
+
 done:
   RAVE_OBJECT_RELEASE(polnav);
   RAVE_OBJECT_RELEASE(ff_field);
index bff9532..bf412d8 100644 (file)
@@ -32,6 +32,7 @@ import _raveio, _rave
 
 class WrwpTest(unittest.TestCase):
   FIXTURE = "fixtures/pvol_seang_20090501T120000Z.h5"
+  FIXTURE2 = "fixtures/selul_pvol_20151114T1615Z.h5"
   
   def setUp(self):
     _helpers.triggerMemoryStatus()
@@ -160,6 +161,73 @@ class WrwpTest(unittest.TestCase):
     robj = _raveio.new()
     robj.object = vp
     robj.save("slask.h5")
+
+  def test_generate_with_several_howattributes(self):
+    pvol = _raveio.open(self.FIXTURE2).object
+    generator = _wrwp.new()
+    generator.hmax = 2000
+    generator.dz = 200
+    
+    vp = generator.generate(pvol)
+    
+    ff = vp.getFF()
+    ff_dev = vp.getFFDev()
+    dd = vp.getDD()
+    dbz = vp.getDBZ()
+    dbz_dev = vp.getDBZDev()
+    
+    self.assertEquals(1, ff.xsize)
+    self.assertEquals(10, ff.ysize)
+    self.assertEquals("ff", ff.getAttribute("what/quantity"))
+
+    self.assertEquals(1, ff_dev.xsize)
+    self.assertEquals(10, ff_dev.ysize)
+    self.assertEquals("ff_dev", ff_dev.getAttribute("what/quantity"))
+
+    self.assertEquals(1, dd.xsize)
+    self.assertEquals(10, dd.ysize)
+    self.assertEquals("dd", dd.getAttribute("what/quantity"))
+    
+    self.assertEquals(1, dbz.xsize)
+    self.assertEquals(10, dbz.ysize)
+    self.assertEquals("dbz", dbz.getAttribute("what/quantity"))
+
+    self.assertEquals(1, dbz_dev.xsize)
+    self.assertEquals(10, dbz_dev.ysize)
+    self.assertEquals("dbz_dev", dbz_dev.getAttribute("what/quantity"))
+
+    self.assertEquals(10, vp.getLevels())
+    self.assertEquals(200, vp.interval)
+    self.assertEquals(100, vp.minheight)
+    self.assertEquals(2000, vp.maxheight)
+    self.assertEquals(pvol.source, vp.source)
+    self.assertEquals(pvol.date, vp.date)
+    self.assertEquals(pvol.time, vp.time)
+    
+    self.assertEquals(900, vp.getAttribute("how/lowprf"))
+    self.assertEquals(1200, vp.getAttribute("how/highprf"))
+    self.assertAlmostEqual(0.61, vp.getAttribute("how/pulsewidth"), 4)
+    self.assertAlmostEqual(5.35, vp.getAttribute("how/wavelength"), 4)
+    self.assertAlmostEqual(0.8, vp.getAttribute("how/RXbandwidth"), 4)
+    self.assertAlmostEqual(3.1, vp.getAttribute("how/RXloss"), 4)
+    self.assertAlmostEqual(1.9, vp.getAttribute("how/TXloss"), 4)
+    self.assertAlmostEqual(44.9, vp.getAttribute("how/antgain"), 4)
+    self.assertEquals("AVERAGE", vp.getAttribute("how/azmethod"))
+    self.assertEquals("AVERAGE", vp.getAttribute("how/binmethod"))
+    self.assertEquals("False", vp.getAttribute("how/malfunc"))
+    self.assertAlmostEqual(277.4, vp.getAttribute("how/nomTXpower"), 4)
+    self.assertEquals("b94 3dd 000 000 000:", vp.getAttribute("how/radar_msg"), 4)
+    self.assertAlmostEqual(73.101, vp.getAttribute("how/radconstH"), 4)
+    self.assertAlmostEqual(0.2, vp.getAttribute("how/radomeloss"), 4)
+    self.assertAlmostEqual(2.0, vp.getAttribute("how/rpm"), 4)
+    self.assertEquals("PARTEC2", vp.getAttribute("how/software"))
+    self.assertEquals("ERIC", vp.getAttribute("how/system"))
+    self.assertEquals(4000, vp.getAttribute("how/minrange"))
+    self.assertEquals(40000, vp.getAttribute("how/maxrange"))
+    
+    robj = _raveio.new()
+    robj.object = vp
+    robj.save("slask.h5")
     
 if __name__ == "__main__":
   unittest.main()
\ No newline at end of file
diff --git a/test/pytest/fixtures/selul_pvol_20151114T1615Z.h5 b/test/pytest/fixtures/selul_pvol_20151114T1615Z.h5
new file mode 100644 (file)
index 0000000..c26252a
Binary files /dev/null and b/test/pytest/fixtures/selul_pvol_20151114T1615Z.h5 differ