Ejemplo n.º 1
0
    def test_attributes_from_image(self):
        obj = _cartesianvolume.new()
        obj.xscale = 200.0
        obj.yscale = 200.0
        image = _cartesian.new()
        a = _area.new()
        a.xsize = 10
        a.ysize = 10
        a.xscale = 100.0
        a.yscale = 100.0
        a.extent = (1.0, 2.0, 3.0, 4.0)
        a.projection = _projection.new(
            "x", "y", "+proj=latlong +ellps=WGS84 +datum=WGS84")

        image.init(a)
        image.date = "20100101"
        image.time = "100000"
        image.source = "PLC:1234"
        image.product = _rave.Rave_ProductType_CAPPI

        self.assertEqual(0, obj.xsize)
        self.assertEqual(0, obj.ysize)

        obj.addImage(image)
        self.assertEqual(10, obj.xsize)
        self.assertEqual(10, obj.ysize)
        self.assertEqual(1, obj.getNumberOfImages())
Ejemplo n.º 2
0
    def testFillGap_onCartesianParameters(self):
        data = numpy.zeros((6, 6), numpy.uint8)
        data[1][2] = 1
        data[2][1] = 1
        data[3][2] = 1
        data[2][3] = 1

        obj = _cartesian.new()

        param = _cartesianparam.new()
        param.setData(data)
        param.nodata = 255.0
        param.quantity = "DBZH"
        obj.addParameter(param)

        param = _cartesianparam.new()
        data[1][2] = 2
        data[2][1] = 2
        data[3][2] = 2
        data[2][3] = 2
        param.setData(data)
        param.nodata = 255.0
        param.quantity = "TH"
        obj.addParameter(param)

        t = _transform.new()
        result = t.fillGap(obj)

        data = result.getParameter("DBZH").getData()
        self.assertEqual(1, data[2][2])
        data = result.getParameter("TH").getData()
        self.assertEqual(2, data[2][2])
Ejemplo n.º 3
0
def readCT(filename):
    ct, cp = _cartesian.new(), _cartesianparam.new()

    nodelist = _pyhl.read_nodelist(filename)
    for n in NODENAMES:
        nodelist.selectNode(n)
    nodelist.fetch()

    ct.defaultParameter = "CT"
    ct.projection = _projection.new("MSG", "no description",
                                    nodelist.getNode("/PROJECTION").data())

    cp.setData(nodelist.getNode("/CT").data())

    ysize = nodelist.getNode("/CT/N_LINES").data()
    xsize = nodelist.getNode("/CT/N_COLS").data()
    ULx = nodelist.getNode("/XGEO_UP_LEFT").data()
    ULy = nodelist.getNode("/YGEO_UP_LEFT").data()
    LRx = nodelist.getNode("/XGEO_LOW_RIGHT").data()
    LRy = nodelist.getNode("/YGEO_LOW_RIGHT").data()
    yscale = (ULy - LRy) / ysize
    xscale = (LRx - ULx) / xsize
    xoffset, yoffset = xscale / 2, yscale / 2  # Offsets to adjust LL and UR corners
    LLx = LRx - (xsize * xscale) - xoffset
    LLy = ULy - (ysize * yscale) - yoffset
    URx = LRx + xoffset
    URy = ULy + yoffset
    ct.areaextent = (LLx, LLy, URx, URy)  # Differs ~5 cm from PPS and PyTROLL
    ct.xscale, ct.yscale = xscale, yscale
    cp.quantity = "CT"
    cp.gain, cp.offset = 1.0, 0.0
    cp.nodata, cp.undetect = -1.0, 0.0
    ct.addParameter(cp)

    return ct
Ejemplo n.º 4
0
 def test_date(self):
     obj = _cartesian.new()
     self.assertEqual(None, obj.date)
     obj.date = "20050101"
     self.assertEqual("20050101", obj.date)
     obj.date = None
     self.assertEqual(None, obj.date)
Ejemplo n.º 5
0
    def test_attributes_to_image(self):
        obj = _cartesianvolume.new()
        obj.xscale = 200.0
        obj.yscale = 200.0
        obj.areaextent = (1.0, 2.0, 3.0, 4.0)
        obj.projection = _projection.new(
            "x", "y", "+proj=latlong +ellps=WGS84 +datum=WGS84")
        obj.date = "20100101"
        obj.time = "100000"
        obj.source = "PLC:1234"

        image = _cartesian.new()
        image.product = _rave.Rave_ProductType_CAPPI

        obj.addImage(image)

        self.assertAlmostEqual(200.0, image.xscale, 4)
        self.assertAlmostEqual(200.0, image.yscale, 4)
        self.assertEqual("20100101", image.date)
        self.assertEqual("100000", image.time)
        self.assertEqual("PLC:1234", image.source)
        self.assertAlmostEqual(1.0, image.areaextent[0], 4)
        self.assertAlmostEqual(2.0, image.areaextent[1], 4)
        self.assertAlmostEqual(3.0, image.areaextent[2], 4)
        self.assertAlmostEqual(4.0, image.areaextent[3], 4)
