Пример #1
0
def main():
    print('main')

    indices = ps.from_latlon([-45, 45], [45, 45], 1)
    print('level zero: ', indices)
    latv, lonv, latc, lonc = ps.to_vertices_latlon(indices)
    print('  latv:     ', latv)
    print('  lonv:     ', lonv)
    print('  latc:     ', latc)
    print('  lonc:     ', lonc)

    if True:
        proj = ccrs.PlateCarree()
        transf = ccrs.Geodetic()
        plt.figure()
        ax = plt.axes(projection=proj)
        ax.set_global()
        ax.coastlines()

        gd.plot_indices(ps.from_latlon(np.arange(-89, 89, dtype=np.float),
                                       -2 * np.arange(-89, 89, dtype=np.float),
                                       0),
                        c='g',
                        transform=transf,
                        lw=0.25)
        # gd.plot_indices(ps.from_latlon([0,0,15],[-15,0,15],1),c='g',transform=transf,lw=0.25)
        # gd.plot_indices(ps.from_latlon([0,0,15],[-15,0,15],2),c='r',transform=transf,lw=0.25)
        # gd.plot_indices(ps.from_latlon([-45,45],[45,45],0),c='r',transform=transf,lw=0.25)
        # gd.plot_indices(ps.from_latlon([-45],[45],0),c='r',transform=transf,lw=0.25)

        plt.show()
        return
Пример #2
0
def make_nc_hull(lat0, lon0, resolution0, restrict=None):
    hull0 = ps.to_nonconvex_hull_range_from_latlon(lat0, lon0, resolution0)
    print('make_nc_hull hull size: ', len(hull0))
    if restrict is not None:
        try:
            hull0 = hull0[restrict[0]:restrict[1]]
        except:
            hull0 = hull0[0:1]
    lath0, lonh0, lathc0, lonhc0 = ps.to_vertices_latlon(hull0)
    lons0, lats0, intmat0 = triangulate1(lath0, lonh0)
    triang0 = tri.Triangulation(lons0, lats0, intmat0)
    return lats0, lons0, triang0, hull0
Пример #3
0
def make_hull(lat0,lon0,resolution0):
    hull0 = ps.to_hull_range_from_latlon(lat0,lon0,resolution0)
    print('hull0 len: ',len(hull0),type(hull0))
    lath0,lonh0,lathc0,lonhc0 = ps.to_vertices_latlon(hull0)
    lons0,lats0,intmat0 = ps.triangulate(lath0,lonh0)
    print('lons0  len: ',len(lons0))
    print('intmat len: ',len(intmat0),type(intmat0))
    triang0 = tri.Triangulation(lons0,lats0,intmat0)
    for i in range(len(intmat0)):
        print(i,intmat0[i],lons0[intmat0[i]],lats0[intmat0[i]])
    print('triang ',triang0.triangles.shape)
    # exit()
    return lats0,lons0,triang0,hull0
Пример #4
0
def plot_indices(indices,c='r',transform=None,lw=1):
    latv,lonv,latc,lonc = ps.to_vertices_latlon(indices)
    lons,lats,intmat = triangulate1(latv,lonv)
    triang = tri.Triangulation(lons,lats,intmat)
    plt.triplot(triang,c+'-',transform=transform,lw=lw,markersize=3)
    return
Пример #5
0
def make_hull(lat0, lon0, resolution0):
    hull0 = ps.to_hull_range_from_latlon(lat0, lon0, resolution0)
    lath0, lonh0, lathc0, lonhc0 = ps.to_vertices_latlon(hull0)
    lons0, lats0, intmat0 = ps.triangulate(lath0, lonh0)
    triang0 = tri.Triangulation(lons0, lats0, intmat0)
    return lats0, lons0, triang0, hull0
Пример #6
0
    intersected = np.full([1000], -1, dtype=np.int64)
    # intersected = ps.intersect(hull0,hull1,multiresolution=False)
    intersected = ps.intersect(hull0, hull1, multiresolution=True)
    # intersected = ps.intersect(hull0,hull1,multiresolution=True)
    # print('hull0: ',[hex(i) for i in hull0])
    # print('hull1: ',[hex(i) for i in hull1])
    # ps._intersect_multiresolution(hull0,hull1,intersected)
    # print('intersected: ',len(intersected))
    # print('np.min:      ',np.amin(intersected))
    # print('intersected: ',[hex(i) for i in intersected])
    # The following are for _intersect_multiresolution's results
    # endarg = np.argmax(intersected < 0)
    # intersected = intersected[:endarg]
    # intersected = ps.intersect(hull0,hull1)
    print('intersected: ', len(intersected))
    lati, loni, latci, lonci = ps.to_vertices_latlon(intersected)
    lonsi, latsi, intmati = ps.triangulate(lati, loni)
    triangi = tri.Triangulation(lonsi, latsi, intmati)

