PX4 / flight_review

web application for flight log analysis & review
https://logs.px4.io/
BSD 3-Clause "New" or "Revised" License
204 stars 196 forks source link

bug: map projections with nan values #138

Open mrpollo opened 6 years ago

mrpollo commented 6 years ago

In plot_app/helper.py#227-229

Consider the following conditionals

    arg = sin_anchor_lat * sin_lat + cos_anchor_lat * cos_lat * cos_d_lon
    arg[arg > 1] = 1
    arg[arg < -1] = -1

for the following example value of arg of type Numpy.Array

array([-0.0488, -0.042 ,  1.    ,  1.    ,  1.    ,     nan,  1.    ,
        1.    ])

Looks like we either filter nan values or learn how to deal with them

Errors:

flight_review/plot_app/helper.py:229: RuntimeWarning: invalid value encountered in greater
  arg[arg > 1] = 1
flight_review/plot_app/helper.py:230: RuntimeWarning: invalid value encountered in less
  arg[arg < -1] = -1
bkueng commented 6 years ago

Probably filtering them out is best.

mrpollo commented 6 years ago

I wasn't sure if that was feasible, I don't think I grasp 100% of the math here, and I wasn't sure if filtering out NaN would even be a problem.

I'll submit a PR shortly.

mrpollo commented 6 years ago

Tried filtering but I noticed setpoints on maps are not displayed correctly with the following change

+    a = sin_anchor_lat * sin_lat + cos_anchor_lat * cos_lat * cos_d_lon
+    arg = np.array([index for index in a if np.isfinite(index)])

Any ideas?

with filter screenshot 2018-11-05 11 25 10

no filter screenshot 2018-11-05 11 24 04

mrpollo commented 6 years ago

Not sure if this is related, but the following plots show NaN regardless of this change

screenshot 2018-11-05 11 26 13 screenshot 2018-11-05 11 25 58

bkueng commented 6 years ago

Can you provide the log(s)? It should not contain NaNs.

mrpollo commented 6 years ago

I randomly picked a log out of logs.px4.io/browse, I lost track of which one it was and since I'm not the original author I won't be re-uploading it to the site, instead here's a link to download that will probably remain available for a few weeks (sorry if you are reading this and the file is no longer available)

bkueng commented 6 years ago

Thanks, I'll have a look. Log is here btw (the ID was still in the filename): https://logs.px4.io/plot_app?log=ba165f7d-113d-4c5d-b479-1fcf21e99175

bkueng commented 6 years ago

For the lat, lon issue, you need to filter earlier, like this:

diff --git a/plot_app/helper.py b/plot_app/helper.py
index c2018eb..a26184c 100644
--- a/plot_app/helper.py
+++ b/plot_app/helper.py
@@ -218,6 +218,11 @@ def WGS84_to_mercator(lon, lat):

 def map_projection(lat, lon, anchor_lat, anchor_lon):
     """ convert lat, lon in [rad] to x, y in [m] with an anchor position """
+
+    # filter NaN values
+    lat = lat[~np.isnan(lat)]
+    lon = lon[~np.isnan(lon)]
+
     sin_lat = np.sin(lat)
     cos_lat = np.cos(lat)
     cos_d_lon = np.cos(lon - anchor_lon)

The NaN's in attitude are valid and fixed in https://github.com/PX4/flight_review/pull/140.