mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-02 05:04:08 +08:00
EKF pytest save plots to pdf
This commit is contained in:
parent
d6a3110918
commit
372f9f430b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
*.DS_Store
|
||||
*~
|
||||
.cache/
|
||||
.pytest_cache/
|
||||
build/
|
||||
EKF/tests/pytest/__pycache__/
|
||||
|
||||
@ -36,20 +36,23 @@ if(EKF_PYTHON_TESTS)
|
||||
# pip3 install -r requirements.txt
|
||||
|
||||
add_custom_target(ecl_EKF_pytest
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --verbose
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --verbose --plots
|
||||
DEPENDS ecl_EKF _ecl_EKF
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
add_custom_target(ecl_EKF_pytest-quick
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --quick --verbose
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --quick --verbose --plots
|
||||
DEPENDS ecl_EKF _ecl_EKF
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
add_custom_target(ecl_EKF_pytest-benchmark
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --benchmark
|
||||
DEPENDS ecl_EKF _ecl_EKF
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
@ -57,6 +60,7 @@ if(EKF_PYTHON_TESTS)
|
||||
add_custom_target(ecl_EKF_pytest-plots
|
||||
COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/EKF/swig/python ${CMAKE_CURRENT_SOURCE_DIR}/ekf_test.py --plots
|
||||
DEPENDS ecl_EKF _ecl_EKF
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
USES_TERMINAL
|
||||
)
|
||||
|
||||
|
||||
@ -44,18 +44,26 @@ import inspect
|
||||
from contextlib import contextmanager
|
||||
|
||||
try:
|
||||
from matplotlib import pyplot as plt
|
||||
import seaborn as sns
|
||||
# matplotlib don't use Xwindows backend (must be before pyplot import)
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.backends.backend_pdf import PdfPages
|
||||
|
||||
#from matplotlib import pyplot as plt
|
||||
#from matplotlib.backends.backend_pdf import PdfPages
|
||||
#import seaborn as sns
|
||||
except ImportError as err:
|
||||
print("Cannot import plotting libraries, "
|
||||
"please install matplotlib and seaborn.")
|
||||
"please install matplotlib.")
|
||||
raise err
|
||||
|
||||
# Nice plot defaults
|
||||
sns.set_style('darkgrid')
|
||||
sns.set_palette('colorblind',
|
||||
desat=0.6)
|
||||
#sns.set_style('darkgrid')
|
||||
#sns.set_palette('colorblind', desat=0.6)
|
||||
|
||||
pp = PdfPages("ecl_EKF_test.pdf")
|
||||
|
||||
def quit_figure_on_key(key, fig=None):
|
||||
"""Add handler to figure (defaults to current figure) that closes it
|
||||
@ -82,10 +90,11 @@ def figure(name=None, params=None, figsize=None, subplots=None):
|
||||
# Get name of function calling the context from the stack
|
||||
name = inspect.stack()[2][3]
|
||||
fig, axes = plt.subplots(*subplots, figsize=figsize)
|
||||
fig.canvas.set_window_title(name)
|
||||
quit_figure_on_key('q', fig)
|
||||
#fig.canvas.set_window_title(name)
|
||||
#quit_figure_on_key('q', fig)
|
||||
yield fig, axes
|
||||
if params is not None:
|
||||
name += "\n" + repr(params)
|
||||
axes[0].set_title(name)
|
||||
plt.show(True)
|
||||
#plt.show(True)
|
||||
pp.savefig()
|
||||
|
||||
@ -2,5 +2,4 @@ pytest>=3.2.1
|
||||
hypothesis>=3.17.0
|
||||
numpy>=1.12.1
|
||||
matplotlib>=2.0.0
|
||||
seaborn>=0.7.1
|
||||
pytest-benchmark>=3.1.1
|
||||
|
||||
1
Jenkinsfile
vendored
1
Jenkinsfile
vendored
@ -84,6 +84,7 @@ pipeline {
|
||||
sh 'make distclean'
|
||||
sh 'make test_EKF'
|
||||
sh 'ccache -s'
|
||||
archiveArtifacts(artifacts: 'build/**/*.pdf')
|
||||
sh 'make distclean'
|
||||
}
|
||||
}
|
||||
|
||||
3
Makefile
3
Makefile
@ -99,6 +99,9 @@ test: test_build
|
||||
|
||||
test_EKF: test_build
|
||||
@cmake --build $(SRC_DIR)/build/test_build --target ecl_EKF_pytest-quick
|
||||
|
||||
test_EKF_plots: test_build
|
||||
@cmake --build $(SRC_DIR)/build/test_build --target ecl_EKF_pytest-plots
|
||||
|
||||
# Cleanup
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user