Пример #1
0
 def test_create_index(self):
     
     GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
     
     track = Track()
     p1 = Obs(ENUCoords(550, 320), GPSTime.readTimestamp('2020-01-01 10:00:00'))
     track.addObs(p1)
     p2 = Obs(ENUCoords(610, 325), GPSTime.readTimestamp('2020-01-01 10:08:00'))
     track.addObs(p2)
     p3 = Obs(ENUCoords(610, 330), GPSTime.readTimestamp('2020-01-01 10:17:00'))
     track.addObs(p3)
     p4 = Obs(ENUCoords(650, 330), GPSTime.readTimestamp('2020-01-01 10:21:00'))
     track.addObs(p4)
     p5 = Obs(ENUCoords(675, 340), GPSTime.readTimestamp('2020-01-01 10:25:00'))
     track.addObs(p5)
     #track.plot()
     #track.plotAsMarkers()
     
     TRACES = []
     TRACES.append(track)
     collection = TrackCollection(TRACES)
     
     res = (25, 4)
     index = SpatialIndex(collection, res, 0.05, True)
     index.plot()
     
     
     # =====================================================================
     self.assertEqual(index.request(0, 0), [0])
     self.assertEqual(index.request(1, 0), [0])
     self.assertEqual(index.request(0, 1), [])
     self.assertEqual(index.request(1, 1), [0])
     self.assertEqual(index.request(2, 0), [])
     self.assertEqual(index.request(2, 1), [0])
Пример #2
0
 def test_write_csv_2AF_desordre(self):
     
     GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
     track = Track()
     p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
     track.addObs(p1)
     p2 = Obs(ENUCoords(0, 1), GPSTime.readTimestamp('2020-01-01 10:00:01'))
     track.addObs(p2)
     p3 = Obs(ENUCoords(1, 1), GPSTime.readTimestamp('2020-01-01 10:00:02'))
     track.addObs(p3)
     p4 = Obs(ENUCoords(1, 2), GPSTime.readTimestamp('2020-01-01 10:00:03'))
     track.addObs(p4)
     p5 = Obs(ENUCoords(2, 2), GPSTime.readTimestamp('2020-01-01 10:00:04'))
     track.addObs(p5)
     
     track.addAnalyticalFeature(Analytics.speed)
     track.compute_abscurv()
     
     csvpath = os.path.join(self.resource_path, 'data/test/test_write_csv_2AF_desordre.wkt')
     af_names = ['speed', 'abs_curv']
     FileWriter.writeToFile(track, csvpath, id_E=3, id_N=2, id_U=0, id_T=1, h=1, 
                            separator=";", af_names=af_names)
     contents = open(csvpath).read()
     
     txt  = "#srid: ENU\n"
     txt += "#U;time;N;E;speed;abs_curv\n"
     txt += "0.000;01/01/2020 10:00:00;0.000;0.000;1.0;0\n"
     txt += "0.000;01/01/2020 10:00:01;1.000;0.000;0.7071067811865476;1.0\n"
     txt += "0.000;01/01/2020 10:00:02;1.000;1.000;0.7071067811865476;2.0\n"
     txt += "0.000;01/01/2020 10:00:03;2.000;1.000;0.7071067811865476;3.0\n"
     txt += "0.000;01/01/2020 10:00:04;2.000;2.000;1.0;4.0\n"
     self.assertEqual(contents.strip(), txt.strip())
Пример #3
0
 def test_write_csv_path(self):
     
     GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
     track = Track()
     p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
     track.addObs(p1)
     p2 = Obs(ENUCoords(0, 1), GPSTime.readTimestamp('2020-01-01 10:00:01'))
     track.addObs(p2)
     p3 = Obs(ENUCoords(1, 1), GPSTime.readTimestamp('2020-01-01 10:00:02'))
     track.addObs(p3)
     p4 = Obs(ENUCoords(1, 2), GPSTime.readTimestamp('2020-01-01 10:00:03'))
     track.addObs(p4)
     p5 = Obs(ENUCoords(2, 2), GPSTime.readTimestamp('2020-01-01 10:00:04'))
     track.addObs(p5)
     
     csvpath = os.path.join(self.resource_path, 'data/test/test_write_csv_path.wkt')
     FileWriter.writeToFile(track, csvpath)
     contents = open(csvpath).read()
     
     txt  = "0.000,0.000,0.000,01/01/2020 10:00:00\n"
     txt += "0.000,1.000,0.000,01/01/2020 10:00:01\n"
     txt += "1.000,1.000,0.000,01/01/2020 10:00:02\n"
     txt += "1.000,2.000,0.000,01/01/2020 10:00:03\n"
     txt += "2.000,2.000,0.000,01/01/2020 10:00:04\n"
     self.assertEqual(contents.strip(), txt.strip())
Пример #4
0
	def test_visvalingam(self):
		GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
		chemin = './data/trace1.dat'
		track = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
		track.simplify(5, MODE_SIMPLIFY_VISVALINGAM)
		
		self.assertTrue((1.289 - 1.28) < 0.01)
Пример #5
0
    def test_generate(self):
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        #track = core_Track.Track.generate(TestOperateurMethods.x2, TestOperateurMethods.y2)
        track = synth.generate(TestOperateurMethods.x2,
                               TestOperateurMethods.y2)

        track.createAnalyticalFeature("a")
        track.operate(Operator.RANDOM, "a", prob, "randx")
        track.operate(Operator.RANDOM, "a", prob, "randy")

        track.operate(Operator.INTEGRATOR, "randx", "randx")
        track.operate(Operator.INTEGRATOR, "randy", "randy")

        track.operate(Operator.SCALAR_MULTIPLIER, "randx", 0.5, "noisex")
        track.operate(Operator.SCALAR_MULTIPLIER, "randx", 0.5, "noisey")

        track.operate(Operator.ADDER, "x", "noisex", "x_noised")
        track.operate(Operator.ADDER, "y", "noisey", "y_noised")

        kernel = GaussianKernel(31)

        track.operate(Operator.FILTER, "x_noised", kernel, "x_filtered")
        track.operate(Operator.FILTER, "y_noised", kernel, "y_filtered")

        plt.plot(track.getAnalyticalFeature("x"),
                 track.getAnalyticalFeature("y"), 'k--')
        plt.plot(track.getAnalyticalFeature("x_noised"),
                 track.getAnalyticalFeature("y_noised"), 'b-')
        plt.plot(track.getAnalyticalFeature("x_filtered"),
                 track.getAnalyticalFeature("y_filtered"), 'r-')

        plt.show()
