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 add(id, description, projection_id, extent, xsize, ysize, xscale, yscale, filename=AREA_REGISTRY): reg = _arearegistry.load(filename) reg.removeByName(id) # Is silent if entry doesn't exist a = _area.new() a.id, a.description, a.pcsid = id, description, projection_id a.extent = extent a.xsize, a.ysize = xsize, ysize a.xscale, a.yscale = xscale, yscale p = rave_projection.pcs(a.pcsid) pid = p.id pname = p.name if isinstance(pid, bytes): pid = pid.decode() if isinstance(pname, bytes): pname = pname.decode() a.projection = _projection.new(pid, pname, " ".join(p.definition)) reg.add(a) reg.write(filename)
def test_write(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) a = _area.new() a.id = "nisse" a.description = "nisses test" a.xsize = 111 a.ysize = 222 a.xscale = 1000.0 a.yscale = 2000.0 a.extent = (-738816.513333, -3995515.596160, 955183.48666699999, -1787515.59616) a.pcsid = "laea20e60n" registry.add(a) registry.write(self.TEMPORARY_FILE) tree = ElementTree.parse(self.TEMPORARY_FILE) areas = tree.findall("area") self.assertEqual(3, len(areas)) self.assertEqual("nisse", areas[2].get('id')) args = areas[2].findall("areadef/arg") self.assertEqual("laea20e60n", self.findArgElements(args, "id", "pcs").text.strip()) self.assertEqual(None, self.findArgElements(args, "id", "pcs").get("type")) self.assertEqual( "111", self.findArgElements(args, "id", "xsize").text.strip()) self.assertEqual("int", self.findArgElements(args, "id", "xsize").get("type")) self.assertEqual( "222", self.findArgElements(args, "id", "ysize").text.strip()) self.assertEqual("int", self.findArgElements(args, "id", "ysize").get("type")) self.assertEqual( "1000.0", self.findArgElements(args, "id", "xscale").text.strip()[:6]) self.assertEqual( "float", self.findArgElements(args, "id", "xscale").get("type")) self.assertEqual( "2000.0", self.findArgElements(args, "id", "yscale").text.strip()[:6]) self.assertEqual( "float", self.findArgElements(args, "id", "yscale").get("type")) extent = self.findArgElements(args, "id", "extent").text.strip().split(",") self.assertEqual("-738816.5", extent[0].strip()[:9]) self.assertEqual("-3995515.5", extent[1].strip()[:10]) self.assertEqual("955183.4", extent[2].strip()[:8]) self.assertEqual("-1787515.5", extent[3].strip()[:10]) self.assertEqual( "sequence", self.findArgElements(args, "id", "extent").get("type"))
def test_attribute_visibility(self): attrs = [ 'extent', 'id', 'projection', 'xscale', 'xsize', 'yscale', 'ysize' ] area = _area.new() alist = dir(area) for a in attrs: self.assertEqual(True, a in alist)
def test_id(self): obj = _area.new() self.assertEqual(None, obj.id) obj.id = "something" self.assertEqual("something", obj.id) obj.id = None self.assertEqual(None, obj.id)
def test_xsize_typeError(self): obj = _area.new() self.assertEqual(0, obj.xsize) try: obj.xsize = 10.0 self.fail("Expected TypeError") except TypeError: pass self.assertEqual(0, obj.xsize)
def test_yscale_typeError(self): obj = _area.new() self.assertAlmostEqual(0.0, obj.yscale, 4) try: obj.yscale = "abc" self.fail("Expected TypeError") except TypeError: pass self.assertAlmostEqual(0.0, obj.yscale, 4)
def test_id_typeError(self): obj = _area.new() try: obj.id = 1.2 self.fail("Expected TypeError") except TypeError: pass self.assertEqual(None, obj.id)
def create_area(self): a = _area.new() a.id = "eua_gmaps" a.xsize = 800 a.ysize = 1090 a.xscale = 6223.0 a.yscale = 6223.0 a.extent = (-3117.83526,-6780019.83039,4975312.43200,3215.41216) a.projection = _projection.new("x", "y", "+proj=merc +lat_ts=0 +lon_0=0 +k=1.0 +x_0=1335833 +y_0=-11000715 +a=6378137.0 +b=6378137.0 +no_defs +datum=WGS84") return a
def test_projection_typeError(self): obj = _area.new() try: obj.projection = "+proj=latlong +ellps=WGS84 +datum=WGS84" self.fail("Expected TypeError") except TypeError: pass self.assertEqual(None, obj.projection)
def test_projection(self): obj = _area.new() self.assertEqual(None, obj.projection) obj.projection = _projection.new( "x", "y", "+proj=latlong +ellps=WGS84 +datum=WGS84") self.assertEqual("x", obj.projection.id) obj.projection = None self.assertEqual(None, obj.projection)
def test_isArea(self): obj = _area.new() self.assertEqual(True, _area.isArea(obj)) self.assertEqual( False, _area.isArea( _projection.new("x", "y", "+proj=latlong +ellps=WGS84 +datum=WGS84"))) self.assertEqual(False, _area.isArea("abc")) self.assertEqual(False, _area.isArea(None))
def concatenate_topo(): ios1 = _raveio.open("./W020N90.h5") src1 = ios1.object data1 = src1.getParameter("TOPO").getData() ios2 = _raveio.open("./E020N90.h5") src2 = ios2.object data2 = src2.getParameter("TOPO").getData() #data2 = numpy.zeros((6000,4800), numpy.int16) a1 = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], numpy.int16) data = concatenate((a1, a1), 1) print(concatenate((a1, a1), 1)) print(data) a = _area.new() a.id = "BALTRAD" a.projection = src1.projection a.extent = (src1.areaextent[0], src1.areaextent[1], src2.areaextent[2], src2.areaextent[3]) a.xsize = src1.xsize + src2.xsize a.ysize = src1.ysize a.xscale = (a.extent[2] - a.extent[0]) / (a.xsize - 1) a.yscale = (a.extent[3] - a.extent[1]) / (a.ysize - 1) print(a.id) print(a.projection.definition) print(a.extent) print(a.xsize, a.ysize) print(a.xscale, a.yscale) src = _cartesian.new() src.init(a, _rave.RaveDataType_SHORT) src.time = src1.time src.date = src1.date src.objectType = src1.objectType src.product = src1.product src.source = src1.source param1 = src1.getParameter("TOPO") param = _cartesianparam.new() param.quantity = param1.quantity param.gain = param1.gain param.offset = param1.offset param.nodata = param1.nodata param.setData(data) ios = _raveio.new() ios.object = src ios.filename = "./BALTRAD_topo.h5" ios.save()
def test_extent(self): obj = _area.new() extent = obj.extent self.assertEqual(4, len(extent)) self.assertAlmostEqual(0.0, extent[0], 4) self.assertAlmostEqual(0.0, extent[1], 4) self.assertAlmostEqual(0.0, extent[2], 4) self.assertAlmostEqual(0.0, extent[3], 4) obj.extent = (1.0, 2.0, 3.0, 4.0) extent = obj.extent self.assertEqual(4, len(extent)) self.assertAlmostEqual(1.0, extent[0], 4) self.assertAlmostEqual(2.0, extent[1], 4) self.assertAlmostEqual(3.0, extent[2], 4) self.assertAlmostEqual(4.0, extent[3], 4)
def test_add(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) a = _area.new() a.id = "nisse" a.xsize = 111 a.ysize = 222 a.xscale = 1000.0 a.yscale = 2000.0 a.extent = (-738816.513333, -3995515.596160, 955183.48666699999, -1787515.59616) a.pcsid = "laea20e60n" registry.add(a) self.assertEqual(3, registry.size()) self.assertEqual("nisse", registry.getByName("nisse").id)
def write(filename=AREA_REGISTRY): check = [] # Used to avoid duplicate entries new_registry = _arearegistry.new() for k, i in items(): if k not in check: tmp = _area.new() tmp.id, tmp.description, tmp.pcsid = i.id, i.name, i.pcs.id tmp.extent = i.extent tmp.xsize, tmp.ysize = i.xsize, i.ysize tmp.xscale, tmp.yscale = i.xscale, i.yscale new_registry.add(tmp) check.append(k) else: print("Duplicate entry for id %s. Ignored." % k) new_registry.write(filename)
def test_extent_typeError(self): obj = _area.new() try: obj.extent = (1.0, 2.0, 3.0) self.fail("Expected TypeError") except TypeError: pass try: obj.extent = (1.0, 2.0, 3.0, 4.0, 5.0) self.fail("Expected TypeError") except TypeError: pass try: obj.extent = (1.0, 2.0, "abc") self.fail("Expected TypeError") except TypeError: pass
def test_init(self): obj = _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") obj.init(a) self.assertEqual(10, obj.xsize) self.assertEqual(10, obj.ysize) self.assertAlmostEqual(100.0, obj.xscale, 4) self.assertAlmostEqual(100.0, obj.yscale, 4) self.assertAlmostEqual(1.0, obj.areaextent[0], 4) self.assertAlmostEqual(2.0, obj.areaextent[1], 4) self.assertAlmostEqual(3.0, obj.areaextent[2], 4) self.assertAlmostEqual(4.0, obj.areaextent[3], 4) self.assertEqual("x", obj.projection.id)
def test_isValid_asImage_no_date(self): obj = _cartesian.new() param = _cartesianparam.new() param.quantity = "DBZH" param.setData(numpy.zeros((10, 10), numpy.uint8)) 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") obj.init(a) obj.time = "100000" obj.source = "PLC:1234" obj.product = _rave.Rave_ProductType_CAPPI obj.addParameter(param) self.assertEqual(False, obj.isValid(_rave.Rave_ObjectType_IMAGE))
def get_tiled_areas(a): if not a.id in _registry: raise KeyError("No such area (%s) with tiles defined" % a.id) tiledareas = [] totalx, totaly = 0, 0 for ta in _registry[a.id]: pyarea = _area.new() pyarea.id = "%s_%s" % (a.id, ta.id) pyarea.xsize = int(round((ta.extent[2] - ta.extent[0]) / a.xscale)) pyarea.ysize = int(round((ta.extent[3] - ta.extent[1]) / a.yscale)) totalx = totalx + pyarea.xsize totaly = totaly + pyarea.ysize pyarea.xscale = a.xscale pyarea.yscale = a.yscale pyarea.projection = a.projection pyarea.extent = ta.extent tiledareas.append(pyarea) return tiledareas
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 getarea(self, areaid): if not areaid in self._registry.keys(): self._loadarea(areaid) if areaid in self._registry.keys(): result = self._registry[areaid] else: a = area.area(areaid) p = a.pcs pyarea = _area.new() pyarea.id = a.Id pyarea.xsize = a.xsize pyarea.ysize = a.ysize pyarea.xscale = a.xscale pyarea.yscale = a.yscale pyarea.extent = a.extent pyarea.projection = _projection.new(p.id, str(p.name), ' '.join(p.definition)) self._registry[pyarea.id] = pyarea result = pyarea return result
def test_createParameter(self): obj = _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") obj.init(a) param = obj.createParameter("DBZH", _rave.RaveDataType_UCHAR) self.assertEqual(10, param.xsize) self.assertEqual(10, param.ysize) self.assertEqual("DBZH", param.quantity) param = obj.createParameter("MMH", _rave.RaveDataType_UCHAR) self.assertEqual(10, param.xsize) self.assertEqual(10, param.ysize) self.assertEqual("MMH", param.quantity) self.assertTrue(obj.hasParameter("DBZH")) self.assertTrue(obj.hasParameter("MMH"))
def test_write_2(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) a = _area.new() a.id = "nisse" a.description = "nisses test" a.xsize = 111 a.ysize = 222 a.xscale = 1000.0 a.yscale = 2000.0 a.extent = (-738816.513333, -3995515.596160, 955183.48666699999, -1787515.59616) a.pcsid = "laea20e60n" registry.add(a) registry.write(self.TEMPORARY_FILE) newreg = _arearegistry.load(self.TEMPORARY_FILE) self.assertEqual(3, newreg.size()) self.assertEqual("nrd2km", newreg.get(0).id) self.assertEqual("nrd2km_laea20e60n", newreg.get(1).id) self.assertEqual("nisse", newreg.get(2).id)
def create_cartesian_with_parameter(self, xsize, ysize, xscale, yscale, extent, projstr, dtype, value, quantity): obj = _cartesian.new() a = _area.new() a.xsize = xsize a.ysize = ysize a.xscale = xscale a.yscale = yscale a.extent = extent a.projection = _projection.new("x", "y", projstr) obj.init(a) for i in range(len(quantity)): data = numpy.zeros((ysize, xsize), dtype) data = data + value[i] param = _cartesianparam.new() param.setData(data) param.nodata = 255.0 param.quantity = quantity[i] obj.addParameter(param) return obj
def read_topo(): for tile in ["W020N90", "E020N90"]: # extract meta-data fnm = "../db/topo/" + tile + "/" + tile + ".HDR" fid = open(fnm, "r") byteorder = fid.readline().split()[1] layout = fid.readline().split()[1] nrows = int(fid.readline().split()[1]) ncols = int(fid.readline().split()[1]) nbands = int(fid.readline().split()[1]) nbits = int(fid.readline().split()[1]) bandrowbytes = int(fid.readline().split()[1]) totalrowbytes = int(fid.readline().split()[1]) bandgapbytes = int(fid.readline().split()[1]) nodata = int(fid.readline().split()[1]) # longitude of the center of the upper-left pixel (decimal degrees) ulxmap = float(fid.readline().split()[1]) # latitude of the center of the upper-left pixel (decimal degrees) ulymap = float(fid.readline().split()[1]) # x dimension of a pixel in geographic units (decimal degrees) xdim = float(fid.readline().split()[1]) # y dimension of a pixel in geographic units (decimal degrees) ydim = float(fid.readline().split()[1]) fid.close() # extract topography fnm = "../db/topo/" + tile + "/" + tile + ".DEM" fid = open(fnm, "r") data = fid.read() data = fromstring(data, short).byteswap() data = data.reshape(nrows, ncols) print("data type and shape: ", data.dtype, data.shape) fid.close() # longitude of the lower-left corner of the lower-left pixel (decimal degrees) llxmap = ulxmap - xdim / 2 # latitude of the lower-left corner of the lower-left pixel (decimal degrees) llymap = (ulymap - ydim / 2) - ((nrows - 1) * ydim) # longitude of the lower-left corner of the upper-right pixel (decimal degrees) urxmap = llxmap + ((ncols - 1) * xdim) # latitude of the lower-left corner of the upper-right pixel (decimal degrees) urymap = llymap + ((nrows - 1) * ydim) a = _area.new() a.id = tile a.projection = _projection.new("longlat_wgs84", "Plate Caree WGS84", "+proj=eqc +ellps=WGS84 +datum=WGS84") (llx, lly) = a.projection.fwd(deg2rad((llxmap, llymap))) (urx, ury) = a.projection.fwd(deg2rad((urxmap, urymap))) a.extent = (llx, lly, urx, ury) a.xsize = ncols a.ysize = nrows a.xscale = (urx - llx) / (ncols - 1) a.yscale = (ury - lly) / (nrows - 1) print("%f,%f,%f,%f" % (llxmap, llymap, urxmap, urymap)) print("%f,%f,%f,%f" % a.extent) print("%f,%f" % (a.xscale, a.yscale)) src = _cartesian.new() src.init(a, _rave.RaveDataType_SHORT) src.time = "000000" src.date = "20100101" src.objectType = _rave.Rave_ObjectType_IMAGE src.product = _rave.Rave_ProductType_COMP src.source = "GTOPO30 topography" param = _cartesianparam.new() param.quantity = "TOPO" param.gain = 1.0 param.offset = 0.0 param.nodata = -9999.0 param.setData(data) src.addParameter(param) src.defaultParameter = "TOPO" ios = _raveio.new() ios.object = src ios.filename = "./" + tile + ".h5" ios.save()
def generate(self, dd, dt, tid): comp = compositing.compositing() comp.xscale = self.xscale comp.yscale = self.yscale comp.detectors = self.detectors comp.ignore_malfunc = self.ignore_malfunc comp.prodpar = self.prodpar comp.product = self.product comp.height = self.height comp.elangle = self.elangle comp.range = self.range comp.selection_method = self.selection_method comp.interpolation_method = self.interpolation_method comp.qitotal_field = self.qitotal_field comp.applygra = self.applygra comp.zr_A = self.zr_A comp.zr_b = self.zr_b comp.applygapfilling = self.applygapfilling comp.applyctfilter = self.applyctfilter comp.quantity = self.quantity comp.gain = self.gain comp.offset = self.offset comp.minvalue = self.minvalue comp.filenames = self.filenames comp.verbose = self.verbose comp.reprocess_quality_field = self.reprocess_quality_field comp.dump = self.dump comp.dumppath = self.dumppath comp.radar_index_mapping = self.radar_index_mapping pyarea = _area.new() pyarea.id = "tiled area subset %s" % tid pyarea.xsize = self.area_definition.xsize pyarea.ysize = self.area_definition.ysize pyarea.xscale = self.area_definition.xscale pyarea.yscale = self.area_definition.yscale pyarea.extent = self.area_definition.extent pyarea.projection = _projection.new("dynamic pcsid", "dynamic pcs name", self.area_definition.pcsdef) logger.info("Generating composite for tile %s" % self.area_definition.id) result = comp.generate(dd, dt, pyarea) if result == None: logger.info("No composite for tile %s could be generated.", self.area_definition.id) return (tid, None) else: logger.info("Finished generating composite for tile %s", self.area_definition.id) fileno, outfile = rave_tempfile.mktemp(suffix='.h5', close="True") rio = _raveio.new() rio.object = result rio.filename = outfile rio.save() return (tid, rio.filename)
def test_xsize(self): obj = _area.new() self.assertEqual(0, obj.xsize) obj.xsize = 10 self.assertEqual(10, obj.xsize)
def test_yscale_int(self): obj = _area.new() self.assertAlmostEqual(0.0, obj.yscale, 4) obj.yscale = 10 self.assertAlmostEqual(10.0, obj.yscale, 4)
def test_new(self): obj = _area.new() isarea = str(type(obj)).find("AreaCore") self.assertNotEqual(-1, isarea)