100% found this document useful (4 votes)
71 views69 pages

Introduction To Python For Science and Engineering 1st Edition David J. Pine - Quickly Access The Ebook and Start Reading Today

The document promotes various educational ebooks available for download at textbookfull.com, including titles on Python, data science, linear algebra, and quantum mechanics. It provides links to specific books and emphasizes the convenience of accessing digital formats for reading on multiple devices. Additionally, it includes copyright and publication information for the featured books.

Uploaded by

ureydaorakci36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
71 views69 pages

Introduction To Python For Science and Engineering 1st Edition David J. Pine - Quickly Access The Ebook and Start Reading Today

The document promotes various educational ebooks available for download at textbookfull.com, including titles on Python, data science, linear algebra, and quantum mechanics. It provides links to specific books and emphasizes the convenience of accessing digital formats for reading on multiple devices. Additionally, it includes copyright and publication information for the featured books.

Uploaded by

ureydaorakci36
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Explore the full ebook collection and download it now at textbookfull.

com

Introduction to Python for Science and Engineering


1st Edition David J. Pine

https://textbookfull.com/product/introduction-to-python-for-
science-and-engineering-1st-edition-david-j-pine/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Data Science Fundamentals for Python and MongoDB 1st


Edition David Paper

https://textbookfull.com/product/data-science-fundamentals-for-python-
and-mongodb-1st-edition-david-paper/

textbookfull.com

Introduction to Linear Algebra for Science and Engineering


Daniel Norman

https://textbookfull.com/product/introduction-to-linear-algebra-for-
science-and-engineering-daniel-norman/

textbookfull.com

Introduction to Quantum Mechanics David J. Griffiths

https://textbookfull.com/product/introduction-to-quantum-mechanics-
david-j-griffiths/

textbookfull.com

Introduction to Linear Algebra for Science and


Engineering, 3rd Edition Daniel Norman

https://textbookfull.com/product/introduction-to-linear-algebra-for-
science-and-engineering-3rd-edition-daniel-norman/

textbookfull.com
Introduction to Electrodynamics Fourth Edition David J.
Griffiths

https://textbookfull.com/product/introduction-to-electrodynamics-
fourth-edition-david-j-griffiths/

textbookfull.com

Introduction to Computing and Programming in Python,


Global Edition Mark J. Guzdial

https://textbookfull.com/product/introduction-to-computing-and-
programming-in-python-global-edition-mark-j-guzdial/

textbookfull.com

Python Programming An Introduction to Computer Science


John M. Zelle

https://textbookfull.com/product/python-programming-an-introduction-
to-computer-science-john-m-zelle/

textbookfull.com

SF1624 Algebra and Geometry Introduction to Linear Algebra


for Science Engineering Daniel Norman

https://textbookfull.com/product/sf1624-algebra-and-geometry-
introduction-to-linear-algebra-for-science-engineering-daniel-norman/

textbookfull.com

Introduction to Software Engineering 2nd Edition Ronald J.


Leach

https://textbookfull.com/product/introduction-to-software-
engineering-2nd-edition-ronald-j-leach/

textbookfull.com
Introduction to
Python for Science
and Engineering
Series in Computational Physics
Parallel Science and Engineering Applications: The Charm++ Approach
Laxmikant V. Kale, Abhinav Bhatele

Introduction to Numerical Programming: A Practical Guide for Scientists and Engi-


neers Using Python and C/C++
Titus A. Beu
Computational Problems for Physics: With Guided Solutions Using Python
Rubin H. Landau, Manual José Páez

Introduction to Python for Science and Engineering


David J. Pine
For more information about this series, please visit: https://www.crcpress.com/
Series-in-Computational-Physics/book-series/CRCSERCOMPHY
Introduction to
Python for Science
and Engineering

David J. Pine
MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks
does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion
of MATLAB® software or related products does not constitute endorsement or sponsorship by The
MathWorks of a particular pedagogical approach or particular use of the MATLAB® software.

CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742

© 2019 by Taylor & Francis Group, LLC

CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed on acid-free paper

International Standard Book Number-13: 978-1-138-58389-4 (Paperback)


International Standard Book Number-13: 978-1-138-58390-0 (Hardback)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts
have been made to publish reliable data and information, but the author and publisher cannot assume
responsibility for the validity of all materials or the consequences of their use. The authors and publishers
have attempted to trace the copyright holders of all material reproduced in this publication and apologize
to copyright holders if permission to publish in this form has not been obtained. If any copyright material
has not been acknowledged please write and let us know so we may rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, trans-
mitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter
invented, including photocopying, microfilming, and recording, or in any information storage or retrieval
system, without written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.
com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood
Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and
registration for a variety of users. For organizations that have been granted a photocopy license by the
CCC, a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are
used only for identification and explanation without intent to infringe.

Library of Congress Cataloging‑in‑Publication Data

Names: Pine, David J., author.


Title: Introduction to Python for science and engineering / by David J. Pine.
Description: Boca Raton, Florida : CRC Press, [2019] | Series: Series in
computational physics | Includes bibliographical references and index.
Identifiers: LCCN 2018027880 (print) | LCCN 2018051956 (ebook) | ISBN
9780429506413 (eBook General) | ISBN 9780429014253 (eBook Adobe Reader) |
ISBN 9780429014246 (eBook ePub) | ISBN 9780429014239 (eBook Mobipocket) |
ISBN 9781138583894 (paperback : acid-free paper) | ISBN 9781138583900
(hardback : acid-free paper).
Subjects:LCSH:Python(Computerprogramlanguage)|Computerprogramming.|
Engineering--Data processing. | Science--Data processing.
Classification: LCC QA76.73.P98 (ebook) | LCC QA76.73.P98 P58 2019 (print) |
DDC 005.13/3--dc23
LC record available at https://lccn.loc.gov/2018027880

Visit the Taylor & Francis Web site at


http://www.taylorandfrancis.com

and the CRC Press Web site at


http://www.crcpress.com
To Alex Pine
who introduced me to Python
Contents

Preface xv

About the Author xix

1 Introduction 1
1.1 Introduction to Python for Science and Engineering . 1

2 Launching Python 3
2.1 Interacting with Python . . . . . . . . . . . . . . . . . 3
2.2 Installing Python on Your Computer . . . . . . . . . . 4
2.3 The Spyder Window . . . . . . . . . . . . . . . . . . . 4
2.4 The IPython Pane . . . . . . . . . . . . . . . . . . . . . 4
2.4.1 Magic commands . . . . . . . . . . . . . . . . . 6
2.4.2 System shell commands . . . . . . . . . . . . . 8
2.4.3 Tab completion . . . . . . . . . . . . . . . . . . 8
2.4.4 Recap of commands . . . . . . . . . . . . . . . . 9
2.5 Interactive Python as a Calculator . . . . . . . . . . . 9
2.5.1 Binary arithmetic operations in Python . . . . . 10
2.5.2 Types of numbers . . . . . . . . . . . . . . . . . 10
2.5.3 Important note on integer division in Python . 12
2.6 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.6.1 Names and the assignment operator . . . . . . 13
2.6.2 Legal and recommended variable names . . . . 14
2.6.3 Reserved words in Python . . . . . . . . . . . . 15
2.7 Script Files and Programs . . . . . . . . . . . . . . . . 16
2.7.1 First scripting example: The Editor pane . . . . 16
2.8 Python Modules . . . . . . . . . . . . . . . . . . . . . . 18
2.8.1 Python modules and functions: A first look . . 20
2.8.2 Some NumPy functions . . . . . . . . . . . . . . 22
2.8.3 Scripting Example 2 . . . . . . . . . . . . . . . 23
2.8.4 Different ways of importing modules . . . . . . 24
2.9 Getting Help: Documentation in IPython . . . . . . . 26

vii
viii Contents

2.10 Stand-alone IPython . . . . . . . . . . . . . . . . . . . 26


2.10.1 Writing Python scripts in a text editor . . . . . 27
2.11 Programming Errors . . . . . . . . . . . . . . . . . . . 28
2.11.1 Pyflakes . . . . . . . . . . . . . . . . . . . . . . 28
2.11.2 Error checking . . . . . . . . . . . . . . . . . . . 29
2.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3 Strings, Lists, Arrays, and Dictionaries 33


3.1 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
3.2.1 Slicing lists . . . . . . . . . . . . . . . . . . . . . 37
3.2.2 The range function: Sequences of numbers . . . 38
3.2.3 Tuples . . . . . . . . . . . . . . . . . . . . . . . 39
3.2.4 Multidimensional lists and tuples . . . . . . . . 40
3.3 NumPy Arrays . . . . . . . . . . . . . . . . . . . . . . . 41
3.3.1 Creating arrays (1-d) . . . . . . . . . . . . . . . 41
3.3.2 Mathematical operations with arrays . . . . . . 43
3.3.3 Slicing and addressing arrays . . . . . . . . . . 46
3.3.4 Fancy indexing: Boolean masks . . . . . . . . . 47
3.3.5 Multi-dimensional arrays and matrices . . . . . 49
3.3.6 Differences between lists and arrays . . . . . . 52
3.4 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . 53
3.5 Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 57

4 Input and Output 61


4.1 Keyboard Input . . . . . . . . . . . . . . . . . . . . . . 61
4.2 Screen Output . . . . . . . . . . . . . . . . . . . . . . . 64
4.2.1 Formatting output with str.format() . . . . . 64
4.2.2 Printing arrays . . . . . . . . . . . . . . . . . . . 68
4.3 File Input . . . . . . . . . . . . . . . . . . . . . . . . . 69
4.3.1 Reading data from a text file . . . . . . . . . . . 69
4.3.2 Reading data from an Excel file: CSV files . . . 71
4.4 File Output . . . . . . . . . . . . . . . . . . . . . . . . 73
4.4.1 Writing data to a text file . . . . . . . . . . . . . 73
4.4.2 Writing data to a CSV file . . . . . . . . . . . . 76
4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Contents ix

5 Conditionals and Loops 81


5.1 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . 82
5.1.1 if, elif, and else statements . . . . . . . . . . 82
5.1.2 Logical operators . . . . . . . . . . . . . . . . . 86
5.2 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.2.1 for loops . . . . . . . . . . . . . . . . . . . . . . 87
5.2.2 while loops . . . . . . . . . . . . . . . . . . . . . 91
5.2.3 Loops and array operations . . . . . . . . . . . 93
5.3 List Comprehensions . . . . . . . . . . . . . . . . . . . 94
5.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 96

