Exemplo n.º 1
0
    def testGridDistances(self):
        for i in range(100):
            gsize = random.uniform(0., 1.) * 2. * 10.**random.uniform(4., 7.)
            north_grid, east_grid = num.meshgrid(
                num.linspace(-gsize / 2., gsize / 2., 11),
                num.linspace(-gsize / 2., gsize / 2., 11))

            north_grid = north_grid.flatten()
            east_grid = east_grid.flatten()

            lon = random.uniform(-180., 180.)
            lat = random.uniform(-90., 90.)

            lat_grid, lon_grid = orthodrome.ne_to_latlon(
                lat, lon, north_grid, east_grid)
            lat_grid_alt, lon_grid_alt = \
                orthodrome.ne_to_latlon_alternative_method(
                    lat, lon, north_grid, east_grid)

            for la, lo, no, ea in zip(lat_grid, lon_grid, north_grid,
                                      east_grid):
                a = orthodrome.Loc(lat=la, lon=lo)
                b = orthodrome.Loc(lat=lat, lon=lon)

                cd = orthodrome.cosdelta(a, b)
                assert cd <= 1.0
                d = num.arccos(cd) * earthradius
                d2 = math.sqrt(no**2 + ea**2)
                assert abs(d - d2) < 1.0e-3 or d2 < 10.
Exemplo n.º 2
0
 def testGridDistances(self):
     for i in range(100):
         w,h = 20,15
     
         km = 1000.
         gsize = random.uniform(0.,1.)*2.*10.**random.uniform(4.,7.)
         north_grid, east_grid = num.meshgrid(num.linspace(-gsize/2.,gsize/2.,11) ,
                                              num.linspace(-gsize/2.,gsize/2.,11) )
         
         north_grid = north_grid.flatten()
         east_grid = east_grid.flatten()
         
         lat_delta = gsize/config.earthradius*r2d*2.
         lon = random.uniform(-180.,180.)
         lat = random.uniform(-90.,90.)
                 
         lat_grid, lon_grid = orthodrome.ne_to_latlon(lat, lon, north_grid, east_grid)
         lat_grid_alt, lon_grid_alt = orthodrome.ne_to_latlon_alternative_method(lat, lon, north_grid, east_grid)
         
         for la, lo, no, ea in zip(lat_grid, lon_grid, north_grid, east_grid):
             a = Loc()
             a.lat = la 
             a.lon = lo
             b = Loc()
             b.lat = lat
             b.lon = lon
             
             cd = orthodrome.cosdelta(a,b)
             assert cd <= 1.0
             d = num.arccos(cd)*config.earthradius
             d2 = math.sqrt(no**2+ea**2)
             assert not (abs(d-d2) > 1.0e-3 and d2 > 1.)
Exemplo n.º 3
0
 def testGridDistances(self):
     for i in range(100):
         w,h = 20,15
     
         km = 1000.
         gsize = random.uniform(0.,1.)*2.*10.**random.uniform(4.,7.)
         north_grid, east_grid = num.meshgrid(num.linspace(-gsize/2.,gsize/2.,11) ,
                                              num.linspace(-gsize/2.,gsize/2.,11) )
         
         north_grid = north_grid.flatten()
         east_grid = east_grid.flatten()
         
         lat_delta = gsize/config.earthradius*r2d*2.
         lon = random.uniform(-180.,180.)
         lat = random.uniform(-90.,90.)
                 
         lat_grid, lon_grid = orthodrome.ne_to_latlon(lat, lon, north_grid, east_grid)
         lat_grid_alt, lon_grid_alt = orthodrome.ne_to_latlon_alternative_method(lat, lon, north_grid, east_grid)
         
         for la, lo, no, ea in zip(lat_grid, lon_grid, north_grid, east_grid):
             a = Loc()
             a.lat = la 
             a.lon = lo
             b = Loc()
             b.lat = lat
             b.lon = lon
             
             d = num.arccos(orthodrome.cosdelta(a,b))*config.earthradius
             d2 = math.sqrt(no**2+ea**2)
             
             if abs(d-d2) > 1.0e-3 and d2 > 1.:
                 print 'x',a.lat, a.lon, b.lat,b.lon
                 print 'y',d, d2, d-d2
