Playing with html generation

I think I prefer just letting nbconvert generating static files,
but if I want to switch to using Bokeh or other javascript based
rendering I'll need the HTML conversion facility.
This commit is contained in:
Roger Labbe 2015-03-07 22:41:39 -08:00
parent c258dd12f6
commit 0343c45445
5 changed files with 246 additions and 27 deletions

49
pdf/build_html_ipynb.py Normal file
View File

@ -0,0 +1,49 @@
from __future__ import print_function
import IPython.nbformat as nbformat
from formatting import *
def prep_for_html_conversion(filename):
added_appendix = False
with io.open('../'+filename, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, nbformat.NO_CONVERT)
remove_formatting(nb)
if not added_appendix and filename[0:8] == 'Appendix':
remove_links_add_appendix(nb)
added_appendix = True
else:
remove_links(nb)
nbformat.write(nb, filename)
if __name__ == '__main__':
notebooks = \
['00_Preface.ipynb',
'01_g-h_filter.ipynb',
'Appendix_A_Installation.ipynb']
for n in notebooks:
prep_for_html_conversion(n)
'''merge_notebooks(
['../00_Preface.ipynb',
'../01_g-h_filter.ipynb',
'../02_Discrete_Bayes.ipynb',
'../03_Least_Squares_Filters.ipynb',
'../04_Gaussians.ipynb',
'../05_Kalman_Filters.ipynb',
'../06_Multivariate_Kalman_Filters.ipynb',
'../07_Kalman_Filter_Math.ipynb',
'../08_Designing_Kalman_Filters.ipynb',
'../09_Nonlinear_Filtering.ipynb',
'../10_Unscented_Kalman_Filter.ipynb',
'../11_Extended_Kalman_Filters.ipynb',
'../12_Designing_Nonlinear_Kalman_Filters.ipynb',
'../13_Smoothing.ipynb',
'../14_Adaptive_Filtering.ipynb',
'../15_HInfinity_Filters.ipynb',
'../16_Ensemble_Kalman_Filters.ipynb',
'../Appendix_A_Installation.ipynb',
'../Appendix_B_Symbols_and_Notations.ipynb'])'''

31
pdf/formatting.py Normal file
View File

@ -0,0 +1,31 @@
from __future__ import print_function
import io
import IPython.nbformat as nbformat
import sys
def remove_formatting(nb):
cells = nb['cells']
for i in range (len(cells)):
if 'source' in cells[i].keys():
if cells[i]['source'][0:16] == '#format the book':
del cells[i]
return
def remove_links(nb):
c = nb['cells']
for i in range (len(c)):
if 'source' in c[i].keys():
if c[i]['source'][0:19] == '[Table of Contents]':
del c[i]
return
def remove_links_add_appendix(nb):
c = nb['cells']
for i in range (len(c)):
if 'source' in c[i].keys():
if c[i]['source'][0:19] == '[Table of Contents]':
c[i]['source'] = '\\appendix'
return

22
pdf/html_build_book Executable file
View File

@ -0,0 +1,22 @@
ipython build_html_ipynb.py
ipython nbconvert index.ipynb
ipython nbconvert ../00_Preface.ipynb
ipython nbconvert ../01_g-h_filter.ipynb
ipython nbconvert ../02_Discrete_Bayes.ipynb
ipython nbconvert ../03_Least_Squares_Filters.ipynb
ipython nbconvert ../04_Gaussians.ipynb
ipython nbconvert ../05_Kalman_Filters.ipynb
ipython nbconvert ../06_Multivariate_Kalman_Filters.ipynb
ipython nbconvert ../07_Kalman_Filter_Math.ipynb
ipython nbconvert ../08_Designing_Kalman_Filters.ipynb
ipython nbconvert ../09_Nonlinear_Filtering.ipynb
ipython nbconvert ../10_Unscented_Kalman_Filter.ipynb
ipython nbconvert ../11_Extended_Kalman_Filters.ipynb
ipython nbconvert ../12_Designing_Nonlinear_Kalman_Filters.ipynb
ipython nbconvert ../13_Smoothing.ipynb
ipython nbconvert ../14_Adaptive_Filtering.ipynb
ipython nbconvert ../15_HInfinity_Filters.ipynb
ipython nbconvert ../16_Ensemble_Kalman_Filters.ipynb
ipython nbconvert ../Appendix_A_Installation.ipynb
ipython nbconvert ../Appendix_B_Symbols_and_Notations.ipynb

143
pdf/index.ipynb Normal file
View File

@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center><h1>Kalman and Bayesian Filters in Python</h1></center>\n",
"<p>\n",
" <p>\n",
"Table of Contents\n",
"-----\n",
"\n",
"[**Preface**](00_Preface.html)\n",
" \n",
"Motivation behind writing the book. How to download and read the book. Requirements for IPython Notebook and Python. github links.\n",
"\n",
"\n",
"[**Chapter 1: The g-h Filter**](01_g-h_filter.html)\n",
"\n",
"Intuitive introduction to the g-h filter, which is a family of filters that includes the Kalman filter. Not filler - once you understand this chapter you will understand the concepts behind the Kalman filter. \n",
"\n",
"\n",
"[**Chapter 2: The Discrete Bayes Filter**](02_Discrete_Bayes.html)\n",
"\n",
"Introduces the Discrete Bayes Filter. From this you will learn the probabilistic reasoning that underpins the Kalman filter in an easy to digest form.\n",
"\n",
"\n",
"[**Chapter 3: Least Squares Filter**](03_Least_Squares_Filters.html)\n",
"\n",
"Introduces the least squares filter in batch and recursive forms. I've not made a start on authoring this yet.\n",
"\n",
"\n",
"[**Chapter 4: Gaussian Probabilities**](04_Gaussians.html)\n",
"\n",
"Introduces using Gaussians to represent beliefs in the Bayesian sense. Gaussians allow us to implement the algorithms used in the Discrete Bayes Filter to work in continuous domains.\n",
"\n",
"\n",
"[**Chapter 5: One Dimensional Kalman Filters**](05_Kalman_Filters.html)\n",
"\n",
"Implements a Kalman filter by modifying the Discrete Bayesian Filter to use Gaussians. This is a full featured Kalman filter, albeit only useful for 1D problems. \n",
"\n",
"\n",
"[**Chapter 6: Multivariate Kalman Filter**](/06_Multivariate_Kalman_Filters.html)\n",
"\n",
"We extend the Kalman filter developed in the previous chapter to the full, generalized filter. \n",
"\n",
"\n",
"[**Chapter 7: Kalman Filter Math**](07_Kalman_Filter_Math.html)\n",
"\n",
"We gotten about as far as we can without forming a strong mathematical foundation. This chapter is optional, especially the first time, but if you intend to write robust, numerically stable filters, or to read the literature, you will need to know this. \n",
"\n",
"*This still needs a lot of work. *\n",
"\n",
"\n",
"[**Chapter 8: Designing Kalman Filters**](08_Designing_Kalman_Filters.html)\n",
"\n",
"Building on material in Chapter 6, walks you through the design of several Kalman filters. Discusses, but does not solve issues like numerical stability.\n",
"\n",
"\n",
"[**Chapter 9: Nonlinear Filtering**](09_Nonlinear_Filtering.html)\n",
"\n",
"Kalman filter as covered only work for linear problems. Here I introduce the problems that nonlinear systems pose to the filter, and briefly discuss the various algorithms that we will be learning in subsequent chapters which work with nonlinear systems.\n",
"\n",
"\n",
"[**Chapter 10: Unscented Kalman Filters**](10_Unscented_Kalman_Filter.html)\n",
"\n",
"Unscented Kalman filters (UKF) are a recent development in Kalman filter theory. They allow you to filter nonlinear problems without requiring a closed form solution like the Extended Kalman filter requires.\n",
"\n",
"\n",
"[**Chapter 11: Extended Kalman Filters**](11_Extended_Kalman_Filters.html)\n",
"\n",
"Kalman filter as covered only work for linear problems. Extended Kalman filters (EKF) are the most common approach to linearizing non-linear problems.\n",
"\n",
"*Still very early going on this chapter.*\n",
"\n",
"\n",
"[**Chapter 12: Designing Nonlinear Kalman Filters**](12_Designing_Nonlinear_Kalman_Filters.html)\n",
"\n",
"Works through some examples of the design of Kalman filters for nonlinear problems. *This is still very much a work in progress.*\n",
"\n",
"\n",
"[**Chapter 13: Smoothing**](13_Smoothing.html)\n",
"\n",
"Kalman filters are recursive, and thus very suitable for real time filtering. However, they work well for post-processing data. We discuss some common approaches.\n",
"\n",
"\n",
"[**Chapter 14: Adaptive Filtering**](14_Adaptive_Filtering.html)\n",
" \n",
"Kalman filters assume a single process model, but manuevering targets typically need to be described by several different process models. Adaptive filtering uses several techniques to allow the Kalman filter to adapt to the changing behavior of the target.\n",
"\n",
"\n",
"[**Chapter 15: H-Infinity Filters**](15_HInfinity_Filters.html)\n",
" \n",
"Describes the $H_\\infty$ filter. \n",
"\n",
"*I have code that implements the filter, but no supporting text yet.*\n",
"\n",
"\n",
"[**Chapter 16: Ensemble Kalman Filters**](16_Ensemble_Kalman_Filters.html)\n",
"\n",
"Discusses the ensemble Kalman Filter, which uses a Monte Carlo approach to deal with very large Kalman filter states in nonlinear systems.\n",
"\n",
"\n",
"[**Appendix: Installation, Python, NumPy, and filterpy**](Appendix_A_Installation.html)\n",
"\n",
"Brief introduction of Python and how it is used in this book. Description of the companion\n",
"library filterpy. \n",
" \n",
"\n",
"[**Appendix: Symbols and Notations**](Appendix_B_Symbols_and_Notations.html)\n",
"\n",
"Symbols and notations used in this book. Comparison with notations used in the literature.\n",
"\n",
"*Still just a collection of notes at this point.*\n",
"\n",
"\n",
"### Github repository\n",
"http://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -2,33 +2,7 @@ from __future__ import print_function
import io
import IPython.nbformat as nbformat
import sys
def remove_formatting(nb):
cells = nb['cells']
for i in range (len(cells)):
if 'source' in cells[i].keys():
if cells[i]['source'][0:16] == '#format the book':
del cells[i]
return
def remove_links(nb):
c = nb['cells']
for i in range (len(c)):
if 'source' in c[i].keys():
if c[i]['source'][0:19] == '[Table of Contents]':
del c[i]
return
def remove_links_add_appendix(nb):
c = nb['cells']
for i in range (len(c)):
if 'source' in c[i].keys():
if c[i]['source'][0:19] == '[Table of Contents]':
c[i]['source'] = '\\appendix'
return
from formatting import *
def merge_notebooks(filenames):