|
|
1 | (26) |
|
Scripting versus Traditional Programming |
|
|
1 | (21) |
|
Why Scripting is Useful in Computational Science |
|
|
2 | (2) |
|
Classification of Programming Languages |
|
|
4 | (1) |
|
Productive Pairs of Programming Languages |
|
|
5 | (1) |
|
Gluing Existing Applications |
|
|
6 | (1) |
|
Scripting Yields Shorter Code |
|
|
7 | (1) |
|
|
8 | (1) |
|
Type-Specification (Declaration) of Variables |
|
|
9 | (2) |
|
Flexible Function Interfaces |
|
|
11 | (1) |
|
|
12 | (1) |
|
Creating Code at Run Time |
|
|
13 | (1) |
|
Nested Heterogeneous Data Structures |
|
|
14 | (2) |
|
|
16 | (1) |
|
Mixed Language Programming |
|
|
17 | (2) |
|
When to Choose a Dynamically Typed Language |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
21 | (1) |
|
Preparations for Working with This Book |
|
|
22 | (5) |
|
Getting Started with Python Scripting |
|
|
27 | (38) |
|
A Scientific Hello World Script |
|
|
27 | (5) |
|
|
28 | (1) |
|
Dissection of the Scientific Hello World Script |
|
|
29 | (3) |
|
Reading and Writing Data Files |
|
|
32 | (8) |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
33 | (3) |
|
Working with Files in Memory |
|
|
36 | (1) |
|
|
37 | (1) |
|
|
38 | (2) |
|
Automating Simulation and Visualization |
|
|
40 | (12) |
|
|
41 | (2) |
|
Using Gnuplot to Visualize Curves |
|
|
43 | (1) |
|
Functionality of the Script |
|
|
44 | (1) |
|
|
45 | (2) |
|
|
47 | (3) |
|
|
50 | (2) |
|
Conducting Numerical Experiments |
|
|
52 | (8) |
|
Wrapping a Loop Around Another Script |
|
|
53 | (1) |
|
Generating an HTML Report |
|
|
54 | (2) |
|
|
56 | (1) |
|
|
57 | (3) |
|
|
60 | (1) |
|
|
60 | (5) |
|
The First Version of the Script |
|
|
61 | (1) |
|
The Second Version of the Script |
|
|
62 | (3) |
|
|
65 | (56) |
|
|
65 | (9) |
|
Recommended Python Documentation |
|
|
66 | (1) |
|
Testing Statements in the Interactive Shell |
|
|
67 | (1) |
|
|
68 | (1) |
|
|
69 | (2) |
|
|
71 | (1) |
|
|
72 | (2) |
|
Variables of Different Types |
|
|
74 | (26) |
|
|
74 | (1) |
|
|
75 | (1) |
|
Numbers and Numerical Expressions |
|
|
76 | (2) |
|
|
78 | (6) |
|
|
84 | (3) |
|
Splitting and Joining Text |
|
|
87 | (1) |
|
|
88 | (1) |
|
|
89 | (2) |
|
The Basics of a Python Class |
|
|
91 | (2) |
|
Determining a Variable's Type |
|
|
93 | (2) |
|
|
95 | (5) |
|
|
100 | (8) |
|
|
101 | (1) |
|
|
102 | (1) |
|
Variable Number of Arguments |
|
|
102 | (2) |
|
|
104 | (1) |
|
Treatment of Input and Output Arguments |
|
|
105 | (1) |
|
|
106 | (2) |
|
Working with Files and Directories |
|
|
108 | (13) |
|
Listing Files in a Directory |
|
|
108 | (1) |
|
|
108 | (1) |
|
Removing Files and Directories |
|
|
109 | (2) |
|
Copying and Renaming Files |
|
|
111 | (1) |
|
|
111 | (1) |
|
Creating and Moving to Directories |
|
|
112 | (1) |
|
Traversing Directory Trees |
|
|
113 | (2) |
|
|
115 | (6) |
|
Numerical Computing in Python |
|
|
121 | (48) |
|
|
123 | (8) |
|
|
123 | (1) |
|
|
124 | (2) |
|
|
126 | (1) |
|
|
127 | (2) |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
131 | (5) |
|
From Scalar to Array Function Arguments |
|
|
131 | (1) |
|
|
132 | (1) |
|
|
133 | (2) |
|
|
135 | (1) |
|
More Advanced Array Computing |
|
|
136 | (20) |
|
|
137 | (1) |
|
|
138 | (1) |
|
|
139 | (3) |
|
|
142 | (1) |
|
Arrays on Structured Grids |
|
|
143 | (3) |
|
File I/O with NumPy Arrays |
|
|
146 | (1) |
|
Reading and Writing Tables with NumPy Arrays |
|
|
147 | (3) |
|
Functionality in the Numpytools Module |
|
|
150 | (2) |
|
|
152 | (4) |
|
Other Tools for Numerical Computations |
|
|
156 | (13) |
|
The ScientificPython Package |
|
|
156 | (5) |
|
|
161 | (4) |
|
The Python-Matlab Interface |
|
|
165 | (1) |
|
Some Useful Python Modules |
|
|
166 | (3) |
|
Combining Python with Fortran, C, and C++ |
|
|
169 | (36) |
|
About Mixed Language Programming |
|
|
169 | (5) |
|
Applications of Mixed Language Programming |
|
|
170 | (1) |
|
|
170 | (2) |
|
Automatic Generation of Wrapper Code |
|
|
172 | (2) |
|
Scientific Hello World Examples |
|
|
174 | (18) |
|
Combining Python and Fortran |
|
|
175 | (5) |
|
|
180 | (6) |
|
Combining Python and C++ Functions |
|
|
186 | (2) |
|
Combining Python and C++ Classes |
|
|
188 | (4) |
|
|
192 | (1) |
|
A Simple Computational Steering Example |
|
|
192 | (9) |
|
Modified Time Loop for Repeated Simulations |
|
|
193 | (1) |
|
Creating a Python Interface |
|
|
194 | (2) |
|
The Steering Python Script |
|
|
196 | (3) |
|
Equipping the Steering Script with a GUI |
|
|
199 | (2) |
|
Scripting Interfaces to Large Libraries |
|
|
201 | (4) |
|
Introduction to GUI Programming |
|
|
205 | (70) |
|
Scientific Hello World GUI |
|
|
205 | (24) |
|
|
205 | (3) |
|
The First Python/Tkinter Encounter |
|
|
208 | (3) |
|
|
211 | (1) |
|
|
212 | (4) |
|
The Final Scientific Hello World GUI |
|
|
216 | (2) |
|
An Alternative to Tkinter Variables |
|
|
218 | (1) |
|
|
219 | (2) |
|
An Introduction to the Grid Geometry Manager |
|
|
221 | (2) |
|
Implementing a GUI as a Class |
|
|
223 | (2) |
|
A Simple Graphical Function Evaluator |
|
|
225 | (2) |
|
|
227 | (2) |
|
|
229 | (6) |
|
A Simulation and Visualization Script with a GUI |
|
|
229 | (3) |
|
|
232 | (2) |
|
|
234 | (1) |
|
A List of Common Widget Operations |
|
|
235 | (40) |
|
|
238 | (1) |
|
|
239 | (1) |
|
|
240 | (1) |
|
|
241 | (1) |
|
|
242 | (1) |
|
|
243 | (1) |
|
|
243 | (1) |
|
|
244 | (1) |
|
Making a Simple Megawidget |
|
|
244 | (1) |
|
|
245 | (3) |
|
|
248 | (1) |
|
|
248 | (3) |
|
|
251 | (2) |
|
|
253 | (1) |
|
|
253 | (2) |
|
|
255 | (1) |
|
|
256 | (3) |
|
|
259 | (1) |
|
|
260 | (1) |
|
Some Other Types of Widgets |
|
|
261 | (1) |
|
Adapting Widgets to the User's Resize Actions |
|
|
262 | (2) |
|
Customizing Fonts and Colors |
|
|
264 | (2) |
|
|
266 | (2) |
|
|
268 | (7) |
|
Web Interfaces and CGI Programming |
|
|
275 | (24) |
|
|
276 | (10) |
|
Web Forms and CGI Scripts |
|
|
277 | (2) |
|
Generating Forms in CGI Scripts |
|
|
279 | (2) |
|
|
281 | (2) |
|
A General Shell Script Wrapper for CGI Scripts |
|
|
283 | (2) |
|
|
285 | (1) |
|
Adding Web Interfaces to Scripts |
|
|
286 | (13) |
|
A Class for Form Parameters |
|
|
286 | (3) |
|
|
289 | (1) |
|
|
290 | (1) |
|
Getting a CGI Script to Work |
|
|
291 | (3) |
|
Using Web Applications from Scripts |
|
|
294 | (2) |
|
|
296 | (3) |
|
|
299 | (132) |
|
|
299 | (6) |
|
Parsing Command-Line Arguments |
|
|
299 | (3) |
|
Platform-Dependent Operations |
|
|
302 | (1) |
|
Run-Time Generation of Code |
|
|
303 | (1) |
|
|
304 | (1) |
|
Regular Expressions and Text Processing |
|
|
305 | (38) |
|
|
306 | (3) |
|
|
309 | (2) |
|
Regular Expressions for Real Numbers |
|
|
311 | (3) |
|
Using Groups to Extract Parts of a Text |
|
|
314 | (1) |
|
Extracting Interval Limits |
|
|
314 | (5) |
|
Extracting Multiple Matches |
|
|
319 | (4) |
|
|
323 | (1) |
|
Pattern-Matching Modifiers |
|
|
324 | (3) |
|
Substitution and Backreferences |
|
|
327 | (1) |
|
Example: Swapping Arguments in Function Calls |
|
|
327 | (4) |
|
A General Substitution Script |
|
|
331 | (1) |
|
Debugging Regular Expressions |
|
|
332 | (1) |
|
|
333 | (10) |
|
Tools for Handling Data in Files |
|
|
343 | (10) |
|
Writing and Reading Python Data Structures |
|
|
343 | (2) |
|
|
345 | (2) |
|
|
347 | (1) |
|
Writing and Reading Zip Archive Files |
|
|
348 | (1) |
|
Downloading Internet Files |
|
|
349 | (1) |
|
|
350 | (2) |
|
|
352 | (1) |
|
A Database for NumPy Arrays |
|
|
353 | (6) |
|
The Structure of the Database |
|
|
353 | (3) |
|
|
356 | (1) |
|
|
357 | (1) |
|
|
358 | (1) |
|
Comparing the Various Techniques |
|
|
359 | (1) |
|
Scripts Involving Local and Remote Hosts |
|
|
359 | (6) |
|
|
360 | (1) |
|
Distributed Simulation and Visualization |
|
|
361 | (2) |
|
Client/Server Programming |
|
|
363 | (1) |
|
|
364 | (1) |
|
|
365 | (35) |
|
|
366 | (3) |
|
|
369 | (1) |
|
|
370 | (1) |
|
|
370 | (1) |
|
|
371 | (1) |
|
|
372 | (1) |
|
|
373 | (1) |
|
Using a Class as a C-like Structure |
|
|
374 | (1) |
|
Attribute Access via String Names |
|
|
374 | (1) |
|
Example: Turning String Formulas into Functions |
|
|
375 | (2) |
|
Example: Class for Structured Grids |
|
|
377 | (2) |
|
|
379 | (1) |
|
Implementing Get/Set Functions via Properties |
|
|
380 | (1) |
|
Subclassing Built-in Types |
|
|
381 | (2) |
|
|
383 | (4) |
|
Building Class Interfaces at Run Time |
|
|
387 | (3) |
|
Building Flexible Class Interfaces |
|
|
390 | (6) |
|
|
396 | (4) |
|
|
400 | (5) |
|
Global, Local, and Class Variables |
|
|
400 | (1) |
|
|
401 | (1) |
|
Dictionaries of Variables in Namespaces |
|
|
402 | (3) |
|
|
405 | (3) |
|
|
406 | (1) |
|
|
407 | (1) |
|
|
408 | (14) |
|
|
408 | (2) |
|
A Pointwise Grid Iterator |
|
|
410 | (3) |
|
A Vectorized Grid Iterator |
|
|
413 | (2) |
|
|
415 | (2) |
|
Some Aspects of Generic Programming |
|
|
417 | (4) |
|
|
421 | (1) |
|
|
422 | (9) |
|
|
422 | (3) |
|
|
425 | (1) |
|
Optimization of Python Code |
|
|
426 | (5) |
|
Fortran Programming with NumPy Arrays |
|
|
431 | (32) |
|
|
431 | (3) |
|
Filling an Array in Fortran |
|
|
434 | (3) |
|
|
434 | (1) |
|
Building and Inspecting the Extension Module |
|
|
435 | (2) |
|
|
437 | (14) |
|
Generating an Erroneous Interface |
|
|
437 | (2) |
|
Array Storage in C and Fortran |
|
|
439 | (1) |
|
Input and Output Arrays as Function Arguments |
|
|
440 | (6) |
|
|
446 | (4) |
|
|
450 | (1) |
|
Increasing Callback Efficiency |
|
|
451 | (7) |
|
Callbacks to Vectorized Python Functions |
|
|
451 | (3) |
|
Avoiding Callbacks to Python |
|
|
454 | (1) |
|
Compiled Inline Callback Functions |
|
|
455 | (3) |
|
|
458 | (1) |
|
|
459 | (4) |
|
C and C++ Programming with NumPy Arrays |
|
|
463 | (40) |
|
C Programming with NumPy Arrays |
|
|
464 | (16) |
|
The Basics of the NumPy C API |
|
|
464 | (2) |
|
The Handwritten Extension Code |
|
|
466 | (1) |
|
Sending Arguments from Python to C |
|
|
467 | (1) |
|
|
468 | (1) |
|
|
468 | (3) |
|
Returning an Output Array |
|
|
471 | (1) |
|
|
472 | (1) |
|
|
473 | (1) |
|
Extension Module Template |
|
|
474 | (2) |
|
Compiling, Linking, and Debugging the Module |
|
|
476 | (1) |
|
Writing a Wrapper for a C Function |
|
|
477 | (3) |
|
C++ Programming with NumPy Arrays |
|
|
480 | (13) |
|
Wrapping a NumPy Array in a C++ Object |
|
|
480 | (2) |
|
|
482 | (3) |
|
NumPy-C++ Class Conversion |
|
|
485 | (8) |
|
Comparison of the Implementations |
|
|
493 | (5) |
|
|
493 | (3) |
|
|
496 | (1) |
|
|
497 | (1) |
|
|
498 | (5) |
|
More Advanced GUI Programming |
|
|
503 | (76) |
|
Adding Plot Areas in GUIs |
|
|
503 | (14) |
|
|
504 | (6) |
|
Animation of Functions in BLT Graph Widgets |
|
|
510 | (2) |
|
Other Tools for Making GUIs with Plots |
|
|
512 | (3) |
|
|
515 | (2) |
|
|
517 | (9) |
|
Binding Events to Functions with Arguments |
|
|
517 | (3) |
|
A Text Widget with Tailored Keyboard Bindings |
|
|
520 | (3) |
|
|
523 | (3) |
|
Animated Graphics with Canvas Widgets |
|
|
526 | (16) |
|
The First Canvas Encounter |
|
|
527 | (1) |
|
|
528 | (4) |
|
The Mathematical Model Class |
|
|
532 | (1) |
|
|
533 | (2) |
|
Drawing and Moving Planets |
|
|
535 | (1) |
|
Dragging Planets to New Positions |
|
|
536 | (4) |
|
Using Pmw's Scrolled Canvas Widget |
|
|
540 | (2) |
|
Simulation and Visualization Scripts |
|
|
542 | (37) |
|
|
543 | (2) |
|
Representing a Parameter by a Class |
|
|
545 | (14) |
|
Improved Command-Line Script |
|
|
559 | (1) |
|
|
560 | (1) |
|
|
561 | (1) |
|
Parameters with Physical Dimensions |
|
|
562 | (2) |
|
|
564 | (2) |
|
Automatic Generation of Scripts |
|
|
566 | (1) |
|
Applications of the Tools |
|
|
567 | (5) |
|
Allowing Physical Units in Input Files |
|
|
572 | (4) |
|
Converting Input Files to GUIs |
|
|
576 | (3) |
|
|
579 | (70) |
|
Running Series of Computer Experiments |
|
|
579 | (13) |
|
Multiple Values of Input Parameters |
|
|
580 | (3) |
|
|
583 | (5) |
|
|
588 | (4) |
|
Tools for Representing Functions |
|
|
592 | (20) |
|
Functions Defined by String Formulas |
|
|
592 | (2) |
|
A Unified Interface to Functions |
|
|
594 | (6) |
|
Interactive Drawing of Functions |
|
|
600 | (5) |
|
A Notebook for Selecting Functions |
|
|
605 | (7) |
|
Solving Partial Differential Equations |
|
|
612 | (37) |
|
Numerical Methods for ID Wave Equations |
|
|
613 | (3) |
|
Implementations of ID Wave Equations |
|
|
616 | (6) |
|
Classes for Solving ID Wave Equations |
|
|
622 | (7) |
|
A Problem Solving Environment |
|
|
629 | (6) |
|
Numerical Methods for 2D Wave Equations |
|
|
635 | (3) |
|
Implementations of 2D Wave Equations |
|
|
638 | (8) |
|
|
646 | (3) |
|
A Setting up the Required Software Environment |
|
|
649 | (16) |
|
Installation on Unix Systems |
|
|
649 | (11) |
|
A Suggested Directory Structure |
|
|
650 | (1) |
|
Setting Some Environment Variables |
|
|
650 | (1) |
|
Installing Tcl/Tk and Additional Modules |
|
|
651 | (1) |
|
|
652 | (2) |
|
Installing Python Modules |
|
|
654 | (4) |
|
|
658 | (1) |
|
|
658 | (1) |
|
Summary of Environment Variables |
|
|
659 | (1) |
|
Testing the Installation of Scripting Utilities |
|
|
659 | (1) |
|
Installation on Windows Systems |
|
|
660 | (5) |
|
B Elements of Software Engineering |
|
|
665 | (50) |
|
Building and Using Modules |
|
|
665 | (8) |
|
|
665 | (4) |
|
|
669 | (1) |
|
Debugging and Troubleshooting |
|
|
670 | (3) |
|
Tools for Documenting Python Software |
|
|
673 | (5) |
|
|
673 | (1) |
|
Tools for Automatic Documentation |
|
|
674 | (4) |
|
|
678 | (9) |
|
|
678 | (4) |
|
|
682 | (5) |
|
|
687 | (18) |
|
Automating Regression Tests |
|
|
687 | (5) |
|
Implementing a Tool for Regression Tests |
|
|
692 | (3) |
|
|
695 | (1) |
|
Verifying Output from Numerical Computations |
|
|
696 | (4) |
|
Automatic Doc String Testing |
|
|
700 | (2) |
|
|
702 | (3) |
|
Version Control Management |
|
|
705 | (5) |
|
|
705 | (4) |
|
Building Scripts to Simplify the Use of CVS |
|
|
709 | (1) |
|
|
710 | (5) |
Bibliography |
|
715 | (2) |
Index |
|
717 | |