コード例 #1
0
 def test_intersect_repetition(self):
     a = [
         4114022797720682508, 4505997421712506892, 4505997834029367308,
         4505997868389105676, 4505998418144919564
     ]
     b = [4528191461944221900, 4505997456072245260]
     for i in range(1, 10000):
         pystare.intersect(a, b)
     self.assertTrue(True)
コード例 #2
0
 def test_intersect_multires3(self):
     indices1 = pystare.from_latlon(lat, lon, 12)
     indices2 = numpy.array([0x100000000000000c], dtype=numpy.int64)
     intersected = pystare.intersect(indices1,
                                     indices2,
                                     multiresolution=True)
     numpy.testing.assert_array_equal(intersected,
                                      numpy.array([], dtype=numpy.int64))
コード例 #3
0
 def test_intersect_multires2(self):
     indices1 = pystare.from_latlon(lat, lon, 12)
     indices2 = numpy.array([indices1[1]], dtype=numpy.int64)
     intersected = pystare.intersect(indices1,
                                     indices2,
                                     multiresolution=True)
     expected = numpy.array([4161865159985332236])
     numpy.testing.assert_array_equal(intersected, expected)
コード例 #4
0
ファイル: staredataframe.py プロジェクト: hdfeos/STAREPandas
 def stare_intersection(self, other):
     """Returns a ``STARESeries`` of the spatial intersection of self with `other`.
     Parameters
     ----------
     other: Collection of STARE indices.
         The STARE index collection representing the object to find the
         intersection with.
     """        
     data = []
     for srange in self._stare_column_name:
         data.append(pystare.intersect(srange, other))
     return pandas.Series(data, index=self.index)
コード例 #5
0
ファイル: test_srange.py プロジェクト: SpatioTemporal/pystare
 def test_multires_intersect2(self):
     sids = numpy.array([
         0x300a30000000000a, 0x300a30800000000a, 0x300a31000000000a,
         0x300a31800000000a
     ])
     parent = pystare.expand_intervals(sids, resolution=9)
     indices = pystare.intersect(parent, sids)
     ivs = indices
     with self.subTest():
         self.assertEqual(ivs.size, 1)
     with self.subTest():
         self.assertEqual(hex(ivs[0]), '0x300a300000000009')
コード例 #6
0
    def test_intersect_single_res(self):
        resolution = 6
        resolution0 = resolution
        lat0 = numpy.array([10, 5, 60, 70], dtype=numpy.double)
        lon0 = numpy.array([-30, -20, 60, 10], dtype=numpy.double)
        hull0 = pystare.to_hull_range_from_latlon(lat0, lon0, resolution0)

        resolution1 = 6
        lat1 = numpy.array([10, 20, 30, 20], dtype=numpy.double)
        lon1 = numpy.array([-60, 60, 60, -60], dtype=numpy.double)
        hull1 = pystare.to_hull_range_from_latlon(lat1, lon1, resolution1)

        intersectedFalse = pystare.intersect(hull0,
                                             hull1,
                                             multiresolution=False)
        intersectedTrue = pystare.intersect(hull0, hull1, multiresolution=True)

        # See examples/test_intersect_single_res.py
        self.assertEqual(328, len(intersectedFalse))
        # self.assertEqual(172, len(intersectedTrue))
        # self.assertEqual(82, len(intersectedTrue))
        self.assertEqual(79, len(intersectedTrue))
コード例 #7
0
ファイル: test_srange.py プロジェクト: SpatioTemporal/pystare
 def test_multires_intersect1(self):
     # Earth are the 8 initial trixels
     earth = numpy.array([
         0x0000000000000000, 0x0800000000000000, 0x1000000000000000,
         0x1800000000000000, 0x2000000000000000, 0x2800000000000000,
         0x3000000000000000, 0x3800000000000000
     ])
     sids = numpy.array([
         0x300a30000000000a, 0x300a30800000000a, 0x300a31000000000a,
         0x300a31800000000a
     ])
     indices = pystare.intersect(earth, sids, multiresolution=True)
     ivs = indices
     with self.subTest():
         self.assertEqual(ivs.size, 1)
     with self.subTest():
         self.assertEqual(hex(ivs[0]), '0x300a300000000009')
コード例 #8
0
 def test_intersect_multires(self):
     indices = pystare.from_latlon(lat, lon, 12)
     intersected = pystare.intersect(indices, indices, multiresolution=True)
     expected = numpy.array(
         [3643626709468577804, 4151504977312874508, 4161865159985332236])
     numpy.testing.assert_array_equal(intersected, expected)
