VOOZH about

URL: https://towardsdatascience.com/assessing-global-temperature-anomaly-using-nasas-space-studies-part-ii-29e5e313a7b3/

⇱ Assessing global temperature anomaly using NASA's space studies - Part II | Towards Data Science


Assessing global temperature anomaly using NASA’s space studies – Part II

Plotting global surface temperature anomaly data obtained from NASA's GISSTEMP using cartopy, matplotlib and netCDF data in Python.

11 min read
👁 Image

At the time of this writing (May 2023), global CO2 emissions concentration in the atmosphere 425 ppm. This concentration level is the highest in 14 million years and is projected to rise in the coming years (The World Counts, 2023). It is no secret that anthropogenic greenhouse gas (GHG) emissions are the main drivers of global warming. In the first part of this series, I discussed the global surface temperature anomaly, the science, and the uncertainties associated with it based on the data of the past 142 years (since 1880) provided by NASA’s Goddard Institute for Space Studies (GISSTEMP).

Assessing global temperature anomaly using NASA’s space studies – Part I

A recent report published by World Meteorological Organization (WMO) stated that the global near-surface temperature is predicted to rise between 1.1 °C and 1.8 °C in the next five years relative to 1850–1900 (WMO, 2023). The report further stated that there is a 98% chance of one of the coming five years being the hottest year on record, with a likely chance that one of the years would temporarily exceed the 1.5 °C threshold.

Globally, 2022 was the fifth warmest year on record (WMO, 2023). Climate-related disasters continued to be the news headlines in 2022, including catastrophic floods in Pakistan, hurricanes in Florida, heat waves in Europe, droughts and record-low water levels in rivers of China, Europe, and America, and record ice sheet melting in Greenland.

In this part of the series, I will focus on the global surface temperature anomaly for 2022, using the data from NASA’s GISSTEMP. In the first section of this post, I will create maps depicting global surface temperature anomaly in April 2023 relative to the 1951–1980 mean in different projections. In the second section, I will plot the maps showing global surface temperature anomalies for different seasons in 2022. I will be using the matplotlib, cartopy, and netcdf4 packages in Python for this purpose. Let’s get started.


A. Global surface temperature anomaly for April 2023 relative to 1951–1980 mean

Data

The data of global surface temperature anomaly for a historical timeframe relative to the base period is open-access and downloaded from NASA’s GISS Surface Temperature analysis website (GISTEMP Team, 2023 and Lenssen et al., 2019). I selected April as the mean period, the beginning to end of 2023 as the time period, and the beginning of 1951 to the end of 1980 as the base period. The smoothing radius of 1200 km refers to the distance over which a station influences regional temperature.

I downloaded the grid data as a netCDF (*.nc) file. netCDF stands for Network Common Data Form, which is a file format containing a set of interfaces for the array-oriented machine-independent data access (National Snow and Ice Data Center, 2023). The data in the netCDF file was read in Python using the Dataset module of the netCDF4 package, as shown below:

The given data variables contain longitude (lon), latitude (lat), and temperature anomaly (TEMPANOMALY) data. These data are of numpy masked array types, which means, the data may contain some missing or invalid entries. Here, temp_anomaly data may not be available for each coordinate.

2. Plotting using Cartopy

Guidelines for installing Cartopy package

To install the cartopy package, first its dependencies shapely and pyproj need to be installed. The compatible wheel files for shapely and pyproj packages, which are based on the Python version and Windows version, can be accessed here. After installing these packages, I succeeded in installing the cartopy package using pip install cartopy.

Function to plot data in different projections

The function below uses projection and projection_name as arguments, which determine the type of projection we want to display the resulting map plot and its title.

In the function temp_anomaly_plot() below, first, an axes is added to the figure with a specific projection. The map is set to cover the global extent. clevs define the range of data (temperature anomaly) that we want to project on the map. Here I defined this range as -5°C to 6°C. cmap refers to the color map. Here, I chose the coolwarm colormap, where the blue color reflects the cold end, and the red color reflects the warm end.

The function plots filled contour using lons and lats as coordinates, and temp_anomaly as data. By default, Cartopy assumes that the coordinates match the projection of the resulting plot. Therefore, the safe option is to supply the transform keyword so that Cartopy understands that the coordinates refer to the specific original projection (here ccrs.PlateCarree()) and needs to transform it into a new projection type. Finally, a horizontal color bar is added below the map.

