<jupyter_start><jupyter_text>Ocean surface Kinetic Energy anomaly trends This Jupyter notebook shows how to compute the KE anomaly trend maps reported in the manuscript "Global changes in oceanic mesoscale currents over the satellite altimetry record".<jupyter_code># Import libraries
import xarray as xr
import cmocean as cm
import cartopy.crs as ccrs

import pylab as plt
import numpy as np
# Inline plotting
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Import Mann Kendall test:<jupyter_code>from xarrayMannKendall import Mann_Kendall_test
from utils import area,ccrs_land,add_patches
import datetime as datetime
from dask.distributed import Client
c = Client()
c
dataset_KE = xr.open_dataset('../datasets/KE_anomaly_timeseries.nc',chunks={'lat':10,'lon':10})
rho=1025 #kg/m^3
KE_density = rho*dataset_KE["KE'"]
KE = KE_density.sortby('time').sel(time=slice('1993','2020'))
# Print function used.
?Mann_Kendall_test<jupyter_output><empty_output><jupyter_text>For more information in the Mann-Kendall method, please refer to: https://doi.org/10.1023/B:WARM.0000043140.61082.60 The reported trends use a modified Mann-Kendall method. A modified Mann-Kendall test is used to assess statistical significance of trends, while properly taking into account the autocorrelation in the time-series. The effective sample size for all the reported trends is always smaller than the actual sample size, due to autocorrelation of the time series.<jupyter_code>ke_trends = Mann_Kendall_test(KE,'time',MK_modified=True,
                               method="linregress",alpha=0.05, 
                               coords_name = {'time':'time','x':'lon','y':'lat'})<jupyter_output><empty_output><jupyter_text>Note that the following cell will take ~1 hour depending on the number of cores, as the Mann-Kendall method requirest to invert a matrix of shape (len(time),len(time)) for each grid point.<jupyter_code>KE_trends = ke_trends.compute()
KE_trends.attrs['title'] = "Kinetic Energy anomaly trends"
KE_trends.attrs['Description'] = """Kinetic Energy anomaly trends computed from AVISO+ altimetry. Then trends were computed using a modified Mann-Kendall test. \n See: https://github.com/josuemtzmo/xarrayMannKendall."""
KE_trends.attrs['Publication'] = "Dataset created for Martínez-Moreno, J. et. al. 2020: \n 'Mesoscale kinetic energy response to changing oceans'"
KE_trends.attrs['Author'] = "<NAME>"
KE_trends.attrs['Contact'] = "<EMAIL>"

KE_trends.attrs['Created date'] = datetime.datetime.now().strftime("%d/%m/%Y %H:%M:%S")

######################################################

KE_trends['trend'].attrs['units'] = r"$J m^{-3} day^{-1}$"
KE_trends['trend'].attrs['name'] = 'trend'
KE_trends['trend'].attrs['long_name'] = "Kinetic Energy anomaly trends"

KE_trends['trend'].attrs['missing_value'] = np.nan
KE_trends['trend'].attrs['valid_min'] = np.nanmin(KE_trends['trend'])
KE_trends['trend'].attrs['valid_max'] = np.nanmax(KE_trends['trend'])
KE_trends['trend'].attrs['valid_range'] = [np.nanmin(KE_trends['trend']),np.nanmax(KE_trends['trend'])]

######################################################

KE_trends['signif'].attrs['units'] = ""
KE_trends['signif'].attrs['name'] = 'signif'
KE_trends['signif'].attrs['long_name'] = "Kinetic Energy anomaly trends significance"

KE_trends['signif'].attrs['missing_value'] = np.nan
KE_trends['signif'].attrs['valid_min'] = np.nanmin(KE_trends['signif'])
KE_trends['signif'].attrs['valid_max'] = np.nanmax(KE_trends['signif'])
KE_trends['signif'].attrs['valid_range'] = [np.nanmin(KE_trends['signif']),np.nanmax(KE_trends['signif'])]

######################################################

KE_trends['p'].attrs['units'] = ""
KE_trends['p'].attrs['name'] = 'p'
KE_trends['p'].attrs['long_name'] = "Kinetic Energy anomaly trends p"

KE_trends['p'].attrs['missing_value'] = np.nan
KE_trends['p'].attrs['valid_min'] = np.nanmin(KE_trends['p'])
KE_trends['p'].attrs['valid_max'] = np.nanmax(KE_trends['p'])
KE_trends['p'].attrs['valid_range'] = [np.nanmin(KE_trends['p']),np.nanmax(KE_trends['p'])]
comp = dict(zlib=True, complevel=5)
encoding = {var: comp for var in KE_trends.data_vars}

KE_trends.to_netcdf('../datasets/KE_anomaly_trends.nc', encoding=encoding)
KE_trends
trends = KE_trends.trend*10*365 # Convert to trends per decade
fig = plt.figure(figsize=(6,2), dpi=200)
ax = fig.add_subplot(1, 1, 1, projection = ccrs.Robinson(central_longitude=180))

im = trends.plot(transform=ccrs.PlateCarree(),cbar_kwargs=dict(label="$J\ m^{-3}\ decade^{-1}$"),
              cmap=cm.cm.balance, vmin=-10, vmax=10,ax=ax)
ax.set_extent([0.1,359.99,-60, 60], crs=ccrs.PlateCarree())
ax.add_feature(ccrs_land)
add_patches(ax)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18560203864939478, 'fraction_numerical': 0.01783818220428966, 'mean_word_length': 6.8762541806020065, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '605188', 'license': 'MIT', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1600, 'n_words': 336, 'path': 'trends/Compute_KE_anomalies_trends.ipynb', 'repo_name': 'josuemtzmo/EKE_SST_trends', 'size': '4748'}