-
Notifications
You must be signed in to change notification settings - Fork 0
/
spa_anom.py
63 lines (51 loc) · 2.01 KB
/
spa_anom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
spa_anom.py
Calculate pdsi spatial
anomaly during the Majapahit era
12/15/22
SHSH <herho@terpmail.umd.edu>
"""
# import libs & plot styling
import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
plt.style.use("bmh")
plt.rcParams['figure.dpi'] = 300
# open netcdf
ds = xr.open_dataset("https://www.ncei.noaa.gov/pub/data/paleo/reconstructions/steiger2018/da_hydro_JunAug_r.1-2000_d.05-Jan-2018.nc")
# data preprocessing
pdsi = ds["pdsi_mn"].sel(lat=slice(-20, 20),lon=slice(90, 160), time=slice(1293, 1527))
ref = (pdsi.mean(dim="time")).rename("PDSI anomaly")
heyday = (pdsi.sel(time=slice(1350, 1389)).mean(dim="time") - ref).rename("PDSI anomaly")
candra = (pdsi.sel(time=1478) - ref).rename("PDSI anomaly")
famine = (pdsi.sel(time=1426) - ref).rename("PDSI anomaly")
jayanegara = (pdsi.sel(time=slice(1309, 1328)).mean(dim="time") - ref).rename("PDSI anomaly")
# plotting
fig = plt.figure(figsize=(12, 5));
ax = fig.add_subplot(111, projection=ccrs.PlateCarree());
jayanegara.plot(ax=ax, transform=ccrs.PlateCarree(),
x='lon', y='lat', cmap="bwr_r", levels=np.arange(-2, 2.5, .5));
ax.coastlines();
ax.gridlines();
ax.set_title("(a) 1309 - 1328 CE");
fig = plt.figure(figsize=(12, 5));
ax = fig.add_subplot(111, projection=ccrs.PlateCarree());
heyday.plot(ax=ax, transform=ccrs.PlateCarree(),
x='lon', y='lat', cmap="bwr_r", levels=np.arange(-2, 2.5, .5));
ax.coastlines();
ax.gridlines();
ax.set_title("(b) 1350 - 1389 CE");
fig = plt.figure(figsize=(12, 5));
ax = fig.add_subplot(111, projection=ccrs.PlateCarree());
famine.plot(ax=ax, transform=ccrs.PlateCarree(),
x='lon', y='lat', cmap="bwr_r", levels=np.arange(-2, 2.5, .5));
ax.coastlines();
ax.gridlines();
ax.set_title("(c) 1426 CE");
fig = plt.figure(figsize=(12, 5));
ax = fig.add_subplot(111, projection=ccrs.PlateCarree());
candra.plot(ax=ax, transform=ccrs.PlateCarree(),
x='lon', y='lat', cmap="bwr_r", levels=np.arange(-2, 2.5, .5));
ax.coastlines();
ax.gridlines();
ax.set_title("(d) 1478 CE");