Пример #6
0
    def test_random(self):
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        #track = core_Track.Track.generate(TestOperateurMethods.x, TestOperateurMethods.y)
        track = synth.generate(x, y)

        track.createAnalyticalFeature("a")

        track.operate(Operator.RANDOM, ("a", "a"), prob,
                      ("x_noised", "y_noised"))
        track.operate(Operator.INTEGRATOR, ("x_noised", "y_noised"))
        track.operate(Operator.SCALAR_MULTIPLIER, ("x_noised", "y_noised"),
                      0.02)
        track.operate(Operator.ADDER, ("x_noised", "y_noised"), ("x", "y"))

        kernel = GaussianKernel(21)
        kernel.setFilterBoundary(True)

        track.operate(Operator.FILTER, ("x_noised", "y_noised"), kernel,
                      ("x_filtered", "y_filtered"))

        plt.plot(track.getX(), track.getY(), 'k--')
        plt.plot(track.getAnalyticalFeature("x_noised"),
                 track.getAnalyticalFeature("y_noised"), 'b-')
        plt.plot(track.getAnalyticalFeature("x_filtered"),
                 track.getAnalyticalFeature("y_filtered"), 'r-')
        plt.show()
Пример #7
0
    def test_tableau_af_rmse_2(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace0.gps')
        track = FileReader.readFromFile(chemin, 2, 3, -1, 1, separator=",")

        track.estimate_speed()

        track.operate(Operator.DIFFERENTIATOR, "x", "dx")
        track.operate(Operator.DIFFERENTIATOR, "y", "dy")
        track.operate(Operator.SQUARE, "dx", "dx2")
        track.operate(Operator.SQUARE, "dy", "dy2")
        track.operate(Operator.ADDER, "dx2", "dy2", "dx2+dy2")
        track.operate(Operator.SQRT, "dx2+dy2", "ds")

        track.operate(Operator.SHIFT_RIGHT, "t", "t1")
        track.operate(Operator.SUBSTRACTER, "t", "t1", "dt")
        track.operate(Operator.DIVIDER, "ds", "dt", "ds/dt")

        self.assertEqual(len(track.getListAnalyticalFeatures()), 10)
        L = [
            'speed', 'dx', 'dy', 'dx2', 'dy2', 'dx2+dy2', 'ds', 't1', 'dt',
            'ds/dt'
        ]
        L.sort()
        T = track.getListAnalyticalFeatures()
        T.sort()
        self.assertEqual(T, L)

        track.operate(Operator.SUBSTRACTER, "speed", "ds/dt", "err")
        track.operate(Operator.SQUARE, "err", "err2")
        mse = track.operate(Operator.AVERAGER, "err2", "merr2")
        rmse = math.sqrt(mse)
        # print("RMSE =", math.sqrt(mse), "m/s")
        self.assertTrue((rmse - 2.36) < 0.01)
Пример #8
0
    def test_selection_combinaison_constraint(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace1.dat')
        trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
        trace.plot()

        t1 = TimeConstraint(begin=GPSTime('2018-07-31 14:00:00'))
        t3 = TimeConstraint(begin=GPSTime('2018-07-25 14:00:00'))

        center = trace.getObs(int(trace.size() / 2)).position
        radius = 91000
        circle1 = Geometrics.Circle(center, radius)
        circle1.plot('b-')

        pt = trace.getObs(int(trace.size() / 2)).position
        ll = ENUCoords(pt.getX() + 1000, pt.getY() + 15000)
        ur = ENUCoords(pt.getX() + 10000, pt.getY() + 40000)
        rect1 = Geometrics.Rectangle(ll, ur)
        rect1.plot()

        # =====================================================================
        c1 = Constraint(shape=circle1, time=t1, mode=MODE_CROSSES)
        s1 = Selector([c1])
        c2 = Constraint(shape=rect1, time=t3, mode=MODE_CROSSES)
        s2 = Selector([c2])

        selector = GlobalSelector([s1, s2])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        selector = GlobalSelector([s1, s2], combination=COMBINATION_OR)
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)
Пример #9
0
def example0():

    path_cam = "../data/hybridation_gnss_camera.dat"
    path_gps = "../data/hybridation_gnss_camera.pos"

    GPSTime.setReadFormat("2D/2M/4Y-2h:2m:2s.3z")
    track_cam = FileReader.readFromFile(path_cam,
                                        1,
                                        2,
                                        3,
                                        0,
                                        " ",
                                        srid="ENUCoords")
    track_gps = FileReader.readFromFile(path_gps,
                                        1,
                                        2,
                                        3,
                                        0,
                                        " ",
                                        srid="ENUCoords")
    track_cam.incrementTime(0, 18 - 3600)

    ini_time = GPSTime("06/06/2021-16:02:00.000")
    fin_time = GPSTime("06/06/2021-16:12:12.000")
    track_cam = track_cam.extractSpanTime(ini_time, fin_time)
    track_gps = track_gps.extractSpanTime(ini_time, fin_time)
    track_gps = track_gps // track_cam

    track_cam.rotate(0.2)
    Mapping.mapOn(track_cam, track_gps)

    track_cam.plot('r-')
    track_gps.plot('b+')
    plt.show()
Пример #10
0
	def test_gaussien(self):
		GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
		chemin = './data/trace1.dat'
		track = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
		kernel = GaussianKernel(201)
		track.operate(Operator.FILTER, "x", kernel, "x2")
		track.operate(Operator.FILTER, "y", kernel, "y2")
		plt.plot(track.getT(), track.getAnalyticalFeature("y"), 'b-', markersize=1.5)
		plt.plot(track.getT(), track.getAnalyticalFeature("y2"), 'r-')
		plt.show()
Пример #11
0
 def test_create_index_collection2(self):
     
     GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
             
     track = Track()
     p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
     track.addObs(p1)
     p2 = Obs(ENUCoords(3.1, 3), GPSTime.readTimestamp('2020-01-01 10:08:00'))
     track.addObs(p2)
     p3 = Obs(ENUCoords(3.1, 4.5), GPSTime.readTimestamp('2020-01-01 10:17:00'))
     track.addObs(p3)
     
     p4 = Obs(ENUCoords(4.5, 4.5), GPSTime.readTimestamp('2020-01-01 10:21:00'))
     track.addObs(p4)
     p5 = Obs(ENUCoords(6, 5.5), GPSTime.readTimestamp('2020-01-01 10:21:00'))
     track.addObs(p5)
     
     p6 = Obs(ENUCoords(7, 4.5), GPSTime.readTimestamp('2020-01-01 10:21:00'))
     track.addObs(p6)
     p7 = Obs(ENUCoords(11, 5.5), GPSTime.readTimestamp('2020-01-01 10:21:00'))
     track.addObs(p7)
     p8 = Obs(ENUCoords(13, 10), GPSTime.readTimestamp('2020-01-01 10:25:00'))
     track.addObs(p8)
             #track.plot()
             #track.plotAsMarkers()
             
     TRACES = []
     TRACES.append(track)
     collection = TrackCollection(TRACES)
             
     index = SpatialIndex(collection, (2, 2))
     index.plot()
     
     # =====================================================================
     # =====================================================================
     self.assertEqual(index.request(0, 0), [0])
     self.assertEqual(index.request(1, 0), [0])
     self.assertEqual(index.request(0, 1), [])
     self.assertEqual(index.request(1, 1), [0])
     self.assertEqual(index.request(2, 0), [])
     self.assertEqual(index.request(2, 1), [])
     self.assertEqual(index.request(1, 2), [0])
     self.assertEqual(index.request(2, 2), [0])
     self.assertEqual(index.request(3, 2), [0])
     self.assertEqual(index.request(3, 3), [])
     self.assertEqual(index.request(4, 2), [0])
     self.assertEqual(index.request(4, 3), [])
     self.assertEqual(index.request(4, 4), [])
     self.assertEqual(index.request(5, 2), [0])
     self.assertEqual(index.request(5, 3), [0])
     self.assertEqual(index.request(5, 4), [])
Пример #12
0
    def test_abs_curv1(self):
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, 'data/trace1.dat')

        track = FileReader.readFromFile(chemin,
                                        2,
                                        3,
                                        -1,
                                        4,
                                        separator=",",
                                        DateIni=-1,
                                        h=0,
                                        com="#",
                                        no_data_value=-999999,
                                        srid="ENUCoords")

        track.addAnalyticalFeature(algo.diffJourAnneeTrace)
        track.operate(Operator.INVERTER, "diffJourAnneeTrace",
                      "rando_jour_neg")
        #track.segmentation(["rando_jour_neg"], "rando_jour", [-1])
        seg.segmentation(track, ["rando_jour_neg"], "rando_jour", [-1])
        self.mafonct(track, "rando_jour")

        TRACES = seg.split(track, "rando_jour")

        self.assertTrue(len(TRACES) == 4)

        if len(TRACES) > 0:
            trace = TRACES[1]
            # trace.summary()
            trace.compute_abscurv()

            trace.resample(3, interpolation.MODE_SPATIAL)
            Sigma = trace.compute_abscurv()
            trace.estimate_speed()
            Speed = trace.getAnalyticalFeature('speed')
            #print (Speed)
            #print (trace.getListAnalyticalFeatures())
            tabAF = trace.getListAnalyticalFeatures()
            self.assertEqual(2, len(tabAF))
            self.assertEqual('abs_curv', tabAF[0])
            self.assertEqual('speed', tabAF[1])

            # =============================================================================
            # ============================================================================
            #
            fig, ax1 = plt.subplots(figsize=(15, 3))
            #plt.plot(trace.getAnalyticalFeature("sigma"), trace.getAnalyticalFeature("speed2"), '-', color='gold')
            plt.plot(Sigma, Speed, '-', color='skyblue')
            plt.show()
