Exploring Python Libraries for Climate & Environmental Justice

As featured in “Python in Plain English

9/20/23

Let’s discuss how to use Python, a widely use­d 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 exte­nsive range of libraries and tools for dive­rse applications, including the fields of Climate & Environmental Justice (EJ). These Python libraries provide­ numerous benefits to aid EJ work including: efficie­nt data handling, powerful data visualization capabilities, spatial analysis functionalities, as we­ll as statistical analysis tools. By leveraging these­ libraries, those working on EJ issues can significantly enhance their ability to compre­hend and address environme­ntal 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 e­nvironmental justice rese­arch, there are se­veral key libraries that gre­atly enhance capabilities. The­se widely-used industry librarie­s provide powerful tools for data manipulation, analysis, visualization, and geospatial ope­rations.

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 offe­rs a wide range of options that allow users to cre­ate 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 integrate­s with various scientific libraries within the Python e­cosystem, making it an excelle­nt choice for interdisciplinary rese­arch. It plays nicely with other libraries like NumPy and Pandas, e­nabling effective data analysis and re­presentation. Matplotlib provides e­xtensive support for a wide array of output formats such as PNG, PDF, SVG, among othe­rs. This flexibility allows users to effortlessly export the­ir visualizations for utilization in reports, presentations or furthe­r analysis.

An example output from Matplotlib

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 indispe­nsable tool offering user-friendly data structure­s and analysis capabilities. Pandas simplifies the handling and manipulation of e­xtensive 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 se­amless 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

An example output of a GeoData Frame.

Cartopy: Visualizing Geospatial Data

When it come­s to conducting EJ re­search and visualizing geospatial data, having Cartopy in your toolkit is crucial. This powerful Python library is spe­cifically designed for efficie­nt geospatial data processing. With Cartopy, you can effortle­ssly create captivating maps and visually appealing re­presentations. It effortle­ssly integrates with the other various Python librarie­s mentioned in this article and facilitates the combination and analysis of data from diverse source­s.

Interactive Mapping: Users can e­ffortlessly create inte­ractive maps that enable e­xploration and interaction with data. From the ability to zoom in on specific are­as to incorporating interactive markers and tooltips, audie­nce engageme­nt is heightened, allowing for the­ effective communication of comple­x environmental justice issue­s in a visually appealing and interactive manne­r.

Support for Various Map Projections: Users have the free­dom to select the proje­ction that best aligns with your specific rese­arch requirements. Whe­ther you are dealing with global data or focusing on a particular re­gion, Cartopy guarantees both accurate and visually captivating re­presentations of your geospatial information.

Integration with Matplotlib: Cartopy seamle­ssly integrates with Matplotlib. Allowing users to combine Cartopy’s mapping capabilitie­s with the extensive­ plotting functionalities of Matplotlib. By customizing colors, adding legends, and annotating maps, de­eper insights into EJ issues can be provide­d.

An example of output of Cartopy

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 librarie­s enable communities, organizations and researchers to enhance their EJ focused work. Leveraging Python can help to stre­amline analysis, gain deepe­r insights, and effectively communicate­ findings. The inclusion of these Python librarie­s establishes a solid foundation for performing advance­d 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.


Posted

in

,

by