Ejemplo n.º 6
0
 def test_time(self):
     obj = _cartesian.new()
     self.assertEqual(None, obj.time)
     obj.time = "200500"
     self.assertEqual("200500", obj.time)
     obj.time = None
     self.assertEqual(None, obj.time)
Ejemplo n.º 7
0
    def test_getConvertedValueAtLonLat(self):
        obj = _cartesian.new()
        obj.projection = _rave.projection(
            "gnom", "gnom",
            "+proj=gnom +R=6371000.0 +lat_0=56.3675 +lon_0=12.8544")
        obj.xscale = 100.0
        obj.yscale = 100.0

        xy = obj.projection.fwd(deg2rad((12.8544, 56.3675)))
        obj.areaextent = (xy[0] - 4 * 100.0, xy[1] - 5 * 100.0,
                          xy[0] + 6 * 100.0, xy[1] + 5 * 100.0)
        param = _cartesianparam.new()
        param.quantity = "DBZH"
        param.nodata = 255.0
        param.undetect = 0.0

        a = numpy.arange(99)
        a = numpy.array(a.astype(numpy.float64), numpy.float64)
        a = numpy.reshape(a, (11, 9)).astype(numpy.float64)

        param.setData(a)

        obj.addParameter(param)
        obj.defaultParameter = "DBZH"

        expected = obj.getConvertedValue((4, 5))
        actual = obj.getConvertedValueAtLonLat(deg2rad((12.8544, 56.3675)))
        self.assertEqual(expected[0], actual[0])
        self.assertAlmostEqual(expected[1], actual[1], 4)
Ejemplo n.º 8
0
 def test_objectType_invalid(self):
     obj = _cartesian.new()
     try:
         obj.objectType = _rave.Rave_ObjectType_CVOL
         fail("Expected ValueError")
     except ValueError:
         pass
Ejemplo n.º 9
0
    def test_getValue(self):
        obj = _cartesian.new()

        param = _cartesianparam.new()
        param.quantity = "DBZH"
        param.nodata = 255.0
        param.undetect = 0.0

        a = numpy.arange(120)
        a = numpy.array(a.astype(numpy.float64), numpy.float64)
        a = numpy.reshape(a, (12, 10)).astype(numpy.float64)
        a[0][1] = param.nodata
        a[1][0] = param.undetect

        param.setData(a)

        obj.addParameter(param)
        obj.defaultParameter = "DBZH"
        pairs = [(0, 0, 0.0, _rave.RaveValueType_UNDETECT),
                 (1, 0, param.nodata, _rave.RaveValueType_NODATA),
                 (0, 1, param.undetect, _rave.RaveValueType_UNDETECT),
                 (2, 0, 2.0, _rave.RaveValueType_DATA),
                 (0, 3, 30.0, _rave.RaveValueType_DATA)]

        for cval in pairs:
            result = obj.getValue((cval[0], cval[1]))
            self.assertAlmostEqual(cval[2], result[1], 4)
            self.assertEqual(cval[3], result[0])
Ejemplo n.º 10
0
    def test_isTransformable_noscale(self):
        proj = _rave.projection(
            "x", "y",
            "+proj=stere +ellps=bessel +lat_0=90 +lon_0=14 +lat_ts=60 +datum=WGS84"
        )
        data = numpy.zeros((10, 10), numpy.float64)

        param = _cartesianparam.new()
        param.quantity = "DBZH"
        param.setData(data)

        obj = _cartesian.new()
        obj.xscale = 1000.0
        obj.yscale = 1000.0

        obj.projection = proj
        obj.addParameter(param)

        self.assertEqual(True, obj.isTransformable())
        obj.xscale = 1000.0
        obj.yscale = 0.0
        self.assertEqual(False, obj.isTransformable())
        obj.xscale = 0.0
        obj.yscale = 1000.0
        self.assertEqual(False, obj.isTransformable())
Ejemplo n.º 11
0
 def test_areaextent_illegalData(self):
     obj = _cartesian.new()
     try:
         obj.areaextent = (10.0, "a", 30.0, 40.0)
         self.fail("Expected type error")
     except TypeError:
         pass