Пример #13
0
    def test_compare_calculs_vitesse(self):
        '''
        '''

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace0.gps')
        track = FileReader.readFromFile(chemin, 2, 3, -1, 1, separator=",")

        # 1ère méthode
        track.estimate_speed()
        # print (track.getListAnalyticalFeatures())
        self.assertEqual(len(track.getListAnalyticalFeatures()), 1)
        L = ['speed']
        self.assertEqual(track.getListAnalyticalFeatures(), L)

        #2ème méthode
        track.operate(Operator.SHIFT_RIGHT, "x", "x1")
        track.operate(Operator.SHIFT_LEFT, "x", "x2")
        track.operate(Operator.SUBSTRACTER, "x2", "x1", "dx")

        track.operate(Operator.SHIFT_RIGHT, "y", "y1")
        track.operate(Operator.SHIFT_LEFT, "y", "y2")
        track.operate(Operator.SUBSTRACTER, "y2", "y1", "dy")

        track.operate(Operator.SQUARE, "dx", "dx2")
        track.operate(Operator.SQUARE, "dy", "dy2")
        track.operate(Operator.ADDER, "dx2", "dy2", "dx2+dy2")
        track.operate(Operator.SQRT, "dx2+dy2", "ds")

        track.operate(Operator.SHIFT_RIGHT, "t", "t1")
        track.operate(Operator.SHIFT_LEFT, "t", "t2")
        track.operate(Operator.SUBSTRACTER, "t2", "t1", "dt")
        track.operate(Operator.DIVIDER, "ds", "dt", "ds/dt")

        #print (track.getListAnalyticalFeatures())

        #print (track.getObsAnalyticalFeature('speed', 10))
        #print (track.getObsAnalyticalFeature('ds/dt', 10))

        VM1 = track.getAnalyticalFeature("speed")
        #print (VM1[0:10])
        VM2 = track.getAnalyticalFeature("ds/dt")
        #print (VM2[0:10])
        self.assertEqual(VM1[1:len(VM1) - 1], VM2[1:len(VM2) - 1])

        track.operate(Operator.SUBSTRACTER, "speed", "ds/dt", "err")
        track.operate(Operator.SQUARE, "err", "err2")
        mse = track.operate(Operator.AVERAGER, "err2", "merr2")
        # print("RMSE =", math.sqrt(mse), "m/s")
        self.assertTrue(math.sqrt(mse) < 0.000001)
