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)
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())
def test_attribute_visibility(self): attrs = [ 'areaextent', 'date', 'objectType', 'projection', 'source', 'time', 'xscale', 'xsize', 'yscale', 'ysize', 'zscale', 'zsize', 'zstart' ] obj = _cartesianvolume.new() alist = dir(obj) for a in attrs: self.assertEqual(True, a in alist)
def test_zscale(self): obj = _cartesianvolume.new() self.assertAlmostEqual(0.0, obj.zscale, 4) obj.zscale = 500.0 self.assertAlmostEqual(500.0, obj.zscale, 4) try: obj.zscale = "ABC" fail("Expected TypeError") except TypeError: pass self.assertAlmostEqual(500.0, obj.zscale, 4)
def test_howSubgroupAttribute(self): obj = _cartesianvolume.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"))
def test_zsize(self): obj = _cartesianvolume.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") try: obj.zsize = 2 fail("Expected AttributeError") except AttributeError: pass self.assertEqual(0, obj.zsize) image1 = _cartesian.new() image2 = _cartesian.new() image1.init(a) image2.init(a) image1.date = "20100101" image1.time = "100000" image1.source = "PLC:1234" image1.product = _rave.Rave_ProductType_CAPPI image2.date = "20100101" image2.time = "100000" image2.source = "PLC:1234" image2.product = _rave.Rave_ProductType_CAPPI obj.addImage(image1) obj.addImage(image2) self.assertEqual(2, obj.getNumberOfImages()) self.assertEqual(2, obj.zsize)
def mergeTiles(fstrs): tiles = {} NODES = [] qfields = 0 # Addressing Issue 33, we should be able to safely assume that # output images always contain at least TH and DBZH, so reading # the number of quality fields from DBZH should suffice qimage = None # For initializing the output fields for fstr in fstrs: icomp = _raveio.open(fstr[0]).object # Currently a tuple (fstr, time) areaid = icomp.source.split(',')[1].split(':')[1] try: nodes = eval(icomp.getAttribute('how/nodes')) for node in nodes: if not node in NODES: NODES.append(node) except: pass image = icomp.getImage(0) tiles[areaid] = image nq = image.getParameter("DBZH").getNumberOfQualityFields() if nq > qfields: qfields = nq qimage = image NODES.sort() NODES = re.sub("[ \[\]]", "", str(NODES)) # Initialize the output composite container ocomp = _cartesianvolume.new() ocomp.objectType = icomp.objectType ocomp.projection = icomp.projection ocomp.date = icomp.date ocomp.time = icomp.time ocomp.source = 'ORG:53,CMT:%s' % AREAID # Canada oimage = _cartesian.new() a = rave_area.area(AREAID) ocomp.areaextent = a.extent ocomp.xscale, ocomp.yscale = a.xscale, a.yscale ocomp.addAttribute('how/nodes', NODES) # Initialize output fields if not present for p in qimage.getParameterNames(): if p not in oimage.getParameterNames(): param = qimage.getParameter(p) newp = _cartesianparam.new() newp.quantity = param.quantity newp.gain, newp.offset = param.gain, param.offset newp.nodata, newp.undetect = param.nodata, param.undetect data = np.zeros((a.ysize, a.xsize), np.uint8) if newp.nodata != 0: data += newp.nodata newp.setData(data) # Initialize quality fields too for i in range(param.getNumberOfQualityFields()): qf = param.getQualityField(i) newq = _ravefield.new() newq.setData(np.zeros((a.ysize, a.xsize), np.uint8)) for attr in qf.getAttributeNames(): newq.addAttribute(attr, qf.getAttribute(attr)) newp.addQualityField(newq) oimage.addParameter(newp) ocomp.addImage(oimage) # Now loop through input tiles and paste them into the output composite for areaid in tiles.keys(): pasteTile(ocomp, tiles[areaid]) # Delete temporary tile files for fstr in fstrs: os.remove(fstr[0]) return ocomp
def test_isCartesianVolume(self): obj = _cartesianvolume.new() self.assertEqual(True, _cartesianvolume.isCartesianVolume(obj))
def test_new(self): obj = _cartesianvolume.new() self.assertNotEqual(-1, str(type(obj)).find("CartesianVolumeCore"))