Pedestrian Graph Plan de l’Aiguille#

[1]:
import os
import sys

import matplotlib.pyplot as plt

# Ajout dans la variable PATH du système du chemin où est installée la librairie tracklib
module_path = os.path.abspath(os.path.join('../../../../tracklib'))
if module_path not in sys.path:
    sys.path.append(module_path)
# Alias pour tracklib
import tracklib as tkl

# Ajout dans la variable PATH du système du chemin où est installée la librairie footprint2graph
module_path = os.path.abspath(os.path.join('../../..'))
if module_path not in sys.path:
    sys.path.append(module_path)
[2]:
import matplotlib.pyplot as plt
import os
import time

from footprint2graph import run_iteration
from footprint2graph import read_config

from footprint2graph.util.Outdoorvision import load_raw_tracks_split

Chargement des paramètres#

[3]:
print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print ('`````````````````````````````````````````````````````````````````````')
print ('  Generate a footprint graph                                         ')
print ('             from hiking trajectories                                ')
print ("             in the Plan de l'Aiguille, dans la vallée de Chamonix, summer 2024.  ")
print ('’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’')
print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print ('')


""" ======================================================================= """
"""     Load parameters                                                     """
"""                                                                         """

config_path = r'/home/md_vandamme/7_LIB/footprint2graph/data/config_plan_de_l_aiguille.yml'
config = read_config(config_path)


print('Paramètres relevés dans la configuration: ')
print ('Résultats enregistrés dans le répertoire: ', config['output']['RESULT_PATH'])

NBITER = int(config['graph_construction']['NUM_ITERATIONS'])
print ('Number of iterations: ', NBITER)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`````````````````````````````````````````````````````````````````````
  Generate a footprint graph
             from hiking trajectories
             in the Plan de l'Aiguille, dans la vallée de Chamonix, summer 2024.
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Paramètres relevés dans la configuration:
Résultats enregistrés dans le répertoire:  /home/md_vandamme/4_RESEAU/ZTEMPZ3/
Number of iterations:  2

Chargement des données#

Les données proviennent de la plateforme Outdoorvision. Après avoir été formatées au format CSV, elles sont chargées dans une collection qui servira d’entrée au pipeline.

[4]:
""" ======================================================================= """
"""     Chargement de la collection de traces                               """
"""                                                                         """

# chemin où sont stockés les traces Outdoorvision:
tracespathsource = r'/home/md_vandamme/5_GPS/OV/CHAM/walk/'

# Paramètre : Coordonnées de la zone d'étude sur laquelle on construit le réseau
#                           Polygone sous la forme d'un tableau de X et de Y
X = [1000852, 1001838, 1001852, 1000853, 1000852]
Y = [6541520,  6541524,  6540842,  6540839,  6541520]

fmt = tkl.TrackFormat({'ext': 'CSV',
                       'srid': 'ENU',
                       'id_E': 1, 'id_N': 0, 'id_U': 3, 'id_T': 2,
                       'time_fmt': '2D/2M/4Y 2h:2m:2s',
                       'separator': ';',
                       'header': 0,
                       'cmt': '#',
                       'read_all': True})
collection = load_raw_tracks_split(config['output']['RESULT_PATH'],
                                   tracespathsource, fmt, X, Y)
Loading and split outdoorvision track data...
Reading track data...
     Number files to load:  21211
Starting split ...
     500 / 21211
     1000 / 21211
     1500 / 21211
     2000 / 21211
     2500 / 21211
     3000 / 21211
     3500 / 21211
     4000 / 21211
     4500 / 21211
     5000 / 21211
     5500 / 21211
     6000 / 21211
     6500 / 21211
     7000 / 21211
     7500 / 21211
     8000 / 21211
     8500 / 21211
     9000 / 21211
     9500 / 21211
     10000 / 21211
     10500 / 21211
     11000 / 21211
     11500 / 21211
     12000 / 21211
     12500 / 21211
     13000 / 21211
     13500 / 21211
     14000 / 21211
     14500 / 21211
     15000 / 21211
     15500 / 21211
     16000 / 21211
     16500 / 21211
     17000 / 21211
     17500 / 21211
     18000 / 21211
     18500 / 21211
     19000 / 21211
     19500 / 21211
     20000 / 21211
     20500 / 21211
     21000 / 21211
     Number of tracks after split: 631

Lancement du pipeline#

[5]:
for idx in range(0, NBITER):
    iteration_index = int(idx) + 1

    # run pipeline for the ith iteration
    run_iteration(iteration_index, config, collection)

print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print ('`````````````````````````````````````````````````````````````````````')
print ('                           FIN                                       ')
print ('’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’')
print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
-----------------------------------------------------------------
-----------------------------------------------------------------
              ITERATION  1
