California august temperature anomaly

How anomalous was the August 2020 average temperature?

California Temperature August 2020

In this first section, we load required packages and modules

[1]:
##This is so variables get printed within jupyter
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
[2]:
##import packages
import os
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import cartopy
import cartopy.crs as ccrs
import matplotlib.ticker as mticker

#for rank calculation
# import bottleneck
[3]:
os.chdir(os.path.abspath('../../'))

Load ERA5

We have retrieve netcdf files of global monthly 2m temperature and 2m dewpoint temperature for each year over 1979-2020.

We load all files with xarray open_mfdataset.

[4]:
ERA5 = xr.open_mfdataset('E:/PhD/California_example/ERA5/ERA5_????.nc',combine='by_coords') ## open the data
ERA5#
[4]:
<xarray.Dataset>
Dimensions:    (latitude: 51, longitude: 61, time: 42)
Coordinates:
  * longitude  (longitude) float32 -130.0 -129.0 -128.0 ... -72.0 -71.0 -70.0
  * latitude   (latitude) float32 70.0 69.0 68.0 67.0 ... 23.0 22.0 21.0 20.0
  * time       (time) datetime64[ns] 1979-08-01 1980-08-01 ... 2020-08-01
Data variables:
    t2m        (time, latitude, longitude) float32 dask.array<chunksize=(1, 51, 61), meta=np.ndarray>
    d2m        (time, latitude, longitude) float32 dask.array<chunksize=(1, 51, 61), meta=np.ndarray>
Attributes:
    Conventions:  CF-1.6
    history:      2020-10-01 23:23:34 GMT by grib_to_netcdf-2.16.0: /opt/ecmw...

Calculating the anomaly

We want to show how anomalous the recorded monthly average temperature for 2020 is compared to the 1979-2010 average.

[13]:
ERA5_anomaly = ERA5['t2m'] - ERA5['t2m'].sel(time=slice('1979','2010')).mean('time')
ERA5_anomaly.attrs = {
    'long_name': 'August temperature anomaly',
    'units': 'C'
}
ERA5_sd_anomaly = ERA5_anomaly / ERA5['t2m'].std('time')
ERA5_sd_anomaly.attrs = {
    'long_name': 'August temperature standardized anomaly',
    'units': '-'
}

Plotting

We define a function to plot the data on a global map:

[14]:
def plot_California(ERA5_input):

    extent = [-120, -80, 20, 50]
    central_lon = np.mean(extent[:2])
    central_lat = np.mean(extent[2:])

    plt.figure(figsize=(12, 6))
    ax = plt.axes(projection=ccrs.AlbersEqualArea(central_lon, central_lat))
    ax.set_extent(extent)

    ERA5_input.plot(
        ax=ax,
        transform=ccrs.PlateCarree(),
    #     levels=[1, 2, 3, 4, 5],
        extend='both')#,
    #     colors=plt.cm.Reds_r)

    ax.add_feature(cartopy.feature.BORDERS, linestyle=':')
    ax.coastlines(
        resolution='110m')  #Currently can be one of “110m”, “50m”, and “10m”.
    ax.set_title('')
    gl = ax.gridlines(crs=ccrs.PlateCarree(),
                      draw_labels=True,
                      linewidth=1,
                      color='gray',
                      alpha=0.5,
                      linestyle='--')
    gl.top_labels = False
    gl.right_labels = False

Temperature anomaly

[15]:
plot_California(ERA5_anomaly.sel(time = '2020'))
plt.savefig('graphs/California_anomaly.png')
../_images/Notebooks_California_august_temperature_anomaly_13_0.png

Plot the standardized anomaly

[16]:
plot_California(ERA5_sd_anomaly.sel(time = '2020'))
plt.savefig('graphs/California_sd_anomaly.png')
../_images/Notebooks_California_august_temperature_anomaly_15_0.png

Define mask as higher than 2 standard deviation anomaly

[17]:
ERA5_masked = (ERA5_sd_anomaly.
               sel(longitude = slice(-125,-100),
                  latitude = slice(45,20)).
               where(ERA5_sd_anomaly.sel(time = '2020').
                     squeeze('time')>2)
              )

# ERA5_masked
plot_California(ERA5_masked.sel(time = '2020'))
../_images/Notebooks_California_august_temperature_anomaly_17_0.png
[21]:
ERA5_anomaly_timeseries = ERA5_anomaly.sel(longitude = slice(-119,-100)).where(ERA5_sd_anomaly.sel(time = '2020').squeeze('time')>2).mean(['longitude','latitude'])
ERA5_anomaly_timeseries.plot()
plt.ylabel('August temperature anomaly (C)')
plt.savefig('graphs/California_anomaly_timeseries.png')
[21]:
[<matplotlib.lines.Line2D at 0x241db54c790>]
[21]:
Text(0, 0.5, 'August temperature anomaly (C)')
../_images/Notebooks_California_august_temperature_anomaly_18_2.png