Plot GISTEMP Climate Data with Python
Intended audience: Early Career/Students; Educators; Science communicators
By Vasco Mantas (Oct 2023)
🎯 Learning objectives:
Motivation
As the world grapples with the far-reaching consequences of climate change, the importance of understanding and monitoring global temperature trends has never been more critical. António Guterres, the Secretary-General of the United Nations, poignantly stated, "Our planet has just endured a season of simmering — the hottest summer on record. Climate breakdown has begun." These words serve as a stark reminder of the urgent need to address the challenges of our changing climate.
At the time of writing, we have just emerged from the warmest September on record ("by a large margin"), a fact underscored by organizations like the Copernicus Climate Change Service and other reputable sources. This alarming trend highlights the pressing nature of climate change and its undeniable impact on our planet.
In this tutorial, we embark on a journey to explore one of the pivotal climate datasets, GISTEMP (GISS Surface Temperature Analysis), which offers invaluable insights into global temperature anomalies. By gaining the skills to access, analyze, and visualize this data, we take a step towards equipping ourselves to comprehend the complex realities of climate change, facilitating informed discussions and actions to mitigate its effects.
Furthermore, it is crucial to share this data with a broad spectrum of audiences, including students, citizens, and decision-makers. In doing so, we not only raise awareness but also empower individuals to make informed choices and influence policies that can address the global challenges posed by climate breakdown.
Let's delve into the world of climate data, uncover trends, and contribute to the global effort to address the challenges of climate breakdown.
Background on the dataset used
GISTEMP v4, short for the GISS Surface Temperature Analysis version 4, is a pivotal climate dataset created by NASA's Goddard Institute for Space Studies. Drawing from meteorological stations (NOAA GHCN v4) and sea surface temperature records (ERSST v5), it serves as a robust tool for estimating changes in global surface temperatures. What makes GISTEMP such an important dataset is its ability to provide a monthly-resolution timeline of temperature records, spanning from 1880 to the present day. An important attribute of the dataset is the careful quantification of uncertainty. Employing interpolation methods to fill data gaps, GISTEMP offers a comprehensive perspective on global and regional temperature fluctuations, making it an indispensable resource for climate researchers.
❓Target audience: This tutorial is designed for those at the introductory level, making it particularly valuable for students or early career professionals seeking to learn about the dataset and quick methods for plotting its data. Additionally, educators and science communicators with similar objectives will find this tutorial a valuable resource.
The tutorial is organized in 2 parts: 1) Access data and create a Google Colab (python); 2) Load GISTEMP data and plot the annual data / trends (full dataset and post-2000).
PART 1: Download data and setup the environment
Step 1: Download GISTEMP Data
The first crucial step in your journey to analyzing climate data with GISS Surface Temperature Analysis version 4 (GISTEMP) in Python is to obtain the dataset. You can access this data from the official GISTEMP website provided by NASA. Here's how to do it:
This section contains links to the GISTEMP data in various formats, including TXT and CSV. For this tutorial, we'll focus on downloading the data in CSV format.
The name of the file is: GLB.Ts+dSST.csv
Important note:
To ensure that everyone can follow this tutorial seamlessly, regardless of Python installations and other technical details, we'll be using the free Google Colab tool.
Google Colab is a cloud-based platform that provides free access to Jupyter notebooks. It's an ideal choice for this tutorial as it requires no setup and allows for collaborative and interactive coding. Google Colab provides a Python runtime environment and integrates with Google Drive, making it an excellent choice for data analysis and machine learning projects without the need for local installations.
Step 2: Set Up a Google Drive Folder, Create a Google Colab Notebook, and Upload the CSV File
In this step, we'll organize your Google Drive by creating a dedicated folder, generating a Google Colab notebook within that folder, and then proceeding to upload the GISTEMP CSV file. This method streamlines access to your data and helps keep your analysis organized.
You now have a dedicated folder on your Google Drive named "GISTEMP Analysis," a Google Colab notebook for your analysis, and the GISTEMP CSV file, all neatly organized within the same location. This setup ensures easy access to your dataset and maintains a tidy workspace for your analysis.
Part 2: Now, let's start coding!
Step 3. Mount your Google Drive folder
Now, we'll proceed to code the processing and analysis of the GISTEMP data within the Google Colab environment.
# Mount the google drive
from google.colab import drive
drive.mount('/content/drive')
In this code snippet, you are using Google Colab, a cloud-based Jupyter Notebook environment, to mount your Google Drive into your Colab session.
Step 4. Load and plot GISTEMP data
The following code essentially loads, preprocesses, visualizes, and analyzes the GISTEMP data to identify and visualize temperature anomalies and their overall trend over time. The trend line helps to reveal long-term climate trends.
The selected CSV file contains monthly temperature anomaly data. Each row represents a different year, and the columns store temperature anomaly values for each month of the year (January to December), as well as annual values (e.g., "J-D" for the annual mean). The temperature anomalies are measured in degrees Celsius (°C) and represent deviations from a reference period. Some missing values are denoted as '***,' and the data spans multiple years, allowing for the analysis of long-term temperature trends.
We will narrow our focus to annual trends in our analysis. This means that we will examine temperature anomalies and trends on a yearly basis, which can provide a more comprehensive and discernible view of how global temperatures have evolved over time. By breaking down the data into yearly increments, we can identify patterns and fluctuations more clearly, making it easier to draw meaningful conclusions from the plot.
Step 5. Read the GISTEMP data
filePath = 'REPLACE WITH YOUR FILE PATH'
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import linregress
import numpy as np
Explaining the code above:
Recommended by LinkedIn
'/content/drive/My Drive/GISTEMP/GLB.Ts+dSST.csv'
data = pd.read_csv(filePath, skiprows=1, na_values='***')
Explaining the code above:
data = data[["Year", "J-D"]]
Explaining the code above:
data = data.replace("***", np.nan)
Explaining the code above:
data["Year"] = pd.to_numeric(data["Year"])
data["J-D"] = pd.to_numeric(data["J-D"])
data = data.dropna()
Explaining the code above:
Step 6. Start plotting the data and calculate trends:
plt.figure(figsize=(12, 6))
sns.lineplot(x='Year', y='J-D', data=data)
plt.title('Global Temperature Anomalies Over Time (Annual Anomaly)')
plt.xlabel('Year')
plt.ylabel('Temperature Anomaly (°C)')
Explaining the code above:
Next, we will calculate the trend and add it to the figure:
slope, intercept, _, _, _ = linregress(range(len(data)), data['J-D'])
trend_line = intercept + slope * range(len(data))
Explaining the code above:
plt.plot(data['Year'], trend_line, label='Trend Line', color='red')
plt.legend()
plt.show()
Explaining the code above:
Congratulations! You reached the end of this tutorial. This is what you should get (approximately) after running the code described above:
In conclusion, this tutorial has guided you through the process of accessing, processing, visualizing, and analyzing GISTEMP temperature anomaly data (clearly highlighting the warming trends) in Python. With these newly acquired skills, you are well-equipped to explore climate data from GISTEMP and other sources and gain a deeper understanding of our planet's changing climate (and sharing it with others).
What if you want to compare trends over different periods within your dataset?
That will be the topic of an upcoming tutorial!
📖 Read more about GISTEMP:
Hansen, J., R. Ruedy, M. Sato, and K. Lo, 2010: Global surface temperature change. Rev. Geophys., 48, RG4004, doi:10.1029/2010RG000345. (🔗 Click here for the pdf)
Lenssen, N., G. Schmidt, J. Hansen, M. Menne, A. Persin, R. Ruedy, and D. Zyss, 2019: Improvements in the GISTEMP uncertainty model. J. Geophys. Res. Atmos., 124, no. 12, 6307-6326, doi:10.1029/2018JD029522. (🔗 Click here)
📖 Read more about Google Colab:
📖 GISTEMP citation:
Thank you for the excellent walk through! I was able to reproduce it in a Jupyter notebook easily to help my daughter with a high school International Baccalaureate project!