O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Python Scientific Computing

Book Description

A complete guide for Python programmers to master scientific computing using Python APIs and tools

About This Book

  • The basics of scientific computing to advanced concepts involving parallel and large scale computation are all covered.
  • Most of the Python APIs and tools used in scientific computing are discussed in detail
  • The concepts are discussed with suitable example programs

Who This Book Is For

If you are a Python programmer and want to get your hands on scientific computing, this book is for you. The book expects you to have had exposure to various concepts of Python programming.

What You Will Learn

  • Fundamentals and components of scientific computing
  • Scientific computing data management
  • Performing numerical computing using NumPy and SciPy
  • Concepts and programming for symbolic computing using SymPy
  • Using the plotting library matplotlib for data visualization
  • Data analysis and visualization using Pandas, matplotlib, and IPython
  • Performing parallel and high performance computing
  • Real-life case studies and best practices of scientific computing

In Detail

In today's world, along with theoretical and experimental work, scientific computing has become an important part of scientific disciplines. Numerical calculations, simulations and computer modeling in this day and age form the vast majority of both experimental and theoretical papers. In the scientific method, replication and reproducibility are two important contributing factors. A complete and concrete scientific result should be reproducible and replicable. Python is suitable for scientific computing. A large community of users, plenty of help and documentation, a large collection of scientific libraries and environments, great performance, and good support makes Python a great choice for scientific computing.

At present Python is among the top choices for developing scientific workflow and the book targets existing Python developers to master this domain using Python. The main things to learn in the book are the concept of scientific workflow, managing scientific workflow data and performing computation on this data using Python.

The book discusses NumPy, SciPy, SymPy, matplotlib, Pandas and IPython with several example programs.

Style and approach

