This page lists addenda and errata to the First Edition (2012) of the book A Hands-On Introduction to Using Python in the Atmospheric and Oceanic Sciences, by Johnny Wei-Bing Lin. (Note that minor typos are not listed.)
- p. vi:
Change the sentence:
If this is all you want, the first half of the book (Chs.1-6), should be all you need.
toIf this is all you want, the first half of the book (Chs.1-6), plus Ch. 9, should be all you need.
Also add a footnote to the corrected sentence saying:Ch. 9 covers visualization using the matplotlib package. You can use much of matplotlib without knowing anything besides procedural programming, but contour plotting in matplotlib, for AOS applications, makes more sense if you understand the object-oriented framework. This is why I put Ch. 9 in the second half of the book.
(Added Aug 26, 2012.) - p. viii: Instead of distributing the course_files directory by putting a tarball on my website, as the book suggests, I've decided to upload that directory to GitHub. This provides multiple ways of obtaining the files. I've redirected the pertinent URLs in the book to automatically go to the page with instructions on how to download the files. Thus, those online instructions, rather than any implied instructions in the book, should be followed to obtain the files. (Updated Aug 25, 2012.)
- p. 8 (and others):
I didn't realize this when I was writing the book, but if you're using
the Enthought Python Distribution (EPD), whether the free version or
the full version, the ScientificPython package is not included.
(I had assumed ScientificPython
was part of it without checking; sorry about that.)
All the code examples I provide, both in the book and in the
course files, assume you have the ScientificPython package.
Thus, if you use EPD, any code I provide that will access
netCDF files will not run.
One workaround for this issue is to use one of the other options I mention for getting and installing Python (p. 8 and 9). Another workaround is to use the netCDF4 package instead of ScientificPython; the netCDF4 package is part of the full version of EPD (thought not the free version), and has an API very similar to that used in ScientificPython. The changes you need to make to make my code work with the netCDF4 package are to change the import line (e.g., the bottom of p. 81) to:
and instead of using theimport netCDF4 as SNetCDFFileconstructor, use theDatasetconstructor; the example on p. 81 then becomes:
Other occurrences of the import and/orfileobj = S.Dataset('file.nc', mode='r')NetCDFFilecalls would likewise be changed. Finally, the netCDF4 package'sgetValuemethod does not work for arrays (it does, however, work for scalars), unlike ScientificPython'sgetValuemethod which works for both arrays and scalars. In array cases, use array slicing syntax to obtain the data. Thus, on the bottom of p. 81, the example becomes:
This works regardless of the rank of the data. (Array slicing syntax, without callingdata = fileobj.variables['Ts'][:]getValue, also works for arrays in both the ScientificPython and netCDF4 packages.) Once these changes are made in all applicable code samples, the rest of the code in those samples should work. Again, I'm so sorry that I didn't catch this error prior to publication of the book. (First updated Nov 13, 2012. Last revised December 8, 2012.) - p. 48:
In Example 24, the definition of
mylistis incorrect; the line should be:
(Added Feb 4, 2014.)mylist = [[2, 3, -5],[21, -2, 1]] - p. 53:
In the solution to the second problem of Exercise 13, the text
says that
a[1:4,0:2]selects the last two rows and first three columns. It should instead read that it selects the last two rows and the first two columns as a subarray. (Added Oct 8, 2015.) - p. 55–56:
In the second bulleted example on p. 55, the one
that begins "Flatten the array ...", the command should read:
rather thanN.ravel(c)N.ravel(a). This is becauseais already a 1-D array. The output on p. 56 forN.ravel(c)should then read:
(Added Oct 21, 2014. Thanks to Andres Sepulveda!)[ 2. 1. 3. 3.2 22. 1. 5.5 4. 2.1 -6.4 0.1 21. -2.2 5.3 1.1 2.4 -9. -2. ] - p. 60:
Near the bottom of the page, the phrase, "Additionally, the output
array
cis automatically created ..." should be changed to specify the variableproduct_abrather thanc. (Added Oct 21, 2014. Thanks to Andres Sepulveda!) - p. 76:
In the final code block at the bottom of the page, insert:
a = ['3.4', '2.1', '-2.6']after theimport numpy as Nline. (Added Oct 30, 2014. Thanks to Andres Sepulveda for pointing out the issue!) - p. 96:
The tokens
N.skewandN.kurtosisshould readscipy.stats.skewandscipy.stats.kurtosis, an there should be animport scipy.statsline at top. (Added Jan 4, 2015. Thanks to my 2015 AMS Beginner's Python short course for catching the error!) - p. 103: In Exercise 21, question 1, the question should ask to create a "3 row, 4 column" array instead of a "3 column, 4 row" array. (Added Feb 2, 2014.)
- p. 108:
In the
make_authoryearmethod, there should be a space before the parenthesis in line 13 of the Exercise 22, question 2 solution. Thus, line 13 should read:
(Added Feb 2, 2014.)+ ' (' + self.year + ')' - p. 110: "Realizations of an object are called instances," should read, "Realizations of a class are called instances." (Added July 3, 2020.)
- p. 130–137:
In my
Atmosphereclass skeleton, I use araisestatement to catch the absence of the quantities needed to calculate a derived quantity. The way the code is written (on p. 132, lines 12–13 and p. 136, lines 12–13 and 23–24), theraisestatements will actually prevent the method from ever calculating your quantity of interest. The text on p. 134 referring to theraise(the penultimate sentence of the penultimate paragraph) should, accordingly, be deleted.Instead of including the
elsestatements that contain theraisestatements, aniftest should be added for any and all quantities that are primary, and cannot be calculated, and an exception thrown if those primary attributes are undefined. Thus, on p. 132, if pressure is a primary attribute, there should be a separateifstatement (not anelif) testing to see if the attributepexists, and if not, araiseis called, i.e.:if not hasattr(self, 'p'):
raise ValueError, "cannot obtain given initial quantities"