6 Plotting 99
6.1 An Interactive Session with PyPlot . . . . . . . . . . . 100
6.2 Basic Plotting . . . . . . . . . . . . . . . . . . . . . . . 102
6.2.1 Specifying line and symbol types and colors . . 106
6.2.2 Error bars . . . . . . . . . . . . . . . . . . . . . 108
6.2.3 Setting plotting limits and excluding data . . . 110
6.2.4 Subplots . . . . . . . . . . . . . . . . . . . . . . 113
6.3 Logarithmic Plots . . . . . . . . . . . . . . . . . . . . . 116
6.3.1 Semi-log plots . . . . . . . . . . . . . . . . . . . 116
6.3.2 Log-log plots . . . . . . . . . . . . . . . . . . . . 118
6.4 More Advanced Graphical Output . . . . . . . . . . . 118
6.4.1 An alternative syntax for a grid of plots . . . . 122
6.5 Plots with multiple axes . . . . . . . . . . . . . . . . . 125
6.6 Mathematics and Greek symbols . . . . . . . . . . . . 126
6.7 The Structure of matplotlib: OOP and All That . . . . 131
6.7.1 The backend layer . . . . . . . . . . . . . . . . . 132
6.7.2 The artist layer . . . . . . . . . . . . . . . . . . . 135
6.7.3 The PyPlot (scripting) layer . . . . . . . . . . . 137
6.8 Contour and Vector Field Plots . . . . . . . . . . . . . 139
6.8.1 Making a 2D grid of points . . . . . . . . . . . . 139
6.8.2 Contour plots . . . . . . . . . . . . . . . . . . . 140
6.8.3 Streamline plots . . . . . . . . . . . . . . . . . . 144
6.9 Three-Dimensional Plots . . . . . . . . . . . . . . . . . 149
6.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 152

7 Functions 155
7.1 User-Defined Functions . . . . . . . . . . . . . . . . . 156
7.1.1 Looping over arrays in user-defined functions . 158
x Contents

7.1.2 Fast array processing for user-defined functions 160


7.1.3 Functions with more than one input or output 161
7.1.4 Positional and keyword arguments . . . . . . . 162
7.1.5 Variable number of arguments . . . . . . . . . . 163
7.1.6 Passing function names and parameters as argu-
ments . . . . . . . . . . . . . . . . . . . . . . . . 164
7.2 Passing data (objects) to and from functions . . . . . . 167
7.2.1 Variables and arrays created entirely within a
function . . . . . . . . . . . . . . . . . . . . . . 167
7.2.2 Passing lists and arrays to functions: Mutable
and immutable objects . . . . . . . . . . . . . . 169
7.3 Anonymous Functions: lambda Expressions . . . . . 171
7.4 NumPy Object Attributes: Methods and Instance Vari-
ables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
7.5 Example: Linear Least Squares Fitting . . . . . . . . . 175
7.5.1 Linear regression . . . . . . . . . . . . . . . . . 177
7.5.2 Linear regression with weighting: χ2 . . . . . . 179
7.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 182

8 Curve Fitting 187


8.1 Using Linear Regression for Fitting Nonlinear Func-
tions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
8.1.1 Linear regression for fitting an exponential
function . . . . . . . . . . . . . . . . . . . . . . 187
8.1.2 Linear regression for fitting a power-law func-
tion . . . . . . . . . . . . . . . . . . . . . . . . . 192
8.2 Nonlinear Fitting . . . . . . . . . . . . . . . . . . . . . 193
8.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 198

9 Numerical Routines: SciPy and NumPy 205


9.1 Special Functions . . . . . . . . . . . . . . . . . . . . . 206
9.2 Random Numbers . . . . . . . . . . . . . . . . . . . . . 209
9.2.1 Uniformly distributed random numbers . . . . 210
9.2.2 Normally distributed random numbers . . . . . 210
9.2.3 Random distribution of integers . . . . . . . . . 211
9.3 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . 212
9.3.1 Basic computations in linear algebra . . . . . . 212
9.3.2 Solving systems of linear equations . . . . . . . 213
9.3.3 Eigenvalue problems . . . . . . . . . . . . . . . 214
Contents xi

9.4 Solving Nonlinear Equations . . . . . . . . . . . . . . 216


9.4.1 Single equations of a single variable . . . . . . 217
9.4.2 Solving systems of nonlinear equations . . . . . 221
9.5 Numerical Integration . . . . . . . . . . . . . . . . . . 221
9.5.1 Single integrals . . . . . . . . . . . . . . . . . . 222
9.5.2 Double integrals . . . . . . . . . . . . . . . . . . 226
9.6 Solving ODEs . . . . . . . . . . . . . . . . . . . . . . . 227
9.7 Discrete (Fast) Fourier Transforms . . . . . . . . . . . 231
9.7.1 Continuous and discrete Fourier transforms . . 231
9.7.2 The SciPy FFT library . . . . . . . . . . . . . . . 232
9.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 234

10 Data Manipulation and Analysis: Pandas 239


10.1 Reading Data from Files Using Pandas . . . . . . . . . 240
10.1.1 Reading from Excel files saved as csv files . . . 240
10.1.2 Reading from text files . . . . . . . . . . . . . . 247
10.1.3 Reading from an Excel file . . . . . . . . . . . . 250
10.2 Dates and Times in Pandas . . . . . . . . . . . . . . . . 251
10.3 Data Structures: Series and DataFrame . . . . . . . . . 253
10.3.1 Series . . . . . . . . . . . . . . . . . . . . . . . . 253
10.3.2 DataFrame . . . . . . . . . . . . . . . . . . . . . 256
10.4 Getting Data from the Web . . . . . . . . . . . . . . . 261
10.5 Extracting Information from a DataFrame . . . . . . . 263
10.6 Plotting with Pandas . . . . . . . . . . . . . . . . . . . 267
10.7 Grouping and Aggregation . . . . . . . . . . . . . . . 272
10.7.1 The groupby method . . . . . . . . . . . . . . . 273
10.7.2 Iterating over groups . . . . . . . . . . . . . . . 274
10.7.3 Reformatting DataFrames . . . . . . . . . . . . 277
10.7.4 Custom aggregation of DataFrames . . . . . . . 280
10.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 281

11 Animation 287
11.1 Animating a Sequence of Images . . . . . . . . . . . . 287
11.1.1 Simple image sequence . . . . . . . . . . . . . . 288
11.1.2 Annotating and embellishing videos . . . . . . 292
11.2 Animating Functions . . . . . . . . . . . . . . . . . . . 294
11.2.1 Animating for a fixed number of frames . . . . 295
11.2.2 Animating until a condition is met . . . . . . . 300
11.3 Combining Videos with Animated Functions . . . . . 306
xii Contents

11.3.1 Using a single animation instance . . . . . . . . 307


11.3.2 Combining multiple animation instances . . . 308
11.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . 311

12 Python Classes and GUIs 315


12.1 Defining and Using a Class . . . . . . . . . . . . . . . 316
12.1.1 The __init__() method . . . . . . . . . . . . . 319
12.1.2 Defining methods for a class . . . . . . . . . . . 320
12.1.3 Calling methods from within a class . . . . . . 321
12.1.4 Updating instance variables . . . . . . . . . . . 322
12.2 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . 323
12.3 Graphical User Interfaces (GUIs) . . . . . . . . . . . . 326
12.3.1 Event-driven programming . . . . . . . . . . . 327
12.3.2 PyQt . . . . . . . . . . . . . . . . . . . . . . . . 328
12.3.3 A basic PyQt dialog . . . . . . . . . . . . . . . . 328
12.3.4 Summary of PyQt5 classes used . . . . . . . . . 337
12.3.5 GUI summary . . . . . . . . . . . . . . . . . . . 337

A Installing Python 339


A.1 Installing Python . . . . . . . . . . . . . . . . . . . . . 339
A.1.1 Setting preferences . . . . . . . . . . . . . . . . 340
A.1.2 Pyflakes . . . . . . . . . . . . . . . . . . . . . . 340
A.1.3 Updating your Python installation . . . . . . . 341
A.2 Testing Your Installation of Python . . . . . . . . . . . 341
A.3 Installing FFmpeg for Saving Animations . . . . . . . 343

B Jupyter Notebooks 345


B.1 Launching a Jupyter Notebook . . . . . . . . . . . . . 345
B.2 Running Programs in a Jupyter Notebook . . . . . . . 347
B.3 Annotating a Jupyter Notebook . . . . . . . . . . . . . 348
B.3.1 Adding headings and text . . . . . . . . . . . . 349
B.3.2 Comments with mathematical expressions . . . 350
B.4 Terminal commands in a Jupyter notebook . . . . . . 351
B.5 Plotting in a Jupyter Notebook . . . . . . . . . . . . . 351
B.6 Editing and Rerunning a Notebook . . . . . . . . . . . 353
B.7 Quitting a Jupyter Notebook . . . . . . . . . . . . . . . 353
B.8 Working with an Existing Jupyter Notebook . . . . . . 353

C Glossary 355
Contents xiii

D Python Resources 359


D.1 Python Programs and Data Files Introduced in This
Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
D.2 Web Resources . . . . . . . . . . . . . . . . . . . . . . 359
D.3 Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361

Index 363
Preface

The aim of this book is to provide science and engineering students


a practical introduction to technical programming in Python. It grew
out of notes I developed for various undergraduate physics courses I
taught at NYU. While it has evolved considerably since I first put pen
to paper, it retains its original purpose: to get students with no previ-
ous programming experience writing and running Python programs
for scientific applications with a minimum of fuss.
The approach is pedagogical and “bottom up,” which means start-
ing with examples and extracting more general principles from that
experience. This is in contrast to presenting the general principles
first and then examples of how those general principles work. In my
experience, the latter approach is satisfying only to the instructor.
Much computer documentation takes a top-down approach, which
is one of the reasons it’s frequently difficult to read and understand.
On the other hand, once examples have been seen, it’s useful to ex-
tract the general ideas in order to develop the conceptual framework
needed for further applications.
In writing this text, I assume that the reader:
• has never programmed before;
• is not familiar with programming environments;
• is familiar with how to get around a Mac or PC at a very basic level;
and
• is competent in basic algebra, and for Chapters 8 and 9, calculus,
linear algebra, ordinary differential equations, and Fourier analy-
sis. The other chapters, including 10–12, require only basic algebra
skills.
This book introduces, in some depth, four Python packages that
are important for scientific applications:
NumPy, short for Numerical Python, provides Python with a multi-
dimensional array object (like a vector or matrix) that is at the cen-
ter of virtually all fast numerical processing in scientific Python.

