14
14
15
15
import json
16
16
from pathlib import Path
17
- from typing import Dict , Optional , Text , Union
17
+ from typing import Dict , Text
18
18
19
19
import networkx as nx
20
20
import pandas as pd
@@ -32,12 +32,12 @@ def _populate_graph(
32
32
):
33
33
"""
34
34
Populate Transition Graph.
35
-
35
+
36
36
Insert the nodes and edges in the transition graph with all the
37
37
necessary attributes for the execution of the search and
38
38
recovery operations of paths / trajectories. The required
39
39
parameters are: latitude, longitude and datetime.
40
-
40
+
41
41
Parameters
42
42
----------
43
43
row: Series
@@ -48,7 +48,7 @@ def _populate_graph(
48
48
Attributes of the transition graph edges.
49
49
label_local: str, optional
50
50
Name of the column referring to the trajectories, by default LOCAL_LABEL
51
-
51
+
52
52
Example
53
53
-------
54
54
>>> from pymove.utils.networkx import _populate_graph
@@ -136,21 +136,21 @@ def _populate_graph(
136
136
def build_transition_graph_from_dict (dict_graph : Dict ) -> DiGraph :
137
137
"""
138
138
Built Graph from Dict.
139
-
139
+
140
140
It builds a transition graph from a dictionary
141
141
with nodes and edges and all necessary parameters.
142
142
Example: {'nodes': nodes, 'edges': edges}.
143
-
143
+
144
144
Parameters
145
145
----------
146
146
dict_graph: dict
147
147
Dictionary with the attributes of nodes and edges.
148
-
148
+
149
149
Return
150
150
------
151
151
graph: DiGraph
152
152
Transition graph constructed from trajectory data.
153
-
153
+
154
154
Example
155
155
-------
156
156
>>> from pymove.utils.networkx import build_transition_graph_from_dict
@@ -202,19 +202,19 @@ def build_transition_graph_from_dict(dict_graph: Dict) -> DiGraph:
202
202
def build_transition_graph_from_df (data : DataFrame ) -> DiGraph :
203
203
"""
204
204
Build Graph from data.
205
-
205
+
206
206
Constructs a Transition Graph from trajectory data.
207
-
207
+
208
208
Parameters
209
209
----------
210
210
data: DataFrame
211
211
Trajectory data in sequence format.
212
-
212
+
213
213
Return
214
214
------
215
215
graph: DiGraph
216
216
Transition graph constructed from trajectory data.
217
-
217
+
218
218
Example
219
219
-------
220
220
>>> from pymove.utils.networkx import build_transition_graph_from_df
@@ -241,11 +241,11 @@ def build_transition_graph_from_df(data: DataFrame) -> DiGraph:
241
241
('263', '224'), ('224', '623')])
242
242
>>>
243
243
>>> graph.adj
244
- AdjacencyView({ '85': {'673': {'weight': 1, 'mean_times': '0 days 00:01:09'}},
245
- '673': {'394': {'weight': 1, 'mean_times': '0 days 00:01:32'}},
246
- '263': {'224': {'weight': 1, 'mean_times': '0 days 00:03:33'}},
247
- '224': {'623': {'weight': 1, 'mean_times': '0 days 00:00:21'}},
248
- '623': {'394': {'weight': 1, 'mean_times': '0 days 00:01:30'}},
244
+ AdjacencyView({ '85': {'673': {'weight': 1, 'mean_times': '0 days 00:01:09'}},
245
+ '673': {'394': {'weight': 1, 'mean_times': '0 days 00:01:32'}},
246
+ '263': {'224': {'weight': 1, 'mean_times': '0 days 00:03:33'}},
247
+ '224': {'623': {'weight': 1, 'mean_times': '0 days 00:00:21'}},
248
+ '623': {'394': {'weight': 1, 'mean_times': '0 days 00:01:30'}},
249
249
'394': {}})
250
250
251
251
"""
@@ -264,20 +264,20 @@ def build_transition_graph_from_df(data: DataFrame) -> DiGraph:
264
264
def graph_to_dict (graph : DiGraph ) -> Dict :
265
265
"""
266
266
Graph to Dict.
267
-
267
+
268
268
Converts nodes and edges from the Transition Graph
269
269
with all your attributes in a dictionary.
270
-
270
+
271
271
Parameters
272
272
----------
273
273
graph: DiGraph
274
274
Transition graph constructed from trajectory data.
275
-
275
+
276
276
Return
277
277
------
278
278
dict
279
279
Dictionary with the attributes of nodes and edges.
280
-
280
+
281
281
Example
282
282
-------
283
283
>>> from pymove.utils.networkx import graph_to_dict
@@ -337,17 +337,17 @@ def save_graph_as_json(
337
337
):
338
338
"""
339
339
Save Graph as JSON.
340
-
340
+
341
341
Saves the data extracted from the Transition Graph
342
342
into a JSON file.
343
-
343
+
344
344
Parameters
345
345
----------
346
346
graph: DiGraph
347
347
Transition graph constructed from trajectory data.
348
348
file_path: str or path, optional
349
349
File name that will be saved with transition graph data, by default 'graph.json'.
350
-
350
+
351
351
Example
352
352
-------
353
353
>>> from pymove.utils.networkx import save_graph_as_json
@@ -411,19 +411,19 @@ def save_graph_as_json(
411
411
def read_graph_json (file_path : Path | str ):
412
412
"""
413
413
Read Graph from JSON file.
414
-
414
+
415
415
You load a Transition Graph from a file in JSON format.
416
-
416
+
417
417
Parameters
418
418
----------
419
419
file_path: str or path
420
420
Name of the JSON file to be read
421
-
421
+
422
422
Return
423
423
------
424
424
dict
425
425
Dictionary with the attributes of nodes and edges
426
-
426
+
427
427
Example
428
428
-------
429
429
>>> from pymove.utils.networkx import read_graph_json
@@ -481,4 +481,4 @@ def read_graph_json(file_path: Path | str):
481
481
with open (file_path , 'r' ) as f :
482
482
dict_graph = json .load (f )
483
483
484
- return dict_graph
484
+ return dict_graph
0 commit comments