For example, when is this heat wave going to end? How many consecutive days above 90 degrees have there been compared to other years?
In Portland, Oregon, 2022 temperatures have been mild compared to many record-setting heatwaves in other parts of the world. Portland was not as lucky in 2021, when the overall heat record was broken and then re-broken multiple times in the same year. By the end of the 2021 summer, the latest record (116 Fahrenheit) was 9 degrees warmer than the record at the start of the year (107 Fahrenheit).
In the Pacific Northwest, many are accustomed to a mild climate. It is not uncommon to hear someone complain about hot days, and I’m not an exception. Although 2022 might be mild compared to the record heat in 2021, this year seems hot. Perhaps consecutive days of hot weather have impacted my perception. Let’s count the hot day streaks (also known as heat waves) with Python to analyze this assumption.
In a previous article, I wrote about the publicly available data source that I’m about to use from the National Centers for Environmental Information (NCEI). Please read that article for more details about how to access the data and visit NCEI to learn more about NCEI and the National Environmental Satellite, Data, and Information Service’s (NESDIS) mission.
In this article, the focus will be on TMAX, the maximum observed daily temperature at particular weather stations. The data for Portland, Oregon and my exploratory data analysis are available on GitHub.
The following data frame was created for this analysis and contains True / False boolean fields that indicate whether the temperature was at least 80 degrees, at least 90 degress, or at least 100 degrees Fahrenheit.
To calculate consecutive occurrences is not as simple as you might think. There are multiple calculations required to arrive at a solution, and developing an algorithm that can work on years of data is not trivial. However, there are packages that reduce the number of functions to write for this algorithm. The
itertools.groupby() package for Python was the easiest method for me to implement for this analysis.
First, import the
groupby()function from the
from itertools import groupby
Next, define a function that takes a list of data points for a year as the parameter and then returns a list. Each element in this returned list contains the length of each heat wave that year. For example, if the threshold that we set for heat is 90 degrees Fahrenheit, then a list of [1, 5, 1, 2] for a given year would mean that there were four heat waves in that year. The first wave contained 1 day with a maximum temperature at or above 90 degrees. The second wave contained 5 days in a row above 90 degrees. And so on.
The next function does a few things:
- Determines the longest heat wave for each year using the function defined above
- Loops through each year in a data frame
- Returns a data frame of the longest 90 degree heat wave (in days) for each year
A similar function is written for 80 degrees and 100 degrees, in order to obtain comparisons.
Before reviewing the longest heatwaves in each year, let’s inspect the number of overall heat days by year. In the next chart, 2022 is filtered out since the year is not yet complete. Last year, 2021, was hot! There were 90 days with at least 80 degree heat overall, the most in recorded history. The number of 100 degree days and 80 degree days also describe the year as one of the hottest on record.
The next chart shows the longest heat waves up to 2022. Although 2022 is not yet complete, it is unlikely that the longest heat wave of the year would begin past mid-August.
There are interesting findings to note from the consecutive hot days captured in the heat wave data, but these findings also reveal that my recent memory was biasing my opinion about the hot summer of 2022.
- The year 2022 did not have a longer heat wave than 2021. The longest 90 and 80 degree heat waves in 2022 were shorter than the longest heat waves in 2021. For 100 degree heat waves, 2021 and 2022 tied at three days in length.
- There are six years with 90 degree heat waves longer than the longest heat wave in 2021, and nine years with 80 degree heat waves longer than the longest heatwave 2021. Therefore, there were more cool-down periods in 2021 compared to the other hottest years. This is why the total number of heat days did not result in the longest heat wave on record.
- The consecutive heat-day streaks seem to be cyclical. The last year (2022) is on the lower end of the cycle.
Although there is a trend of an increasing number of days of hot weather each year, 2021 was hotter than 2022 whether measured by the number of hot days or the longest heat waves.