xv
xvi Introduction to Python for Science & Engineering

It is both versatile and powerful, enabling fast numerical compu-


tation that, in some cases, approaches speeds close to those of a
compiled language like C, C++, or Fortran.

SciPy, short for Scientific Python, provides access through a Python


interface to a very broad spectrum of scientific and numerical soft-
ware written in C, C++, and Fortran. These include routines to
numerically differentiate and integrate functions, solve differen-
tial equations, diagonalize matrices, take discrete Fourier trans-
forms, perform least-squares fitting, as well as many other numer-
ical tasks.

matplotlib is a powerful plotting package written for Python and


capable of producing publication-quality plots. While there are
other Python plotting packages available, matplotlib is the most
widely used and is the de facto standard.

Pandas is a powerful package for manipulating and analyzing data


formatted and labeled in a manner similar to a spreadsheet (think
Excel). Pandas is very useful for handling data produced in exper-
iments, and is particularly adept at manipulating large data sets
in different ways.

In addition, Chapter 12 provides a brief introduction to Python


classes and to PyQt5, which provides Python routines for building
graphical user interfaces (GUIs) that work on Macs, PCs, and Linux
platforms.
Chapters 1–7 provide the basic introduction to scientific Python
and should be read in order. Chapters 8–12 do not depend on each
other and, with a few mild caveats, can be read in any order.
As the book’s title implies, the text is focused on scientific uses of
Python. Many of the topics that are of primary importance to com-
puter scientists, such as object-oriented design, are of secondary im-
portance here. Our focus is on learning how to harness Python’s abil-
ity to perform scientific computations quickly and efficiently.
The text shows the reader how to interact with Python using
IPython, which stands for Interactive Python, through one of three
different interfaces, all freely available on the web: Spyder, an inte-
grated development environment, Jupyter Notebooks, and a simple
IPython terminal. Chapter 2 provides an overview of Spyder and an
introduction to IPython, which is a powerful interactive environment
Preface xvii

tailored to scientific use of Python. Appendix B provides an introduc-


tion to Jupyter notebooks.
Python 3 is used exclusively throughout the text with little refer-
ence to any version of Python 2. It’s been nearly 10 years since Python
3 was introduced and there is little reason to write new code in Python
2; all the major Python packages have been updated to Python 3.
Moreover, once Python 3 has been learned, it’s a simple task to learn
how Python 2 differs, which may be needed to deal with legacy code.
There are many lucid web sites dedicated to this sometimes necessary
but otherwise mind-numbing task.
The scripts, programs, and data files introduced in this book are
available at https://github.com/djpine/python-scieng-public.
Finally, I would like to thank Étienne Ducrot, Wenhai Zheng, and
Stefano Sacanna for providing some of the data and images used in
Chapter 11, and Mingxin He and Wenhai Zheng for their critical read-
ing of early versions of the text.
About the Author

David Pine has taught physics and chemical engineering for over 30
years at four different institutions: Cornell University (as a graduate
student), Haverford College, UCSB, and, at NYU, where he is a Profes-
sor of Physics, Mathematics, and Chemical & Biomolecular Engineer-
ing. He has taught a broad spectrum of courses, including numerical
methods. He does research in experimental soft-matter physics, which
is concerned with materials such as polymers, emulsions, and col-
loids. These materials constitute most of the material building blocks
of biological organisms.

xix
chapter 1
Introduction

1.1 Introduction to Python for Science and Engineering


This book is meant to serve as an introduction to the Python program-
ming language and its use for scientific computing. It’s ok if you have
never programmed a computer before. This book will teach you how
to do it from the ground up.
The Python programming language is useful for all kinds of sci-
entific and engineering tasks. You can use it to analyze and plot data.
You can also use it to numerically solve science and engineering prob-
lems that are difficult or even impossible to solve analytically.
While we want to marshal Python’s powers to address scientific
problems, you should know that Python is a general purpose com-
puter language that is widely used to address all kinds of comput-
ing tasks, from web applications to processing financial data on Wall
Street and various scripting tasks for computer system management.
Over the past decade it has been increasingly used by scientists and
engineers for numerical computations, graphics, and as a “wrapper”
for numerical software originally written in other languages, like For-
tran and C.
Python is similar to MATLAB® , another computer language that
is frequently used in science and engineering applications. Like
MATLAB® , Python is an interpreted language, meaning you can run
your code without having to go through an extra step of compiling, as
required for the C and Fortran programming languages. It is also a dy-
namically typed language, meaning you don’t have to declare variables
and set aside memory before using them.1
Don’t worry if you don’t know exactly what these terms mean.
Their primary significance for you is that you can write Python code,
test, and use it quickly with a minimum of fuss.
One advantage of Python compared to MATLAB® is that it is free.
It can be downloaded from the web and is available on all the stan-
dard computer platforms, including Windows, macOS, and Linux.
1 Appendix C contains a glossary of terms you may find helpful.

1
2 Introduction to Python for Science & Engineering

This also means that you can use Python without being tethered to
the internet, as required for commercial software that is tied to a re-
mote license server.
Another advantage is Python’s clean and simple syntax, including
its implementation of object-oriented programming. This should not
be discounted; Python’s rich and elegant syntax renders a number of
tasks that are difficult or arcane in other languages either simpler or
more understandable in Python.
An important disadvantage is that Python programs can be slower
than compiled languages like C. For large-scale simulations and other
demanding applications, there can be a considerable speed penalty in
using Python. In these cases, C, C++, or Fortran is recommended, al-
though intelligent use of Python’s array processing tools contained in
the NumPy module can greatly speed up Python code. Another dis-
advantage is that, compared to MATLAB® , Python is less well docu-
mented. This stems from the fact that it is public open source software
and thus is dependent on volunteers from the community of develop-
ers and users for documentation. The documentation is freely avail-
able on the web but is scattered among a number of different sites and
can be terse. This manual will acquaint you with the most commonly
used web sites. Search engines like Google can help you find others.
You are not assumed to have had any previous programming ex-
perience. However, the purpose of this manual isn’t to teach you the
principles of computer programming; it’s to provide a very practical
guide to getting started with Python for scientific computing. Perhaps
once you see some of the powerful tasks that you can accomplish with
Python, you will be inspired to study computational science and en-
gineering, as well as computer programming, in greater depth.
chapter 2
Launching Python

In this chapter you learn about IPython, an interface that allows


you to use Python interactively with tools that have been optimized
for mathematical and computational tasks. You learn how to use
IPython as a calculator and how to add, subtract, multiply, divide,
and perform other common mathematical functions. You also learn
the basic elements of the Python programming language, including
functions, variables, and scripts, which are rudimentary com-
puter programs. We introduce Python modules, which extend the
capabilities of the core Python language and allow you to perform
advanced mathematical tasks. You also learn some new ways to
navigate your computer’s file directories. Finally, you learn how to
get help with Python commands and functions.

2.1 Interacting with Python


There are many different ways to interact with Python. For general
purpose use, people typically use the Python command shell, which is
also called the Python Interpreter or Console. A shell or console is just
a window on your computer that you use to issue written commands.
For scientific Python, which is what we are concerned with here, peo-
ple generally use the IPython shell (or console). It has been specifically
designed for scientific and engineering use.
There are different ways to launch an IPython shell and write
Python code. As a beginner, we recommend using an Integrated De-
velopment Environment or IDE such as Spyder, a popular IDE that we
introduce in the following sections. Spyder uses an IPython shell and
provides other features that make it a convenient platform for you to
learn about Python. Eventually, you will want to learn about other
ways of interacting with Python, such as Jupyter Notebooks, which are
described in Appendix B. Alternatively, you can interact with Python
by writing code using a simple text editor and then running the code

3
4 Introduction to Python for Science & Engineering

from an IPython shell. We describe how to do this in §2.10 towards


the end of this chapter. In the end, you should learn to interact with
Python in all these ways, as each is valuable, depending on the ap-
plication. For now, however, we begin our exploration of Python with
the Spyder IDE.

2.2 Installing Python on Your Computer


If you haven’t already installed Python on your computer, see Ap-
pendix A, which includes instructions for installing Python on Macs
running under macOSX and on PCs running under Windows.
Once you have installed Python, launch Spyder as directed in Ap-
pendix A, and wait for the Spyder window to appear, like the one
shown in Fig. 2.1.

2.3 The Spyder Window


The default Spyder window has three panes: the IPython pane, the
Editor pane, and the Help pane. The IPython pane is the primary way
that you interact with Python. You can use it to run Python computer
programs, test snippets of Python code, navigate through your com-
puter file directories, and perform system tasks like creating, mov-
ing, and deleting files and directories. You will use the Editor Pane
to write and edit Python programs (or scripts), which are simply se-
quences of Python commands (code) stored in a file on your computer.
The Help Pane in Spyder gives help on Python commands.
The individual panes in the Spyder window are reconfigurable
and detachable but we will leave them pretty much as they are. How-
ever, you may want to adjust the overall size of the window to suit
your computer screen. You can find more information about Spyder
using the Help menu.

2.4 The IPython Pane


The default input prompt of the IPython pane looks like this:
In [1]:

This prompt signifies that Spyder is running the IPython shell. The
IPython shell has been specifically designed for scientific and engi-
Launching Python 5

Help Pane
Editor Pane

IPython Pane

Figure 2.1 Spyder IDE window.

neering use. The standard Python interactive shell uses the prompt
>>>. You can pretty much do everything you want to do with either
shell, but we will be using the IPython shell as we want to take ad-
vantage of some of its special features for scientific computing.
By typing commands at the prompt, IPython can be used to per-
form various system tasks, such as running programs and creating
and moving files around on your computer. This is a different kind
of computer interface than the icon-based interface (or graphical user
interface, GUI) that you usually use to communicate with your com-
puter. While it may seem more cumbersome for some tasks, it can
be more powerful for other tasks, particularly those associated with
programming.
Before getting started, we point out that like most modern com-
puter languages, Python is case sensitive. That is, Python distinguishes
between upper- and lower-case letters. Thus, two words spelled the
same but having different letters capitalized are treated as different
names in Python. Keep that in mind as we introduce different com-
mands.
6 Introduction to Python for Science & Engineering