Ejemplo n.º 12
0
 def test_prodname(self):
     obj = _cartesian.new()
     self.assertEqual(None, obj.prodname)
     obj.prodname = "a product"
     self.assertEqual("a product", obj.prodname)
     obj.prodname = None
     self.assertEqual(None, obj.prodname)
Ejemplo n.º 13
0
 def test_source(self):
     obj = _cartesian.new()
     self.assertEqual(None, obj.source)
     obj.source = "ABC:10, ABD:1"
     self.assertEqual("ABC:10, ABD:1", obj.source)
     obj.source = None
     self.assertEqual(None, obj.source)
Ejemplo n.º 14
0
    def test_setGetValue(self):
        obj = _cartesian.new()

        param = _cartesianparam.new()
        param.quantity = "DBZH"
        param.nodata = 255.0
        param.undetect = 0.0

        a = numpy.arange(120)
        a = numpy.array(a.astype(numpy.float64), numpy.float64)
        a = numpy.reshape(a, (12, 10)).astype(numpy.float64)
        param.setData(a)

        obj.addParameter(param)
        obj.defaultParameter = "DBZH"

        data = [
            ((0, 1), 10.0, _rave.RaveValueType_DATA),
            ((1, 1), 20.0, _rave.RaveValueType_DATA),
            ((2, 2), 30.0, _rave.RaveValueType_DATA),
            ((9, 4), 49.0, _rave.RaveValueType_DATA),
            ((8, 4), param.nodata, _rave.RaveValueType_NODATA),
            ((4, 8), param.undetect, _rave.RaveValueType_UNDETECT),
        ]

        for v in data:
            obj.setValue(v[0], v[1])

        # Verify
        for v in data:
            r = obj.getValue(v[0])
            self.assertAlmostEqual(v[1], r[1], 4)
            self.assertEqual(v[2], r[0])
Ejemplo n.º 15
0
 def test_projection(self):
     obj = _cartesian.new()
     proj = _rave.projection(
         "x", "y",
         "+proj=stere +ellps=bessel +lat_0=90 +lon_0=14 +lat_ts=60 +datum=WGS84"
     )
     obj.projection = proj
     self.assertTrue(proj == obj.projection)
Ejemplo n.º 16
0
 def test_starttime(self):
     obj = _cartesian.new()
     self.assertEqual(None, obj.starttime)
     obj.time = "100000"
     self.assertEqual("100000", obj.starttime)
     obj.starttime = "110000"
     self.assertEqual("100000", obj.time)
     self.assertEqual("110000", obj.starttime)
Ejemplo n.º 17
0
 def test_prodname_typeError(self):
     obj = _cartesian.new()
     try:
         obj.prodname = 10
         self.fail("Expected TypeError")
     except TypeError:
         pass
     self.assertEqual(None, obj.prodname)
Ejemplo n.º 18
0
 def test_time_badValues(self):
     obj = _cartesian.new()
     values = ["10101", "1010101", "1010ab", "1010x0", "abcdef", 123456]
     for val in values:
         try:
             obj.time = val
             self.fail("Expected ValueError")
         except ValueError:
             pass
Ejemplo n.º 19
0
    def test_createParameter_notInitialized(self):
        obj = _cartesian.new()

        try:
            obj.createParameter("DBZH", _rave.RaveDataType_UCHAR)
            self.fail("Expected AttributeError")
        except AttributeError:
            pass
        self.assertFalse(obj.hasParameter("DBZH"))
Ejemplo n.º 20
0
 def test_yscale_typeError(self):
     obj = _cartesian.new()
     self.assertAlmostEqual(0.0, obj.yscale, 4)
     try:
         obj.yscale = 10
         self.fail("Expected TypeError")
     except TypeError:
         pass
     self.assertAlmostEqual(0.0, obj.yscale, 4)
Ejemplo n.º 21
0
 def test_ysize(self):
     obj = _cartesian.new()
     self.assertEqual(0, obj.ysize)
     try:
         obj.ysize = 10
         self.fail("Expected AttributeError")
     except AttributeError:
         pass
     self.assertEqual(0, obj.ysize)
Ejemplo n.º 22
0
    def test_hasParameter(self):
        obj = _cartesian.new()
        param = _cartesianparam.new()
        param.quantity = "DBZH"
        param.setData(numpy.zeros((240, 240), numpy.uint8))

        self.assertFalse(obj.hasParameter("DBZH"))
        obj.addParameter(param)
        self.assertTrue(obj.hasParameter("DBZH"))
Ejemplo n.º 23
0
 def test_date_badValues(self):
     obj = _cartesian.new()
     values = ["200910101", "2001010", "200a1010", 20091010]
     for val in values:
         try:
             obj.time = val
             self.fail("Expected ValueError")
         except ValueError:
             pass