Exemplo n.º 4
0
    def testGridDistances(self):
        for i in range(100):
            w, h = 20, 15

            km = 1000.0
            gsize = random.uniform(0.0, 1.0) * 2.0 * 10.0 ** random.uniform(4.0, 7.0)
            north_grid, east_grid = num.meshgrid(
                num.linspace(-gsize / 2.0, gsize / 2.0, 11), num.linspace(-gsize / 2.0, gsize / 2.0, 11)
            )

            north_grid = north_grid.flatten()
            east_grid = east_grid.flatten()

            lat_delta = gsize / config.earthradius * r2d * 2.0
            lon = random.uniform(-180.0, 180.0)
            lat = random.uniform(-90.0, 90.0)

            lat_grid, lon_grid = orthodrome.ne_to_latlon(lat, lon, north_grid, east_grid)
            lat_grid_alt, lon_grid_alt = orthodrome.ne_to_latlon_alternative_method(lat, lon, north_grid, east_grid)

            for la, lo, no, ea in zip(lat_grid, lon_grid, north_grid, east_grid):
                a = Loc()
                a.lat = la
                a.lon = lo
                b = Loc()
                b.lat = lat
                b.lon = lon

                d = num.arccos(orthodrome.cosdelta(a, b)) * config.earthradius
                d2 = math.sqrt(no ** 2 + ea ** 2)

                if abs(d - d2) > 1.0e-3 and d2 > 1.0:
                    print "x", a.lat, a.lon, b.lat, b.lon
                    print "y", d, d2, d - d2
Exemplo n.º 5
0
    def export_geojson(self, filename):
        import geojson
        self._log.debug('Exporting GeoJSON Quadtree to %s', filename)
        features = []

        for lf in self.leaves:
            llN, llE, urN, urE = (lf.llN, lf.llE, lf.urN, lf.urE)

            if self.frame.isDegree():
                llN += self.frame.llLat
                llE += self.frame.llLon
                urN += self.frame.llLat
                urE += self.frame.llLon

            coords = [(llE, llN), (urE, llN), (urE, urN), (llE, urN),
                      (llE, llN)]

            if self.frame.isMeter():
                coords_deg = []
                for c in coords:
                    c_deg = od.ne_to_latlon_alternative_method(
                        self.frame.llLon, self.frame.llLat, *c)
                    coords_deg.append(c_deg)

                coords = coords_deg

            feature = geojson.Feature(
                geometry=geojson.Polygon(coordinates=[coords]),
                id=lf.id,
                properties={
                    'mean': lf.mean,
                    'median': lf.median,
                    'std': lf.std,
                    'var': lf.var
                })
            features.append(feature)

        collection = geojson.FeatureCollection(features)
        with open(filename, 'w') as f:
            geojson.dump(collection, f)