2.4.1 Magic commands


IPython features a number of commands called “magic” commands
that let you perform various useful tasks. There are two types of magic
commands, line magic commands that begin with %—these are ex-
ecuted on a single line—and cell magic commands that begin with
%%—these are executed on several lines. Here, we concern ourselves
only with line magic commands.
The first thing to know about magic commands is that you can
toggle (turn on and off) the need to use the % prefix for line magic
commands by typing %automagic. By default, the Automagic switch
is set to ON in the Spyder IDE so you don’t need the % prefix. To set
Automagic to OFF, simply type %automagic at the IPython prompt. Cell
magic commands always need the %% prefix.
In what follows below, we assume that Automagic is OFF and thus
use the % sign for magic commands.

Navigation commands
IPython recognizes several common navigation commands that are
used under the Unix/Linux operating systems. In the IPython shell,
these few commands work on Macs, PCs, and Linux machines.
At the IPython prompt, type %cd ∼ (i.e., “%cd” – “space” – “tilde”,
where tilde is found near the upper left corner of most keyboards).
This will set your computer to its home (default) directory.
In [1]: %cd ~
/Users/pine

Next type %pwd (print working directory) and press Return. The con-
sole should return the path of the current directory of your computer.
It might look like this on a Mac:
In [2]: %pwd
Out[2]: '/Users/pine'

or this on a PC:
In [3]: %pwd
Out[3]: C:\\Users\\pine

Typing %cd .. (“%cd” – “space” – two periods) moves the IPython shell
up one directory in the directory tree, as illustrated by the set of com-
mands below.
In [4]: %cd ..
/Users
Launching Python 7

In [5]: %pwd
Out[5]: '/Users'

The directory moved up one from /Users/pine to /Users. Now type ls


(list) and press Return. The console should list the names of the files
and subdirectories in the current directory.
In [6]: %ls
Shared/ pine/

In this case, there are only two directories (indicated by the slash) and
no files (although the names of the files may be different for you).
Type %cd ∼ again to return to your home directory and then type pwd
to verify where you are in your directory tree.

Making a directory
Let’s create a directory within your documents directory that you can
use to store your Python programs. We will call it programs. First, re-
turn to your home directory by typing %cd ~. Then type %ls to list the
files and directories in your home directory.
In [7]: %cd ~
/Users/pine

In [8]: %ls
Applications/ Library/ Pictures/
Desktop/ Movies/ Public/
Documents/ Music/
Downloads/ News/

To create a directory called programs, type %mkdir programs (make


directory). Then type %ls to confirm that you have created programs.
In [9]: %mkdir programs

In [10]: %ls
Applications/ Library/ Pictures/
Desktop/ Movies/ Public/
Documents/ Music/ programs/
Downloads/ News/

You should see that a new directory named programs has been added
to the list of directories. Next, type %cd programs to navigate to that
new directory.
In [11]: %cd programs
/Users/pine/programs
8 Introduction to Python for Science & Engineering

Sometimes, the IPython shell becomes cluttered. You can clean up


the shell by typing %clear, which will give you a fresh shell window.

The %run magic command


A very important magic command is %run filename where filename is
the name of a Python program you have created. We haven’t done this
yet but include it here just for reference. We will come back to this
later in the chapter.
There are a lot of other magic commands, most of which we don’t
need, and others that we will introduce as we need them. If you are
curious about them, you can get a list of them by typing %lsmagic.

2.4.2 System shell commands


You can also run system shell commands from the IPython shell by
typing ! followed by a system shell command. For Macs running
OSX and for Linux machines, this means that Unix (or equivalently
Linux) commands can be issued from the IPython prompt. For PCs,
this means that Windows (DOS) commands can be issued from the
IPython prompt. For example, typing !ls (list) and pressing Return
lists all the files in the current directory on a Mac. Typing !dir on a
PC does essentially the same thing (note that system shell commands
in Windows are not case sensitive).

2.4.3 Tab completion


IPython also incorporates a number of shortcuts that make using the
shell more efficient. One of the most useful is tab completion. Let’s
assume you have been following along and that your are in the direc-
tory Documents or My Documents. To switch to the directory programs,
you could type cd programs. Instead of doing that, type cd prog and
then press the TAB key. This will complete the command, provided
there is no ambiguity in how to finish the command. In the present
case, that would mean that there is no other subdirectory beginning
with prog. Tab completion works with any command you type into the
IPython terminal. Try it out! It will make your life more wonderful.
A related shortcut involves the ↑ key. If you type a command,
say cd and then press the ↑ key, IPython will complete the cd com-
mand with the last instance of that command. Thus, when you launch
Discovering Diverse Content Through
Random Scribd Documents
unable to support its body, either when walking or perching. When
upon the wing the powers of the Swallow are seen in their full
perfection, and few objects are more beautiful than one of these
birds, as it skims over the face of the country, now soaring upwards
to a great height, and now sinking suddenly down until it almost
sweeps the ground; then changing its course, it flies backwards and
forwards with amazing celerity, pursuing its way with untiring speed,
and not unfrequently indulging in a bathe in the lake or stream over
the bosom of which it delights to skim. This proceeding, like all its
other evolutions on the wing, is rapidly and easily accomplished; the
bird sinks close to the water, and suddenly darts beneath its surface,
re-appearing in less than a moment, and then flies off to a distance
to shake the moisture from its plumage. The Swallow devours
enormous numbers of flies, beetles, and butterflies; when in pursuit
of prey it either keeps near the ground, or skims through the air at
an altitude regulated according to the barometrical state of the
atmosphere, insomuch that from this fact has arisen the popular
idea that its movements indicate the kind of weather to be expected.
The eggs (see Fig. 35, Coloured Plate XVI.), from four to six in
number, are laid about May, and are incubated entirely by the
female. If the season is fine the male ministers to her wants, and
the young are hatched in twelve days; but should the weather be
cold or wet the unfortunate mother is expected to provide for
herself, and must therefore leave her nest; if this is the case the
nestlings do not quit the shell for about seventeen days. The young
grow rapidly, and before they are fully fledged may be often seen
peering and gaping above the sides of the nest, until able to
accompany their parents during their daily excursions; yet, even
then, they return to the nest for a short period as evening closes in.
No sooner has the first family become self-supporting than the
female again lays, but this time the eggs are fewer than before, and
it is not uncommon for this second brood to be hatched so late in
the season that the nestlings are too weak to accompany the rest of
the family when the time for migrating arrives. A Spanish proverb
says, "He who could destroy a Swallow could kill his own mother;"
but, in spite of the reprobation of the act expressed in this popular
adage, hundreds and thousands of these useful and sprightly birds
are annually slaughtered out of mere wanton mischief, not only in
that country, but in all parts of Europe, and yet few members of the
feathered creation are more innocent, more useful, or more
ornamental to the landscape. "The Swallow," says Sir Humphry
Davy, "is one of my favourite birds, and a rival of the Nightingale, for
he cheers my sense of seeing as much as the other does my sense
of hearing. He is the glad prophet of the year, the harbinger of the
best season; he lives a life of enjoyment, among the loveliest forms
of Nature. Winter is unknown to him, and he leaves the green
meadows of England in autumn, for the myrtle and orange groves of
Italy, and for the palms of Africa. He has always objects of pursuit,
and his success is secure. Even the beings selected for his prey are
poetical, beautiful, and transient. The ephemeræ are saved by his
means from a slow and lingering death in the evening, and killed in
a moment when they have known nothing but pleasure. He is the
constant destroyer of insects, the friend of man, and a sacred bird.
His instinct, which gives him his appointed season, and teaches him
when and where to move, may be regarded as flowing from a Divine
source; and he belongs to the oracles of Nature, which speak the
awful and intelligible fiats of a present Deity."
THE THREAD-TAILED SWALLOW (Cecropis-Uromitus-filifera).

The power of flight possessed by these birds is truly wonderful, and


the distance to which they can travel through the air, without the
possibility of rest, is almost incredible. Nevertheless, at one time,
and that not many years ago, it was believed that on the approach
of cold weather Swallows plunged to the bottom of some pond, in
the mud of which they passed the winter, and revived again in
spring. So long ago as the year 1849 this subject was brought before
the Academy of Sciences at Stockholm, and the following document,
which, coming from the quarter it did, was by some looked upon as
an irrefragable proof of the truth of this strange story, was submitted
to and gravely discussed by that learned body:—"Near to the estate
of Kafvelas, in the province of West Gothland, there is a little lake
called Djpasjon, where on several occasions in the winter time, when
the ice-net has been drawn, stelnade, or stiffened Swallows, have
been brought up in my presence. My father, then Inspector at
Kafvelas, who was also present, directed me to take some of them
home, and place them in a chair at some little distance from the fire.
This I did, and, to my great astonishment, I soon observed the birds
to draw their heads from under their wings, where they had been
previously placed, and in a few moments to fly about the room. But
as this was not the proper season for their quickening, they lived but
a short time afterwards."
So often has this statement been repeated, that even Wilson felt
himself called upon to confute it. "The Swallow," says that graphic
writer, "flies in his usual way, at the rate of one mile in a minute, and
he is so engaged for ten hours every day; his active life is extended
on an average for ten years, which gives us two million one hundred
and ninety thousand miles—upwards of eighty-seven times the
circumference of the globe. And yet this little winged seraph, if I
may so speak, who in a few days can pass from the Arctic regions to
the torrid zone, is forced when winter approaches to descend to the
bottom of lakes, rivers, and mill-ponds, to bury itself in the mud with
eels and snapping turtles, or to creep ingloriously into a cavern, a
rat-hole, or a hollow tree, with snakes, toads, and other reptiles, till
the return of spring! Is not this true, ye wise men of Europe and
America, who have published so many credible narratives upon this
subject? The Geese, the Ducks, the Cat-bird, and even the Wren,
which creeps about our houses like a mouse, are all declared to be
migratory, and to pass to southern regions on the approach of
winter. The Swallow alone, on whom Heaven has conferred superior
powers of wing, must sink in torpidity to the bottom of some pond to
pass the winter in the mud!"
THE MARTIN (Chelidon urbica).

We must confine our notice of the True Swallows to the mention of


two other species, one remarkable for its size, and the other for the
very peculiar formation of its tail.

THE SENEGAL SWALLOW.


