Skip to content

Commit 763dd7d

Browse files
author
pedroccufc
committed
adding examples and updating functions
1 parent b5a4e28 commit 763dd7d

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

pymove/utils/networkx.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import json
1616
from pathlib import Path
17-
from typing import Dict, Optional, Text, Union
17+
from typing import Dict, Text
1818

1919
import networkx as nx
2020
import pandas as pd
@@ -32,12 +32,12 @@ def _populate_graph(
3232
):
3333
"""
3434
Populate Transition Graph.
35-
35+
3636
Insert the nodes and edges in the transition graph with all the
3737
necessary attributes for the execution of the search and
3838
recovery operations of paths / trajectories. The required
3939
parameters are: latitude, longitude and datetime.
40-
40+
4141
Parameters
4242
----------
4343
row: Series
@@ -48,7 +48,7 @@ def _populate_graph(
4848
Attributes of the transition graph edges.
4949
label_local: str, optional
5050
Name of the column referring to the trajectories, by default LOCAL_LABEL
51-
51+
5252
Example
5353
-------
5454
>>> from pymove.utils.networkx import _populate_graph
@@ -136,21 +136,21 @@ def _populate_graph(
136136
def build_transition_graph_from_dict(dict_graph: Dict) -> DiGraph:
137137
"""
138138
Built Graph from Dict.
139-
139+
140140
It builds a transition graph from a dictionary
141141
with nodes and edges and all necessary parameters.
142142
Example: {'nodes': nodes, 'edges': edges}.
143-
143+
144144
Parameters
145145
----------
146146
dict_graph: dict
147147
Dictionary with the attributes of nodes and edges.
148-
148+
149149
Return
150150
------
151151
graph: DiGraph
152152
Transition graph constructed from trajectory data.
153-
153+
154154
Example
155155
-------
156156
>>> from pymove.utils.networkx import build_transition_graph_from_dict
@@ -202,19 +202,19 @@ def build_transition_graph_from_dict(dict_graph: Dict) -> DiGraph:
202202
def build_transition_graph_from_df(data: DataFrame) -> DiGraph:
203203
"""
204204
Build Graph from data.
205-
205+
206206
Constructs a Transition Graph from trajectory data.
207-
207+
208208
Parameters
209209
----------
210210
data: DataFrame
211211
Trajectory data in sequence format.
212-
212+
213213
Return
214214
------
215215
graph: DiGraph
216216
Transition graph constructed from trajectory data.
217-
217+
218218
Example
219219
-------
220220
>>> from pymove.utils.networkx import build_transition_graph_from_df
@@ -241,11 +241,11 @@ def build_transition_graph_from_df(data: DataFrame) -> DiGraph:
241241
('263', '224'), ('224', '623')])
242242
>>>
243243
>>> 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'}},
249249
'394': {}})
250250
251251
"""
@@ -264,20 +264,20 @@ def build_transition_graph_from_df(data: DataFrame) -> DiGraph:
264264
def graph_to_dict(graph: DiGraph) -> Dict:
265265
"""
266266
Graph to Dict.
267-
267+
268268
Converts nodes and edges from the Transition Graph
269269
with all your attributes in a dictionary.
270-
270+
271271
Parameters
272272
----------
273273
graph: DiGraph
274274
Transition graph constructed from trajectory data.
275-
275+
276276
Return
277277
------
278278
dict
279279
Dictionary with the attributes of nodes and edges.
280-
280+
281281
Example
282282
-------
283283
>>> from pymove.utils.networkx import graph_to_dict
@@ -337,17 +337,17 @@ def save_graph_as_json(
337337
):
338338
"""
339339
Save Graph as JSON.
340-
340+
341341
Saves the data extracted from the Transition Graph
342342
into a JSON file.
343-
343+
344344
Parameters
345345
----------
346346
graph: DiGraph
347347
Transition graph constructed from trajectory data.
348348
file_path: str or path, optional
349349
File name that will be saved with transition graph data, by default 'graph.json'.
350-
350+
351351
Example
352352
-------
353353
>>> from pymove.utils.networkx import save_graph_as_json
@@ -411,19 +411,19 @@ def save_graph_as_json(
411411
def read_graph_json(file_path: Path | str):
412412
"""
413413
Read Graph from JSON file.
414-
414+
415415
You load a Transition Graph from a file in JSON format.
416-
416+
417417
Parameters
418418
----------
419419
file_path: str or path
420420
Name of the JSON file to be read
421-
421+
422422
Return
423423
------
424424
dict
425425
Dictionary with the attributes of nodes and edges
426-
426+
427427
Example
428428
-------
429429
>>> from pymove.utils.networkx import read_graph_json
@@ -481,4 +481,4 @@ def read_graph_json(file_path: Path | str):
481481
with open(file_path, 'r') as f:
482482
dict_graph = json.load(f)
483483

484-
return dict_graph
484+
return dict_graph

0 commit comments

Comments
 (0)