Esempio n. 1
0
    def test_daToLl2(self):
        obj = _polarnav.new()
        obj.lat0 = 60.0 * math.pi / 180.0
        obj.lon0 = 14.0 * math.pi / 180.0
        obj.alt0 = 0.0

        lon, lat = obj.daToLl(9000.0, 0.0)
Esempio n. 2
0
    def test_new(self):
        obj = _polarnav.new()

        ispolnav = str(type(obj)).find("PolarNavigatorCore")
        self.assertNotEqual(-1, ispolnav)
        self.assertAlmostEqual(6356780.0, obj.poleradius, 4)
        self.assertAlmostEqual(6378160.0, obj.equatorradius, 4)
        self.assertAlmostEqual((-3.9e-5) / 1000, obj.dndh, 4)
Esempio n. 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)
Esempio n. 4
0
    def test_getDistance(self):
        obj = _polarnav.new()
        obj.lat0 = 60.0 * math.pi / 180.0
        obj.lon0 = 14.0 * math.pi / 180.0

        result = obj.getDistance(
            (61.0 * math.pi / 180.0, 14.0 * math.pi / 180.0))

        self.assertAlmostEqual(111040.1, result, 1)
Esempio n. 5
0
    def test_reToDh(self):
        obj = _polarnav.new()
        obj.lat0 = 60.0 * math.pi / 180.0
        obj.lon0 = 12.0 * math.pi / 180.0
        obj.alt0 = 0.0

        d, h = obj.reToDh(50012.88, 0.976411 * math.pi / 180.0)
        self.assertAlmostEqual(50000.0, d, 2)
        self.assertAlmostEqual(1000.0, h, 2)
Esempio n. 6
0
    def test_dhToRe(self):
        obj = _polarnav.new()
        obj.lat0 = 60.0 * math.pi / 180.0
        obj.lon0 = 12.0 * math.pi / 180.0
        obj.alt0 = 0.0

        r, e = obj.dhToRe(50000.0, 1000.0)
        self.assertAlmostEqual(50012.88, r, 2)
        self.assertAlmostEqual(0.976411, e * 180.0 / math.pi, 4)
Esempio n. 7
0
def MakeSingleAreaFromSCAN(scan, pcsid, xscale, yscale):
    import numpy
    from xml.etree.ElementTree import Element, SubElement
    import _polarnav

    pn = _polarnav.new()
    pn.lon0, pn.lat0, pn.alt0 = scan.longitude, scan.latitude, scan.height
    maxR = scan.nbins * scan.rscale
    nrays = scan.nrays * 2  # Doubled for greater accuracy

    minx = 10e100
    maxx = -10e100
    miny = 10e100
    maxy = -10e100

    azres = 360.0 / nrays
    #az = 0.5*azres  # Start properly: half an azimuth gate from north
    az = 0.0  # Let's not and say we did ...
    while az < 360.0:
        latr, lonr = pn.daToLl(maxR, az * Proj.dr)
        herec = lonr * Proj.rd, latr * Proj.rd

        thislon, thislat = Proj.c2s([herec], pcsid)[0]

        if thislon < minx: minx = thislon
        if thislon > maxx: maxx = thislon
        if thislat < miny: miny = thislat
        if thislat > maxy: maxy = thislat

        az += azres

    # Expand to nearest pixel and buffer by one just to be sure
    dx = (maxx - minx) / xscale
    dx = (1.0 - (dx - int(dx))) * xscale
    if dx < xscale:
        minx -= xscale + dx
        maxx += xscale
    dy = (maxy - miny) / yscale
    dy = (1.0 - (dy - int(dy))) * yscale
    if dy < yscale:
        miny -= yscale + dy
        maxy += yscale

    xsize = int(round((maxx - minx) / xscale, 0))
    ysize = int(round((maxy - miny) / yscale, 0))

    A = AREA()
    A.xsize, A.ysize, A.xscale, A.yscale = xsize, ysize, xscale, yscale
    A.extent = minx, miny, maxx, maxy
    A.pcs = pcsid

    return A