The SENEGAL SWALLOW (Cecropis Senegalensis) is about eight inches
long and fifteen broad; the wing measures five and a half, and the
tail about four inches. The plumage of the upper part of the body is
of a glossy blueish black, with the exception of the rump and a ring
round the neck, which are reddish brown; the under side is entirely
of the latter hue, somewhat paler upon the throat and upper part of
the breast. This very large species inhabits Central Africa in great
numbers, and is met with from the western coast to the shores of
the Red Sea. In its mode of life and habits it so closely resembles
the Chimney Swallow that a description of its habits would be mere
repetition; unlike that bird, however, it does not always dwell in the
immediate vicinity of man, but frequently wanders forth and lives
upon the vast and barren steppes. Another very similar species is
found in Angola and at the Cape of Good Hope.

THE THREAD-TAILED SWALLOW.


The THREAD-TAILED SWALLOW (Cecropis-Uromitus-filifera) is a small and
delicate bird, easily recognisable by the long threads in which the
two outer feathers of the tail terminate. The upper part of the body
is of a beautiful metallic blue, the top of the head rust-red, the
region of the cheeks black, the under side white, and the tail spotted
with white. The length of this species is five, and its breadth eleven
inches. The thread-like appendages are not so long in the tail of the
female as in that of her mate. This singular bird principally frequents
India and Central Africa, and we have met with it living solitarily or
in pairs during our travels in Nubia. As far as we were able to
ascertain, its habits exactly correspond with our account of its
European congener. The Indians call this species "Leischra," as the
threads attached to the tail are supposed to resemble the grass
known by that name.

THE MARTIN.
The MARTIN or ROOF SWALLOW (Chelidon urbica) we have selected as
the type of a group, recognisable by their slightly forked tail and
strong feet, the toes of which are connected from the first joint, and,
like the tarsi, are thickly covered with feathers. This bird is five
inches and a half long, and ten and three-quarters broad; the wing
measures four inches, and the tail two and a half. Upon the back the
plumage is almost entirely of an uniform blueish black; the under
side and rump are white. The eye is dark brown, the beak black, and
the bare parts of the foot black. Both sexes are alike in colour, but
the plumage of the young is less clear in its tints than that of the
adult. The Martin inhabits the whole of Europe, and penetrates
further north than the Chimney Swallow; it is numerous in Siberia,
and during its migrations visits the interior of Africa and Southern
Asia. In most respects it closely resembles the species already
described, but is somewhat less brisk and intelligent; its flight also is
not so rapid and varied as that of the Chimney Swallow, but it
frequently soars to an enormous height in pursuit of the insects
upon which it subsists. Its voice is very far inferior to that of the rest
of its family, and its cry monotonous and harsh.
In populous districts the nests of this bird are invariably constructed
upon houses, but where human habitations are scarce, the Roof
Swallow is content to make its preparations upon rocks, or any
situation that will afford it a secure shelter from the wind and rain.
The nest is very similar to that of the Chimney Swallow, but with this
difference, that it is always built against a hole, and has no external
entrance; sometimes many pairs construct their dwellings under the
same eaves or the same rock, and thus form a kind of settlement.
Although usually peaceful, during the breeding season disputes and
battles are of constant occurrence; each couple naturally
endeavouring to obtain the snuggest corner, and to oust its
neighbour should the opportunity offer. The brood consists of from
four to six delicate snow-white eggs, and the nestlings are hatched
in about twelve days. The female alone broods, and is fed by her
mate only when the weather is fine; the young also frequently have
but an insufficient supply of food, owing to the difficulty of procuring
insects when the season is inclement, and thus must very often be
left behind when the flocks migrate, as they are still too weak to
undergo such great fatigue. If all goes well, the nestlings are fully
fledged in about sixteen days, but generally remain for some time
longer under the care of their parents. During this period the whole
family return at night to their nest, which they fill so completely that
we have often been inclined to wonder that the walls did not give
way under the pressure to which they were subjected. Desperate
fights often ensue when a stray bird finds its way into a wrong nest,
and most courageously do those in possession exert themselves to
expel the intruder, who is generally equally determined to remain.
Far less brave is the Swallow when brought into collision with its
principal enemy, the Sparrow; it often happens that no sooner is the
Swallow's nest completed than a male Sparrow creeps in and takes
possession, keeping guard at the door, in order to prevent the
entrance of the rightful owner; under these circumstances, the latter,
not venturing to obtain admittance by force, usually summons its
companions, who together beset the impudent intruder with loud
cries and every demonstration of anger. In most cases the Sparrow
retains possession of its ill-gotten abode, but should the Swallow be
bold, a battle sometimes takes place that proves fatal to one or
other of the combatants. So constant are these attempts of the
Sparrow to obtain a home for its young, that a pair of Swallows
sometimes are deprived twice in the season of the domicile they
have laboriously completed, and, should this occur, do not breed at
all that year. It was formerly imagined that the Swallow revenged
itself on its foe by building it up in the nest, but we need hardly say
that this is untrue.
The Martins make their appearance in England a few days after the
Chimney Swallow (Cecropis-Hirundo-rustica), and on their arrival are
usually seen in warm and low situations, such being most likely to
supply an abundance of their natural food. They are equally
distributed throughout the kingdom, and are found wherever man
has fixed his residence, seeming to court his protection. They
commence nidification early in May, and build in the upper angles of
windows and under the eaves of houses, sometimes under the
arches of bridges or against the face of rocks. The nest is formed of
mud completely worked and cemented, and is closed all round
except a small orifice, usually on the sheltered side, just of sufficient
size to permit the passage of the inhabitant; the interior is well lined
with a collection of straw, hay, and feathers. These birds leave us in
October; preparatory to their departure, they congregate in great
numbers on the roofs of houses.
The MOUNTAIN or SHORE SWALLOWS (Cotyle) are recognisable by
their slightly forked tail, and lax, lustreless plumage. Two species are
indigenous to Europe; a description of these will serve for the entire
group.

THE ROCK SWALLOW.


The ROCK SWALLOW (Cotyle rupestris) is about five inches and a half
long, and from twelve and a half to thirteen and three-quarters
broad; the wing measures about five inches. The coloration of the
plumage closely resembles that of the rocks upon which this species
principally lives. The upper parts of the body are light brown, the
quills and tail blackish; the centre feathers that compose the latter
are beautifully marked with oval yellowish white spots; the throat is
whitish; the breast and belly dirty reddish grey; the eye is dark
brown, the beak black, and the foot reddish grey. The sexes are
nearly alike; the young are somewhat more uniform in hue than the
adult bird.
The actual habitat of the Rock Swallows appears to be Spain, Italy,
and Greece, but they are constantly met with and are known to
breed in the Tyrol, and even in still more central parts of Europe. So
hardy are they that such as migrate do not leave till the autumn is
far advanced, and return as early as February or March; whilst
others, inhabiting the extreme south, remain in their native land
throughout the entire year. In Egypt and South-western Asia they
are replaced by a smaller but very similar species. The Rock
Swallows seldom associate with their congeners, and are readily
distinguished from them by their greyish hue, and comparatively
slow and hovering flight. In Switzerland, after their return in the
spring, they usually allow some time to elapse before they seek their
own nests or build new ones; during the interval they busy
themselves in making excursions in all directions, either skimming
near the mountains, or, if the weather be fine, soaring to a
considerable height in the air. If, on the contrary, the season be dull
or rainy, they keep close to the earth, or beneath projecting rocks
and stones. If the day be bright, they come down from their retreats
among the mountains, and perch upon the roofs of cottages, but
never venture actually into houses. The nest is placed beneath a
projecting ledge of rock, or in some similar situation, and resembles
that of the Chimney Swallow. Several pairs frequently build together,
but we have never seen settlements like those formed by some
other species. Many various statements have been made as to their
mode of nidification, seeing that, owing to the precipitous nature of
the localities selected, it is very often extremely difficult to approach
the abode of a Rock Swallow. The eggs are white, spotted with red,
and are from three to five in number. After the nestlings are fully
fledged, they still remain for some time with the old birds, following
them about in search of insects, which are caught on the wing, but
as soon as a fly or a beetle is thus obtained, the hungry young perch
for a moment upon a tree, and receive the morsel from the parent's
beak. When the period of incubation is over, the different families
form small parties, and wander about the country, as in the spring,
until the proper time for commencing their migrations. In its general
disposition, the Rock Swallow is less alert and brisk than its
congeners, and its voice has a deeper and rather hoarse sound.

THE SAND MARTIN.


The SAND MARTIN (Cotyle riparia), one of the smallest members of its
family, is only five inches long and eleven broad; the wing measures
four, and the tail two inches. The plumage is greyish brown above,
white beneath, and marked on the breast with a greyish brown ring.
The sexes are nearly alike, but the young are darker than the adults.
These birds inhabit and breed in all parts of Europe, except the
extreme northern countries, and usually frequent such rocks or hills
as overhang streams and rivers. The wonderful nests that have
rendered the members of this group so famous, are made either in
natural hollows, or in holes excavated with enormous labour by the
builders; they appear, however, to prefer the cavities which they
have themselves prepared, and are most careful to dig their retreats
at such an elevation as to be above high-water mark. "It appears,"
says Naumann, "almost incredible that a pair of these small birds,
with no other instruments than their delicate beaks, can dig, as they
do, a horizontal passage several inches in diameter, and from three
to six feet deep, in the space of two, or sometimes three days. The
male and female both assist in this, for them, gigantic undertaking,
and work with the utmost energy and ardour, disposing of the loose
earth by throwing it out behind them with their feet; and yet,
strange to say, it is not uncommon for them suddenly to leave one of
these excavations when almost finished, and commence another;
occasionally, they will even dig a third. Why they do this has never
been satisfactorily ascertained, for it is only the passage to the
chamber in which the nest is made that is ever occupied either by
the parents or the young family. Many pairs invariably work close
together, thus forming an extensive settlement, and it is most
amusing to watch the earth flying out of a number of their holes as
it is ejected by the busy labourers, who are usually quite out of
sight." It is to these settlements that Pliny alludes in the following
amusing terms: "At the Heracleotic mouth of the Nile in Egypt, the
Swallows present an insuperable obstacle to the inroads of that river,
by the embankment formed by their nests in one continuous line,
nearly a stadium in length—a thing that could not possibly have
been effected by the agency of man. In Egypt, too, near the city of
Coptos, there is an island sacred to Isis; in the early days of spring,
the Swallows strengthen the angular corner of this island with chaff
and straw, thus fortifying it in order that the river may not sweep it
away. This work they persevere in for three days and nights
together, with such unremitting labour that it is a well-known fact
that many of them die in consequence of their exertions; moreover,
this is a toil which recurs to them regularly every year."
The nest itself is made at the end of the above-mentioned passage,
and consists of a bed of straw, hay, and fibres, snugly lined with
wool, hair, and feathers. The eggs, five or six in number, are of an
oval shape, and have a thin, pure white shell. The young are
hatched in a fortnight, and remain for a similar period under the care
of their parents. Should the first family not be reared, a second
brood is at once laid. The flight of the Sand Martin is so light as to
bear comparison with that of the butterfly. Its voice is weak and
gentle, and its disposition lively and active; it is extremely social, and
lives at peace with most other birds. In its general habits it
resembles its congeners, but leaves for warmer climes earlier in the
year than they do, and does not reappear till about May.

