Discover more from Grokking Python
Python in Action: Scientific Research (3 cutting-edge use cases)
Learn about some of Python's most powerful and unique applications in the world of science — and how you can start contributing to open-source projects in the sciences today.
Hey Grokking Python readers!
From seafloors to satellites, Python is helping researchers learn more about the universe and humanity’s place within it. As a versatile programming language with a wealth of open-source libraries, Python has a wide range of applications in fields outside of traditional computer science.
Today, we’ll explore these applications in three fields of scientific research: space science, Earth science, and bioinformatics. Next we’ll learn how to get involved with open-source projects in these fields.
Using Python for Scientific Computing: Pros and Cons
Scientists taking on a research project have a range of programming languages to choose from. Python is a popular choice, but it has some tough competitors. There are definitely arguments in favor of using languages like C/C++, Fortran, and Julia for specialized and intensive computations. So, before looking at some specific Python use-cases in scientific research, let’s consider the pros and cons of using Python for scientific computing, broadly.
Not all scientists are expert programmers. The relative simplicity of Python’s syntax enables non-specialists to learn and apply it without too much difficulty.
Python has functionalities that make it easy to automate tasks, which can help to streamline data analysis processes.
Python can integrate with external scientific computing tools like MATLAB.
Scientific research in a wide range of fields relies on machine learning, data analysis, and data visualization. There are excellent, pre-existing Python tools designed for these tasks.
CPython, the standard implementation of Python, is slower than C/C++, Fortran, and Julia. As a high-level language, Python is designed to be user-friendly: it has built-in capabilities that reduce the need for highly-specified code. Consequently, Python needs to perform a range of operations in the background to make the code work. This results in slower execution.
Accelerating Python’s runtime so that it’s competitive with faster languages requires using libraries or tools designed for that purpose (Numba, for example, is a compilation tool that makes Python faster). However, since writing Python code is usually time-efficient and there are tools available to accelerate its runtime, it’s debatable whether Python’s speed is a significant weakness.
In short, Python has great capabilities for scientific research. More specialized languages like Fortran might be better suited to certain projects, but Python remains a powerful and versatile option. Below, we’ll explore cutting-edge Python use-cases in a few scientific disciplines.
1) Space Science
The relationship between humans and space has been changing radically in recent years. Companies like SpaceX, Blue Origin, and Virgin Galactic are gradually turning commercial spaceflight into a reality. Python is an important part of this process. Spend a few minutes scanning the job postings at the companies listed above, and you’ll see that Python knowledge is in high demand (if you’re interested in pursuing an aerospace programming job, take a look at this blog article for some practical tips).
As corporations increasingly look toward the stars, NASA’s Artemis Program is working to return astronauts to the moon—partly as a test run for the systems that will enable a voyage to Mars. Python has actually already made significant contributions to the exploration of Mars, as NASA’s Ingenuity helicopter relies on open-source Python software for a number of critical operations.
NASA uses Python in a wide range of applications, some of which are available to the public. Explore NASA’s vast collection of open-source software to get a sense for the diversity of the tools NASA employs and the importance of Python among them. Search for “Python” at the top of the page and you’ll get a list of Python-based projects. It’s a long list, but here are a few representative examples:
SimuPy Flight Vehicle Toolkit provides a Python framework for flight simulations.
Dnppy facilitates analysis of NASA satellite data.
SunPy is a useful tool for solar data analysis.
Image credit: https://code.nasa.gov/
To get started exploring some of NASA’s open-source Python tools, check out this tutorial that explains how to retrieve NASA’s Astronomy Picture of the Day.
Space science is a broad field with a wide range of contributors. The Python resources listed above are just a small subset of those available. To continue exploring, check out Astropy, a Python library widely used by astronomers. Astropy also maintains an index of affiliated packages that leverage Python for a variety of applications in astronomical research.
2) Earth Science
Most of us associate NASA with space science, but many of its open-source Python projects are actually aimed at studying systems here on Earth. Some of these tools can be used to estimate turbulence, visualize precipitating weather systems, and analyze wind patterns.
There’s a well-developed constellation of Python libraries designed for use in Earth science disciplines like meteorology, oceanography, geology, and atmospheric science.
The PyAOS ecosystem, for instance, includes a number of packages used by atmospheric scientists and oceanographers. Here are a few of the most popular:
SciTools is a project that creates and maintains open-source Python tools for Earth scientists.
Iris is a SciTools package that facilitates analysis and visualization of Earth science data.
Cartopy is another SciTools package; it’s primarily used for analyzing geospatial data.
Python can also be used for climate modeling. Climate scientists are continually working to create better models to predict the future effects of climate change. Fortran is widely used for this purpose, but Python offers some accessible, user-friendly tools for climate modeling, too.
Image credit: https://climt.readthedocs.io/en/latest/index.html
Climate-indices provides Python implementations of climate index algorithms used for tracking precipitation and temperature anomalies.
Climtas helps users to manage large-scale climate analyses.
Climpred is a package for analyzing the outputs of weather and climate forecast models.
PyAOS also maintains an expansive package index with links to a wide range of Python tools used in Earth science disciplines.
Python is a potent tool for data analysis in biology and the other life sciences. Bioinformatics is the field that interfaces between these disciplines and computer science, as researchers seeking to manage vast quantities of biological data must increasingly turn to programming tools to analyze and visualize that data. A growing ecosystem of Python libraries are designed to facilitate bioinformatics research. Here are a few resources worth exploring:
Biopython provides a set of libraries and tools for biological computations.
PyMOL is a molecular visualization tool.
Pygr is a graph database tool designed for genomic analysis.
Nilearn facilitates neurological analysis and imaging.
Scikit-bio is an open-source Python library that provides algorithms and data structures for bioinformatics research.
Other Scientific Fields
The examples above are just a small sampling of Python’s uses in scientific research. There are plenty of other scientific disciplines with well-developed Python tools. PsychoPy, for instance, provides a range of tools for research in the behavioral sciences.
Image credit: https://www.psychopy.org/index.html
There are also a number of great Python packages designed for chemistry research, including Chemlib, ChemPy, and ChemFormula. Whatever your scientific discipline might be, there’s a good chance that there are Python libraries dedicated to it. This is one of the advantages of Python’s large and engaged community of users. If you’re undertaking a scientific research project that will depend on Python, it’s very likely that someone’s already written code that you can repurpose.
Contributing to Open-Source Projects
The Python ecosystem offers an abundance of tools for scientific research. You can help develop those tools—and maybe even make some new ones.
Explore the open-source projects in your field to see if there’s one that you’d like to participate in. Many of these projects will provide instructions for how to contribute, and some might even be actively seeking out new contributors. For example, climpred, one of the climate libraries mentioned above, currently has a note on its homepage inviting programmers to contribute. Contributing to an open-source project like this is a great way of honing your coding skills while also building some credentials in your field.
If you’re curious about Python’s applications in a scientific field that we didn’t mention here, let us know in the comments or by replying to this email.
As always, happy learning!