Exemple #1
0
    def test_getScanWithMaxDistance(self):
        obj = _polarvolume.new()
        s1 = _polarscan.new()
        s1.rscale = 500.0
        s1.elangle = 0.5 * math.pi / 180.0
        s1.longitude = 60.0 * math.pi / 180.0
        s1.latitude = 14.0 * math.pi / 180.0
        s1.height = 100.0
        s1.addAttribute("how/value", "s1")
        p1 = _polarscanparam.new()
        p1.quantity = "DBZH"
        p1.setData(numpy.zeros((100, 120), numpy.uint8))
        s1.addParameter(p1)

        s2 = _polarscan.new()
        s2.rscale = 1000.0
        s2.elangle = 0.5 * math.pi / 180.0
        s2.longitude = 60.0 * math.pi / 180.0
        s2.latitude = 14.0 * math.pi / 180.0
        s2.height = 100.0
        s2.addAttribute("how/value", "s2")
        p2 = _polarscanparam.new()
        p2.quantity = "DBZH"
        p2.setData(numpy.zeros((100, 120), numpy.uint8))
        s2.addParameter(p2)

        obj.addScan(s1)
        obj.addScan(s2)

        result = obj.getScanWithMaxDistance()
        self.assertEqual("s2", result.getAttribute("how/value"))
Exemple #2
0
    def test_getMaxDistance(self):
        s1 = _polarscan.new()
        s1.longitude = 60.0 * math.pi / 180.0
        s1.latitude = 12.0 * math.pi / 180.0
        s1.height = 0.0
        s1.rscale = 1000.0
        s1.elangle = (math.pi / 180.0) * 0.5
        param = _polarscanparam.new()
        param.quantity = "DBZH"
        data = numpy.zeros((10, 10), numpy.int8)
        param.setData(data)
        s1.addParameter(param)

        s2 = _polarscan.new()
        s2.longitude = 60.0 * math.pi / 180.0
        s2.latitude = 12.0 * math.pi / 180.0
        s2.height = 0.0
        s2.rscale = 1000.0
        s2.elangle = (math.pi / 180.0) * 1.5
        param = _polarscanparam.new()
        param.quantity = "DBZH"
        data = numpy.zeros((10, 10), numpy.int8)
        param.setData(data)
        s2.addParameter(param)

        vol = _polarvolume.new()
        vol.addScan(s1)
        vol.addScan(s2)

        self.assertAlmostEqual(10999.45, vol.getMaxDistance(), 2)
Exemple #3
0
    def test_getHeightField(self):
        polnav = _polarnav.new()
        polnav.lat0 = 60.0 * math.pi / 180.0
        polnav.lon0 = 12.0 * math.pi / 180.0
        polnav.alt0 = 0.0

        expected = []
        rarr = []
        for i in range(10):
            rarr.append(polnav.reToDh(100.0 * i, (math.pi / 180.0) * 0.5)[1])
        rarr.append(-99999.0)
        rarr.append(-99999.0)

        expected.append(rarr)
        rarr = []
        for i in range(12):
            rarr.append(polnav.reToDh(100.0 * i, (math.pi / 180.0) * 1.0)[1])
        expected.append(rarr)

        s1 = _polarscan.new()
        s1.longitude = polnav.lon0  # We want same settings as the polar navigator so that we can test result
        s1.latitude = polnav.lat0
        s1.height = polnav.alt0
        s1.rscale = 100.0
        s1.elangle = (math.pi / 180.0) * 0.5

        p1 = _polarscanparam.new()
        p1.quantity = "DBZH"
        data = numpy.zeros((5, 10), numpy.int8)
        p1.setData(data)

        s1.addParameter(p1)

        s2 = _polarscan.new()
        s2.longitude = polnav.lon0  # We want same settings as the polar navigator so that we can test result
        s2.latitude = polnav.lat0
        s2.height = polnav.alt0
        s2.rscale = 100.0
        s2.elangle = (math.pi / 180.0) * 1.0

        p2 = _polarscanparam.new()
        p2.quantity = "DBZH"
        data = numpy.zeros((5, 12), numpy.int8)
        p2.setData(data)

        s2.addParameter(p2)

        obj = _polarvolume.new()
        obj.addScan(s1)
        obj.addScan(s2)

        f = obj.getHeightField()
        self.assertEqual(12, f.xsize)
        self.assertEqual(2, f.ysize)

        for j in range(2):
            for i in range(12):
                self.assertAlmostEqual(expected[j][i], f.getValue(i, j)[1], 2)
