top of page

Extreme Precipitation in Texas

This was my python final project regarding precipitation in Texas.

Introduction and Background:

My research project is looking at precipitation data in Texas from 2022 and to see how precipitation has changed over the past five years across the state. Precipitation data is very important to analyze as it tells information related to flooding and drought: impacting crops, farming, food and nutrition, and social vulnerability. Without adequate precipitation, food sources can be affected limiting food to low income areas causing unequitable conditions. Drought is especially prevalent in the state of Texas. Without proper drinking water, people are more greatly affected by the high temperatures. The homeless population in addition can sometimes be most at risk for these extreme weather conditions as they are not livable for an equitable lifestyle.

From the NOAA National Severe Storms Laboratory, "In the U.S. floods kill more people each year than tornadoes, hurricanes or lightning."

Methods:

In order to show precipitation data across the state of Texas, I pulled all 2017-2022 daily values. Precipitation was measured in millimeters, and I averaged the precipitaiton over time to determined the mean precipitation levels for the 2022 year and then over a 5 year range. In addition to the annual precipitation averages, I displayed the precipitation data seasonally to show the variations in rain over spring, summer, fall, and winter.

To clip the raster of precipitation, I initially used the .sel function to pull specific latitudes and longitudes that contained that state of Texas and overlayed an outline of Texas. This still displayed the surrounding southern states and I wished to only show Texas. Becuase of this I learned how to mask the netcdf4 file with a shapefile through the package of shapely and rioxarray.

Description of Data:

For precipitation data, I used the nClimGrid-Daily data from the year 2022. This information is from NOAA National Centers for Environmental Information (NCEI); https://www.ncei.noaa.gov/access/metadata/landing-page/bin/iso?id=gov.noaa.ncdc:C00332 I ran this data through xarray as a dataset; it contained daily data for every grid across the US. I masked the precipitation data to have the extent of the state of Texas through the rioxarray package. This shapefile for the state of texas was obtained through the public domain natural earth which contains public mapping datasets; https://www.naturalearthdata.com/


# Load Libraries: 
import numpy as np
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import xarray as xr

from shapely.geometry import mapping
import rioxarray as rio

import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER



# Obtain Data: 
data22 = xr.open_mfdataset("2022/ncdd*.nc") # 2022 data
data5 = xr.open_mfdataset("20**/ncdd*.nc") # 5 Year Data (2017-2022)

# Get Outline of state of Texas: 
gdf_states = gpd.read_file("ne_110m_admin_1_states_provinces/ne_110m_admin_1_states_provinces.shp")
Texas = gdf_states.loc[gdf_states['name'] == 'Texas'] # pull state of Texas from shapefile
Texas["geometry"].plot(facecolor = "none")


# Slice Precipitation and Temperature Data to the state of Texas: 
data5 = data5.sel(lat=slice(26,38), lon=slice(-110,-90))
data22 = data22.sel(lat=slice(26,38), lon=slice(-110,-90))

temp_mean = data22["tavg"].mean("time") # daily mean temperature in 2022
prcp_mean = data22['prcp'].mean('time') # daily mean precipitation in 2022 

# The extent was clipped to the lat and lon of Texas using the sel function
# The mean/average of those values over time were taken for each grid cell 

# Clip Raster Data to the Shape of Texas: 
texasprcp = prcp_mean.rename({"lat":"y", "lon":"x"}).rio.write_crs("EPSG:4326") # set CRS
texastemp = temp_mean.rename({"lat":"y", "lon":"x"}).rio.write_crs("EPSG:4326") 

prcpclipped = texasprcp.rio.clip(Texas.geometry.apply(mapping)) # use rioxarray to clip to Texas geometry 
tempclipped = texastemp.rio.clip(Texas.geometry.apply(mapping))

# Average Precipitation and Temperature:

# plot blank figure:
fig, axs = plt.subplots(1,2, figsize = (10,6))

#Average Precip: 
mappable = axs[0].contourf(prcpclipped, cmap = "Blues")
axs[0].set_title("Precipitation", size = 14)
cb = plt.colorbar(mappable, ax=axs[0], orientation = "horizontal", aspect = 30, pad=0.1) # color bar
cb.set_label('Precipitation (mm)', fontsize=12) # color bar units

# Average Temp: 
mappable2 = axs[1].contourf(tempclipped, cmap = "Reds",)
axs[1].set_title("Temperature", size = 14)
cb = plt.colorbar(mappable2, ax=axs[1], orientation = "horizontal", aspect = 30, pad=0.1) # color bar
cb.set_label('Temperature (C)', fontsize=12) # color bar units

# Title: 
fig.suptitle("Average Precipitation and Temperature in Texas in 2022", size = 17)
fig.tight_layout()

