In [56]:
import xarray as xr
In [57]:
daily_temp_data = xr.open_dataset('/projects/w/wenchang/analysis/people/Isabella_Valentine/era5.2m_temperature.daily.2023-08_to_2024-07.nc')

Task 1: On the day of August 12, 2023 what was the global temperature on a map in Fahrenheit and Celsius?

My thinking:

  • Need to plot data on a map (JP map code)
  • Extract global August 12, 2023 data
  • and calculate the daily means at each lat and lon coordinate in space (already done)

About the data set: Coordinates are number, latitude, longitude, time. Data variables are t2m. Time is already datetime.

In [58]:
aug_12_global_data = daily_temp_data.t2m.sel(time  = "2023-08-12") #datetime in same format as dates in dataset
In [59]:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER, mticker
import numpy as np
In [60]:
fig = plt.figure(figsize=(16,10),dpi=100)
ax = fig.add_subplot(projection=ccrs.PlateCarree(), frameon=True)

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,linewidth=0.3, color='gray', alpha=0.5, linestyle='--')

mesh = ax.pcolormesh(aug_12_global_data.longitude, aug_12_global_data.latitude,
              aug_12_global_data.values, cmap='RdYlBu_r', transform=ccrs.PlateCarree())
ax.coastlines()

plt.colorbar(mesh, ax=ax, label="Temperature (K)", shrink=0.65)

plt.title("Global Temperature on August 12, 2023 (Isabella's birthday between gap year and college)")

plt.show()
No description has been provided for this image
In [61]:
aug_12_global_data_fahrenheit = (aug_12_global_data-273.15)*(9/5)+32
#(0K − 273.15) × 9/5 + 32 = -459.7°F
In [62]:
fig = plt.figure(figsize=(16,10),dpi=100)
ax = fig.add_subplot(projection=ccrs.PlateCarree(), frameon=True)

gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,linewidth=0.3, color='gray', alpha=0.5, linestyle='--')

mesh = ax.pcolormesh(aug_12_global_data_fahrenheit.longitude, aug_12_global_data_fahrenheit.latitude,
              aug_12_global_data_fahrenheit.values, cmap='RdYlBu_r', transform=ccrs.PlateCarree())
ax.coastlines()

plt.colorbar(mesh, ax=ax, label="Temperature (°F)", shrink=0.65)

plt.title("Global Temperature on August 12, 2023 (Isabella's birthday between gap year and college)")

plt.show()
No description has been provided for this image

Task 2: In Santa Barbara, CA, what was the temperature between Sept 2023--May 2024 (Fahrenheit)

In [63]:
# define Santa Barbara bounds

buffer=0.1
daily_temp_data_santa_barbara = daily_temp_data.sel(
        latitude=slice(34.460+buffer, 34.406-buffer),
        longitude=slice(240.22-buffer, 240.34+buffer)
    )

daily_temp_data_santa_barbara

# define Santa Barbara timing
daily_temp_data_santa_barbara_dates  = daily_temp_data_santa_barbara.sel(time = slice('2023-09-01', '2024-05-31'))
In [64]:
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
In [65]:
# Initial plot + get ax dimensions sorted out
fig, ax = plt.subplots(figsize=(8,4))
temp_squeezed = daily_temp_data_santa_barbara_dates.t2m.squeeze()
ax.plot(daily_temp_data_santa_barbara_dates.time, temp_squeezed)

# Ticks (get year sorted out)
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y"))
ax.tick_params(axis="x", rotation=45)

# Plot
ax.set_ylabel("Temperature (K)")
ax.grid(alpha=0.3)
ax.set_title("Daily Temperature (2m Above Surface) in Santa Barbara, CA")
ax.set_xlabel("Time")

plt.tight_layout()
plt.show()
No description has been provided for this image
In [66]:
# Initial plot + get ax dimensions sorted out
fig, ax = plt.subplots(figsize=(8,4))
daily_temp_data_santa_barbara_dates_fahrenheit = (daily_temp_data_santa_barbara_dates-273.15)*(9/5)+32
temp_squeezed = daily_temp_data_santa_barbara_dates_fahrenheit.t2m.squeeze()
ax.plot(daily_temp_data_santa_barbara_dates_fahrenheit.time, temp_squeezed)

# Ticks (get year sorted out)
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y"))
ax.tick_params(axis="x", rotation=45)

# Plot
ax.set_ylabel("Temperature (°F)")
ax.grid(alpha=0.3)
ax.set_title("Daily Temperature (2m Above Surface) in Santa Barbara, CA")
ax.set_xlabel("Time")

plt.tight_layout()
plt.show()
No description has been provided for this image

Task 3: In Kona, HI what was the temperature between Sept 2023--May 2024 (Fahrenheit)

In [67]:
# define Kona bounds

buffer=0.05
daily_temp_data_kona = daily_temp_data.sel(
        latitude=slice(19.75+buffer, 19.6-buffer),
        longitude=slice(203.95-buffer, 204.05+buffer)
    )

daily_temp_data_kona

# define Santa Barbara timing
daily_temp_data_kona_dates  = daily_temp_data_kona.sel(time = slice('2023-09-01', '2024-05-31'))
In [68]:
# Initial plot + get ax dimensions sorted out
fig, ax = plt.subplots(figsize=(8,4))
daily_temp_data_kona_dates_fahrenheit = (daily_temp_data_kona_dates-273.15)*(9/5)+32
temp_squeezed = daily_temp_data_kona_dates_fahrenheit.t2m.squeeze()
ax.plot(daily_temp_data_kona_dates_fahrenheit.time, temp_squeezed)

# Ticks (get year sorted out)
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b %Y"))
ax.tick_params(axis="x", rotation=45)

# Plot
ax.set_ylabel("Temperature (°F)")
ax.grid(alpha=0.3)
ax.set_title("Daily Temperature (2m Above Surface) in Kona, HI")
ax.set_xlabel("Time")

plt.tight_layout()
plt.show()
No description has been provided for this image