def temp_anomaly_plot(projection, projection_name):

 fig = plt.figure(figsize = (12, 6))

 #Add an axes to the current figure and make it the current axes.
 ax = plt.axes(projection = projection)

 #make the map global rather than having it zoom in to extent of the plotted data
 ax.set_global()

 ax.gridlines(linestyle = "--", color = "black")

 #Set contour levels, then draw the plot and a colorbar
 clevs = np.arange(-5, 6)
 cmap = "coolwarm"

 #Plot filled contours
 plt.contourf(lons, lats, 
 temp_anomaly,
 clevs,
 transform = ccrs.PlateCarree(),
 cmap = cmap,
 extend = "both" #To add arrows on both ends of the colorbar
 )

 #Add coastlines after filling contours
 ax.coastlines(resolution = "110m", lw = 1)

 plt.title(f"April 2023 L-OTI (°C) vs 1951-1980 meann Projection: {projection_name}")

 cb = plt.colorbar(ax = ax,
 orientation = "horizontal",
 pad = 0.02,
 aspect = 20, #ratio of long to short dimension
 shrink = 0.5, #Fraction by which to multiply the size of the colorbar
 ticks = clevs #To get the ticks same as clevs -5 to 5 degree Celsius in colorbar
 )

 cb.set_label("°C", size = 12, rotation = 0, labelpad = 15)
 cb.ax.tick_params(labelsize = 10)
 plt.savefig(f"../output/temp_anomaly_{projection_name}.jpeg",
 dpi = 300)

 plt.show()

3. Projections

Map projections are never absolutely accurate representations of the spherical earth. Map projections try to portray the surface of the earth, or a portion of the earth, from its spherical shape (3D) to a planar shape (2D). As a result of the map projection process, every map shows distortions of angular conformity, distance, and area (QGIS Documentation, 2023). In Python, geospatial data can be plotted in various projections using the Cartopy package.

Using the temp_anomaly_plot function defined in the section above, I plotted the global surface temperature anomaly on the global map in three different projections below:

PlateCarree projection

PlateCarree projection is an equidistant cylindrical projection with the standard parallel located at the equator.

Robinson Projection

