示例#1
0
def points_on_sphere(dx,xmin=-180.,xmax=180.,ymin=-89.999,ymax=89.999,c_centr=None,\
radius=None):
    """
    Calculate a more or less equally spaced grid on spherical Earth's surface.
    :param dx: spacing in latitudinal and longitudinal direction in meter
    :type c_centr: Tuple
    :param c_centr: Specify a central location
    :type radius: float
    :param radius: Radius around central location in m; no sources beyond this will be included
    :returns: np.array(latitude, longitude) of grid points, where -180<=lon<180     and -90 <= lat < 90
    """

    if xmax <= xmin or ymax <= ymin:
        msg = 'Lower bounds must be lower than upper bounds.'
        raise ValueError(msg)

    gridx = []
    gridy = []

    lat = ymin
    if ymin == -90.:
        ymin = -89.999
        warn("Resetting lat_min to -89.999 degree")

    while lat <= ymax:
        d_lat = dx / len_deg_lat(lat)
        d_lon = dx / len_deg_lon(lat)

        lon = xmin + np.random.rand(1)[0] * d_lon

        while lon <= xmax:

            gridx.append(lon)
            gridy.append(lat)

            if c_centr and radius:
                if gps2dist_azimuth(lat, lon, c_centr[0],
                                    c_centr[1])[0] > radius:
                    print(
                        lat, lon,
                        gps2dist_azimuth(lat, lon, c_centr[0], c_centr[1])[0])
                    if abs(lat) != 90.:
                        d_lon = dx / len_deg_lon(lat)
                        lon += d_lon
                        continue
                    else:
                        break

            if abs(lat) == 90:
                # length of a degree longitude will be 0.
                break
            else:
                d_lon = dx / len_deg_lon(lat)
                lon += d_lon
        lat += d_lat  # do not start at pole or zero division will raise...

    # return values sorted by longitude, basemap likes it.
    grid = list(zip(*sorted(zip(gridx, gridy), key=lambda it: it[0])))
    return list((gridx, gridy))  #grid
示例#2
0
def points_on_sphere(dx,xmin=-180.,xmax=180.,ymin=-89.999,ymax=89.999,c_centr=None,\
radius=None):
    """
    Calculate a more or less equally spaced grid on spherical Earth's surface.
    :param dx: spacing in latitudinal and longitudinal direction in meter
    :type c_centr: Tuple
    :param c_centr: Specify a central location
    :type radius: float
    :param radius: Radius around central location in m; no sources beyond this will be included
    :returns: np.array(latitude, longitude) of grid points, where -180<=lon<180     and -90 <= lat < 90
    """
    
    if xmax <= xmin or ymax <= ymin:
        msg = 'Lower bounds must be lower than upper bounds.'
        raise ValueError(msg)

    
    gridx = []
    gridy = []
    
    lat = ymin
    if ymin == -90.:
        ymin = -89.999
        warn("Resetting lat_min to -89.999 degree")
    
    while lat <= ymax:
        d_lat = dx / len_deg_lat(lat)
        d_lon = dx / len_deg_lon(lat)
            
        lon = xmin + np.random.rand(1)[0] * d_lon

        while lon <= xmax:
                    
            gridx.append(lon)
            gridy.append(lat)

            if c_centr and radius:
                if gps2dist_azimuth(lat,lon,c_centr[0],c_centr[1])[0] > radius:
                    print(lat,lon,gps2dist_azimuth(lat,lon,c_centr[0],c_centr[1])[0])
                    if abs(lat) != 90.:
                        d_lon = dx / len_deg_lon(lat)
                        lon += d_lon
                        continue
                    else:
                        break

            
            if abs(lat) == 90:
                # length of a degree longitude will be 0.
                break
            else:
                d_lon = dx / len_deg_lon(lat)
                lon += d_lon
        lat += d_lat # do not start at pole or zero division will raise...
        
            
    # return values sorted by longitude, basemap likes it.
    grid = list(zip(*sorted(zip(gridx, gridy), key=lambda it: it[0])))
    return list((gridx,gridy))#grid
示例#3
0
def test_geostuff():

    grid = np.zeros((2, 5))
    location = [45.0, 45.0]

    dist = geographical_distances(grid, location)
    assert (type(dist) == np.ndarray)
    assert (pytest.approx(dist[0]) == 6662472.7182103)
    assert is_land(location, location)[0]
    assert (floor(geograph_to_geocent(location[0])) == 44)
    assert (pytest.approx(len_deg_lat(location[0])) == 111131.779)
    assert (pytest.approx(len_deg_lon(location[0])) == 78582.91976)