On average in a year, precipitation shows a gradient trend east to west. The east side of the state receives the most rain in a given year. Whereas temperature shows a gradient north to south.


# Seasonal Precipitation: 
seas_prcp = data22['prcp'].sel(lat=slice(26,38), lon=slice(-110,-90)).groupby('time.season').mean('time')

# Clip Seasonal Raster Data to the Shape of Texas: 
seas_prcp = seas_prcp.rename({"lat":"y", "lon":"x"}).rio.write_crs("EPSG:4326") # set CRS

# Seasons: 
winterprcp = seas_prcp.sel(season = "DJF")
springprcp = seas_prcp.sel(season = "MAM")                           
summerprcp = seas_prcp.sel(season = "JJA")
fallprcp = seas_prcp.sel(season = "SON")

w_prcpclipped = winterprcp.rio.clip(Texas.geometry.apply(mapping)) # use rioxarray to clip to Texas geometry 
sp_prcpclipped = springprcp.rio.clip(Texas.geometry.apply(mapping)) 
su_prcpclipped = summerprcp.rio.clip(Texas.geometry.apply(mapping)) 
f_prcpclipped = fallprcp.rio.clip(Texas.geometry.apply(mapping)) 

# Plot Fig: 
fig, axs = plt.subplots(1,4, figsize = (14,5))

# Plot Winter, Spring, Summer, Fall: 
mappable = axs[0].contourf(w_prcpclipped, cmap = "Blues")
axs[0].set_title("Winter", size = 14)

axs[1].contourf(sp_prcpclipped, cmap = "Blues")
axs[1].set_title("Spring", size = 14)

axs[2].contourf(su_prcpclipped, cmap = "Blues")
axs[2].set_title("Summer", size = 14)

axs[3].contourf(f_prcpclipped, cmap = "Blues")
axs[3].set_title("Fall", size = 14)

fig.suptitle("Seasonal Precipitation 2022", size = 17)

fig.tight_layout()

cb = plt.colorbar(mappable, ax=axs, orientation = "horizontal", aspect = 40, pad=0.2) # color bar
cb.set_label('Precipitation (mm)', fontsize=10) # color bar units

Seasonally, in 2022, precipitation is seen greatest on the east side of the state near the Gulf of Mexico. Spring and fall show the rainiest times of the year; summer and winter are the driest.




# pull two 30-year periods from the climate dataset within the Texas region: 

#1981-2010
clim81 = climatedata.sel(lat=slice(26,37), lon=slice(-110,-84)).loc[dict(time=slice("1981-01-01","2010-12-31"))]

#1991-2020
clim91 = climatedata.sel(lat=slice(26,37), lon=slice(-110,-84)).loc[dict(time=slice("1991-01-01","2020-12-31"))]

# Cut data to the extent of Texas: 
texasprcp81 = clim81['prcp'].rename({"lat":"y", "lon":"x"}).rio.write_crs("EPSG:4326") # set CRS
texasprcp91 = clim91['prcp'].rename({"lat":"y", "lon":"x"}).rio.write_crs("EPSG:4326") 
texasprcp81 = texasprcp81.rio.clip(Texas.geometry.apply(mapping)) 

# use rioxarray to clip to Texas geometry 
texasprcp91 = texasprcp91.rio.clip(Texas.geometry.apply(mapping)) #1981-2010  clim81 = climatedata.sel(lat=slice(26,37), lon=slice(-110,-84)).loc[dict(time=slice("1981-01-01","2010-12-31"))]


# Pulls the mean precipitation value for each grid point over the 30-year period: 

prcp_mean_1981 = texasprcp81.mean('time') 
prcp_mean_1991 = texasprcp91.mean('time')


# Average Precipitation Difference: #1991-2020 - 1981-2010:

# Difference between 2 precipitation rasters: 
meanprcpdif = (prcp_mean_1991 - prcp_mean_1981)

# Plot figure:

fig, axs = plt.subplots(1, figsize = (8, 6))

# Precip difference: 

norm = TwoSlopeNorm(vcenter=0)

mappable = axs.contourf(meanprcpdif, cmap = "bwr_r", norm=norm)

axs.set_title("Difference between 2 30-Year Periods", size = 14)

fig.suptitle("Average Precipitation", size = 17)

fig.tight_layout()

cb = fig.colorbar(mappable, ax=axs, orientation = "vertical", aspect = 30, pad=0.05) # color bar

cb.set_label('Precipitation (mm)', fontsize=10) # color bar units

Comparing the two 30-year periods, 1980-2010 and 1990-2020, precipitation has increased the greatest on the east side of the state near the gulf. Precipitation has decreased on average on the west side of the state.







Project Gallery

©2021 by Emma Heienickle. Proudly created with Wix.com

bottom of page