Exemple #4
0
    def test_getNearest(self):
        obj = _polarvolume.new()
        obj.longitude = 12.0 * math.pi / 180.0
        obj.latitude = 60.0 * math.pi / 180.0
        obj.height = 0.0
        scan1 = _polarscan.new()
        scan1.elangle = 0.1 * math.pi / 180.0
        scan1.rstart = 0.0
        scan1.rscale = 5000.0
        param = _polarscanparam.new()
        param.nodata = 10.0
        param.undetect = 11.0
        param.quantity = "DBZH"
        data = numpy.zeros((100, 120), numpy.uint8)
        param.setData(data)
        scan1.addParameter(param)

        scan2 = _polarscan.new()
        scan2.elangle = 1.0 * math.pi / 180.0
        scan2.rstart = 0.0
        scan2.rscale = 5000.0
        param = _polarscanparam.new()
        param.nodata = 10.0
        param.undetect = 11.0
        param.quantity = "DBZH"
        data = numpy.ones((100, 120), numpy.uint8)
        param.setData(data)
        scan2.addParameter(param)

        obj.addScan(scan1)
        obj.addScan(scan2)

        # Allow outside ranges
        t, v = obj.getNearest(
            (12.0 * math.pi / 180.0, 60.45 * math.pi / 180.0), 1000.0, 0)
        self.assertEqual(_rave.RaveValueType_DATA, t)
        self.assertAlmostEqual(1.0, v, 4)

        t, v = obj.getNearest(
            (12.0 * math.pi / 180.0, 62.00 * math.pi / 180.0), 1000.0, 0)
        self.assertEqual(_rave.RaveValueType_DATA, t)
        self.assertAlmostEqual(0.0, v, 4)

        # Only allow inside ranges
        t, v = obj.getNearest(
            (12.0 * math.pi / 180.0, 60.45 * math.pi / 180.0), 1000.0, 1)
        self.assertEqual(_rave.RaveValueType_DATA, t)
        self.assertAlmostEqual(1.0, v, 4)

        t, v = obj.getNearest(
            (12.0 * math.pi / 180.0, 62.00 * math.pi / 180.0), 1000.0, 1)
        self.assertEqual(_rave.RaveValueType_NODATA, t)
Exemple #5
0
 def test_notDealiased_notVRADh(self):
     scan = _polarscan.new()
     vrad = _polarscanparam.new()
     vrad.quantity = "VRAD"
     vrad.addAttribute("how/dealiased", "True")
     scan.addParameter(vrad)
     self.assertFalse(_dealias.dealiased(scan)) 
Exemple #6
0
    def test_getConvertedValue(self):
        obj = _polarscanparam.new()
        obj.nodata = 255.0
        obj.undetect = 0.0
        obj.gain = 0.5
        obj.offset = 10.0
        a = numpy.arange(30)
        a = numpy.array(a.astype(numpy.float64), numpy.float64)
        a = numpy.reshape(a, (5, 6)).astype(numpy.float64)
        a[0][0] = obj.undetect
        a[2][1] = obj.nodata
        a[4][5] = obj.undetect

        obj.setData(a)

        pts = [((0, 0), (_rave.RaveValueType_UNDETECT, 0.0)),
               ((1, 0), (_rave.RaveValueType_DATA, 10.5)),
               ((0, 1), (_rave.RaveValueType_DATA, 13.0)),
               ((1, 2), (_rave.RaveValueType_NODATA, obj.nodata)),
               ((4, 4), (_rave.RaveValueType_DATA, 24.0)),
               ((5, 4), (_rave.RaveValueType_UNDETECT, obj.undetect)),
               ((5, 5), (_rave.RaveValueType_NODATA, obj.nodata))]

        for tval in pts:
            result = obj.getConvertedValue(tval[0][0], tval[0][1])
            self.assertEqual(tval[1][0], result[0])
            self.assertAlmostEqual(tval[1][1], result[1], 4)