# Set up the projection and transformation
proj = ccrs.PlateCarree()
# proj = ccrs.Robinson()
# proj = ccrs.Geodesic()
# proj   = ccrs.Mollweide()
transf = ccrs.Geodetic()
# transf = ccrs.PlateCarree()
plt.figure()
plt.subplot(projection=proj, transform=transf)
ax = plt.axes(projection=proj, transform=transf)
ax.set_global()
ax.coastlines()
Пример #7
0
plt.scatter(test1_lons,test1_lats,s=5,c='r',transform=ccrs.PlateCarree())  

# resolution = 2;
resolution = 4;
# resolution = 7;
# hull = ps.to_hull_range(indices,resolution,100)
hull = ps.to_hull_range_from_latlon(lat,lon,resolution)
print('0 hull len:      ',len(hull))

# print(90)
# lats0 = np.zeros(len(hull)*4,dtype=np.int64)
# lons0 = np.zeros(len(hull)*4,dtype=np.int64)
# lats0,lons0 = ps._to_vertices_latlon(hull)
# print('lats0,lons0: ',len(lats0),len(lons0))
# print(100)
lath,lonh,lathc,lonhc = ps.to_vertices_latlon(hull)
print('lath,lathc: ',len(lath),len(lathc))
# print(110)
lons1,lats1,intmat1 = triangulate1(lath,lonh)

## h0,h1,h2,hc = ps.to_vertices(hull)
## lons1,lats1,intmat1 = triangulate(h0,h1,h2)

print('0 hull len:      ',len(hull))
print('0 hull lats len: ',len(lats1))
jtest=18
j=jtest
print('0 hull lats1:    ',j,lats1[j*3:(j+1)*3])
print('0 hull lons1:    ',j,lons1[j*3:(j+1)*3])
j=0
# print('0 hull lats1:    ',[i for i in lats1[j:j+12]])
Пример #8
0
def plot2(sivs, c1='g', transf=None):
    lath0, lonh0, lathc0, lonhc0 = ps.to_vertices_latlon(sivs)
    lons0, lats0, intmat0 = triangulate1(lath0, lonh0)
    triang0 = tri.Triangulation(lons0, lats0, intmat0)
    ax.triplot(triang0, c1 + '-', transform=transf)
    return
Пример #9
0
# figax = add_coastlines(plt.subplots(subplot_kw={'projection':proj,'transform':transf}))

# resolution = 7
# resolution = 12
resolution = 13
resolution0 = resolution
lat0 = np.array([0, 0, 1, 1], dtype=np.double)
lon0 = np.array([0, 1, 1, 0], dtype=np.double)
lats0, lons0, triang0, hull0 = make_hull(lat0, lon0, resolution0)
print('hull0: ', len(hull0))

idx = ps.from_latlon(np.array([1.25], dtype=np.double),
                     np.array([1.25], dtype=np.double), 10)
nbrs = ps.to_neighbors(idx)

latn, lonn, latcn, loncn = ps.to_vertices_latlon(idx)
lons1, lats1, intmat1 = triangulate1(latn, lonn)
triang1 = tri.Triangulation(lons1, lats1, intmat1)

lata, lona, latca, lonca = ps.to_vertices_latlon(nbrs)
lons2, lats2, intmat2 = triangulate1(lata, lona)
triang2 = tri.Triangulation(lons2, lats2, intmat2)

# idx1  = ps.from_latlon(np.array([1.5],dtype=np.double),np.array([0.5],dtype=np.double),10)
cover = ps.to_circular_cover(1.5, 0.5, 0.25, 13)
latco, lonco, latcco, loncco = ps.to_vertices_latlon(cover)
lons3, lats3, intmat3 = triangulate1(latco, lonco)
triang3 = tri.Triangulation(lons3, lats3, intmat3)

# Set up the projection and transformation
# proj = ccrs.PlateCarree()