Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 3D plotting option to Plotterly #932

Merged
merged 6 commits into from
Feb 12, 2024
Merged

Add 3D plotting option to Plotterly #932

merged 6 commits into from
Feb 12, 2024

Conversation

mharris-dstl
Copy link
Contributor

This PR gives the option of plotting in 3D using Plotterly. It also adds more tests and makes dimension checking in Plotterly more holistic. More details are:

  • Plotting is now supported in 3D for ground truth, measurements, and tracks. Sensor plotting is not here but no reason why it can't be added in the future.
  • Dimension checking has been simplified so that integers can always be used in cases like if self.dimension == 1:
  • Track uncertainty has been added in the way of error bars in the x, y, and z direction, as suggested by @Carlson-J here. It is not perfect because it does not show times where covariance is large, but it's a simple way of getting an idea of track uncertainty. It makes use of scatterplot3d's error arguments - making custom error bars that plot the eigenvectors would require significant effort to implement. Unfortunately, I think a bug in Plotly means 3d error bars are fixed at 1 pixel wide, so they are quite hard to see. I think it's still better than not having them, but the functionality can be removed from this PR if desired. See the pictures below:

image

@mharris-dstl mharris-dstl requested a review from a team as a code owner January 15, 2024 16:28
@mharris-dstl mharris-dstl requested review from nperree-dstl, spike-dstl and gawebb-dstl and removed request for a team January 15, 2024 16:28
@gawebb-dstl
Copy link
Contributor

Code changes look good from reading them. I'll try using the new code soon

Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: 11 lines in your changes are missing coverage. Please review.

Comparison is base (0a0f43b) 93.23% compared to head (6e8eadb) 93.40%.
Report is 23 commits behind head on main.

Files Patch % Lines
stonesoup/plotter.py 79.24% 3 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #932      +/-   ##
==========================================
+ Coverage   93.23%   93.40%   +0.17%     
==========================================
  Files         200      200              
  Lines       12516    12538      +22     
  Branches     2580     2591      +11     
==========================================
+ Hits        11669    11711      +42     
+ Misses        595      585      -10     
+ Partials      252      242      -10     
Flag Coverage Δ
integration 67.03% <22.64%> (-0.03%) ⬇️
unittests 88.84% <77.35%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@spike-dstl spike-dstl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and runs well. Couple comments that you may wish to think about but no issues. Looks good on the track-stitching example:
image

stonesoup/plotter.py Outdated Show resolved Hide resolved
Comment on lines +1019 to +1021
elif len(mapping) != self.dimension:
raise TypeError("Plotter dimension is not same as the mapping dimension.")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original logic allowed the number of mapping dimensions to be greater than the number of plotter dimensions. Both methods appear to be valid, and throwing an error rather than a warning is arguably more sensible. Nonetheless, I believe the following represents the original logic. Thought this was worth flagging, but feel free to mark as resolved.

Suggested change
elif len(mapping) != self.dimension:
raise TypeError("Plotter dimension is not same as the mapping dimension.")
elif len(mapping) < self.dimension:
raise TypeError("Plotter dimension is larger than the mapping dimension.")
elif len(mapping) > self.dimension:
warnings.warn("Mapping has length greater than plotter dimension. Additional mapping indices are ignored")

track_colors[track] = (self.fig.data[-1].line.color
or self.fig.data[-1].marker.color
or self.get_next_color())

if uncertainty:
# earlier checking means this only applies to 2D.
if uncertainty and self.dimension == 2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, does it make more sense to move the checks for particle and uncertainty within the "dimension == 2" block / move the other dimensions checks out here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitant to do that because the dimension==2 line sits within a for-loop that goes through each track whereas uncertainty plotting is outside that. The current implementation plots all the tracks at once and then all the uncertainty at once. My worry is that changing the logic order to track, uncertainty for track, track2, uncertainty for track2, etc. may cause some unintended consequences. It's probably fine but I haven't tried it.

Copy link
Contributor

@gawebb-dstl gawebb-dstl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good to me. A good addition to the stone-soup plotting library.

You could change the plotting examples/MTT_3D_Platform.py to use Plotterly instead of Plotter.

@sdhiscocks sdhiscocks merged commit b018512 into main Feb 12, 2024
9 of 10 checks passed
@sdhiscocks sdhiscocks deleted the plotterly3d branch February 12, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants