Skip to content

Commit

Permalink
Converted chapters 4-7. Start on chapter 8.
Browse files Browse the repository at this point in the history
  • Loading branch information
rlabbe committed Aug 5, 2015
1 parent 7093971 commit 47a27c9
Show file tree
Hide file tree
Showing 16 changed files with 3,221 additions and 904 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Expand Up @@ -35,4 +35,9 @@ nosetests.xml
.pydevproject

# Jupiter Notebooks
.ipynb_checkpoints/
.ipynb_checkpoints/

# generated plots
*.eps
*.pdf
*.png
47 changes: 47 additions & 0 deletions code/538.json
@@ -0,0 +1,47 @@
{
"lines.linewidth": 2.0,
"patch.linewidth": 0.5,
"legend.fancybox": true,
"axes.color_cycle": [
"#6d904f",
"#013afe",
"#202020",
"#fc4f30",
"#e5ae38",
"#A60628",
"#30a2da",
"#008080",
"#7A68A6",
"#CF4457",
"#188487",
"#E24A33"
],
"axes.facecolor": "#ffffff",
"axes.labelsize": "large",
"axes.axisbelow": true,
"axes.grid": true,
"patch.edgecolor": "#f0f0f0",
"axes.titlesize": "x-large",
"examples.directory": "",
"figure.facecolor": "#ffffff",
"grid.linestyle": "-",
"grid.linewidth": 2.0,
"grid.color": "#cbcbcb",
"axes.edgecolor":"#f0f0f0",
"xtick.major.size": 0,
"xtick.minor.size": 0,
"ytick.major.size": 0,
"ytick.minor.size": 0,
"axes.linewidth": 3.0,
"font.size":14.0,
"lines.linewidth": 3,
"lines.solid_capstyle": "butt",
"savefig.edgecolor": "#f0f0f0",
"savefig.facecolor": "#f0f0f0",
"figure.subplot.left" : 0.08,
"figure.subplot.right" : 0.95,
"figure.subplot.bottom" : 0.07,
"figure.subplot.hspace" : 0.5,
"legend.scatterpoints" : 1
}

127 changes: 127 additions & 0 deletions code/book_format.py
@@ -0,0 +1,127 @@
# -*- coding: utf-8 -*-

"""Copyright 2015 Roger R Labbe Jr.
Code supporting the book
Kalman and Bayesian Filters in Python
https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
This is licensed under an MIT license. See the LICENSE.txt file
for more information.
"""

from __future__ import (absolute_import, division, print_function,
unicode_literals)

from contextlib import contextmanager
from IPython.core.display import HTML
import json
import matplotlib.pylab as pylab
import matplotlib.pyplot as plt
import numpy as np
import os.path
import sys


sys.path.insert(0, './code') # allow us to import book_format

def test_filterpy_version():
import filterpy
min_version = [0,0,25]
v = filterpy.__version__
tokens = v.split('.')
for i,v in enumerate(tokens):
if int(v) > min_version[i]:
return

i = len(tokens) - 1
if min_version[i] > int(tokens[i]):
raise Exception("Minimum FilterPy version supported is {}.{}.{}.\n"
"Please install a more recent version.\n"
" ex: pip install filterpy --upgrade".format(
*min_version))
v = int(tokens[0]*1000)


# ensure that we have the correct filterpy loaded. This is
# called when this module is imported at the top of each book
# chapter so the reader can see that they need to update FilterPy.
test_filterpy_version()


def equal_axis():
pylab.rcParams['figure.figsize'] = 10,10
plt.axis('equal')


def reset_axis():
pylab.rcParams['figure.figsize'] = 11, 4

def set_figsize(x=11, y=4):
pylab.rcParams['figure.figsize'] = x, y


@contextmanager
def figsize(x=11, y=4):
"""Temporarily set the figure size using 'with figsize(a,b):'"""

size = pylab.rcParams['figure.figsize']
set_figsize(x, y)
yield
pylab.rcParams['figure.figsize'] = size

@contextmanager
def numpy_precision(precision):
old = np.get_printoptions()['precision']
np.set_printoptions(precision=precision)
yield
np.set_printoptions(old)

@contextmanager
def printoptions(*args, **kwargs):
original = np.get_printoptions()
np.set_printoptions(*args, **kwargs)
yield
np.set_printoptions(**original)

def _decode_list(data):
rv = []
for item in data:
if isinstance(item, unicode):
item = item.encode('utf-8')
elif isinstance(item, list):
item = _decode_list(item)
elif isinstance(item, dict):
item = _decode_dict(item)
rv.append(item)
return rv

def _decode_dict(data):
rv = {}
for key, value in data.iteritems():
if isinstance(key, unicode):
key = key.encode('utf-8')
if isinstance(value, unicode):
value = value.encode('utf-8')
elif isinstance(value, list):
value = _decode_list(value)
elif isinstance(value, dict):
value = _decode_dict(value)
rv[key] = value
return rv


def load_style(directory = '.', name='custom.css'):
if sys.version_info[0] >= 3:
s = json.load(open(os.path.join(directory, "538.json")))
else:
s = json.load(open(directory + "538.json"), object_hook=_decode_dict)
plt.rcParams.update(s)
reset_axis ()
np.set_printoptions(suppress=True)

styles = open(os.path.join(directory, name), 'r').read()
return HTML(styles)
4 changes: 3 additions & 1 deletion code/columns.py
@@ -1,3 +1,5 @@
from __future__ import print_function

"""This file contains code related to "Think Stats",
by Allen B. Downey, available from greenteapress.com
Expand Down Expand Up @@ -47,7 +49,7 @@ def print_cols(cols):
cols: list of columns
"""
for i, col in enumerate(cols):
print i, col[0], col[1]
print(i, col[0], col[1])


def make_col_dict(cols, names):
Expand Down

0 comments on commit 47a27c9

Please sign in to comment.