pH - El Niño vs La Niña#
Show code cell source
import warnings
warnings.filterwarnings("ignore")
import os
import os.path as op
import sys
import pandas as pd
import numpy as np
import xarray as xr
import geopandas as gpd
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
sys.path.append("../../../../indicators_setup")
from ind_setup.plotting_int import plot_timeseries_interactive, plot_oni_index_th
from ind_setup.plotting import plot_base_map, plot_map_subplots, add_oni_cat
from ind_setup.core import fontsize
sys.path.append("../../../functions")
from data_downloaders import download_ERDDAP_data, download_oni_index
Define area of interest
#Area of interest
lon_range = [129.4088, 137.0541]
lat_range = [1.5214, 11.6587]
EEZ shapefile
path_figs = "../../../matrix_cc/figures"
shp_f = op.join(os.getcwd(), '..', '..','..', 'data/Palau_EEZ/pw_eez_pol_april2022.shp')
shp_eez = gpd.read_file(shp_f)
Download Data#
data_xr = xr.open_dataset(op.join(os.getcwd(), '..', '..','..', 'data/data_phyc_o2_ph.nc')).isel(depth = 0)
dataset_id = 'ph'
label = 'pH'
ONI index#
p_data = 'https://psl.noaa.gov/data/correlation/oni.data'
df1 = download_oni_index(p_data)
lims = [-.5, .5]
plot_oni_index_th(df1, lims = lims)
df1 = add_oni_cat(df1, lims = lims)
df1['ONI'] = df1['oni_cat']
data_xr['ONI'] = (('time'), df1.iloc[np.intersect1d(data_xr.time, df1.index, return_indices=True)[2]].ONI.values)
data_xr['ONI_cat'] = (('time'), np.where(data_xr.ONI < lims[0], -1, np.where(data_xr.ONI > lims[1], 1, 0)))
data_oni = data_xr.groupby('ONI_cat').mean()
fig = plot_map_subplots(data_oni, dataset_id, shp_eez = shp_eez, cmap = 'magma_r',
vmin = np.nanpercentile(data_xr.mean(dim = 'time')[dataset_id], 1)-.005,
vmax = np.nanpercentile(data_xr.mean(dim = 'time')[dataset_id], 99) + .005,
sub_plot= [1, 3], figsize = (20, 9), cbar = True, cbar_pad = 0.1,
titles = ['La Niña', 'Neutral', 'El Niño'],)
plt.savefig(op.join(path_figs, 'F14_pH_ENSO.png'), dpi=300, bbox_inches='tight')
data_an = data_oni - data_xr.mean(dim='time')
fig = plot_map_subplots(data_an, dataset_id, shp_eez = shp_eez, cmap='RdBu_r', vmin=-.005, vmax=.005,
sub_plot= [1, 3], figsize = (20, 9), cbar = True, cbar_pad = 0.1,
titles = ['La Niña', 'Neutral', 'El Niño'],)