Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
EKF pytest save plots to pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
dagar committed May 4, 2018
1 parent d6a3110 commit 372f9f4
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.DS_Store
*~
.cache/
.pytest_cache/
build/
EKF/tests/pytest/__pycache__/
8 changes: 6 additions & 2 deletions EKF/tests/pytest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,31 @@ 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
)

# requires python3-tk
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
)

Expand Down
27 changes: 18 additions & 9 deletions EKF/tests/pytest/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,26 @@
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
Expand All @@ -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()
1 change: 0 additions & 1 deletion EKF/tests/pytest/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pipeline {
sh 'make distclean'
sh 'make test_EKF'
sh 'ccache -s'
archiveArtifacts(artifacts: 'build/**/*.pdf')
sh 'make distclean'
}
}
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
# --------------------------------------------------------------------
Expand Down

0 comments on commit 372f9f4

Please sign in to comment.