-----------------------------------------------------------------
-----------------------------------------------------------------
Starting segmentation and resampling...
Starting segmentation ...
     500 / 631
    Number of tracks after segmentation: 688
Finished saving segmented tracks.
Starting resampling ...
    Number of tracks to resample:  688
    Number of tracks after resampling: 688
    Number of tracks after resampling: 688
Finished saving resampled tracks.
Stage 1 finished: segmentation and resampling.
Starting rasterization and vectorization (iteration 1)

    Loading tracks from :  resample_grid
    Number of tracks to load:  688
    Building high-resolution geometry density grid G1 :  2 m ...
    Building low-resolution contextual density grid G2 :  30 m ...
    Assigning track points to the G1 and G2 grids
         500 / 688
    Computing G1 ...
    Computing G2 ...
    Number of neighboring cells to consider: 7
    Building contrast grid :  2 m
    Execution time (seconds): 22.76438069343567
    Finished heatmap computation.
    Starting morphological closing image ...
    Execution time (seconds): 2.9393832683563232
    Finished morphological opening.
Vectorizing cleaned image ...
Extracting road surface vector features ...
    Number of polygonize features:  32
    Number of polygonize features copied:  10
    Execution time (seconds): 0.03627943992614746
    Vectorization completed.
Smoothing polygon to remove stair-step artifacts ...
100% (341 of 341) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (846 of 846) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (403 of 403) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (663 of 663) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
  0% (0 of 1273) |                       | Elapsed Time: 0:00:00 ETA:  --:--:--
    Execution time (seconds): 0.500645637512207
    Road surface smoothing completed.
    Starting centerline computation ...
100% (1273 of 1273) |####################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (621 of 621) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (618 of 618) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (2711 of 2711) |####################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (1113 of 1113) |####################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (967 of 967) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (963 of 963) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
    Execution time (seconds): 0.7983303070068359
    Centerline computed.
Stage 2 completed: rasterization and vectorization.
Starting topology creation for the network
    Number of edges in the skeleton: 1669
    Finished loaded skeleton.
    /home/md_vandamme/4_RESEAU/ZTEMPZ3/network/tmp_in.csv not exists
    /home/md_vandamme/4_RESEAU/ZTEMPZ3/network/tmp_out.csv not exists
 50% (16 of 32) |############            | Elapsed Time: 0:00:00 ETA:   0:00:00

    Finished removing hooked parts of the skeleton.
100% (32 of 32) |########################| Elapsed Time: 0:00:00 Time:  0:00:000000
100% (32 of 32) |########################| Elapsed Time: 0:00:00 Time:  0:00:00
    Finished simplification of the skeleton.
Building [100 x 74] spatial index...
    Number of edges in the skeleton (after snapping): 32
    Edge count difference after snapping :  0
    Number of edges in the simplified skeleton: 22
    Number of nodes: 32
     Shortest edges limit :  50
    Number of edges in the skeleton (after removing the shortest edges): 0
    Conflation cannot be performed for node  27 ; the three incident edges are too long: 74 172 76
    Edge count after conflation: 12
Stage 3 completed: adding topology to the skeleton.
Starting map-matching, aggregation, and conflation of GNSS trajectories.
    Loading network (1) ...
        Number of edges =  12
        Number of nodes =  22
        Total segment length of the network =  4437.851352451303
    Loading collection of tracks ...
100% (22 of 22) |########################| Elapsed Time: 0:00:00 Time:  0:00:00
        Number of tracks: 688
        Execution time (seconds): 2.79937744140625
    Starting map-matching ...
        Index spatial :  [100 x 74] spatial index centered on [1001326.7471449398; 6541196.7582587]
Map-matching preparation...
        Parameter search_radius:  25
        Map-matching ended.
        Execution time (seconds): 78.48061347007751
        Prepare map-matching results for candidate segment generation
    Number of map-matched points = 143634 (88.37 %)
    Map-matching results restructuring completed.
        Map-matching results exported.