THE ARIEL SWALLOW.


THE ARIEL (Chelidon Ariel).

The ARIEL SWALLOW, or FAIRY MARTIN (Chelidon Ariel), as the Australian


representative of our Roof Swallow is called, is about three inches
and a half in length. The upper part of its body is deep blue, the top
of the head rust-red, the rump brownish white, and the tail dark
brown; the eye is blackish brown, the beak black, and the foot
brownish grey. According to Gould, the Ariel appears in the southern
and western portions of Australia about August, and, seeking after
its old haunts, lays two or three broods, and departs again in
February. In some situations the nests of this species are built
crowded together under eaves of houses and hollow trees, or
beneath the shelter of an overhanging rock; the male birds assist in
the construction of the long flask-like passage by which the actual
home for the young is entered, and fetch clay for the females while
employed in building.
"Until my arrival in the colony of New South Wales," says Gould, "I
had no idea of the existence of this new and beautiful Martin, nor, in
fact, until I was awakened by its twittering notes at the bedroom
window at the inn in Maitland did I discover that I was surrounded
by hundreds of this species, which were breeding under the
verandahs and corners of the windows, precisely after the manner of
the Common Martin. Several of their bottle-shaped nests were built
round the house, and from thence I obtained as many eggs as I
desired. I observed this bird throughout the district of the Upper
Hunter, as well as in every part of the interior, breeding in various
localities, wherever suitable situations presented themselves,
sometimes in the holes of low decayed trees, while not unfrequently
clusters of nests were attached to the perpendicular banks of rivers,
the sides of rocks, &c., always, however, in the vicinity of water. The
nest, which is bottle-shaped, with a long neck, is composed of mud
or clay, and, like that of our Common Martin, is only constructed in
the morning and evening, unless the day be wet or lowering. While
building these nests they appear to work in small companies, six or
seven assisting in the formation of each, one of them remaining
within and receiving the mud brought by the others in their mouths.
In shape the nests are nearly round, but vary in size from four to six
inches in diameter, the spouts being eight, nine, or ten inches in
length; when built on the sides of rocks or in the hollows of trees,
they are placed without any regular order in clusters of thirty or forty
together, some with their spouts inclining downwards, others at right
angles, &c.; they are lined with feathers and fine grasses." The
eggs, which are four or five in number, are sometimes quite white,
or spotted or blotched with red; they are eleven-sixteenths of an
inch long, by half an inch broad.

The WOOD SWALLOWS (Atticora) are delicate birds with long wings
(in which the first and second quills are of equal length), forked tails,
thin beaks, and slender legs, furnished with short toes; the plumage
gleams with metallic lustre, and is much varied in its hues. All the
species included in this group inhabit South America and Africa; they
frequent woods and forests, and build their nests in the trunks of
hollow trees.
THE STRIPED WOOD SWALLOW.
The STRIPED WOOD SWALLOW (Atticora fasciata) is a native of Brazil. Its
plumage is black, marked with white upon the breast and under part
of the thigh; the rump has a blueish gloss. The length of the body is
six inches, the wing measures four, and the tail three inches. This
active, lively bird frequents the forests of Northern Brazil, from
whence it flies, in search of its insect fare, over the neighbouring
streams and rivers, and perches or sleeps amongst the surrounding
trees.

We must not omit to mention the American SAILOR SWALLOWS


(Progne), partly because they have frequently been seen in Europe,
but more especially as they form the connecting link between the
Swallows and the Swifts; they are powerful birds, with long, broad
wings, extending beyond the very decidedly forked tail. Their beak is
strong, broad at the base, compressed at its sides, much arched,
and terminates in a hook; the legs are robust, the tarsi bare, and the
toes thicker and more fleshy than those of other Swallows. The
plumage is very dense.

THE PURPLE SWALLOW.


The PURPLE SWALLOW (Progne purpurea) is seven inches and a half
long and fifteen and a half broad; the wing measures about five, and
the tail two and a half inches; the centre feather of the latter does
not exceed two inches. The female is a trifle smaller and more
slender than her mate. The plumage is of a deep blackish blue,
shaded with purple; the quills and tail-feathers are blackish brown;
the eye dark brown, the beak blackish brown, and the foot purplish
black. The head of the female is brownish grey, spotted with black;
the upper part of the body is greyer in tint than that of the male,
and streaked with black.
This bird is a particular favourite with the Americans, and has been
described at great length by many writers. According to Audubon,
the Purple Swallows appear in New Orleans about February, and at
once come sweeping about the towns or over the streams and
rivers. Near the Falls of the Ohio, they are not seen till March, and in
Missouri not before the middle of April. In August they leave for
more southern countries, assembling like their European brethren
upon steeples or high trees, preparatory to starting upon their
travels. The flight of this species resembles that of the Roof Swallow,
but upon the earth and among the branches of trees its movements
are far more easy, and it frequently alights to seek for insects on the
ground. Whilst upon the wing, it often bathes and drinks in the same
manner as our English Swallows, and like them seizes its prey as it
darts through the air. Its disposition is bold and courageous,
insomuch that it will frequently chase cats, dogs, Falcons, Cranes, or
even Vultures, with great intrepidity.
The nest of the Purple Swallow, which is long and flask-shaped, is
formed of dry twigs, grass, leaves, feathers, and other elastic
materials, and is either built against a tree or placed in similar
situations to those selected by its congeners. The female produces
two and sometimes three broods, and lays from four to six purely
white eggs; the first family is fully fledged by May, and the second
about July. Both parents assist in the work of incubation; the male
proves himself a most tender and devoted spouse, and often spends
whole hours at the side of his mate, singing to her with great
vivacity. Should several pairs brood near the same spot, the utmost
harmony prevails among them.

Pursuant to our intention of laying a natural classification of the


Animal Kingdom before our readers, we shall now proceed to
describe the SWIFTS, although we are well aware that many modern
naturalists consider that they should not be grouped with the
Swallows.
The family of the SWIFTS (Cypseli) are small or moderate-sized
birds, with a long slender body, short neck, broad flat head, and
small delicate beak, which is broad at its base, slightly curved, and
somewhat compressed at its tip. The gape is uncommonly wide; the
wings are narrow and curved like a sabre; the tail is very variously
formed, being sometimes long, sometimes short, and more or less
deeply incised at its extremity; the feet and toes are stunted, the
latter armed with short, powerful, and much curved claws. The
plumage is thick and composed of small feathers, it is usually of a
dusky hue, but occasionally exhibits considerable metallic lustre. The
various members of this family are found throughout all the divisions
of our earth, except its most northern portions, and inhabit every
situation from the sea-coast to the snow boundary of lofty mountain
ranges. From early morning till late in the evening, they may be seen
skimming through the air with astonishing rapidity, or soaring to
such an elevation as to be almost beyond the reach of our vision. So
powerful are their wings that no amount of exertion appears to
fatigue them; their pinions, which when extended form a crescent,
are wielded with a force and rapidity rivalling the activity of the
Humming Birds—they dart with the velocity of an arrow upon their
prey, or indulge in every conceivable variety of flight or motion, as
they skim through what may certainly be called their native element;
even when among the branches of trees, they display considerable
agility, but are perfectly helpless upon the ground. All the members
of this family are of a restless disposition; they spend but a few
hours of the night in repose, and require a very large amount of
food to enable them to support their prolonged exertions, so that
they consume insects in enormous quantities, seizing them whilst
upon the wing.
THE KLECHO (Dendrochelidon klecho).

All such species as inhabit the temperate zone migrate with the
utmost regularity as winter approaches, and return to their native
haunts with such unfailing precision that the day on which they will
re-appear may be accurately prognosticated. Those species
inhabiting the interior of Africa never actually migrate, but occupy
themselves in flying over the face of the country during the wet
season. The work of constructing the nest is commenced as soon as
the winter journeyings are over, and is always carried on amidst
great excitement; the males chasing and fighting each other most
furiously during the whole time, and constantly engaging in pitched
battles with the birds whose nests they prefer taking rather than
undergo the labour of constructing a home for themselves. Unlike
the nests of the Swallows, those built by the Swifts seldom consist of
more than a few slight materials laid carelessly together, and
cemented with saliva from the builder's beak. The eggs are round
and white; the female alone broods, but both parents share in the
toil of satisfying their hungry progeny.

SALANGANES.

The TREE SWIFTS (Dendrochelidon) constitute a group whose


various species form a link between the Swallows and the Swifts
Proper. These birds are recognisable by their elongate body, long
wings, in which the two first quills are of equal length, their long,
deeply-forked tail, and the crest with which their head is adorned:
their feet resemble those of the Swallow.

THE KLECHO.
The KLECHO (Dendrochelidon klecho), so called from the sound of its
cry, is about seven inches long; the wing measures six, and the tail
three inches. Upon the upper part of the body the plumage is of a
brilliant metallic steel-green; the wing-covers have a blueish lustre;
the quills are blackish on the inner and blue on the outer web, and
the shoulder-feathers white. The belly is white, the rest of the under
surface and rump of a beautiful deep grey. The male has a reddish
brown and the female a black spot near the eye.
The Tree Swifts differ almost entirely in their mode of life from any
other members of their family. Extensive woods and dense forests
are their favourite resorts, such being preferred as are in lowland
districts; according to Jerdon, the Indian Klecho constantly builds in
these localities, flying from thence over the streams or lakes in the
vicinity in search of insects on which it subsists. Whilst resting from
its labours it usually selects a withered tree for its perch, and
amuses itself by expanding and playing with the beautiful crest upon
its head. Its flight is excellent, but it climbs awkwardly among the
branches. When upon the wing it utters almost incessantly a loud
parrot-like scream; when perched its voice is not quite so harsh. We
learn from Bernstein that, unlike all other Swifts, the Klecho usually
builds at the summit of a tree, upon a branch of about an inch in
thickness. Its strange nest, the walls of which are scarcely thicker
than parchment, is constructed of bits of bark, feathers, and other
similar materials, woven together, and cemented with saliva. The
great peculiarity of the nest consists in the fact that it is only just big
enough to contain the one large egg laid by the female, and that the
walls are far too delicate to bear the weight of the brooding mother;
the bird is, therefore, compelled to perch and support herself upon
the branch, and merely allow her breast to cover and warm her
offspring. The female lays twice in the season; the egg is perfectly
oval and of a blueish tint.