Exemple #7
0
    def testPadding(self):
        import numpy

        scan = _polarscan.new()
        dbzh = _polarscanparam.new()
        dbzh.quantity = "DBZH"
        l = []
        for i in range(360):
            l.append([i, i, i])

        data = numpy.array(l).astype(numpy.uint16)
        dbzh.setData(data)
        scan.addParameter(dbzh)
        dbzh.quantity = "TH"
        scan.addParameter(dbzh)

        options = ropo_realtime.options()
        options.emitter2 = (-10, 3, 3)  # default

        newscan, gates = ropo_realtime.PadNrays(scan, options)
        newdata = newscan.getParameter("DBZH").getData()

        # Test data wrapping
        self.assertEqual(newdata[:4].tolist(), data[356:, ].tolist())
        self.assertEqual(newdata[364:, ].tolist(), data[:4, ].tolist())

        classification = _ravefield.new()
        classification.setData(newdata)  # bogus probability of anomaly array
        unwrapped, classification = ropo_realtime.UnpadNrays(
            newscan, classification, gates)

        # Test data unwrapping
        self.assertEqual(
            unwrapped.getParameter("DBZH").getData().tolist(), data.tolist())
Exemple #8
0
 def test_invalid_attributes(self):
     obj = _polarscanparam.new()
     try:
         obj.lon = 1.0
         self.fail("Expected AttributeError")
     except AttributeError:
         pass
Exemple #9
0
    def test_toField(self):
        obj = _polarscanparam.new()

        a = numpy.arange(120)
        a = numpy.array(a.astype(numpy.uint8), numpy.uint8)
        a = numpy.reshape(a, (12, 10)).astype(numpy.uint8)

        obj.setData(a)

        obj.addAttribute("how/this", "ABC")
        obj.addAttribute("how/that", 1.0)
        obj.addAttribute("what/value", 2)

        obj.gain = 2.0
        obj.offset = 3.0
        obj.undetect = 4.0
        obj.nodata = 5.0

        result = obj.toField()
        self.assertEqual("ABC", result.getAttribute("how/this"))
        self.assertAlmostEqual(1.0, result.getAttribute("how/that"), 4)
        self.assertEqual(2, result.getAttribute("what/value"))
        self.assertAlmostEqual(2.0, result.getAttribute("what/gain"), 4)
        self.assertAlmostEqual(3.0, result.getAttribute("what/offset"), 4)
        self.assertAlmostEqual(4.0, result.getAttribute("what/undetect"), 4)
        self.assertAlmostEqual(5.0, result.getAttribute("what/nodata"), 4)
        self.assertEqual(_rave.RaveDataType_UCHAR, result.datatype)
        self.assertEqual(10, result.xsize)
        self.assertEqual(12, result.ysize)
