Python Tools for Scientists An Introduction to Using Anaconda JupyterLab and Python s Scientific Libraries 1st Edition Lee Vaughan instant download
Python Tools for Scientists An Introduction to Using Anaconda JupyterLab and Python s Scientific Libraries 1st Edition Lee Vaughan instant download
by Lee Vaughan
San Francisco
PYTHON TOOLS FOR SCIENTISTS. Copyright © 2023 by Lee Vaughan.
All rights reserved. No part of this work may be reproduced or transmitted in any
form or by any means, electronic or mechanical, including photocopying,
recording, or by any information storage or retrieval system, without the prior
written permission of the copyright owner and the publisher.
First printing
26 25 24 23 22 12345
The information in this book is distributed on an “As Is” basis, without warranty.
While every precaution has been taken in the preparation of this work, neither the
author nor No Starch Press, Inc. shall have any liability to any person or entity
with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
This book is dedicated to the worldwide army of open source
software developers. I am immensely grateful for your hard work
and the immeasurable good it produces.
About the Author
Lee Vaughan is a programmer, educator, and author of Impractical
Python Projects (No Starch Press, 2019) and Real-World Python (No
Starch Press, 2021). As an executive-level scientist at ExxonMobil, he
constructed and reviewed computer models, developed and tested
software, and trained geoscientists and engineers. His books are
dedicated to helping self-learners develop and hone their Python
skills and have fun doing it!
About the Technical Reviewer
John Mayhew is a geoscientist with an extensive background in
mathematics, data analysis, and scientific computing. He is a co-
founder of the nonprofit organization Land of Jershon and currently
serves on its board of directors and as the CEO. He has also
established a charitable giving consultantship, East Gate Advocates,
designed to connect donors with nonprofit projects.
BRIEF CONTENTS
Acknowledgments
Introduction
INTRODUCTION
Why Python?
Navigating This Book
Part I: Setting Up Your Scientific Coding Environment
Part II: A Python Primer
Part III: The Anaconda Ecosystem
Part IV: The Essential Libraries
Appendix
Updates and Errata
Leaving Reviews
2
KEEPING ORGANIZED WITH CONDA ENVIRONMENTS
Understanding Conda Environments
Working with Conda Environments Using Navigator
Launching Navigator
Creating a New Environment
Managing Packages
Duplicating Environments
Backing Up Environments
Removing Environments
Working with Conda Environments Using the Command Line
Interface
Launching the Command Line Interface
Creating a New Environment
Specifying an Environment’s Location
Managing Packages
Duplicating and Sharing Environments
Restoring Environments
Removing Environments
Cleaning the Package Cache
Summary
3
SIMPLE SCRIPTING IN THE JUPYTER QT CONSOLE
Installing seaborn
Installing and Launching the Jupyter Qt Console Using Navigator
Installing and Launching the Jupyter Qt Console Using the CLI
The Qt Console Controls
Choosing a Syntax Style
Using Keyboard Shortcuts
Using Tabs and Kernels
Printing and Saving
Multiline Editing
Summary
4
SERIOUS SCRIPTING WITH SPYDER
Installing and Launching Spyder with Anaconda Navigator
Installing and Launching Spyder Using the CLI
Launching Spyder from the Start Menu
Configuring the Spyder Interface
Using Spyder with Environments and Packages
The Naive Approach
The Modular Approach
Using Project Files and Folders
Creating a Project in a New Directory
Creating a Project in an Existing Directory
Using the Project Pane
The Help Pane
The IPython Console
Using the Console for Output and Plotting
Using Kernels with the Console
Clearing the Namespace
The History Pane
Special Consoles
The Editor Pane
Writing a Program Using the Editor
Defining Code Cells
Setting the Run Configuration
Autocompleting Text
The Code Analysis Pane
The Variable Explorer Pane
The Profiler Pane
The Debugger Pane
Summary
5
JUPYTER NOTEBOOK: AN INTERACTIVE JOURNAL FOR
COMPUTATIONAL RESEARCH
Installing Jupyter Notebook
The Naive Approach
The Modular Approach
Your First Jupyter Notebook
Creating Dedicated Project Folders
Navigating the Notebook Dashboard and User Interface
Naming a Notebook
Adding Text with a Markdown Cell
Adding Code and Making Plots with a Code Cell
Working with Output Cells
Adding an Image with a Markdown Cell
Saving the Notebook
Closing the Notebook
Getting Help
Keyboard Shortcuts
The Command Palette
Using Notebook Extensions
Installing Extensions
Enabling Extensions
Working with Widgets
Installing ipywidgets
Creating Widgets with Interact
Creating Widgets with Interactive
Manually Creating Widgets
Handling Events
Customizing Widgets
Embedding Widgets in Other Formats
Sharing Notebooks
Checking and Running Notebooks with the Kernel Menu
Downloading Notebooks
Sharing Notebooks via GitHub and Gist
Sharing Notebooks via Jupyter Notebook Viewer
Sharing Notebooks via Binder
Other Sharing Options
Trusting Notebooks
Turning Notebooks into Slideshows
Installing the RISE Extension
Creating a Slideshow
Using Speaker Notes
Summary
6
JUPYTERLAB: YOUR CENTER FOR SCIENCE
When to Use JupyterLab Instead of Notebook?
Installing JupyterLab
The Naive Approach
The Modular Approach
Building a 3D Astronomical Simulation
Using Dedicated Project Folders
The JupyterLab Interface
The Menu Bar
The Left Sidebar
Creating a New Notebook
Naming the Notebook
Using Markdown Cells
Adding Code and Making Plots
Adding a Console
Displaying an Image File
Exploring the Simulation
Opening Multiple Notebooks
Saving the Workspace
Clearing the Workspace
Closing the Workspace
Taking Advantage of the JupyterLab Interface
Creating Synchronized Views
Copying Cells Between Notebooks
Staying Focused by Using Single Document Mode
Using the Text Editor
Running a Script in a Terminal
Running a Script in a Notebook
Simultaneously Writing and Documenting Code
Using JupyterLab Extensions
Installing and Managing Extensions with the Extension
Manager
Installing and Managing Extensions Using the CLI
Installing ipywidgets for JupyterLab
Creating Custom Extensions
Sharing
Summary