The SALANGANES (Collocalia) are a group of Swifts whose edible


nests have been famous from time immemorial, but as to whose life
and habits little information has been acquired. These birds are
distinguished by their small size, long wings, in which the second
quill exceeds the rest in length, their forked or slightly incised tail,
small but powerful beak, and delicate feet, the exterior toe of which
is directed backwards. In all the members of this group the salivary
glands are much developed.

THE SALANGANE PROPER.


The SALANGANE PROPER (Collocalia nidifica), as we will call the species
most extensively met with, is from four to five inches long, and
twelve inches broad. Its wing measures about four inches and a half,
and its tail two and a quarter. The plumage is of a greyish brown,
paler upon the under surface; the quills and tail are blackish, and
the vicinity of the eyes marked with white. The feathers of the adult
have a slight metallic lustre that is not perceptible in the young. It
was formerly supposed that these remarkable birds were only found
upon the Sunda Islands, but modern observation has proved that
they also inhabit the mountains of Assam, the Neilgherries, Sikkim,
and Ceylon. Most contradictory tales have been told by travellers as
to the materials of which their famous edible nests are composed.
The earliest account of these nests is met with in Bontius, who tells
us that "Large flocks of very small birds of the Swallow kind come
down during the breeding season, and settle upon the Chinese
coasts, where they swarm over the cliffs that overhang the sea. In
these situations they build their strange nests, forming them of fish
spawn, which they collect from the shore. These nests are much
valued by the natives, who will often pay very large sums of money
for them, in order to make them into soup, which is considered a
dainty." More modern investigators have been equally inaccurate in
their surmises, some pronouncing them to be constructed of the
flesh of a kind of snail or worm, or a peculiar species of sea-weed,
gathered from the shore. Recent observations upon this interesting
point have, however, proved that all these explanations are
incorrect, and we learn that these luxuries, in which the Chinese so
much delight, are formed of a secretion resembling saliva, drawn
from under the bird's own tongue. After a great variety of
experiments as to its component parts, Marsden pronounces that the
material resembles a mixture of gelatine and white of egg, an
opinion in which Bernstein, who is a trustworthy authority on this
disputed question, entirely coincides; we will, however, describe the
nest of the Salangane before we give our readers the real secret of
its construction, as vouched for and described by the last-mentioned
naturalist. The Salangane usually builds in such deep and dark
cavities that the observation of its proceedings as it fastens its small,
thin, gelatinous nest to the rock, is attended with great difficulty.
This structure is in shape like the quarter of an egg-shell, divided
longitudinally along its entire length. Some of these nests are white,
some of a brown colour, and opinion differs considerably as to the
reason of this variety; we ourselves believe it to depend on the age
of the structure, as we have never seen a brown nest occupied, but
other authorities pronounce them to be the work of two distinct
species. In the markets the white nests command a very high price,
while such as are dark are but little esteemed. The two white eggs
laid by the Salangane are deposited at the bottom of this remarkable
gelatinous receptacle, without any further preparation for their
warmth or comfort.

THE KUSAPPI.
THE WHITE-THROATED PRICKLY-TAILED SWIFT (Acanthylis caudacuta).

The abode of the KUSAPPI (Collocalia fuciphaga) is much more easy of


access than that of its congener above described, as it is either
placed at the bottom of a hole, or affixed to the naked rock. In
shape it resembles that of the Salangane, but its walls are partially
composed of stalks of plants, horsehair, and blades of grass, not
woven, but cemented together with the aforesaid gelatinous
secretion, by which it is also attached to the surface of the cliff. The
amount of the mucilaginous substance used varies considerably,
some nests being in great measure composed of it, whilst such as
are formed of very pliable extraneous materials are made to a
certain extent without its aid. Bernstein gives the following account
of the process of building the nests of the Kusappi, and has proved
the accuracy of his statements by numberless experiments, having
even drawn the slimy thread himself from the bird's beak. "Shortly
before the breeding season," says Bernstein, "the glands beneath
the tongue of these birds become unusually distended, and present
the appearance of two large swellings, which diminish considerably
in size after the nest is completed. When about to make the
foundation of its future abode, the Kusappi presses its tongue
against the rock that is to serve for a support, and then, retiring a
few paces, draws out a long gummy thread, which dries with great
rapidity; this process is repeated, until a crescent-shaped mass is
formed, and firmly fastened to the stone. The bird then takes the
blades of grass, or stalks of other plants, one after another, from a
heap it has already prepared, and cements them together by a
similar operation, producing, as it turns its head from side to side, in
order to draw out its thread, the undulating lines so frequently seen
upon these remarkable structures, and this process is continued until
the nest has assumed the necessary dimensions." The Salangane's
method of proceeding is essentially similar to that adopted by the
Kusappi, but, as we have already said, it builds entirely with the
gelatinous threads, without any foreign admixture. We have
frequently remarked that such of these birds as are well fed exhibit a
much more considerable enlargement of the glands than is
observable in those that have only been able to obtain a scanty
supply of nourishment. This fact explains the reason why so much
difference is constantly noticeable both in the size and beauty of
these much-prized nests, millions of which are annually consumed,
such as are very clear and delicate often realising fabulous prices.
Java is particularly rich in this article of commerce, and Epp thus
describes one of the localities in which the nests are most
numerously met with:—"The Karang Kallong," he says, "is a huge
chalk rock, rising perpendicularly from the sea, by which it is
surrounded, and is garrisoned with a force of twenty-five men,
whose sole duty is to protect the birds while building. A large tree
grows at the edge of the steep, and from this point of view those
who venture to look down behold the busy workers swarming
beneath, appearing in the distance no larger than bees. The sides of
the precipice contain nine caverns, each of which has its name, and
can only be entered by a man lowered from above; should the rope
break, his death is inevitable, and even if this danger be escaped,
the task of finding the entrance to the cavern is attended with great
peril, as the foaming waves constantly dash high enough to conceal
it from view. The natives who engage in this terrible undertaking
fortify themselves for their task by a dose of opium, and offer up a
prayer to the Goddess Njaikidul before making the descent." In 1847
no fewer than 2,700 people inhabited the summit of the Karang
Kallong, and of these 1,500 men were thus employed. Enormous
numbers of nests are exported annually from this place to China,
and are sold at very high prices; but those who thus risk their lives
to obtain the expensive luxury are but poorly remunerated. We are
but little acquainted with the habits of these birds, except that they
fly with great rapidity, and constantly frequent the sea-shore.

THE STEEPLE SWIFT (Cypselus apus).


The PRICKLY-TAILED SWIFTS (Acanthylis) are distinguished from
other members of their family by the very peculiar construction of
their tail-feathers, the shafts of which extend beyond the web; the
plumage is also thicker, and the tarsi longer and more powerful than
in most other species.

THE WHITE-THROATED PRICKLY-TAILED


SWIFT.
The WHITE-THROATED PRICKLY-TAILED SWIFT (Acanthylis caudacuta) is
about eight inches and a half long, and twenty broad; the wing
measures eight and the tail two inches. The head, upper tail-covers,
sides of the wings, quills, and tail are pale black, with a metallic
greenish blue gloss; the back and shoulder-feathers are whitish
brown, the breast and nape white. The under side is blackish brown,
the lower wing-covers and a streak on the side of the head are
white, more or less intermixed with glossy, blackish blue feathers.
The inner web of the secondary quills is also white; the beak is
black, the foot lead-colour, and the eye deep brown.
We learn from Jerdon that this species is found in the south-eastern
provinces of the Himalaya, Nepaul, Sikkim, and Bhotan, and that its
flight is extraordinarily light and rapid. The breeding settlements are
generally at a considerable height in the mountains, but always
below the snow boundary. The strange prickly tail appears to be
employed to assist the bird while climbing. Further particulars as to
its habits and mode of life are entirely wanting.

THE DWARF SWIFT.


The DWARF SWIFT (Cypselus parvus) is a small species found in some
parts of Central Africa, where it usually frequents the forests or
woodland districts. Its length does not exceed five inches and a half,
and its breadth is eleven inches. The plumage is almost entirely dark
grey, lightest upon the throat; the wings are of a brownish hue. In
its general habits the Dwarf Swift resembles its congeners, but the
structure of its nest is so remarkable as to merit a minute
description. Brehm tells us that upon one occasion, whilst travelling
in the vicinity of the Blue River, he was attracted by cries uttered by
one of these birds as it flew backwards and forwards near a lofty
palm whose branches towered above the surrounding trees. On
going nearer the spot, he observed that the Swift kept disappearing,
as it were, within one of the large, fan-like leaves, against the glossy
green of which several white objects were distinctly visible. Thinking
this circumstance somewhat extraordinary, he climbed the tree, and
found, to his no small astonishment, that the said green leaf was the
nest, and the white objects, the eggs, of the noisy bird. We should,
perhaps, be more accurate if we said that the leaf formed the outer
part of the nest, the actual chamber for the young being composed
of cotton wool and feathers, fastened together with saliva, and in
shape resembling a round spoon: the interior did not exceed two
inches and a half in diameter. Guided by a most wonderful instinct,
this little builder seems perfectly aware of the danger to which its
aërial abode is exposed from a strong wind, and takes the very safe
precaution of gumming with her tenacious spittle not only the nest
and eggs, but the nestlings also, firmly to the leaf. Another
peculiarity in the domestic arrangements of this species is that the
two white eggs that compose a brood are fastened end upwards, in
the very limited bed prepared for their reception.

THE PALM-TREE SWIFT.


The PALM-TREE SWIFT (Cypselus palmarum) constructs its nest in a
very similar manner to the Dwarf Swift.

THE STEEPLE SWIFT.


