Skip to main content

A Few Updates

We have been busy working on A Student’s Guide to Python for Physical Modeling this summer. We are preparing an updated edition for Winter of 2018. We wanted to take this opportunity to alert readers to a few items that have changed since the publication of the first edition, back in 2015.

Python 3.6

The “latest version” of any software package is a moving target, and putting a version number in print ensures that it will be outdated at some point in the future. In the first edition, we used Python 3.4. The latest stable release of Python is version 3.6, and Python 3.7 is under development. Happily, all of the code samples in the book run with Python 3.6.

One change that came with Python 3.5 may be of interest to scientific programmers. Python introduced a new operator for matrix multiplication: the “@” symbol. NumPy recognizes this operator, and it can be used as shorthand for the np.dot() function. This may allow you to write simpler, more intuitive code, which usually leads to fewer errors.

x = np.random.random(3)
M = np.random.random((3,3))

x @ M == np.dot(x,M)
M @ x == np.dot(M,x)

If you want to explore the latest changes to Python, you can read about what’s new.

Goodbye, Continuum. Hello, Anaconda, Inc.

Continuum Analytics is no more. The company has changed its name to Anaconda, Inc. One significant result of this decision is that many of the Web links in the first edition — Appendix A (Installation) in particular — may no longer work in the future.

The new home page of Anaconda is now anaconda.com. This is where you can download the Anaconda distribution of Python and find all of the official Anaconda documentation. The old continuum.io links in the first edition will probably continue to work for some time, but if you find a broken link, you may need to search for the relevant material at anaconda.com instead.

The Anaconda distribution has evolved over time. Some of the instructions in Appendix A of the first edition for command line installation with the conda package manager are now unnecessary:

  • The Anaconda distribution now includes the mkl package by default.

  • The accelerate package has evolved into something beyond the scope of our book. You can read about it here.

  • Installing spyder with Miniconda is now even simpler. As of August 2017, we found no missing packages when installing spyder with the conda package manager. There is no need to install jinja2, docutils, or pyflakes separately.

Errata

Since publication of A Student’s Guide to Python for Physical Modeling, we have discovered a few errors. We have recently updated the Errata on this Web site. Happily, the list is short. All of these will be corrected in the upcoming revised edition. Thanks to all of the alert readers who brought these to our attention!

Updated Edition

Some readers may be wondering what will be changed in the updated edition. We did not feel the changes were substantial enough to justify calling the work a “second edition,” but we did put a lot of work into improving the text:

  • We corrected all known errors.

  • We made many changes merely to bring the content of the book up to date with the constantly changing content of the World Wide Web and open-source software packages.

  • We added an introduction to Jupyter notebooks. Our blog post provided an outline for the new material.

  • We added a discussion of 2D histograms.

  • We added a discussion of displaying data as images with plt.imshow.

Much of our effort went into reorganizing and rewriting the original material so that that it will be clearer and easier to follow. We hope that anyone who reads the two editions side by side will find much that is improved, even if there is not a lot that is new.

Comments

Popular posts from this blog

Paths in Python

How do you get your Python interpreter to find modules that are not located in your current working directory? The answer is … you tell it where to look. When you type something like from my_module import my_function Python searches a collection of directories (i.e., folders) on your computer. If the directory containing <my_module.py> is not in this collection, you will receive an ImportError . This can be frustrating if you know the file exists, and even more so if you know where it exists. In this post, we will take a brief look at how to add paths to the collection of directories searched by Python. Paths A path is essentially a set of directions to a file: /Users/username/modules/my_module.py [Mac OS X, Linux] C:\modules\my_module.py [Windows] It tells your operating system how to navigate from a fixed starting point — the “root directory” / in Unix-based systems, or C:\ in Windows — through a collection of folders to the de

Illuminating Surface Plots

Matplotlib provides functions for visualizing three-dimensional data sets. One useful tool is a surface plot. A surface plot is a two-dimensional projection of a three-dimensional object. Much like a sketch artist, Python uses techniques like perspective and shading to give the illusion of a three-dimensional object in space. In this post, I describe how you can control the lighting of a surface plot. Surface Plots First, let’s look at some of the options available with the default three-dimensional plotting tools. This script will create a surface plot of a Bessel function. Its ripples will emphasize the effects of lighting later. import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Import 3D plotting tools. from scipy.special import jn # Import Bessel function. # Define grid of points. points = np.linspace(-10, 10, 51) X, Y = np.meshgrid(points, points) R = np.sqrt(X**2 + Y**2) Z = jn(0,R) # Create 3D surface plo

Raising a Figure Window to the Foreground

This post describes a utility function that will raise a plot window to the foreground of your screen. The function will only work with the Qt graphics backend, so I will start with a brief overview of graphics backends. If you just want to use the function as a black box, you can do the following: Set the Graphics Backend to “Qt” in the Spyder preferences menu. Copy this function into your working directory. Graphics Backends You may have have written a script to produce precisely the data you need, but a lot of processing is required to transform these numbers into a figure. You need to create a plot window, draw a figure inside of it, and manage all of the attributes that control a figure’s appearance: title, axis labels, line widths, colors, tick marks, etc. All of this happens in the background when you type a command like plt.plot(x,y) . A graphics backend is the software that Python uses to physically draw a figure on your computer screen. If you have already import