Starting construction of candidate trajectory segments for each topology edge ...
    31  candidates for edge 46
    115  candidates for edge 44
    113  candidates for edge 43
    20  candidates for edge 19
    29  candidates for edge 3
    25  candidates for edge 45
    50  candidates for edge 41
    24  candidates for edge 21
    8  candidates for edge 35
    25  candidates for edge 20
    1  candidates for edge 37
    7  candidates for edge 42
    Number of processed edges:  12
    Minimum number of candidate tracks per edge:  1
    Maximum number of candidate traces per edge:  115
    Average number of candidate tracks per edge:  37
    Segment construction completed.
        Execution time (seconds): 6.564183950424194
    Starting track segment aggregation for all network edges ...
        Number of candidate tracks / number of sampled tracks 31 / 30
        Number of candidate tracks / number of sampled tracks 115 / 30
        Number of candidate tracks / number of sampled tracks 113 / 30
        Number of candidate tracks / number of sampled tracks 20 / 20
        Number of candidate tracks / number of sampled tracks 29 / 29
        Number of candidate tracks / number of sampled tracks 25 / 25
        Number of candidate tracks / number of sampled tracks 50 / 30
        Number of candidate tracks / number of sampled tracks 24 / 24
        Number of candidate tracks / number of sampled tracks 8 / 8
        Number of candidate tracks / number of sampled tracks 25 / 25
        Number of candidate tracks / number of sampled tracks 1 / 1
    Only one trajectory available for aggregation: no processing required
        Number of candidate tracks / number of sampled tracks 7 / 7
        Number of aggregations: 12
        Number of aggregations with 30 traces: 4
        Number of aggregations with fewer than 30 traces: 8
        Minimum number of traces in aggregation: 1
        Average number of traces in aggregation: 37
        Aggregation process finished.
        Execution time (seconds): 9.709306716918945
    Starting conflation ...
        Conflation process finished.
        Execution time (seconds): 0.02811574935913086
Stage 4 completed: map-matching, aggregation, and conflation.
-----------------------------------------------------------------
-----------------------------------------------------------------
              ITERATION  2
-----------------------------------------------------------------
-----------------------------------------------------------------
Number of tracks map matched : 688
1293
Starting rasterization and vectorization (iteration 2)

    Loading tracks from :  points_not_mm_2
    Number of tracks to load:  1293
    Building high-resolution geometry density grid G1 :  2 m ...
    Building low-resolution contextual density grid G2 :  30 m ...
    Assigning track points to the G1 and G2 grids
         500 / 1293
         1000 / 1293
    Computing G1 ...
    Computing G2 ...
    Number of neighboring cells to consider: 7
    Building contrast grid :  2 m
    Execution time (seconds): 8.377056360244751
    Finished heatmap computation.
    Starting morphological closing image ...
    Execution time (seconds): 2.9527673721313477
    Finished morphological opening.
Vectorizing cleaned image ...
Extracting road surface vector features ...
    Number of polygonize features:  43
    Number of polygonize features copied:  19
    Execution time (seconds): 0.022061824798583984
    Vectorization completed.
Smoothing polygon to remove stair-step artifacts ...
100% (102 of 102) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (186 of 186) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (152 of 152) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (159 of 159) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (113 of 113) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (175 of 175) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (128 of 128) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (219 of 219) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (189 of 189) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (197 of 197) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (163 of 163) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (367 of 367) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (364 of 364) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (391 of 391) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
    Execution time (seconds): 0.21992087364196777
    Road surface smoothing completed.
    Starting centerline computation ...
100% (175 of 175) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (86 of 86) |########################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (135 of 135) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (966 of 966) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
100% (193 of 193) |######################| Elapsed Time: 0:00:00 Time:  0:00:00
    Execution time (seconds): 0.45319151878356934
    Centerline computed.
Stage 2 completed: rasterization and vectorization.
Starting topology creation for the network
    Number of edges in the skeleton: 631
    Finished loaded skeleton.
100% (50 of 50) |########################| Elapsed Time: 0:00:00 Time:  0:00:000000
100% (50 of 50) |########################| Elapsed Time: 0:00:00 Time:  0:00:00

    Finished removing hooked parts of the skeleton.
    Finished simplification of the skeleton.
Building [100 x 87] spatial index...
    Number of edges in the skeleton (after snapping): 50
    Edge count difference after snapping :  0
    Number of edges in the simplified skeleton: 46
    Number of nodes: 65
     Shortest edges limit :  50
    Number of edges in the skeleton (after removing the shortest edges): 5
    Conflation cannot be performed for node  54 ; the three incident edges are too long: 30 42 59
    Edge count after conflation: 19
Stage 3 completed: adding topology to the skeleton.
Starting map-matching, aggregation, and conflation of GNSS trajectories.
    Loading network (2) ...
        Number of edges =  19
        Number of nodes =  33
        Total segment length of the network =  1439.7164877840992
    Loading collection of tracks ...
100% (33 of 33) |########################| Elapsed Time: 0:00:00 Time:  0:00:00
        Number of tracks: 1293
        Execution time (seconds): 1.837005853652954
    Starting map-matching ...
        Index spatial :  [100 x 87] spatial index centered on [1001240.6166657063; 6541182.303244937]
