As featured in “Python in Plain English“
9/20/23
Let’s discuss how to use Python, a widely used programming language, for Environmental and Climate Justice. In this post we will provide a very basic background and understanding of how to use Python. Python offers an extensive range of libraries and tools for diverse applications, including the fields of Climate & Environmental Justice (EJ). These Python libraries provide numerous benefits to aid EJ work including: efficient data handling, powerful data visualization capabilities, spatial analysis functionalities, as well as statistical analysis tools. By leveraging these libraries, those working on EJ issues can significantly enhance their ability to comprehend and address environmental inequities. In this article we’ll provide a brief overview of some of the essential Python libraries and don’t forget to check out the Google Colab Demo so you can try some analysis for yourself!
Essential Libraries for Environmental Justice Research
When utilizing Python for environmental justice research, there are several key libraries that greatly enhance capabilities. These widely-used industry libraries provide powerful tools for data manipulation, analysis, visualization, and geospatial operations.
Matplotlib: Visualizing Environmental Data
Matplotlib is one of the essential Python libraries for EJ when it comes to visualizing data. It is a powerful plotting library that allows users to create a wide range of visualizations, including line plots, scatter plots, bar plots, histograms, and more. Matplotlib offers a wide range of options that allow users to create captivating and informative graphics.
One of the key features of Matplotlib is its ability to handle large datasets efficiently. Users working with EJ data often deal with vast amounts of information, such as pollution levels, demographic data, and geographic boundaries. Matplotlib’s capabilities make it much easier to analyze and summarize these datasets.
Matplotlib seamlessly integrates with various scientific libraries within the Python ecosystem, making it an excellent choice for interdisciplinary research. It plays nicely with other libraries like NumPy and Pandas, enabling effective data analysis and representation. Matplotlib provides extensive support for a wide array of output formats such as PNG, PDF, SVG, among others. This flexibility allows users to effortlessly export their visualizations for utilization in reports, presentations or further analysis.

NumPy — Math Functions
NumPy, short for Numerical Python, is a widely-used open-source library for scientific computing in Python. It provides efficient mathematical functions and powerful numerical operations, making it a crucial tool for environmental justice research. With NumPy, users can perform complex calculations, manipulate large arrays of data, and analyze scientific datasets with ease. Some of the
Fast array operations: The n-dimensional array object allows for efficient handling of large datasets. This is particularly useful in EJ projects where datasets can be extensive and require advanced computations
Mathematical functions: NumPy provides a broad range of mathematical functions, including advanced mathematical operations, linear algebra, Fourier transforms, and random number generation. These capabilities enable users to perform various statistical analyses and modeling techniques
Interoperability with other libraries: NumPy is the foundation for many other scientific Python libraries. It seamlessly integrates with libraries like Pandas and Matplotlib, allowing users to leverage the full potential of these tools for data analysis and visualization.
Pandas — Data Made Easy
Pandas, is an indispensable tool offering user-friendly data structures and analysis capabilities. Pandas simplifies the handling and manipulation of extensive datasets which helps with efficient organization and cleaning of data.
Arguably the best Pandas feature is the DataFrame object, which allows for the efficient storage and manipulation of structured data. This allows for easy and fast filtering, sorting, aggregating and visualizing of data. This helps users to discover valuable insights from their data and uncover patterns and trends that may not be immediately apparent. Whether analyzing air quality data, studying the impact of pollution on marginalized communities, or investigating the spatial distribution of environmental hazards.
GeoPandas : Geospatial Data
GeoPandas extends the capabilities of Pandas for geospatial analysis. It allows users to seamlessly work with geospatial data, making it a valuable tool for those working on EJ topics. With GeoPandas, users can effectively analyze and visualize spatial data related to environmental factors and social indicators.
Spatial data structures: GeoSeries and GeoDataFrames are specialized versions of Pandas Series and DataFrame, specifically designed to handle geometric data (i.e. vector geospatial features)
Geometric operations: Easily buffer, intersect, and perform union functions on spatial datasets
Coordinate Reference Systems: Users can easily transform and project features to facilitate the seamless integration of data from various sources
Geospatial Files: Users can read and write data in popular geospatial file formats, like GeoJSONs and Shapefiles, making it easier to work with external datasets

Cartopy: Visualizing Geospatial Data
When it comes to conducting EJ research and visualizing geospatial data, having Cartopy in your toolkit is crucial. This powerful Python library is specifically designed for efficient geospatial data processing. With Cartopy, you can effortlessly create captivating maps and visually appealing representations. It effortlessly integrates with the other various Python libraries mentioned in this article and facilitates the combination and analysis of data from diverse sources.
Interactive Mapping: Users can effortlessly create interactive maps that enable exploration and interaction with data. From the ability to zoom in on specific areas to incorporating interactive markers and tooltips, audience engagement is heightened, allowing for the effective communication of complex environmental justice issues in a visually appealing and interactive manner.
Support for Various Map Projections: Users have the freedom to select the projection that best aligns with your specific research requirements. Whether you are dealing with global data or focusing on a particular region, Cartopy guarantees both accurate and visually captivating representations of your geospatial information.
Integration with Matplotlib: Cartopy seamlessly integrates with Matplotlib. Allowing users to combine Cartopy’s mapping capabilities with the extensive plotting functionalities of Matplotlib. By customizing colors, adding legends, and annotating maps, deeper insights into EJ issues can be provided.

EarthPy: Geospatial (Playing with Rasters)
EarthPy is specifically designed for geospatial data analysis and visualization. It provides a wide range of tools and functions that are particularly useful for EJ work. With EarthPy, users can easily manipulate, analyze, and visualize geospatial data.
EarthPy offers a set of functions tailored for common EJ research tasks. For example, EarthPy provides easy access to elevation data, making it simple to study how topography influences environmental health outcomes. Additionally, EarthPy includes functions for calculating indices such as the Normalized Difference Vegetation Index (NDVI), which can help users assess the impact of land cover on EJ.
These various Python libraries enable communities, organizations and researchers to enhance their EJ focused work. Leveraging Python can help to streamline analysis, gain deeper insights, and effectively communicate findings. The inclusion of these Python libraries establishes a solid foundation for performing advanced data analysis and visualization tasks, making them invaluable tools for EJ work.
Check out the Companion Google Colab Demo!
For the demo, users will explore a Justice40 dataset. Users will aggregate, by census tract the number of indicator thresholds exceeded and then weight the rankings by the population for each census tract. Then the users will use the libraries explained above to analyze and visualize the data.