Robinson projection is one of the most commonly used pseudocyclindrical map [projections](http://the most commonly used compromise pseudocylindrical map projection for world maps) for world maps. It is a compromise where the distortions of area, angular conformity, and distance are acceptable on this map (QGIS Documentation, 2023).

Orthographic Projection

Orthographic projection is an azimuthal perspective projection, projecting the Earth’s surface from an infinite distance to a plane. In this projection, one needs to state the central_longitude and central_latitude that one wants to view in the centre of the plane. Therefore, not all locations of the globe are visible at once in this projection.

B. Global surface temperature anomaly by seasons

In this section, I intended to plot the global surface temperature anomaly for different seasons of 2022. The data is accessed from the same NASA GISSTEMP website. However, in this case, I selected data for four meteorological seasons (winter, spring, summer, and autumn) individually as Mean Period, and downloaded the corresponding grid data as a netCDF file. To get the data for the entire calendar year of 2022, I chose Time Interval between the beginning and the end of 2022.

Next, I created a get_data function to derive longitude, latitude, temperature anomaly, and average temperature anomaly data for four seasons from the corresponding netCDF file as shown below:

I intended to plot the temperature anomaly for four seasons as four subplots within a single figure. This has been coded accordingly in the code snippet below. I also added a common legend colorbar for the entire figure.

clevs = np.arange(-5, 6)
cmap = "coolwarm"
projection = ccrs.PlateCarree()

# Use subplot_kw to declare the projection
fig, axs = plt.subplots(2, 2, figsize = (24, 7), subplot_kw = {"projection": projection},
 #gridspec_kw = {'wspace':0.01, 'hspace':0.3}
 )
plt.subplots_adjust(left = 0.2, right = 0.8, top = 0.9, bottom = -0.25)

fig.suptitle(title, x = 0.5, y = 1, fontsize = 20, fontweight = "bold")

cf1 = axs[0, 0].contourf(winter_lons, winter_lats, 
 winter_temp_anomaly,
 clevs,
 #transform = ccrs.PlateCarree(),
 cmap = cmap,
 extend = "both"
 )

axs[0, 0].set_title(f'Winter 2022: +{winter_temp_anomaly_mean} °C', fontsize = 20)
axs[0, 0].coastlines()
axs[0, 0].gridlines(draw_labels=True)
axs[0, 0].set_aspect('equal', adjustable=None)

cf2 = axs[0, 1].contourf(spring_lons, spring_lats, 
 spring_temp_anomaly,
 clevs,
 #transform = ccrs.PlateCarree(),
 cmap = cmap,
 extend = "both"
 )
axs[0, 1].set_title(f'Spring 2022: +{spring_temp_anomaly_mean} °C', fontsize = 20)
axs[0, 1].coastlines()
axs[0, 1].gridlines(draw_labels=True)
axs[0, 1].set_aspect('equal', adjustable=None)

cf3 = axs[1, 0].contourf(summer_lons, summer_lats, 
 summer_temp_anomaly,
 clevs,
 #transform = ccrs.PlateCarree(),
 cmap = cmap,
 extend = "both"
 )
axs[1, 0].set_title(f'Summer 2022: +{summer_temp_anomaly_mean} °C', fontsize = 20)
axs[1, 0].coastlines()
axs[1, 0].gridlines(draw_labels=True)
axs[1, 0].set_aspect('equal', adjustable=None)

cf4 = axs[1, 1].contourf(autumn_lons, autumn_lats, 
 autumn_temp_anomaly,
 clevs,
 #transform = ccrs.PlateCarree(),
 cmap = cmap,

 #To add arrows in the colorbar
 extend = "both"
 )

cax = fig.add_axes([0.25, -0.35, 0.5, 0.025]) #[left, bottom, width, height]

lgd = fig.colorbar(cf4,
 orientation = "horizontal",
 ticks = clevs,
 cax = cax,
 label = "°C"
 ).set_label("°C", rotation = 0)

axs[1, 1].set_title(f'Autumn 2022: +{autumn_temp_anomaly_mean} °C', fontsize = 20)
axs[1, 1].coastlines()
axs[1, 1].gridlines(draw_labels=True)
axs[1, 1].set_aspect('equal', adjustable=None)

plt.savefig("../output/temperature_anomalies_by_seasons.jpeg",
 bbox_inches = "tight",
 dpi = 300)

plt.show()

The resulting plot is as shown below:

Key Takeaways

Some key takeaways from this analysis are as follows:

  • 2022 was a year of La Nina, which typically has a cooling effect on global temperature. Despite that, the global average surface temperature anomaly in 2022 was 1.2 °C relative to the 1951–80 mean. 2022 was the warmest La Nina year on record, which highlights the extremeness of global warming (CNN, 2023).
  • The surface temperature anomaly is not uniform across different parts of the world. As discussed in the previous post, global surface temperature anomaly is much higher in land as compared to oceans. A study stated that temperature over land has risen around twice as those over oceans in recent decades.
  • There are some parts of the ocean, which are slightly cooler in different seasons of 2022 as compared to the historical 1951–80 base period. These are depicted by bluish color on the map. For example, parts of the Pacific Ocean to the left of South America, and some areas below Greenland. However, this doesn’t paint the complete picture as the majority of the places have warmed up as depicted by the reddish color.
  • The Arctic region has warmed up much higher as compared to other parts of the world in recent years. This can broadly be attributed to the melting of sea ice and snow cover, causing the reducing in reflection and an increase in absorption of solar radiation (PBS News Hour, 2022). In 2022, the Arctic temperature anomaly was more prominent in winter as compared to other months.
  • Section B above showed that the global surface temperature anomaly in 2022 differed across seasons. The highest temperature anomaly was observed in summer (1.15 °C), followed by spring (1.14 °C), winter (1.08 °C), and autumn (1.02 °C). This can relate to the fact that summer has got much warmer and quite intolerable in recent years as compared to other seasons.

Conclusion

In this post, first, I plotted the global surface temperature anomaly data for April 2023 relative to the 1951–80 mean using the data obtained from NASA’s GISSTEMP as a netCDF file. I demonstrated ways to plot the map in different projections using the Cartopy package. Next, I plotted the surface temperature anomaly across four meteorological seasons of 2022 as four subplots within one figure. Using the map plots, I extracted the key takeaway messages around global surface temperature anomaly in recent years across different parts of the world and different seasons of the year.

Xarray is another useful package in Python, which can be used for working with geospatial data in netCDF or other file formats. For example, the posts by Lubomir Franko and Giannis Tolios showcase plotting surface temperature anomaly data for Europe using xarray, cartopy, and matplotlib. The possibilities of working with spatial data with xarray can be a topic for a different post.

The notebooks and the data used in the analysis in this post and the previous post of this series are available in this GitHub repository. Thank you for reading!

References

CNN, 2023. 2022 was the warmest La Niña year on record. Scientists say this year will be warmer | CNN

GISTEMP Team, 2023: GISS Surface Temperature Analysis (GISTEMP), version 4. NASA Goddard Institute for Space Studies. Dataset accessed 2023–05–31 at data.giss.nasa.gov/gistemp/.

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.

National Snow and Ice Data Center – Advancing knowledge of Earth’s frozen region, 2023. [What is netCDF? | National Snow and Ice Data Center (nsidc.org)](https://nsidc.org/data/user-resources/help-center/what-netcdf#:~:text=NetCDF%20(network%20Common%20Data%20Form,format%20for%20representing%20scientific%20data.)

PBS News Hour, 2022. The Arctic is warming nearly four times faster than the rest of the world | PBS NewsHour

QGIS Documentation, 2023. 8. Coordinate Reference Systems – QGIS Documentation documentation

The World Counts, 2023. Global warming and CO2 Concentration (theworldcounts.com)

World Meteorological Organization (WMO), 2023. Global Annual to Decadal Climate Update | World Meteorological Organization (wmo.int)


Written By

Himalaya Bir Shrestha

Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.

Write for TDS

Related Articles