Map-matching preparation...
        Parameter search_radius:  25
        Map-matching ended.
        Execution time (seconds): 12.17409062385559
        Prepare map-matching results for candidate segment generation
    Number of map-matched points = 73193 (49.96 %)
    Map-matching results restructuring completed.
        Map-matching results exported.
Starting construction of candidate trajectory segments for each topology edge ...
    16  candidates for edge 52
    50  candidates for edge 56
    3  candidates for edge 61
    51  candidates for edge 5
    89  candidates for edge 6
    18  candidates for edge 38
    68  candidates for edge 12
    3  candidates for edge 28
    1  candidates for edge 53
    3  candidates for edge 64
    26  candidates for edge 63
    3  candidates for edge 46
    6  candidates for edge 27
    2  candidates for edge 58
    2  candidates for edge 55
    35  candidates for edge 24
    13  candidates for edge 59
    7  candidates for edge 36
    18  candidates for edge 57
    Number of processed edges:  19
    Minimum number of candidate tracks per edge:  1
    Maximum number of candidate traces per edge:  89
    Average number of candidate tracks per edge:  22
    Segment construction completed.
        Execution time (seconds): 4.859700441360474
    Starting track segment aggregation for all network edges ...
        Number of candidate tracks / number of sampled tracks 16 / 16
        Number of candidate tracks / number of sampled tracks 50 / 30
        Number of candidate tracks / number of sampled tracks 3 / 3
        Number of candidate tracks / number of sampled tracks 18 / 18
        Number of candidate tracks / number of sampled tracks 68 / 30
        Number of candidate tracks / number of sampled tracks 3 / 3
        Number of candidate tracks / number of sampled tracks 1 / 1
    Only one trajectory available for aggregation: no processing required
        Number of candidate tracks / number of sampled tracks 3 / 3
        Number of candidate tracks / number of sampled tracks 26 / 26
        Number of candidate tracks / number of sampled tracks 3 / 3
        Number of candidate tracks / number of sampled tracks 6 / 6
        Number of candidate tracks / number of sampled tracks 2 / 2
        Number of candidate tracks / number of sampled tracks 2 / 2
        Number of candidate tracks / number of sampled tracks 35 / 30
        Number of candidate tracks / number of sampled tracks 13 / 13
        Number of candidate tracks / number of sampled tracks 7 / 7
        Number of candidate tracks / number of sampled tracks 18 / 18
        Number of aggregations: 19
        Number of aggregations with 30 traces: 3
        Number of aggregations with fewer than 30 traces: 14
        Minimum number of traces in aggregation: 1
        Average number of traces in aggregation: 14
        Aggregation process finished.
        Execution time (seconds): 1.9753568172454834
    Starting conflation ...
        Conflation process finished.
        Execution time (seconds): 0.01727581024169922
Stage 4 completed: map-matching, aggregation, and conflation.
Merging the mobility network with the result of iteration 2.
100% (31 of 31) |########################| Elapsed Time: 0:00:00 Time:  0:00:00
Size of collection In  :  12
Size of collection In+1:  19
Size of collection In+In+1:  31
Building [100 x 75] spatial index...
Size of collection In+In+1 avec intersection:  31
Size of collection In+In+1 avec intersection et raccordement:  46
Nombre de géométries :  46
Size of reseau de mobilité:  46
End building the mobility network.
==================================================================
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
`````````````````````````````````````````````````````````````````````
                           FIN
’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

On affiche le résultat#

[6]:
fig, ax = plt.subplots(figsize=(20, 16))

fmt = tkl.NetworkFormat({
           "pos_edge_id": 0,
           "pos_source": 1,
           "pos_target": 2,
           "pos_wkt": 4,
           "srid": "ENU",
           "separator": ",",
           "header": 1})
networkpath = config['output']['RESULT_PATH'] + 'merge_2/reseau_mobilite_2.csv'
squelette = tkl.NetworkReader.readFromFile(networkpath, fmt, verbose=False)

L = list(squelette.EDGES.items())
for i in range(len(L)):
    x1d = []
    y1d = []
    edge = L[i][1]
    for j in range(edge.geom.size()):
        x1d.append(edge.geom.getX()[j])
        y1d.append(edge.geom.getY()[j])
    ax.plot(x1d, y1d, 'r-', linewidth=3, label='Mobility Network')


# Supprime les doublons dans la légende
handles, labels = ax.get_legend_handles_labels()
by_label = dict(zip(labels, handles))
ax.legend(by_label.values(), by_label.keys())
[6]:
<matplotlib.legend.Legend at 0x7f263c291030>
../_images/examples_PedestrianGraphPlanDeLAiguille_10_1.png