def MakeSingleAreaFromSCAN(scan, area=AREA):
    import numpy
    import _polarnav

    pn = _polarnav.new()
    pn.lon0, pn.lat0, pn.alt0 = scan.longitude, scan.latitude, scan.height
    maxR = scan.nbins * scan.rscale + scan.rscale # Add extra bin
    nrays = scan.nrays# * 2  # Doubled for greater accuracy

    minx =  10e100
    maxx = -10e100
    miny =  10e100
    maxy = -10e100

    azres = 360.0/nrays
    #az = 0.5*azres  # Start properly: half an azimuth gate from north
    az = 0.0  # Let's not and say we did ...
    while az < 360.0:
        latr, lonr = pn.daToLl(maxR, az*dr)
        herec = lonr*rd, latr*rd

        thislon, thislat = c2s([herec], area.pcs.id)[0]

        if thislon < minx: minx = thislon
        if thislon > maxx: maxx = thislon
        if thislat < miny: miny = thislat
        if thislat > maxy: maxy = thislat

        az+=azres

    # Expand to nearest pixel and buffer by one just to be sure
    dx = (maxx-minx) / area.xscale
    dx = (1.0-(dx-int(dx))) * area.xscale
    if dx < area.xscale:
        minx -= area.xscale + dx
        maxx += area.xscale
    dy = (maxy-miny) / area.yscale
    dy = (1.0-(dy-int(dy))) * area.yscale
    if dy < area.yscale:
        miny -= area.yscale + dy
        maxy += area.yscale

    xsize = int(round((maxx-minx)/area.xscale, 0))
    ysize = int(round((maxy-miny)/area.yscale, 0))

    A = rave_area.AREA()
    A.xsize, A.ysize, A.xscale, A.yscale = xsize, ysize, area.xscale, area.yscale
    A.extent = minx, miny, maxx, maxy
    A.pcs = area.pcs.id

    return A
Esempio n. 9
0
    def testLlToDa_and_daToLl(self):
        obj = _polarnav.new()
        obj.lat0 = 60.0 * math.pi / 180.0
        obj.lon0 = 14.0 * math.pi / 180.0
        obj.alt0 = 100.0

        lat = 61.0 * math.pi / 180.0
        lon = 15.0 * math.pi / 180.0

        d, a = obj.llToDa((lat, lon))

        nlat, nlon = obj.daToLl(d, a)

        self.assertAlmostEqual(lat, nlat, 4)
        self.assertAlmostEqual(lon, nlon, 4)
Esempio n. 10
0
 def test_dndh(self):
     obj = _polarnav.new()
     self.assertAlmostEqual((-3.9e-5) / 1000.0, obj.dndh, 4)
     obj.dndh = 0.2
     self.assertAlmostEqual(0.2, obj.dndh, 4)
Esempio n. 11
0
 def test_alt0(self):
     obj = _polarnav.new()
     self.assertAlmostEqual(0.0, obj.alt0, 4)
     obj.alt0 = 10.2
     self.assertAlmostEqual(10.2, obj.alt0, 4)
Esempio n. 12
0
 def test_lat0(self):
     obj = _polarnav.new()
     self.assertAlmostEqual(0.0, obj.lat0, 4)
     obj.lat0 = 0.2
     self.assertAlmostEqual(0.2, obj.lat0, 4)
Esempio n. 13
0
 def test_equatorradius(self):
     obj = _polarnav.new()
     self.assertAlmostEqual(6378160.0, obj.equatorradius, 4)
     obj.equatorradius = 10.2
     self.assertAlmostEqual(10.2, obj.equatorradius, 4)
Esempio n. 14
0
 def test_poleradius(self):
     obj = _polarnav.new()
     self.assertAlmostEqual(6356780.0, obj.poleradius, 4)
     obj.poleradius = 10.2
     self.assertAlmostEqual(10.2, obj.poleradius, 4)
Esempio n. 15
0
 def test_attribute_visibility(self):
     attrs = ['poleradius', 'equatorradius', 'lon0', 'lat0', 'alt0', 'dndh']
     obj = _polarnav.new()
     alist = dir(obj)
     for a in attrs:
         self.assertEqual(True, a in alist)
Esempio n. 16
0
 def test_daToLl(self):
     obj = _polarnav.new()
     obj.lat0 = 60.0 * math.pi / 180.0
     obj.lon0 = 12.0 * math.pi / 180.0
     obj.alt0 = 0.0
     nlat, nlon = obj.daToLl(50000.0, 0.0)