Ejemplo n.º 24
0
 def test_attribute_visibility(self):
     attrs = [
         'areaextent', 'date', 'objectType', 'product', 'projection',
         'source', 'time', 'xscale', 'xsize', 'yscale', 'ysize', 'prodname'
     ]
     obj = _cartesian.new()
     alist = dir(obj)
     for a in attrs:
         self.assertEqual(True, a in alist)
Ejemplo n.º 25
0
    def test_getIndexX(self):
        obj = _cartesian.new()
        obj.areaextent = (100.0, 200.0, 300.0, 400.0)
        obj.xscale = 10.0

        xpos = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        for x in xpos:
            value = 100.0 + x * 10.0
            result = obj.getIndexX(value)
            self.assertEqual(x, result)
Ejemplo n.º 26
0
    def test_addParameter_no_quantity(self):
        obj = _cartesian.new()

        param = _cartesianparam.new()
        param.setData(numpy.zeros((10, 10), numpy.uint8))

        try:
            obj.addParameter(param)
            self.fail("Expected AttributeError")
        except AttributeError:
            pass
Ejemplo n.º 27
0
    def test_getIndexY(self):
        obj = _cartesian.new()
        obj.areaextent = (100.0, 200.0, 300.0, 400.0)
        obj.yscale = 10.0

        ypos = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        for y in ypos:
            value = 400.0 - y * 10.0
            result = obj.getIndexY(value)
            self.assertEqual(y, result)
Ejemplo n.º 28
0
    def test_getConvertedQualityValueAtLonLat(self):
        obj = _cartesian.new()
        obj.projection = _rave.projection(
            "gnom", "gnom",
            "+proj=gnom +R=6371000.0 +lat_0=56.3675 +lon_0=12.8544")
        obj.xscale = 100.0
        obj.yscale = 100.0

        xy = obj.projection.fwd(deg2rad((12.8544, 56.3675)))
        obj.areaextent = (xy[0] - 4 * 100.0, xy[1] - 5 * 100.0,
                          xy[0] + 6 * 100.0, xy[1] + 5 * 100.0)
        param = _cartesianparam.new()
        param.quantity = "DBZH"
        param.nodata = 255.0
        param.undetect = 0.0

        a = numpy.zeros((11, 9))
        a = numpy.array(a.astype(numpy.float64), numpy.float64)
        a = numpy.reshape(a, (11, 9)).astype(numpy.float64)

        param.setData(a)

        qf = numpy.arange(99)
        qf = numpy.array(qf.astype(numpy.float64), numpy.float64)
        qf = numpy.reshape(qf, (11, 9)).astype(numpy.float64)

        qf2 = numpy.arange(99)
        qf2 = numpy.array(qf.astype(numpy.float64), numpy.float64)
        qf2 = numpy.reshape(qf, (11, 9)).astype(numpy.float64)
        qf2[5][4] = 199.0

        field1 = _ravefield.new()
        field1.addAttribute("how/task", "se.task.1")
        field1.addAttribute("what/offset", 10.0)
        field1.addAttribute("what/gain", 2.0)
        field1.setData(qf)
        param.addQualityField(field1)

        field2 = _ravefield.new()
        field2.addAttribute("how/task", "se.task.2")
        field2.addAttribute("what/gain", 3.0)
        field2.setData(qf2)
        param.addQualityField(field2)

        obj.addParameter(param)
        obj.defaultParameter = "DBZH"

        #expected = obj.getConvertedValue((4,5))
        result = obj.getConvertedQualityValueAtLonLat(
            deg2rad((12.8544, 56.3675)), "se.task.1")
        self.assertAlmostEqual(10.0 + 2.0 * 49.0, result, 4)
        result = obj.getConvertedQualityValueAtLonLat(
            deg2rad((12.8544, 56.3675)), "se.task.2")
        self.assertAlmostEqual(3.0 * 199.0, result, 4)
Ejemplo n.º 29
0
    def test_getLocationX(self):
        obj = _cartesian.new()
        obj.areaextent = (100.0, 200.0, 300.0, 400.0)
        obj.xscale = 10.0

        xpos = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        for x in xpos:
            expected = 100.0 + x * 10.0
            result = obj.getLocationX(x)
            self.assertAlmostEqual(expected, result, 4)
Ejemplo n.º 30
0
    def test_getLocationY(self):
        obj = _cartesian.new()
        obj.areaextent = (100.0, 200.0, 300.0, 400.0)
        obj.yscale = 10.0

        ypos = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        for y in ypos:
            expected = 400.0 - y * 10.0
            result = obj.getLocationY(y)
            self.assertAlmostEqual(expected, result, 4)