The STEEPLE SWIFT (Cypselus apus) is from six to seven inches long
and fifteen and a half broad; its wing measures six and a half, and
tail three inches. Its plumage is of a blackish brown, with the
exception of the throat, which is white; the eyes are brown, the
beak and feet black.
The Steeple Swifts are met with throughout the southern countries
of Europe, in Central Asia, and over the entire continent of Africa.
They appear in Europe with the utmost regularity on the first or
second of May, and usually leave about the first of August. Such of
them as are seen after that period find their way to us from more
northern countries, having been left behind by their companions.
The migrations of these birds are undertaken in large flocks and are
usually commenced at midnight. Like all its congeners, the Steeple
Swift is extremely restless, active, and lively in disposition, but
differs considerably in its habits from all other members of its family.
The air is its home, and almost its entire life is passed upon the
wing. From early morning it may be seen, either sailing through the
sky at a considerable height, or skimming along in its tortuous
course as it pursues its insect prey. In general, however, it is only
towards evening, or if the sky be wet or cloudy, that it approaches
the surface of the earth. Such of these birds as inhabit the Canary
Islands are an exception to this rule, for, according to Bolle, they
invariably seek the shelter of their holes for a couple of hours during
the forenoon. So extremely awkward are the movements of this
species when upon the ground, that it is commonly supposed to be
unable to rise if it should chance to alight on terra firma. This idea
is, however, incorrect, for with the aid of its wings it is enabled to
make a violent spring, and thus recommence its flight. The feet of
the Swift are almost useless for walking; they are, however,
invaluable assistants to the bird when climbing, and the sharp claws
with which they are armed are most formidable weapons of defence
against its adversaries. The sight and hearing of the Steeple Swifts is
excellent, but in every other respect they are far below their
congeners, with whom they live in a constant state of warfare; even
towards their own species they exhibit the same violent and
revengeful disposition, falling upon and clawing each other with such
violence as often to tear the flesh from their opponent's breast. We
ourselves have seen the males become so excited in these
encounters, as to permit us to approach and seize them with our
hands, and Naumann mentions having observed one of these birds
dart like a Falcon upon a Sparrow quietly picking up worms in a field,
and attack it with such fierceness that the terrified little creature
sought refuge between the feet of a man who was standing near the
spot.
Steeples, lofty edifices, and in some countries rocks, are the
situations preferred by this species when about to build. The nest is
constructed of hay, dry leaves, blades of grass, or even bits of rag,
cemented into a solid mass by the saliva from the builder's beak.
The two or at most three eggs that constitute a brood are white,
elongate, and of the same breadth at both ends. The female begins
to lay at the end of May; she alone performs the work of incubation,
and is fed by her mate if the weather be fine; should it, however, be
wet, she is compelled to leave her little family, and go herself in
pursuit of insects, as the male can only provide for his own
requirements. The young grow very slowly and remain for many
weeks under parental care, indeed, they are rarely fully fledged until
the end of August. It is by no means uncommon for these birds to
avoid all the trouble attendant on nidification, by setting upon and
worrying a Starling or Sparrow until they have compelled it to resign
its little domicile; under these circumstances, if the eggs of the late
occupier have been already laid, the marauder simply covers them
with a layer of some elastic material, and on this the female deposits
her brood. These Swifts subsist almost entirely on insects, and
usually require a large supply of food; they can, however,
occasionally fast for a lengthened period.

THE ALPINE SWIFT.


The ALPINE SWIFT (Cypselus Melba) is considerably larger and more
powerful than the bird last described, its length being about eight,
and its breadth from nineteen to twenty inches; the wing measures
eight and the tail three inches. The plumage of this species is dusky
greyish brown above, and white upon the throat and belly; the rings
around the eyes are deep brown, and the feet and beak black. The
young are recognisable by the light edge upon their feathers.
All the mountains of Southern Europe, and a large part of Asia,
afford a home to the Alpine Swift; it is, however, rarely met with in
the central or northern parts of the European continent. According to
Jerdon, it is by no means uncommon in India, around the Ghauts,
and Neilgherries, and on the Malabar coast; it is also sometimes
seen near Madras; and all parts of Africa are visited by these birds
during the course of their migrations. Although the favourite resorts
of this species are in the mountains in Switzerland, it constantly
frequents the steeples of the churches, appearing in that country
about the end of March, and only leaving for warmer regions in
October. We have been informed by the monks upon Montserrat that
the Alpine Swift has been seen from time to time near their cloisters
throughout the entire winter. In most particulars of its life and habits
this bird closely resembles the Steeple Swift, but it is capable of
mounting to even a still greater height in the air. Its voice resembles
that of the Kestrel. Like its congeners it is eminently social, and
generally flies about in considerable flocks; we have seen thousands
at a time swarming around the summit of Montserrat, and Jerdon
tells us that they congregate in similar multitudes on the heights of
some Indian mountains. Their nests are built in holes of rocks,
steeples, or similar situations; they are formed externally of twigs,
upon which are laid leaves, straw, rags, paper cuttings, or other
materials of like description, the whole being consolidated by means
of the glutinous spittle to which we have so frequently alluded. The
three elongated white eggs that form the brood are laid at the end
of May; the nestlings are hatched by the middle of June, and are
fully fledged by the last week in July.
The NIGHT JARS or GOATSUCKERS (Caprimulgi) constitute a family
of very remarkable birds, in some respects resembling the Swallows
and Swifts, but differing from them in many important particulars.
Some species fully equal the Raven in size, whilst others, on the
contrary, are not larger than a Lark; in all, the body is elongate, the
neck short, the head large, broad, and flat, the eye prominent. The
beak is broad, short, and tapers towards its tip, which is much
compressed; the jaws are unusually large, and the gape wide; the
legs are weak, the tarsi short and covered with horny plates, the
upper part being occasionally feathered, or quite bare. The toes vary
considerably in different species, but are usually weak and short, the
centre one only being well developed; this middle toe is sometimes
furnished with a large serrated claw. The wings are long and
pointed, but not to such a degree as those of the Swallow, the
second and third quills, instead of the first, generally exceeding the
rest in length. The tail is formed of ten feathers, and differs
considerably as to its shape; the plumage, like that of the Owl, is
soft, and composed of large feathers; it is usually dark in colour, but
much variegated and very delicately marked. The base of the beak is
covered with a very remarkable growth of stiff bristles, and the eyes
are surrounded with short but thick lashes. In some species the
males have long and peculiarly formed feathers in the region of the
tail and on the wings.
Plate 13, Cassell's Book of Birds
THE TAWNY GOATSUCKER ____ Nyctibius grandis
(two-thirds Nat. size)

[See larger version]


The Night Jars, or Fern Owls, as they are sometimes called, are
found throughout all divisions of our globe, with the exception of its
most northern latitudes; two species are met with in Europe, and
others occur in America, Africa, and Asia. Though thus spread over
the face of the earth, the actual habitat of this group is somewhat
limited; certain amongst them occupy mountains, others frequent
desert tracts or fruitful plains, but all keep to a certain extent within
the limits of their appointed domain, their plumage being usually
coloured so as to harmonise and blend with the tints of the rocks,
sand, or tree trunks, among which they pass the greatest portion of
their lives. Such of these birds as dwell in tropical forests do not
migrate; and the greater number skim over the surrounding country
at certain seasons; but all those inhabiting northern latitudes
withdraw in the autumn towards the south. It is only during these
migratory excursions—which often extend as far as the interior of
Africa—that the Night Jars exhibit anything like a social disposition;
in their native haunts each pair keeps entirely apart from others, and
never allows the slightest intrusion within the precincts of the locality
selected for its abode. It may occasionally happen that some
tempting neighbourhood will induce several couples to settle
comparatively near together, but under any circumstances the same
utter want of intercourse among them is observable. Towards man
they by no means exhibit this want of sociability, and in most parts
of the earth more or less frequent the immediate vicinity of his
dwellings. Almost all these birds seek for insects—upon which they
principally subsist—during the night, and retire to sleep within their
favourite recesses as soon as morning dawns; but some American
species are an exception to this rule, as they fly about in quest of
prey not only in the daylight, but even when exposed to the full
glare of the sun. Upon the ground they may be said to recline,
rather than to perch or sit, and their gait, when attempting to take a
few steps over its surface, is remarkably clumsy; their powers of
flight, however, make ample amends for this deficiency, combining
the facility and swiftness with which we are familiar in the
movements of the Falcon and the Swallow.
The sight of the Night Jars is very keen, their hearing tolerably well
developed, and their temperament by no means so sluggish as those
who only see them drowsily perched among the branches during the
day are usually inclined to suppose. They make no nest, and are
content to deposit their eggs upon the naked ground, without even
such scant preparation as the hollowing out of a slight cavity in
which they might be more securely placed. Audubon tells us that it is
not uncommon for the female, when disturbed, to conceal an egg in
her mouth, and hurry with it to a spot where she can brood upon it
unobserved. The young (usually not more than one or two in
number) are tended and provided for with great care. Despite the
important services rendered by this family, its members are in most
countries regarded with unaccountable disfavour. One idea prevalent
among the peasantry in some parts of Europe is so absurd that we
cannot refrain from mentioning it; we allude to the idea that some
species of Night Jars employ their huge jaws in relieving the goats of
their milk—a superstition from whence is derived their usual name of
Goatsuckers, an appellation conferred upon them from the most
remote antiquity.

THE NACUNDA.
The NACUNDA (Podager nacunda) has obtained its name from the
unusual size of its mouth, and may be regarded as the type of a
South American group, distinguished by their powerful body, very
broad head, strong beak, and thick plumage; their beak curves
slightly downwards at its tip, and the mouth is surrounded by a
growth of very stiff, short bristles; the nostrils are situated
immediately above the upper mandibles. The wings, in which the
second and third quills exceed the rest in length, are long and
pointed; the short tail is composed of broad feathers and slightly
rounded at its tip. The legs are powerful, the tarsi long and bare, the
toes fleshy, and the nail of the middle toe serrated. The plumage of
the Nacunda on the upper part of the body is blackish brown,
marked with fine reddish yellow lines; the head is darker than the
middle of the back, and the region of the shoulder indicated by large
blackish brown spots. The tail-feathers exhibit six or eight dark lines,
those of the male being edged with white. The throat, cheek-stripes,
and region of the ear are reddish yellow, and slightly spotted; the
belly, legs, lower tail-covers, and a line which passes from ear to ear
around the throat are of a pure white; the breast is marked with
undulating lines. The very large eyes are light brown; the beak
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like