mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 20:33:34 +08:00
EKF pytest save plots to pdf
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
*.DS_Store
|
*.DS_Store
|
||||||
*~
|
*~
|
||||||
.cache/
|
.cache/
|
||||||
|
.pytest_cache/
|
||||||
build/
|
build/
|
||||||
EKF/tests/pytest/__pycache__/
|
EKF/tests/pytest/__pycache__/
|
||||||
|
|||||||
@@ -36,20 +36,23 @@ if(EKF_PYTHON_TESTS)
|
|||||||
# pip3 install -r requirements.txt
|
# pip3 install -r requirements.txt
|
||||||
|
|
||||||
add_custom_target(ecl_EKF_pytest
|
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
|
DEPENDS ecl_EKF _ecl_EKF
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(ecl_EKF_pytest-quick
|
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
|
DEPENDS ecl_EKF _ecl_EKF
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(ecl_EKF_pytest-benchmark
|
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
|
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
|
DEPENDS ecl_EKF _ecl_EKF
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,6 +60,7 @@ if(EKF_PYTHON_TESTS)
|
|||||||
add_custom_target(ecl_EKF_pytest-plots
|
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
|
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
|
DEPENDS ecl_EKF _ecl_EKF
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
USES_TERMINAL
|
USES_TERMINAL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -44,18 +44,26 @@ import inspect
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from matplotlib import pyplot as plt
|
# matplotlib don't use Xwindows backend (must be before pyplot import)
|
||||||
import seaborn as sns
|
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:
|
except ImportError as err:
|
||||||
print("Cannot import plotting libraries, "
|
print("Cannot import plotting libraries, "
|
||||||
"please install matplotlib and seaborn.")
|
"please install matplotlib.")
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
# Nice plot defaults
|
# Nice plot defaults
|
||||||
sns.set_style('darkgrid')
|
#sns.set_style('darkgrid')
|
||||||
sns.set_palette('colorblind',
|
#sns.set_palette('colorblind', desat=0.6)
|
||||||
desat=0.6)
|
|
||||||
|
|
||||||
|
pp = PdfPages("ecl_EKF_test.pdf")
|
||||||
|
|
||||||
def quit_figure_on_key(key, fig=None):
|
def quit_figure_on_key(key, fig=None):
|
||||||
"""Add handler to figure (defaults to current figure) that closes it
|
"""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
|
# Get name of function calling the context from the stack
|
||||||
name = inspect.stack()[2][3]
|
name = inspect.stack()[2][3]
|
||||||
fig, axes = plt.subplots(*subplots, figsize=figsize)
|
fig, axes = plt.subplots(*subplots, figsize=figsize)
|
||||||
fig.canvas.set_window_title(name)
|
#fig.canvas.set_window_title(name)
|
||||||
quit_figure_on_key('q', fig)
|
#quit_figure_on_key('q', fig)
|
||||||
yield fig, axes
|
yield fig, axes
|
||||||
if params is not None:
|
if params is not None:
|
||||||
name += "\n" + repr(params)
|
name += "\n" + repr(params)
|
||||||
axes[0].set_title(name)
|
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
|
hypothesis>=3.17.0
|
||||||
numpy>=1.12.1
|
numpy>=1.12.1
|
||||||
matplotlib>=2.0.0
|
matplotlib>=2.0.0
|
||||||
seaborn>=0.7.1
|
|
||||||
pytest-benchmark>=3.1.1
|
pytest-benchmark>=3.1.1
|
||||||
|
|||||||
Vendored
+1
@@ -84,6 +84,7 @@ pipeline {
|
|||||||
sh 'make distclean'
|
sh 'make distclean'
|
||||||
sh 'make test_EKF'
|
sh 'make test_EKF'
|
||||||
sh 'ccache -s'
|
sh 'ccache -s'
|
||||||
|
archiveArtifacts(artifacts: 'build/**/*.pdf')
|
||||||
sh 'make distclean'
|
sh 'make distclean'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ test: test_build
|
|||||||
test_EKF: test_build
|
test_EKF: test_build
|
||||||
@cmake --build $(SRC_DIR)/build/test_build --target ecl_EKF_pytest-quick
|
@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
|
# Cleanup
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
.PHONY: clean distclean
|
.PHONY: clean distclean
|
||||||
|
|||||||
Reference in New Issue
Block a user