Пример #14
0
    def test_selection_one_shape_time_constraint(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace1.dat')
        trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
        trace.plot()

        t1 = TimeConstraint(begin=GPSTime('2018-07-31 14:00:00'))
        t2 = TimeConstraint(begin=GPSTime('2019-07-31 14:00:00'))
        t3 = TimeConstraint(begin=GPSTime('2018-07-25 14:00:00'))

        center = trace.getObs(int(trace.size() / 2)).position
        radius = 91000
        circle1 = Geometrics.Circle(center, radius)
        #circle1.plot()
        #plt.show()

        pt = trace.getObs(int(trace.size() / 2)).position
        center = ENUCoords(pt.getX() + 10000, pt.getY() + 30000)
        radius = 10000
        circle4 = Geometrics.Circle(center, radius)

        # =====================================================================
        c1 = Constraint(shape=circle1, time=t1, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        # =====================================================================
        c1 = Constraint(shape=circle1, time=t2, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        # =====================================================================
        c1 = Constraint(shape=circle1, time=t3, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        # =====================================================================
        c1 = Constraint(shape=circle4, time=t1, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)
Пример #15
0
    def __init__(self, arg, ext=-1):
        """TODO"""

        if ext >= 0:

            fields = FileFormat.__search_fmt_from_ext_or_name(
                FileFormat.TRACK_FILE_FORMAT, arg, ext)

            self.name = fields[0].strip()
            self.id_E = int(fields[2].strip())
            self.id_N = int(fields[3].strip())
            self.id_U = int(fields[4].strip())
            self.id_T = int(fields[5].strip())
            self.DateIni = fields[6].strip()
            self.separator = fields[7].strip()
            self.h = int(fields[8].strip())
            self.com = fields[9].strip()
            self.no_data_value = float(fields[10].strip())
            self.srid = fields[11].strip()
            self.read_all = fields[13].strip().upper() == "TRUE"

            self.time_fmt = fields[12].strip()

            self.separator = self.separator.replace("b", " ")
            self.separator = self.separator.replace("c", ",")
            self.separator = self.separator.replace("s", ";")

            if self.DateIni == "-1":
                self.DateIni = -1
            else:
                fmt_temp = GPSTime.getReadFormat()
                GPSTime.setReadFormat(self.time_fmt)
                self.DateIni = GPSTime(self.DateIni)
                GPSTime.setReadFormat(fmt_temp)
        else:

            self.id_E = -1
            self.id_N = -1
            self.id_U = -1
            self.id_T = -1
            self.DateIni = -1
            self.separator = ","
            self.h = 0
            self.com = "#"
            self.no_data_value = -999999
            self.srid = "ENUCoords"
            self.read_all = False

            self.time_fmt = GPSTime.getReadFormat()
Пример #16
0
 def test_write_csv_minim(self):
     
     GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
     track = Track()
     p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
     track.addObs(p1)
     p2 = Obs(ENUCoords(0, 1), GPSTime.readTimestamp('2020-01-01 10:00:01'))
     track.addObs(p2)
     
     csvpath = os.path.join(self.resource_path, 'data/test/test_write_csv_minim.wkt')
     FileWriter.writeToFile(track, csvpath, id_E=0,id_N=1,id_U=2,id_T=3,h=1, separator=";")
     contents = open(csvpath).read()
     
     txt  = "#srid: ENU\n"
     txt += "#E;N;U;time\n"
     txt += "0.000;0.000;0.000;01/01/2020 10:00:00\n"
     txt += "0.000;1.000;0.000;01/01/2020 10:00:01\n"
     self.assertEqual(contents.strip(), txt.strip())
Пример #17
0
    def readFromGpx(path, srid="GEO"):
        """
        Reads (multiple) tracks in .gpx file
        """

        tracks = TrackCollection()

        format_old = GPSTime.getReadFormat()
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")

        doc = minidom.parse(path)

        trks = doc.getElementsByTagName("trk")

        for trk in trks:
            trace = t.Track()
            trkpts = trk.getElementsByTagName("trkpt")
            for trkpt in trkpts:
                lon = float(trkpt.attributes["lon"].value)
                lat = float(trkpt.attributes["lat"].value)

                hgt = utils.NAN
                eles = trkpt.getElementsByTagName("ele")
                if eles.length > 0:
                    hgt = float(eles[0].firstChild.data)

                time = ""
                times = trkpt.getElementsByTagName("time")
                if times.length > 0:
                    time = GPSTime(times[0].firstChild.data)
                else:
                    time = GPSTime()

                point = Obs(utils.makeCoords(lon, lat, hgt, srid), time)
                trace.addObs(point)

            tracks.addTrack(trace)

        # pourquoi ?
        # --> pour remettre le format comme il etait avant la lectre :)   
        GPSTime.setReadFormat(format_old)

        collection = TrackCollection(tracks)
        return collection
Пример #18
0
    def test_format_time(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        madate = '2018-01-31 13:21:46'
        t = GPSTime.readTimestamp(madate)
        self.assertEqual("31/01/2018 13:21:46", str(t))

        GPSTime.setReadFormat("4Y-2M-2DT2h:2m:2s1Z")
        madate = '2018-01-31T11:17:46Z'
        t = GPSTime.readTimestamp(madate)
        self.assertEqual("31/01/2018 11:17:46", str(t))

        d = GPSTime.readUnixTime(1550941038.0)
        self.assertIsInstance(d, GPSTime)
        self.assertEqual('23/02/2019 16:57:18', str(d))
        self.assertEqual(23, d.day)
        self.assertEqual(2, d.month)
        self.assertEqual(2019, d.year)
        self.assertEqual(16, d.hour)
        self.assertEqual(57, d.min)
        self.assertEqual(18, d.sec)
Пример #19
0
    def setUp(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")

        self.track = Track()
        p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.track.addObs(p1)
        p2 = Obs(ENUCoords(0, 1), GPSTime.readTimestamp('2020-01-01 10:00:01'))
        self.track.addObs(p2)
        p3 = Obs(ENUCoords(1, 1), GPSTime.readTimestamp('2020-01-01 10:00:02'))
        self.track.addObs(p3)
        p4 = Obs(ENUCoords(1, 2), GPSTime.readTimestamp('2020-01-01 10:00:03'))
        self.track.addObs(p4)
        p5 = Obs(ENUCoords(2, 2), GPSTime.readTimestamp('2020-01-01 10:00:04'))
        self.track.addObs(p5)
        p6 = Obs(ENUCoords(2, 3), GPSTime.readTimestamp('2020-01-01 10:00:06'))
        self.track.addObs(p6)
        p7 = Obs(ENUCoords(3, 3), GPSTime.readTimestamp('2020-01-01 10:00:08'))
        self.track.addObs(p7)
        p8 = Obs(ENUCoords(3, 4), GPSTime.readTimestamp('2020-01-01 10:00:10'))
        self.track.addObs(p8)
        p9 = Obs(ENUCoords(4, 4), GPSTime.readTimestamp('2020-01-01 10:00:12'))
        self.track.addObs(p9)
Пример #20
0
from tracklib.core.Coords import GeoCoords
from tracklib.core.Obs import Obs
from tracklib.core.Operator import Operator
from tracklib.core.Kernel import GaussianKernel
from tracklib.io.FileReader import FileReader

import sys
import math
import time
import random
import numpy as np

# ---------------------------------------------------
# Lecture des donnees
# ---------------------------------------------------
GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
GPSTime.setPrintFormat("4Y-2M-2D 2h:2m:2s.3z")

chemin = "../data/trace0.gps"

GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")

track = FileReader.readFromFile(chemin, 2, 3, -1, 1, separator=",")

track = track.extract(100, 300)
track %= 20

#			- MODE_SPATIAL        (1)
#			- MODE_TEMPORAL       (2)
#		algorithm:
#			- ALGO_LINEAR            (1)
Пример #21
0
def example2():

    path_cam = "data/hybridation_gnss_camera.dat"
    path_gps = "data/hybridation_gnss_camera.pos"

    GPSTime.setReadFormat("2D/2M/4Y-2h:2m:2s.3z")

    track_cam = FileReader.readFromFile(path_cam,
                                        1,
                                        2,
                                        3,
                                        0,
                                        " ",
                                        srid="ENUCoords")
    track_gps = FileReader.readFromFile(path_gps,
                                        1,
                                        2,
                                        3,
                                        0,
                                        " ",
                                        srid="ENUCoords")
    track_cam.incrementTime(0, 18 - 3600)

    ini_time = GPSTime("06/06/2021-16:02:00.000")
    fin_time = GPSTime("06/06/2021-16:12:12.000")
    track_cam = track_cam.extractSpanTime(ini_time, fin_time)
    track_gps = track_gps.extractSpanTime(ini_time, fin_time)
    track_gps = track_gps // track_cam

    Mapping.mapOn(track_cam, track_gps, TP1=list(range(0, 50, 10)))

    def vx(track, i):
        if i == len(track) - 1:
            return track[i].position.getX() - track[i - 1].position.getX()
        return track[i + 1].position.getX() - track[i].position.getX()

    def vy(track, i):
        if i == len(track) - 1:
            return track[i].position.getY() - track[i - 1].position.getY()
        return track[i + 1].position.getY() - track[i].position.getY()

    track_cam.addAnalyticalFeature(vx)
    track_cam.addAnalyticalFeature(vy)
    track_gps.createAnalyticalFeature("vx", track_cam["vx"])
    track_gps.createAnalyticalFeature("vy", track_cam["vy"])

    def F(x, k, track):
        vx = track.getObsAnalyticalFeature("vx", k)
        vy = track.getObsAnalyticalFeature("vy", k)
        return Dynamics.DYN_MAT_2D_CST_POS() @ x + np.array([[vx], [vy]])

    H = np.eye(2, 2)

    Q = 1e-1 * np.eye(2, 2)
    R = 1.8**2 * np.eye(2, 2)

    X0 = np.zeros((2, 1))
    P0 = R

    UKF = Kalman(spreading=1)
    UKF.setTransition(F, Q)
    UKF.setObservation(H, R)
    UKF.setInitState(X0, 1e2 * P0)

    UKF.summary()

    track_filtered = track_gps.copy()
    UKF.estimate(track_filtered, ["x", "y"],
                 mode=Dynamics.MODE_STATES_AS_2D_POSITIONS)

    track_filtered.summary()

    # Track plot
    track_gps.plot('k+')
    track_cam.plot('r-')
    track_filtered.plot('g-')
    #track_filtered.plotEllipses('g-', factor=10)

    # Statistics
    print("Std gps =",
          '{:3.2f}'.format(track_filtered.operate(Operator.RMSE,
                                                  "kf_x_inov")), "m")

    plt.show()
Пример #22
0
 def testFindStopsLocal(self):
     GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
     chemin = os.path.join(self.resource_path, './data/trace1.dat')
     trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
     stops = findStopsLocal(trace)
     self.assertLessEqual(3, 5)
Пример #23
0
    def test_selection_one_timestamp_constraint(self):
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace1.dat')
        trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")

        t1 = TimeConstraint(begin=GPSTime('2018-07-31 14:00:00'))
        c = Constraint(time=t1)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        t2 = TimeConstraint(begin=GPSTime('2018-07-31 18:00:00'))
        c = Constraint(time=t2)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        t3 = TimeConstraint(begin=GPSTime('2018-07-31 11:35:00'),
                            end=GPSTime('2018-07-31 17:55:00'))
        c = Constraint(time=t3)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        t4 = TimeConstraint(begin=GPSTime('2018-07-31 12:13:58'),
                            end=GPSTime('2018-07-31 14:03:41'))
        c = Constraint(time=t4)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        t5 = TimeConstraint(begin=GPSTime('2018-07-31 18:01:58'),
                            end=GPSTime('2018-07-31 18:03:41'))
        c = Constraint(time=t5)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        t6 = TimeConstraint(begin=GPSTime('2015-07-31 18:01:58'),
                            end=GPSTime('2018-06-28 14:03:41'))
        c = Constraint(time=t6)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        t7 = TimeConstraint(begin=GPSTime('2018-07-31 18:01:58'),
                            end=GPSTime('2018-07-31 18:03:41'))
        c = Constraint(time=t7)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        t8 = TimeConstraint(begin=GPSTime('2018-07-31 05:03:04'),
                            end=GPSTime('2018-07-31 05:45:09'))
        c = Constraint(time=t8)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        t9 = TimeConstraint(begin=GPSTime('2018-07-31 17:57:59'),
                            end=GPSTime('2018-07-31 18:12:01'))
        c = Constraint(time=t9)
        s = Selector([c])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)
Пример #24
0
    def test_selection_one_shape_constraint(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace1.dat')
        trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
        trace.plot()

        center = trace.getObs(int(trace.size() / 2)).position
        radius = 91000
        circle1 = Geometrics.Circle(center, radius)
        #circle.plot()
        #plt.show()

        c1 = Constraint(shape=circle1, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        c2 = Constraint(shape=circle1, mode=MODE_INSIDE)
        s = Selector([c2])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        c3 = Constraint(shape=circle1, mode=MODE_GETS_IN)
        s = Selector([c3])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c4 = Constraint(shape=circle1, mode=MODE_GETS_OUT)
        s = Selector([c4])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        # -------------------------------------------------------

        center = trace.getObs(int(trace.size() / 2)).position
        radius = 45000
        circle2 = Geometrics.Circle(center, radius)
        #circle2.plot()
        #plt.show()

        c1 = Constraint(shape=circle2, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        c2 = Constraint(shape=circle2, mode=MODE_INSIDE)
        s = Selector([c2])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c3 = Constraint(shape=circle2, mode=MODE_GETS_IN)
        s = Selector([c3])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        c4 = Constraint(shape=circle2, mode=MODE_GETS_OUT)
        s = Selector([c4])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        # -------------------------------------------------------

        center = trace.getObs(0).position
        radius = 10000
        circle3 = Geometrics.Circle(center, radius)
        # circle3.plot()
        # plt.show()

        c1 = Constraint(shape=circle3, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        c2 = Constraint(shape=circle3, mode=MODE_INSIDE)
        s = Selector([c2])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c3 = Constraint(shape=circle3, mode=MODE_GETS_IN)
        s = Selector([c3])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c4 = Constraint(shape=circle3, mode=MODE_GETS_OUT)
        s = Selector([c4])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        # -------------------------------------------------------

        pt = trace.getObs(int(trace.size() / 2)).position
        center = ENUCoords(pt.getX() + 10000, pt.getY() + 30000)
        radius = 10000
        circle4 = Geometrics.Circle(center, radius)
        circle4.plot()
        plt.show()

        c1 = Constraint(shape=circle4, mode=MODE_CROSSES)
        s = Selector([c1])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c2 = Constraint(shape=circle4, mode=MODE_INSIDE)
        s = Selector([c2])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c3 = Constraint(shape=circle4, mode=MODE_GETS_IN)
        s = Selector([c3])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c4 = Constraint(shape=circle4, mode=MODE_GETS_OUT)
        s = Selector([c4])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)
Пример #25
0
    def test_create_index_collection1(self):
        
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
                
        track = Track()
        p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        track.addObs(p1)
        p2 = Obs(ENUCoords(2.5, 3), GPSTime.readTimestamp('2020-01-01 10:08:00'))
        track.addObs(p2)
        p3 = Obs(ENUCoords(2.5, 5), GPSTime.readTimestamp('2020-01-01 10:17:00'))
        track.addObs(p3)
        p4 = Obs(ENUCoords(7, 5), GPSTime.readTimestamp('2020-01-01 10:21:00'))
        track.addObs(p4)
        p5 = Obs(ENUCoords(10, 10), GPSTime.readTimestamp('2020-01-01 10:25:00'))
        track.addObs(p5)
                #track.plot()
                #track.plotAsMarkers()
                
        TRACES = []
        TRACES.append(track)
        collection = TrackCollection(TRACES)
                
        index = SpatialIndex(collection, (2, 2))
        index.plot()
        
        # =====================================================================
        # =====================================================================
        self.assertEqual(index.request(0, 0), [0])
        self.assertEqual(index.request(1, 0), [])
        self.assertEqual(index.request(0, 1), [0])
        self.assertEqual(index.request(1, 1), [0])
        self.assertEqual(index.request(2, 0), [])
        self.assertEqual(index.request(2, 1), [])
        self.assertEqual(index.request(1, 2), [0])
        self.assertEqual(index.request(2, 2), [0])
        self.assertEqual(index.request(3, 2), [0])
        self.assertEqual(index.request(3, 3), [0])
        self.assertEqual(index.request(4, 3), [0])
        self.assertEqual(index.request(4, 4), [0])
        
        
        # # =====================================================================
        self.assertEqual(index.request(ENUCoords(0, 0)), [0])
        self.assertEqual(index.request(ENUCoords(2.5, 3)), [0])
        self.assertEqual(index.request(ENUCoords(2.5, 5)), [0])
        self.assertEqual(index.request(ENUCoords(7, 5)), [0])
        self.assertEqual(index.request(ENUCoords(10, 10)), [0])
        self.assertEqual(index.request(ENUCoords(0.5, 2.5)), [0])
        self.assertEqual(index.request(ENUCoords(4.2, 5.8)), [0])

        
        # # =====================================================================
        self.assertEqual(index.request([ENUCoords(2.1, 0.5), ENUCoords(1.1, 1.1)]), [0])
        self.assertEqual(index.request([ENUCoords(2.1, 0.5), ENUCoords(7.1, 3.5)]), [])
        self.assertEqual(index.request([ENUCoords(5.8, 5.8), ENUCoords(2.1, 1.1)]), [0])
        
        
        # # =====================================================================
        self.assertEqual(index.request(track), [0])
 
        track2 = Track()
        p6 = Obs(ENUCoords(2.2, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        track2.addObs(p6)
        p7 = Obs(ENUCoords(2.2, 3.8), GPSTime.readTimestamp('2020-01-01 10:08:00'))
        track2.addObs(p7)
        p8 = Obs(ENUCoords(6.5, 3.8), GPSTime.readTimestamp('2020-01-01 10:08:00'))
        track2.addObs(p8)
        self.assertEqual(index.request(track2), [0])
        
        
        track3 = Track()
        p9 = Obs(ENUCoords(6.5, 3.8), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        track3.addObs(p9)
        p10 = Obs(ENUCoords(6.5, 7), GPSTime.readTimestamp('2020-01-01 10:08:00'))
        track3.addObs(p10)
        p11 = Obs(ENUCoords(10, 7), GPSTime.readTimestamp('2020-01-01 10:08:00'))
        track3.addObs(p11)
        self.assertEqual(index.request(track3), [0])


        # # =====================================================================
        # # =====================================================================
        self.assertCountEqual(index.neighborhood(0, 4, 0), [])
        self.assertCountEqual(index.neighborhood(0, 4, 1), [])
        self.assertCountEqual(index.neighborhood(0, 4, 2), [0])
        self.assertCountEqual(index.neighborhood(0, 4, 3), [0])
    
        self.assertCountEqual(index.neighborhood(3, 0, 0), [])
        self.assertCountEqual(index.neighborhood(3, 0, 1), [])
        self.assertCountEqual(index.neighborhood(3, 0, 2), [0])
        self.assertCountEqual(index.neighborhood(3, 0, 3), [0])
    
        self.assertCountEqual(index.neighborhood(2, 2, 0), [0])
        self.assertCountEqual(index.neighborhood(2, 2, 1), [0])
        self.assertCountEqual(index.neighborhood(2, 2, 2), [0])
        #self.assertCountEqual(index.neighborhood(2, 2, 3), [0])
    
        # # UNIT = -1
        self.assertCountEqual(index.neighborhood(2, 1, -1), [0])
        self.assertCountEqual(index.neighborhood(2, 0, -1), [0])
        self.assertCountEqual(index.neighborhood(0, 1, -1), [0])
        self.assertCountEqual(index.neighborhood(1, 1, -1), [0])
        self.assertCountEqual(index.neighborhood(0, 4, -1), [0])
        self.assertCountEqual(index.neighborhood(3, 4, -1), [0])
        self.assertCountEqual(index.neighborhood(4, 4, -1), [0])
        self.assertCountEqual(index.neighborhood(2, 4, -1), [0])
        
        
        # # =====================================================================
        self.assertCountEqual(index.neighborhood(ENUCoords(0, 0.1)), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.5, 3)), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.5, 5)), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(7, 5)), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(10, 10)), [0])
        
        self.assertCountEqual(index.neighborhood(ENUCoords(6.5, 3.8), None, 0), [])
        self.assertCountEqual(index.neighborhood(ENUCoords(6.5, 3.8), None, 1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(6.5, 3.8), None, 2), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(6.5, 3.8), None, 3), [0])

        self.assertCountEqual(index.neighborhood(ENUCoords(2.2, 3.8), None, 0), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.2, 3.8), None, 1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.2, 3.8), None, 2), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.2, 3.8), None, 3), [0])
        
        self.assertCountEqual(index.neighborhood(ENUCoords(9.9, 7), None, 0), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(9.9, 7), None, 1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(9.9, 7), None, 2), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(9.9, 7), None, 3), [0])
       
        #  # UNIT = -1
        self.assertCountEqual(index.neighborhood(ENUCoords(0, 0), None, -1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.5, 3), None, -1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.5, 5), None, -1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(7, 5), None, -1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(10, 10), None, -1), [0])
        
        self.assertCountEqual(index.neighborhood(ENUCoords(6.5, 3.8), None, -1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(2.2, 3.8), None, -1), [0])
        self.assertCountEqual(index.neighborhood(ENUCoords(9.9, 7), None, -1), [0])
  
    
        # # =====================================================================
        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(0.1, 2.1)], None, 0), [0])
        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(0.1, 2.1)], None, 1), [0])
        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(0.1, 2.1)], None, 2), [0])
        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(0.1, 2.1)], None, -1), [0])

        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(7.1, 3.5)]), [])
        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(7.1, 3.5)], None, 2), [0])
        self.assertEqual(index.neighborhood([ENUCoords(2.1, 0.5), ENUCoords(7.1, 3.5)], None, -1), [0])
        
        self.assertEqual(index.neighborhood([ENUCoords(5.8, 5.8), ENUCoords(2.1, 1.1)]), [0])
        self.assertEqual(index.neighborhood([ENUCoords(5.8, 5.8), ENUCoords(2.1, 1.1)], None, 1), [0])
        self.assertEqual(index.neighborhood([ENUCoords(5.8, 5.8), ENUCoords(2.1, 1.1)], None, 2), [0])
        self.assertEqual(index.neighborhood([ENUCoords(5.8, 5.8), ENUCoords(2.1, 1.1)], None, -1), [0])
        
        
        # # =====================================================================
        self.assertEqual(index.neighborhood(track), [0])
        self.assertEqual(index.neighborhood(track, None, 1), [0])
        self.assertEqual(index.neighborhood(track, None, 3), [0])
        self.assertEqual(index.neighborhood(track, None, -1), [0])
 
        self.assertEqual(index.neighborhood(track2), [0])
        self.assertEqual(index.neighborhood(track2, None, 0), [0])
        self.assertEqual(index.neighborhood(track2, None, 1), [0])
        self.assertEqual(index.neighborhood(track2, None, 3), [0])
        self.assertEqual(index.neighborhood(track2, None, -1), [0])
        
        self.assertEqual(index.neighborhood(track3), [0])
        self.assertEqual(index.neighborhood(track3, None, 0), [0])
        self.assertEqual(index.neighborhood(track3, None, 1), [0])
        self.assertEqual(index.neighborhood(track3, None, 2), [0])
        self.assertEqual(index.neighborhood(track3, None, 3), [0])
        self.assertEqual(index.neighborhood(track3, None, -1), [0])