Exemple #10
0
    def test_shiftData_neg(self):
        obj = _polarscanparam.new()
        f1 = _ravefield.new()
        f2 = _ravefield.new()
        obj.setData(
            numpy.array(
                [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],
                numpy.uint8))
        f1.setData(
            numpy.array(
                [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],
                numpy.uint8))
        f2.setData(
            numpy.array(
                [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]],
                numpy.uint8))
        obj.addQualityField(f1)
        obj.addQualityField(f2)
        obj.shiftData(-1)

        self.assertTrue((numpy.array(
            [[4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [0, 1, 2, 3]],
            numpy.uint8) == obj.getData()).all())
        self.assertTrue((numpy.array(
            [[4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [0, 1, 2, 3]],
            numpy.uint8) == obj.getQualityField(0).getData()).all())
        self.assertTrue((numpy.array(
            [[4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [0, 1, 2, 3]],
            numpy.uint8) == obj.getQualityField(1).getData()).all())
Exemple #11
0
 def test_addAttribute_goodNames(self):
     obj = _polarscanparam.new()
     GOODNAMES = [
         "how/this", "HOW/this", "HoW/this", "What/that", "wHAT/that",
         "Where/doobi", "WHERE/DOOBI"
     ]
     for n in GOODNAMES:
         obj.addAttribute(n, "XYZ")
Exemple #12
0
 def test_nrays(self):
     obj = _polarscanparam.new()
     self.assertEqual(0, obj.nrays)
     try:
         obj.nrays = 10
         self.fail("Expected AttributeError")
     except AttributeError:
         pass
     self.assertEqual(0, obj.nrays)
Exemple #13
0
 def test_nodata_typeError(self):
     obj = _polarscanparam.new()
     self.assertAlmostEqual(0.0, obj.nodata, 4)
     try:
         obj.nodata = 10
         self.fail("Expected TypeError")
     except TypeError:
         pass
     self.assertAlmostEqual(0.0, obj.nodata, 4)
Exemple #14
0
 def test_undetect_typeError(self):
     obj = _polarscanparam.new()
     self.assertAlmostEqual(0.0, obj.undetect, 4)
     try:
         obj.undetect = 10
         self.fail("Expected TypeError")
     except TypeError:
         pass
     self.assertAlmostEqual(0.0, obj.undetect, 4)
Exemple #15
0
 def test_attribute_visibility(self):
     attrs = [
         'nbins', 'nrays', 'quantity', 'gain', 'offset', 'nodata',
         'undetect', 'datatype'
     ]
     obj = _polarscanparam.new()
     alist = dir(obj)
     for a in attrs:
         self.assertEqual(True, a in alist)
Exemple #16
0
 def test_setValue_outOfBounds(self):
     obj = _polarscanparam.new()
     a = numpy.zeros((12, 10), numpy.int8)
     obj.setData(a)
     try:
         obj.setValue((15, 5), 5)
         self.fail("Expected ValueError")
     except ValueError:
         pass
Exemple #17
0
 def test_datatype(self):
     obj = _polarscanparam.new()
     self.assertEqual(_rave.RaveDataType_UNDEFINED, obj.datatype)
     try:
         obj.datatype = _rave.RaveDataType_INT
         self.fail("Expected AttributeError")
     except AttributeError:
         pass
     self.assertEqual(_rave.RaveDataType_UNDEFINED, obj.datatype)
Exemple #18
0
 def test_addAttribute_badNames(self):
     obj = _polarscanparam.new()
     BADNAMES = ["/how/this", "/HOW/this"]
     for n in BADNAMES:
         try:
             obj.addAttribute(n, "XYZ")
             self.fail("Expected AttributeError")
         except AttributeError:
             pass
Exemple #19
0
 def test_quantity_typeError(self):
     obj = _polarscanparam.new()
     self.assertEqual(None, obj.quantity)
     try:
         obj.quantity = 10
         self.fail("Expected ValueError")
     except ValueError:
         pass
     self.assertEqual(None, obj.quantity)
Exemple #20
0
 def create_simple_scan_with_param(self, elangle, dshape, quantities):
     scan = _polarscan.new()
     scan.elangle = elangle
     for q in quantities:
         param = _polarscanparam.new()
         param.quantity = q
         param.setData(numpy.zeros(dshape, numpy.int8))
         scan.addParameter(param)
     return scan
Exemple #21
0
def CopyParam(param):
    new = _polarscanparam.new()
    new.gain, new.offset = param.gain, param.offset
    new.nodata, new.undetect = param.nodata, param.undetect
    new.setData(param.getData())
    for attr in param.getAttributeNames():
        new.addAttribute(attr, param.getAttribute(attr))
    for i in range(param.getNumberOfQualityFields()):
        new.addQualityField(param.getQualityField(i))
    return new
Exemple #22
0
    def test_setData_uint64(self):
        obj = _polarscanparam.new()
        a = numpy.arange(120)
        a = numpy.array(a.astype(numpy.uint64), numpy.uint64)
        a = numpy.reshape(a, (12, 10)).astype(numpy.uint64)

        obj.setData(a)

        self.assertEqual(_rave.RaveDataType_ULONG, obj.datatype)
        self.assertEqual(10, obj.nbins)
        self.assertEqual(12, obj.nrays)
Exemple #23
0
 def testDealiased(self):
     scan = _polarscan.new()
     vrad = _polarscanparam.new()
     vrad.quantity = "VRADH"
     vrad.addAttribute("how/dealiased", "True")
     scan.addParameter(vrad)
     self.assertTrue(_dealias.dealiased(scan)) 
     try:
       scan.getParameter("VRADH").getAttribute("how/task")
       self.fail("Expected AttributeError")
     except AttributeError:
       pass
Exemple #24
0
    def test_attributes_nonexisting(self):
        obj = _polarscanparam.new()
        obj.addAttribute("how/this", "ABC")
        obj.addAttribute("how/that", 1.0)
        obj.addAttribute("what/value", 2)
        obj.addAttribute("where/value", "1.0, 2.0, 3.0")

        try:
            obj.getAttribute("how/miffo")
            self.fail("Expected AttributeError")
        except AttributeError:
            pass
Exemple #25
0
 def test_convertWrongDataType(self):
     obj = _polarscanparam.new()
     obj.setData(
         numpy.array([[-32.0, -32.0, -32.0], [31.5, 31.5, 31.5],
                      [95.5, 95.5, 95.5]]).astype(numpy.float32))
     obj.gain = 0.5
     obj.offset = -32.0
     obj.nodata = 255.0
     obj.undetect = 0.0
     try:
         obj.convertDataDoubleToUchar()
     except TypeError:
         pass
Exemple #26
0
def copyParam(param, newquantity):
    newparam = _polarscanparam.new()
    newparam.setData(param.getData())
    newparam.quantity=newquantity
    newparam.gain = param.gain
    newparam.offset = param.offset
    newparam.undetect = param.undetect
    newparam.nodata = param.nodata
    if param.hasAttribute("how/task"):
        newparam.addAttribute("how/task", param.getAttribute("how/task"))
    if param.hasAttribute("how/dealiased"):
        newparam.addAttribute("how/dealiased", param.getAttribute("how/dealiased"))
    return newparam
Exemple #27
0
    def test_howSubgroupAttribute(self):
        obj = _polarscanparam.new()

        obj.addAttribute("how/something", 1.0)
        obj.addAttribute("how/grp/something", 2.0)
        try:
            obj.addAttribute("how/grp/else/", 2.0)
            self.fail("Expected AttributeError")
        except AttributeError:
            pass

        self.assertAlmostEqual(1.0, obj.getAttribute("how/something"), 2)
        self.assertAlmostEqual(2.0, obj.getAttribute("how/grp/something"), 2)
        self.assertTrue(obj.hasAttribute("how/something"))
        self.assertTrue(obj.hasAttribute("how/grp/something"))
Exemple #28
0
    def test_convertDataDoubleToUchar(self):
        obj = _polarscanparam.new()
        obj.setData(
            numpy.array([[-32.0, -32.0, -32.0], [31.5, 31.5, 31.5],
                         [95.5, 95.5, 95.5]]).astype(numpy.float64))
        self.assertEqual(_rave.RaveDataType_DOUBLE, obj.datatype)

        obj.gain = 0.5
        obj.offset = -32.0
        obj.nodata = 255.0
        obj.undetect = 0.0

        obj.convertDataDoubleToUchar()
        self.assertEqual(_rave.RaveDataType_UCHAR, obj.datatype)
        self.assertEqual([[0, 0, 0], [127, 127, 127], [255, 255, 255]],
                         obj.getData().tolist())
Exemple #29
0
    def test_qualityfields(self):
        obj = _polarscanparam.new()
        field1 = _ravefield.new()
        field2 = _ravefield.new()
        field1.addAttribute("what/name", "field1")
        field2.addAttribute("what/name", "field2")

        obj.addQualityField(field1)
        obj.addQualityField(field2)

        self.assertEqual(2, obj.getNumberOfQualityFields())
        self.assertEqual("field1",
                         obj.getQualityField(0).getAttribute("what/name"))
        obj.removeQualityField(0)
        self.assertEqual(1, obj.getNumberOfQualityFields())
        self.assertEqual("field2",
                         obj.getQualityField(0).getAttribute("what/name"))
Exemple #30
0
  def create_scan(self, dbzh0_0=3.0, dbzh0_1=4.0, th0_0=53.0, th0_1=40.0):
    scan = _raveio.open(self.SCAN_FIXTURE).object
    param_dbzh = scan.getParameter("DBZH")
    param_dbzh.setValue((0,0), (dbzh0_0 - param_dbzh.offset)/param_dbzh.gain)
    param_dbzh.setValue((0,1), (dbzh0_1 - param_dbzh.offset)/param_dbzh.gain)
    param_th = _polarscanparam.new()
    data = param_dbzh.getData()
    param_th.setData(data)
    param_th.quantity = "TH"
    param_th.gain = param_dbzh.gain
    param_th.offset = param_dbzh.offset
    param_th.setValue((0,0), (th0_0 - param_th.offset)/param_th.gain)
    param_th.setValue((0,1), (th0_1 - param_th.offset)/param_th.gain)
    scan.addParameter(param_th)
    return scan