Skip to content

Commit 3fb1199

Browse files
committed
Updated docs and docstrings
1 parent 96017ca commit 3fb1199

4 files changed

Lines changed: 74 additions & 25 deletions

File tree

docs/source/tutorials/tutorials.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ The tutorials below show you how to interact with our standard
1111
:code:`NavData` class and how to run standard baselines all with only a
1212
few lines of code.
1313

14-
NavData Tutorials
14+
NavData Tutorial
1515
---------------------
1616

17-
This tutorial shows how to interact with our standard :code:`NavData`
17+
Sections of this tutorial shows how to interact with our standard :code:`NavData`
1818
class.
1919

2020
.. toctree::
21-
:maxdepth: 1
21+
:maxdepth: 2
2222

2323
tutorials_navdata_notebook
2424

gnss_lib_py/algorithms/fde.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from gnss_lib_py.algorithms.residuals import solve_residuals
1212
from gnss_lib_py.algorithms.snapshot import solve_wls
1313

14+
1415
def solve_fde(navdata, method="residual", remove_outliers=False,
1516
max_faults=None, threshold=None, verbose=False,
1617
**kwargs):
@@ -30,8 +31,9 @@ def solve_fde(navdata, method="residual", remove_outliers=False,
3031
Method for fault detection and exclusion either "residual" for
3132
residual-based or "edm" for Euclidean Distance Matrix-based.
3233
remove_outliers : bool
33-
If true, will remove detected faults from the returned NavData
34-
instance and unknown timesteps (both 1 and 2 fault status).
34+
If `True`, removes measurements with detected faults (fault status 1)
35+
and measurements with unknown fault status (fault status 2)
36+
from the returned NavData instance.
3537
If false, will detect but not exclude faults or unknowns.
3638
max_faults : int
3739
Maximum number of faults to detect and/or exclude.
@@ -44,9 +46,9 @@ def solve_fde(navdata, method="residual", remove_outliers=False,
4446
-------
4547
navdata : gnss_lib_py.parsers.navdata.NavData
4648
Result includes a new row of ``fault_<method>`` where a
47-
value of 1 indicates a detected fault and 0 indicates that
49+
value of 1 indicates a detected fault, 0 indicates that
4850
no fault was detected, and 2 indicates an unknown fault status
49-
usually due to lack of necessary columns or information.
51+
which is usually due to lack of necessary columns or information.
5052
5153
"""
5254

@@ -66,6 +68,7 @@ def solve_fde(navdata, method="residual", remove_outliers=False,
6668

6769
return navdata
6870

71+
6972
def fde_edm(navdata, max_faults=None, threshold=1.0, time_fde=False,
7073
verbose=False):
7174
"""Euclidean distance matrix-based fault detection and exclusion.
@@ -249,6 +252,7 @@ def fde_edm(navdata, max_faults=None, threshold=1.0, time_fde=False,
249252
return navdata, timing_info
250253
return navdata
251254

255+
252256
def fde_greedy_residual(navdata, max_faults, threshold, time_fde=False,
253257
verbose=False):
254258
"""Residual-based fault detection and exclusion.
@@ -331,11 +335,12 @@ def fde_greedy_residual(navdata, max_faults, threshold, time_fde=False,
331335
chi_square = _residual_chi_square(navdata_subset, receiver_state)
332336

333337
if verbose:
334-
print("residual test statistic:",chi_square)
338+
print("chi squared residual test statistic:",chi_square)
335339

336340
# greedy removal if chi_square above detection threshold
337341
while chi_square > threshold:
338-
342+
# stop removing indexes either b/c you need at least four
343+
# satellites or if maximum number of faults has been reached
339344
if len(navdata_subset) < 5 or (max_faults is not None \
340345
and len(fault_idxs) >= max_faults):
341346
break
@@ -353,7 +358,7 @@ def fde_greedy_residual(navdata, max_faults, threshold, time_fde=False,
353358
chi_square = _residual_chi_square(navdata_subset, receiver_state)
354359

355360
if verbose:
356-
print("chi square:",chi_square,"after removing index:",fault_idxs)
361+
print("chi squared:",chi_square,"after removing index:",fault_idxs)
357362

358363
fault_residual_subset = np.array([0] * subset_length)
359364
fault_residual_subset[fault_idxs] = 1
@@ -376,6 +381,7 @@ def fde_greedy_residual(navdata, max_faults, threshold, time_fde=False,
376381
return navdata, timing_info
377382
return navdata
378383

384+
379385
def evaluate_fde(navdata, method, fault_truth_row="fault_gt",
380386
time_fde=False, verbose=False,
381387
**kwargs):
@@ -418,8 +424,7 @@ def evaluate_fde(navdata, method, fault_truth_row="fault_gt",
418424
by the fault the ``fault_truth_row`` variable.
419425
method : string
420426
Method for fault detection and exclusion either "residual" for
421-
residual-based, "ss" for solution separation or "edm" for
422-
Euclidean Distance Matrix-based.
427+
residual-based or "edm" for Euclidean Distance Matrix-based.
423428
fault_truth_row : string
424429
Row that indicates the ground truth for the fault status. This
425430
row is used to provide results on how well each method performs
@@ -570,6 +575,7 @@ def evaluate_fde(navdata, method, fault_truth_row="fault_gt",
570575

571576
return metrics, navdata
572577

578+
573579
def _edm(points):
574580
"""Creates a Euclidean distance matrix (EDM) from point locations.
575581
@@ -601,6 +607,7 @@ def _edm(points):
601607
- 2.*gram + np.ones((dims,1)).dot(np.diag(gram).reshape(1,-1))
602608
return edm
603609

610+
604611
def _edm_from_satellites_ranges(sv_pos, ranges):
605612
"""Creates a Euclidean distance matrix (EDM) from points and ranges.
606613
@@ -640,6 +647,7 @@ def _edm_from_satellites_ranges(sv_pos, ranges):
640647

641648
return edm
642649

650+
643651
def _edm_detection_statistic(edm):
644652
"""Calculate the EDM FDE detection statistic [5]_.
645653
@@ -685,6 +693,7 @@ def _edm_detection_statistic(edm):
685693

686694
return detection_statistic, svd_u, svd_s, svd_v
687695

696+
688697
def _residual_chi_square(navdata, receiver_state):
689698
"""Chi square test for residuals.
690699
@@ -732,6 +741,7 @@ def _residual_chi_square(navdata, receiver_state):
732741

733742
return chi_square
734743

744+
735745
def _residual_exclude(navdata, receiver_state):
736746
"""Detection statistic for Residual-based fault detection.
737747

notebooks/tutorials/fde.ipynb

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@
2323
"navdata = glp.AndroidDerived2022(\"device_gnss.csv\")"
2424
]
2525
},
26+
{
27+
"cell_type": "markdown",
28+
"id": "e0888750",
29+
"metadata": {},
30+
"source": [
31+
"For this demonstration, we limit ourselves to the first time instance. This better shows when more faults are detected and how changing different hyperparameters changes each method's behaviour."
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "32531cac",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"navdata = navdata.where('gps_millis', navdata['gps_millis', 0], 'eq')"
42+
]
43+
},
2644
{
2745
"cell_type": "markdown",
2846
"id": "76ee7e5e",
@@ -88,7 +106,7 @@
88106
"id": "9805d5a9-5138-4588-a0af-3e5649ecef36",
89107
"metadata": {},
90108
"source": [
91-
"You can channge the ``threshold`` variable to be more or less sensitive based on false alarm or missed detection system requirements. Greedy EDM FDE has a range for the threshold between 0 and 1 since the detection statistic is normalized to 1. Note that if the threshold is set to the lower limit of zero, faults are detected until only four measurements remain at each timestep."
109+
"You can change the ``threshold`` variable to be more or less sensitive based on false alarm or missed detection system requirements. Greedy EDM FDE has a range for the threshold between 0 and 1 since the detection statistic is normalized to 1. Note that if the threshold is set to the lower limit of zero, faults are detected until only four measurements remain at each timestep."
92110
]
93111
},
94112
{
@@ -156,9 +174,15 @@
156174
"id": "85df2e4f-0298-4cf6-8184-9cc13361bdfc",
157175
"metadata": {},
158176
"source": [
159-
"This FDE method is based on \"Fast multiple fault exclusion with a large number of measurements.\" by Juan, Blanch, Todd Walter, and Per Enge from the ION GNSS+ 2015 conference."
177+
"This FDE method is based on \"Fast multiple fault exclusion with a large number of measurements.\" by Juan Blanch, Todd Walter, and Per Enge from the ION GNSS+ 2015 conference."
160178
]
161179
},
180+
{
181+
"cell_type": "markdown",
182+
"id": "637b591a",
183+
"metadata": {},
184+
"source": []
185+
},
162186
{
163187
"cell_type": "code",
164188
"execution_count": null,
@@ -236,7 +260,7 @@
236260
"id": "cb756cd0-9382-4991-9ed0-3b41b7482841",
237261
"metadata": {},
238262
"source": [
239-
"Checkout the timing difference between the too methods!"
263+
"You can also compare the two methods based on the time they take."
240264
]
241265
},
242266
{

notebooks/tutorials/navdata.ipynb

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"This tutorial shows how to use the `NavData` class, including how to initialize\n",
8+
"instances and perform basic operations."
9+
]
10+
},
311
{
412
"cell_type": "code",
513
"execution_count": null,
@@ -27,7 +35,14 @@
2735
"cell_type": "markdown",
2836
"metadata": {},
2937
"source": [
30-
"# Initializing"
38+
"# NavData"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {},
44+
"source": [
45+
"## Initializing"
3146
]
3247
},
3348
{
@@ -104,7 +119,7 @@
104119
"cell_type": "markdown",
105120
"metadata": {},
106121
"source": [
107-
"# Accessing values"
122+
"## Accessing values"
108123
]
109124
},
110125
{
@@ -221,7 +236,7 @@
221236
"cell_type": "markdown",
222237
"metadata": {},
223238
"source": [
224-
"# Setting values"
239+
"## Setting values"
225240
]
226241
},
227242
{
@@ -262,7 +277,7 @@
262277
"cell_type": "markdown",
263278
"metadata": {},
264279
"source": [
265-
"# Setting new row"
280+
"## Setting new row"
266281
]
267282
},
268283
{
@@ -306,7 +321,7 @@
306321
"cell_type": "markdown",
307322
"metadata": {},
308323
"source": [
309-
"# Adding new columns"
324+
"## Adding new columns"
310325
]
311326
},
312327
{
@@ -348,7 +363,7 @@
348363
"cell_type": "markdown",
349364
"metadata": {},
350365
"source": [
351-
"# Find rows, shape and length"
366+
"## Find rows, shape and length"
352367
]
353368
},
354369
{
@@ -390,7 +405,7 @@
390405
"cell_type": "markdown",
391406
"metadata": {},
392407
"source": [
393-
"# Removing rows or columns"
408+
"## Removing rows or columns"
394409
]
395410
},
396411
{
@@ -425,7 +440,7 @@
425440
"cell_type": "markdown",
426441
"metadata": {},
427442
"source": [
428-
"# Copy"
443+
"## Copy"
429444
]
430445
},
431446
{
@@ -474,7 +489,7 @@
474489
"cell_type": "markdown",
475490
"metadata": {},
476491
"source": [
477-
"# Convert to `pd.DataFrame` and save to csv"
492+
"## Convert to `pd.DataFrame` and save to csv"
478493
]
479494
},
480495
{
@@ -497,7 +512,7 @@
497512
"cell_type": "markdown",
498513
"metadata": {},
499514
"source": [
500-
"# Looping"
515+
"## Looping"
501516
]
502517
},
503518
{

0 commit comments

Comments
 (0)