This book follows a hands-on approach to explain the complex concepts related to scientific computing. It details various APIs using appropriate examples.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Mastering Python Scientific Computing
    1. Table of Contents
    2. Mastering Python Scientific Computing
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. The Landscape of Scientific Computing – and Why Python?
      1. Definition of scientific computing
      2. A simple flow of the scientific computation process
      3. Examples from scientific/engineering domains
      4. A strategy for solving complex problems
      5. Approximation, errors, and associated concepts and terms
        1. Error analysis
        2. Conditioning, stability, and accuracy
        3. Backward and forward error analysis
        4. Is it okay to ignore these errors?
      6. Computer arithmetic and floating-point numbers
      7. The background of the Python programming language
        1. The guiding principles of the Python language
        2. Why Python for scientific computing?
          1. Compact and readable code
          2. Holistic language design
          3. Free and open source
          4. Language interoperability
          5. Portable and extensible
          6. Hierarchical module system
          7. Graphical user interface packages
          8. Data structures
          9. Python's testing framework
          10. Available libraries
        3. The downsides of Python
      8. Summary
    9. 2. A Deeper Dive into Scientific Workflows and the Ingredients of Scientific Computing Recipes
      1. Mathematical components of scientific computations
        1. A system of linear equations
        2. A system of nonlinear equations
        3. Optimization
        4. Interpolation
        5. Extrapolation
        6. Numerical integration
        7. Numerical differentiation
        8. Differential equations
          1. The initial value problem
          2. The boundary value problem
        9. Random number generator
      2. Python scientific computing
        1. Introduction to NumPy
        2. The SciPy library
          1. The SciPy Subpackage
        3. Data analysis using pandas
      3. A brief idea of interactive programming using IPython
        1. IPython parallel computing
        2. IPython Notebook
      4. Symbolic computing using SymPy
        1. The features of SymPy
        2. Why SymPy?
        3. The plotting library
      5. Summary
    10. 3. Efficiently Fabricating and Managing Scientific Data
      1. The basic concepts of data
      2. Data storage software and toolkits
        1. Files
          1. Structured files
          2. Unstructured files
        2. Database
      3. Possible operations on data
      4. Scientific data format
      5. Ready-to-use standard datasets
      6. Data generation
      7. Synthetic data generation (fabrication)
        1. Using Python's built-in functions for random number generation
          1. Bookkeeping functions
          2. Functions for integer random number generation
          3. Functions for sequences
          4. Statistical-distribution-based functions
          5. Nondeterministic random number generator
        2. Designing and implementing random number generators based on statistical distributions
        3. A program with simple logic to generate five-digit random numbers
      8. A brief note about large-scale datasets
      9. Summary
    11. 4. Scientific Computing APIs for Python
      1. Numerical scientific computing in Python
        1. The NumPy package
          1. The ndarrays data structure
          2. File handling
          3. Some sample NumPy programs
        2. The SciPy package
          1. The optimization package
          2. The interpolation package
          3. Integration and differential equations in SciPy
          4. The stats module
          5. Clustering package and spatial algorithms in SciPy
          6. Image processing in SciPy
        3. Sample SciPy programs
          1. Statistics using SciPy
          2. Optimization in SciPy
          3. Image processing using SciPy
      2. Symbolic computations using SymPy
        1. Computer Algebra System
        2. Features of a general-purpose CAS
        3. A brief idea of SymPy
          1. Core capability
          2. Polynomials
          3. Calculus
          4. Solving equations
          5. Discrete math
          6. Matrices
          7. Geometry
          8. Plotting
          9. Physics
          10. Statistics
          11. Printing
        4. SymPy modules
        5. Simple exemplary programs
          1. Basic symbol manipulation
          2. Expression expansion in SymPy
          3. Simplification of an expression or formula
          4. Simple integrations
      3. APIs and toolkits for data analysis and visualization
        1. Data analysis and manipulation using pandas
          1. Important data structures of pandas
          2. Special features of pandas
        2. Data visualization using matplotlib
        3. Interactive computing in Python using IPython
        4. Sample data analysis and visualization programs
      4. Summary
    12. 5. Performing Numerical Computing
      1. The NumPy fundamental objects
        1. The ndarray object
          1. The attributes of an array
          2. Basic operations on arrays
          3. Special operations on arrays (shape change and conversion)
          4. Classes associated with arrays
            1. The matrix sub class
            2. Masked array
            3. The structured/recor array
        2. The universal function object
          1. Attributes
          2. Methods
          3. Various available ufunc
        3. The NumPy mathematical modules
      2. Introduction to SciPy
        1. Mathematical functions in SciPy
        2. Advanced modules/packages
          1. Integration
          2. Signal processing (scipy.signal)
          3. Fourier transforms (scipy.fftpack)
          4. Spatial data structures and algorithms (scipy.spatial)
          5. Optimization (scipy.optimize)
          6. Interpolation (scipy.interpolate)
          7. Linear algebra (scipy.linalg)
          8. Sparse eigenvalue problems with ARPACK
          9. Statistics (scipy.stats)
          10. Multidimensional image processing (scipy.ndimage)
          11. Clustering
          12. Curve fitting
          13. File I/O (scipy.io)
      3. Summary
    13. 6. Applying Python for Symbolic Computing
      1. Symbols, expressions, and basic arithmetic
      2. Equation solving
      3. Functions for rational numbers, exponentials, and logarithms
      4. Polynomials
      5. Trigonometry and complex numbers
      6. Linear algebra
      7. Calculus
      8. Vectors
      9. The physics module
        1. Hydrogen wave functions
        2. Matrices and Pauli algebra
        3. The quantum harmonic oscillator in 1-D and 3-D
        4. Second quantization
        5. High-energy Physics
        6. Mechanics
      10. Pretty printing
        1. LaTeX Printing
      11. The cryptography module
      12. Parsing input
      13. The logic module
      14. The geometry module
      15. Symbolic integrals
      16. Polynomial manipulation
      17. Sets
      18. The simplify and collect operations
      19. Summary
    14. 7. Data Analysis and Visualization
      1. Matplotlib
        1. The architecture of matplotlib
          1. The scripting layer (pyplot)
          2. The artist layer
          3. The backend layer
        2. Graphics with matplotlib
          1. Output generation
      2. The pandas library
        1. Series
        2. DataFrame
        3. Panel
        4. The common functionality among the data structures
        5. Time series and date functions
        6. Handling missing data
      3. I/O operations
        1. Working on CSV files
        2. Ready-to-eat datasets
          1. The pandas plotting
      4. IPython
        1. The IPython console and system shell
          1. The operating system interface
          2. Nonblocking plotting
          3. Debugging
        2. IPython Notebook
      5. Summary
    15. 8. Parallel and Large-scale Scientific Computing
      1. Parallel computing using IPython
      2. The architecture of IPython parallel computing
        1. The components of parallel computing
          1. The IPython engine
          2. The IPython controller
          3. IPython view and interfaces
          4. The IPython client
      3. Example of performing parallel computing
        1. A parallel decorator
        2. IPython's magic functions
          1. Activating specific views
          2. Engines and QtConsole
      4. Advanced features of IPython
        1. Fault-tolerant execution
        2. Dynamic load balancing
        3. Pushing and pulling objects between clients and engines
        4. Database support for storing the requests and results
        5. Using MPI in IPython
        6. Managing dependencies among tasks
          1. Functional dependency
            1. Decorators for functional dependency
          2. Graph dependency
          3. Impossible dependencies
          4. The DAG dependency and the NetworkX library
        7. Using IPython on an Amazon EC2 cluster with StarCluster
      5. A note on security of IPython
        1. Well-known parallel programming styles
          1. Issues in parallel programming
          2. Parallel programming
          3. Concurrent programming
          4. Distributed programming
          5. Multiprocessing in Python
          6. Multithreading in Python
        2. Hadoop-based MapReduce in Python
        3. Spark in Python
      6. Summary
    16. 9. Revisiting Real-life Case Studies
      1. Scientific computing applications developed in Python
        1. The one Laptop per Child project used Python for their user interface
        2. ExpEYES – eyes for science
        3. A weather prediction application in Python
        4. An aircraft conceptual designing tool and API in Python
        5. OpenQuake Engine
        6. SMS Siemag AG application for energy efficiency
        7. Automated code generator for analysis of High-energy Physics data
        8. Python for computational chemistry applications
      2. Python for developing a Blind Audio Tactile Mapping System
        1. TAPTools for air traffic control
        2. Energy-efficient lights with an embedded system
      3. Scientific computing libraries developed in Python
        1. A maritime designing API by Tribon
        2. Molecular Modeling Toolkit
        3. Standard Python packages
      4. Summary
    17. 10. Best Practices for Scientific Computing
      1. The best practices for designing
      2. The implementation of best practices
      3. The best practices for data management and application deployment
      4. The best practices to achieving high performance
      5. The best practices for data privacy and security
      6. Testing and maintenance best practices
      7. General Python best practices
      8. Summary
    18. Index