Пример #26
0
    def setUp(self):

        #----------------------------------------------------------------------
        #   4 sommets sur axes du cercle trigonométrique
        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")

        self.trace1 = Track()
        c1 = ENUCoords(1, 0, 0)
        p1 = Obs(c1, GPSTime.readTimestamp("2018-01-01 10:00:00"))
        self.trace1.addObs(p1)
        c2 = ENUCoords(0, 1, 0)
        p2 = Obs(c2, GPSTime.readTimestamp("2018-01-01 10:00:12"))
        self.trace1.addObs(p2)
        c3 = ENUCoords(-1, 0, 0)
        p3 = Obs(c3, GPSTime.readTimestamp("2018-01-01 10:00:40"))
        self.trace1.addObs(p3)
        c4 = ENUCoords(0, -1, 0)
        p4 = Obs(c4, GPSTime.readTimestamp("2018-01-01 10:01:50"))
        self.trace1.addObs(p4)
        self.trace1.addObs(p1)

        # ---------------------------------------------------------------------
        # Un escalier
        self.trace2 = Track()
        pm3 = Obs(ENUCoords(-2, -1),
                  GPSTime.readTimestamp('2020-01-01 09:59:44'))
        self.trace2.addObs(pm3)
        pm2 = Obs(ENUCoords(-1, -1),
                  GPSTime.readTimestamp('2020-01-01 09:59:48'))
        self.trace2.addObs(pm2)
        pm1 = Obs(ENUCoords(-1, 0),
                  GPSTime.readTimestamp('2020-01-01 09:59:55'))
        self.trace2.addObs(pm1)
        p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace2.addObs(p1)
        p2 = Obs(ENUCoords(0, 2), GPSTime.readTimestamp('2020-01-01 10:00:01'))
        self.trace2.addObs(p2)
        p3 = Obs(ENUCoords(1, 2), GPSTime.readTimestamp('2020-01-01 10:00:02'))
        self.trace2.addObs(p3)
        p4 = Obs(ENUCoords(1, 5), GPSTime.readTimestamp('2020-01-01 10:00:03'))
        self.trace2.addObs(p4)
        p5 = Obs(ENUCoords(2, 5), GPSTime.readTimestamp('2020-01-01 10:00:04'))
        self.trace2.addObs(p5)
        p6 = Obs(ENUCoords(2, 9), GPSTime.readTimestamp('2020-01-01 10:00:06'))
        self.trace2.addObs(p6)
        p7 = Obs(ENUCoords(3, 9), GPSTime.readTimestamp('2020-01-01 10:00:08'))
        self.trace2.addObs(p7)
        p8 = Obs(ENUCoords(3, 14),
                 GPSTime.readTimestamp('2020-01-01 10:00:10'))
        self.trace2.addObs(p8)
        p9 = Obs(ENUCoords(4, 14),
                 GPSTime.readTimestamp('2020-01-01 10:00:12'))
        self.trace2.addObs(p9)
        p10 = Obs(ENUCoords(4, 20),
                  GPSTime.readTimestamp('2020-01-01 10:00:15'))
        self.trace2.addObs(p10)

        # ---------------------------------------------------------------------
        #
        self.trace3 = Track()
        p1 = Obs(ENUCoords(0, 0), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p1)
        p2 = Obs(ENUCoords(1.5, 0.5),
                 GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p2)
        p3 = Obs(ENUCoords(2, 2), GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p3)
        p4 = Obs(ENUCoords(3.75, 0.6),
                 GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p4)
        p5 = Obs(ENUCoords(5, 0.5),
                 GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p5)
        p6 = Obs(ENUCoords(3.55, -0.5),
                 GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p6)
        p7 = Obs(ENUCoords(1.8, -1.2),
                 GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p7)
        p8 = Obs(ENUCoords(1, -3),
                 GPSTime.readTimestamp('2020-01-01 10:00:00'))
        self.trace3.addObs(p8)