Exemplo n.º 6
0
def plot_erroneous_ne_to_latlon():
    import gmtpy
    import random
    import subprocess
    import time

    while True:
        w, h = 20, 15

        gsize = random.uniform(0., 1.) * 4. * 10.**random.uniform(4., 7.)
        north_grid, east_grid = num.meshgrid(
            num.linspace(-gsize / 2., gsize / 2., 11),
            num.linspace(-gsize / 2., gsize / 2., 11))

        north_grid = north_grid.flatten()
        east_grid = east_grid.flatten()

        lat_delta = gsize / earthradius * r2d * 2.
        lon = random.uniform(-180., 180.)
        lat = random.uniform(-90., 90.)

        print(gsize / 1000.)

        lat_grid, lon_grid = orthodrome.ne_to_latlon(lat, lon, north_grid,
                                                     east_grid)
        lat_grid_alt, lon_grid_alt = \
            orthodrome.ne_to_latlon_alternative_method(
                lat, lon, north_grid, east_grid)

        maxerrlat = num.max(num.abs(lat_grid - lat_grid_alt))
        maxerrlon = num.max(num.abs(lon_grid - lon_grid_alt))
        eps = 1.0e-8
        if maxerrlon > eps or maxerrlat > eps:
            print(lat, lon, maxerrlat, maxerrlon)

            gmt = gmtpy.GMT(
                config={
                    'PLOT_DEGREE_FORMAT': 'ddd.xxxF',
                    'PAPER_MEDIA': 'Custom_%ix%i' %
                    (w * gmtpy.cm, h * gmtpy.cm),
                    'GRID_PEN_PRIMARY': 'thinnest/0/50/0'
                })

            south = max(-85., lat - 0.5 * lat_delta)
            north = min(85., lat + 0.5 * lat_delta)

            lon_delta = lat_delta / math.cos(lat * d2r)

            delta = lat_delta / 360. * earthradius * 2. * math.pi
            scale_km = gmtpy.nice_value(delta / 10.) / 1000.

            west = lon - 0.5 * lon_delta
            east = lon + 0.5 * lon_delta

            x, y = (west, east), (south, north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio,
                                     mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget['J'] = (
                '-JE%g/%g/%g' % (lon, lat, min(lat_delta/2., 180.)))\
                + '/%(width)gp'
            aspect = gmtpy.aspect_for_projection(*(widget.J() + scaler.R()))
            widget.set_aspect(aspect)

            gmt.psbasemap(B='5g5',
                          L=('x%gp/%gp/%g/%g/%gk' %
                             (widget.width() / 2., widget.height() / 7., lon,
                              lat, scale_km)),
                          *(widget.JXY() + scaler.R()))

            gmt.psxy(in_columns=(lon_grid, lat_grid),
                     S='x10p',
                     W='1p/200/0/0',
                     *(widget.JXY() + scaler.R()))
            gmt.psxy(in_columns=(lon_grid_alt, lat_grid_alt),
                     S='c10p',
                     W='1p/0/0/200',
                     *(widget.JXY() + scaler.R()))

            gmt.save('orthodrome.pdf')
            subprocess.call(['xpdf', '-remote', 'ortho', '-reload'])
            time.sleep(2)
        else:
            print('ok', gsize, lat, lon)
def plot_erroneous_ne_to_latlon():
    import gmtpy
    import random
    import subprocess
    import time

    while True:
        w, h = 20, 15

        gsize = random.uniform(0., 1.)*4.*10.**random.uniform(4., 7.)
        north_grid, east_grid = num.meshgrid(
            num.linspace(-gsize/2., gsize/2., 11),
            num.linspace(-gsize/2., gsize/2., 11))

        north_grid = north_grid.flatten()
        east_grid = east_grid.flatten()

        lat_delta = gsize/earthradius*r2d*2.
        lon = random.uniform(-180., 180.)
        lat = random.uniform(-90., 90.)

        print(gsize/1000.)

        lat_grid, lon_grid = orthodrome.ne_to_latlon(
            lat, lon, north_grid, east_grid)
        lat_grid_alt, lon_grid_alt = \
            orthodrome.ne_to_latlon_alternative_method(
                lat, lon, north_grid, east_grid)

        maxerrlat = num.max(num.abs(lat_grid-lat_grid_alt))
        maxerrlon = num.max(num.abs(lon_grid-lon_grid_alt))
        eps = 1.0e-8
        if maxerrlon > eps or maxerrlat > eps:
            print(lat, lon, maxerrlat, maxerrlon)

            gmt = gmtpy.GMT(
                config={
                    'PLOT_DEGREE_FORMAT': 'ddd.xxxF',
                    'PAPER_MEDIA': 'Custom_%ix%i' % (w*gmtpy.cm, h*gmtpy.cm),
                    'GRID_PEN_PRIMARY': 'thinnest/0/50/0'})

            south = max(-85., lat - 0.5*lat_delta)
            north = min(85., lat + 0.5*lat_delta)

            lon_delta = lat_delta/math.cos(lat*d2r)

            delta = lat_delta/360.*earthradius*2.*math.pi
            scale_km = gmtpy.nice_value(delta/10.)/1000.

            west = lon - 0.5*lon_delta
            east = lon + 0.5*lon_delta

            x, y = (west, east), (south, north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5*gmtpy.cm
            layout.set_fixed_margins(
                mw, mw, mw/gmtpy.golden_ratio, mw/gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget['J'] = (
                '-JE%g/%g/%g' % (lon, lat, min(lat_delta/2., 180.)))\
                + '/%(width)gp'
            aspect = gmtpy.aspect_for_projection(*(widget.J() + scaler.R()))
            widget.set_aspect(aspect)

            gmt.psbasemap(
                B='5g5',
                L=('x%gp/%gp/%g/%g/%gk' % (
                    widget.width()/2., widget.height()/7.,
                    lon, lat, scale_km)),
                *(widget.JXY()+scaler.R()))

            gmt.psxy(
                in_columns=(lon_grid, lat_grid),
                S='x10p', W='1p/200/0/0', *(widget.JXY()+scaler.R()))
            gmt.psxy(
                in_columns=(lon_grid_alt, lat_grid_alt),
                S='c10p', W='1p/0/0/200', *(widget.JXY()+scaler.R()))

            gmt.save('orthodrome.pdf')
            subprocess.call(['xpdf', '-remote', 'ortho', '-reload'])
            time.sleep(2)
        else:
            print('ok', gsize, lat, lon)