コード例 #9
0
def test_intersect_single_res(proj, transf):
    resolution = 6
    resolution0 = resolution
    lat0 = numpy.array([10, 5, 60, 70], dtype=numpy.double)
    lon0 = numpy.array([-30, -20, 60, 10], dtype=numpy.double)
    hull0 = pystare.to_hull_range_from_latlon(lat0, lon0, resolution0)

    lons0, lats0, intmat0 = pystare.triangulate_indices(hull0)
    triang0 = tri.Triangulation(lons0, lats0, intmat0)

    resolution1 = 6
    lat1 = numpy.array([10, 20, 30, 20], dtype=numpy.double)
    lon1 = numpy.array([-60, 60, 60, -60], dtype=numpy.double)
    hull1 = pystare.to_hull_range_from_latlon(lat1, lon1, resolution1)

    lons1, lats1, intmat1 = pystare.triangulate_indices(hull1)
    triang1 = tri.Triangulation(lons1, lats1, intmat1)

    #+ fig, axs = plt.subplots(3,subplot_kw={'projection':proj,'transform':transf})
    fig, axs = plt.subplots(4,
                            subplot_kw={
                                'projection': proj,
                                'transform': transf
                            })
    # plt.figure()
    # plt.subplot(projection=proj,transform=transf)
    ax = axs[0]
    # ax.set_global()
    ax.coastlines()

    plot1(None,
          None,
          lons0,
          lats0,
          triang0,
          c0='r',
          c1='b',
          transf=transf,
          ax=ax)
    plot1(None,
          None,
          lons1,
          lats1,
          triang1,
          c0='c',
          c1='r',
          transf=transf,
          ax=ax)
    # plt.show()

    intersectedFalse = pystare.intersect(hull0, hull1, multiresolution=False)
    # print('intersectedFalse: ',intersectedFalse)

    intersectedTrue = pystare.intersect(hull0, hull1, multiresolution=True)

    # plt.figure()
    # plt.subplot(projection=proj,transform=transf)
    ax = axs[1]
    # ax.set_global()
    ax.coastlines()

    lonsF, latsF, intmatF = pystare.triangulate_indices(intersectedFalse)
    triangF = tri.Triangulation(lonsF, latsF, intmatF)
    plot1(None,
          None,
          lonsF,
          latsF,
          triangF,
          c0='r',
          c1='b',
          transf=transf,
          ax=ax)
    # plt.show()

    # plt.figure()
    # plt.subplot(projection=proj,transform=transf)
    ax = axs[2]
    # ax.set_global()
    ax.coastlines()

    lonsT, latsT, intmatT = pystare.triangulate_indices(intersectedTrue)
    triangT = tri.Triangulation(lonsT, latsT, intmatT)
    plot1(None,
          None,
          lonsT,
          latsT,
          triangT,
          c0='r',
          c1='b',
          transf=transf,
          ax=ax)
    # plt.show()

    ## ok ## print('   len(False),len(True),delta: ',len(intersectedFalse),len(intersectedTrue),len(intersectedTrue)-len(intersectedFalse))
    ## ok ## print('un len(False),len(True),delta: ',len(numpy.unique(intersectedFalse)),len(numpy.unique(intersectedTrue)),len(numpy.unique(intersectedTrue))-len(numpy.unique(intersectedFalse)))
    ## ok ## print('compressed==True, first total, then w/o double counting: ',(7*16)+(17*4),(7*16)+(17*4)-(7+17))
    # print('count 0:    ',sum([1,34,34,4*6,24,22,9]))

    if True:
        r0 = pystare.srange()
        r0.add_intervals(hull0)

        r1 = pystare.srange()
        r1.add_intervals(hull1)

        r01 = pystare.srange()
        r01.add_intersect(r0, r1, False)
        n01 = r01.get_size_as_values()

        # self.assertEqual(328, n01)
        intersected = numpy.zeros([n01], dtype=numpy.int64)
        r01.copy_values(intersected)
        # See examples/test_intersect_single_res.py
        # self.assertEqual(328, len(intersected))

        r01.purge()
        n01 = r01.get_size_as_values()
        # self.assertEqual(0, n01)

        r01.reset()
        r01.add_intersect(r0, r1, True)
        # n01 = r01.get_size_as_values()
        # n01 = r01.get_size_as_values_multi_resolution(False)
        n01 = r01.get_size_as_values()
        #? self.assertEqual(172, n01)
        # self.assertEqual(82, n01)
        print('r01 n01: ', n01)

        intersected = numpy.zeros([n01], dtype=numpy.int64)
        r01.copy_values(intersected)

        ###??? Would intervals be different?

        lonsRT, latsRT, intmatRT = pystare.triangulate_indices(intersected)
        triangRT = tri.Triangulation(lonsRT, latsRT, intmatRT)

        # fig, axs = plt.subplots(3,subplot_kw={'projection':proj,'transform':transf})

        # plt.figure()
        # plt.subplot(projection=proj,transform=transf)
        ax = axs[3]
        # ax.set_global()
        ax.coastlines()
        # plot1(None,None,lonsRT,latsRT,triangRT,c0='r',c1='b',transf=transf,ax=ax)

        lonsRT_, latsRT_, intmatRT_ = pystare.triangulate_indices(
            intersected[51:55])
        triangRT_ = tri.Triangulation(lonsRT_, latsRT_, intmatRT_)

        # k = 51
        # for j in intersected[51:55]:
        #     print(k,' siv: 0x%016x'%intersected[k])
        #     k += 1

        plot1(None,
              None,
              lonsRT_,
              latsRT_,
              triangRT_,
              c0='g',
              c1='g',
              transf=transf,
              ax=ax)

        print('len(intersected): ', len(intersected))

    plt.show()
コード例 #10
0
resolution0 = resolution
lat0 = np.array([10, 5, 60, 70], dtype=np.double)
lon0 = np.array([-30, -20, 60, 10], dtype=np.double)
lats0, lons0, triang0, hull0 = make_hull(lat0, lon0, resolution0)
print('hull0: ', len(hull0))

resolution1 = resolution
lat1 = np.array([10, 20, 30, 20], dtype=np.double)
lon1 = np.array([-60, 60, 60, -60], dtype=np.double)
lats1, lons1, triang1, hull1 = make_hull(lat1, lon1, resolution1)
print('hull1: ', len(hull1))

if True:
    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)