Пример #27
0
from tracklib.core.GPSTime import GPSTime
from tracklib.io.GpxReader import GpxReader
from tracklib.core.Operator import Operator

import tracklib.algo.Analytics as algo
import tracklib.algo.Interpolation as interp
import tracklib.algo.Segmentation as segmentation

import tracklib.core.Grid as grid
import tracklib.core.TrackCollection as trackCollection
import tracklib.algo.Summarising as summ

# ---------------------------------------------------
# Lecture des donnees
# ---------------------------------------------------
GPSTime.setReadFormat("4Y-2M-2DT2h:2m:2sZ")
tracks = GpxReader.readFromGpx("./data/activity_5807084803.gpx")
trace = tracks.getTrack(0)

# Transformation GEO coordinates to ENU
trace.toENUCoords()

# Display
trace.plot()
#trace.plot('POINT')

# ================================================
# SPEED : different
trace.estimate_speed()

trace.plotAnalyticalFeature('speed', 'BOXPLOT')
Пример #28
0
    def test_selection_track_constraint(self):

        GPSTime.setReadFormat("4Y-2M-2D 2h:2m:2s")
        chemin = os.path.join(self.resource_path, './data/trace1.dat')
        trace = FileReader.readFromFile(chemin, 2, 3, -1, 4, separator=",")
        trace.plot()

        # =====================================================================
        trace1 = Track()
        c1 = trace.getObs(1350).position
        c0 = ENUCoords(c1.getX() + 5000, c1.getY())
        c2 = ENUCoords(c1.getX() - 5000, c1.getY())
        p1 = Obs(c0, GPSTime.readTimestamp("2018-07-31 14:00:00"))
        p2 = Obs(c1, GPSTime.readTimestamp("2018-07-31 14:01:00"))
        p3 = Obs(c2, GPSTime.readTimestamp("2018-07-31 14:02:00"))
        trace1.addObs(p1)
        trace1.addObs(p2)
        trace1.addObs(p3)
        plt.plot(trace1.getX(), trace1.getY(), 'r-')
        plt.show()

        c3 = TrackConstraint(trace1, mode=MODE_PARALLEL)
        s = Selector([c3])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertFalse(isSelection)

        c4 = TrackConstraint(trace1, mode=MODE_CROSSES)
        s = Selector([c4])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        # =====================================================================
        trace1 = Track()
        c0 = ENUCoords(
            trace.getObs(1349).position.getX(),
            trace.getObs(1349).position.getY())
        c1 = ENUCoords(
            trace.getObs(1350).position.getX(),
            trace.getObs(1350).position.getY())
        c2 = ENUCoords(
            trace.getObs(1351).position.getX(),
            trace.getObs(1351).position.getY())
        p1 = Obs(c0, GPSTime.readTimestamp("2018-07-31 14:00:00"))
        p2 = Obs(c1, GPSTime.readTimestamp("2018-07-31 14:01:00"))
        p3 = Obs(c2, GPSTime.readTimestamp("2018-07-31 14:02:00"))
        trace1.addObs(p1)
        trace1.addObs(p2)
        trace1.addObs(p3)
        trace.plot()
        plt.plot(trace1.getX(), trace1.getY(), 'r-')
        plt.show()

        c3 = TrackConstraint(trace1, mode=MODE_PARALLEL)
        s = Selector([c3])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)

        c4 = TrackConstraint(trace1, mode=MODE_CROSSES)
        s = Selector([c4])
        selector = GlobalSelector([s])
        isSelection = selector.contains(trace)
        self.assertTrue(isSelection)