<jupyter_start><jupyter_text>EKE preprocessing This notebook shows how to generate the EKE_timeseries.nc file<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
from dask.distributed import Client
from utils import area,ccrs_land,add_patches
import datetime
c = Client()
c
files = '/g/data/ua8/CMEMS_SeaLevel/v2019/*/*.nc'
# files='path2AVISO+/*.nc'
dataset_AVISO = xr.open_mfdataset(files,parallel=True)
dataset_AVISO<jupyter_output><empty_output><jupyter_text>Compute EKE:\begin{equation}EKE = \frac{1}{2} \left(u'^2+v'^2\right)\end{equation}The provided $u'$ and $v'$ from AVISO is an anomaly from 1993-2012. Changing this period does not affect the main result of the study.<jupyter_code>EKE = 1/2 * (dataset_AVISO.ugosa**2 + dataset_AVISO.vgosa**2)<jupyter_output><empty_output><jupyter_text>Rechunk dataset<jupyter_code>EKE_rechunk = EKE.chunk({"latitude": 100, "longitude": 100,'time':357})<jupyter_output><empty_output><jupyter_text>Coarsen dataset to a 1 degree grid.<jupyter_code>EKE_coarsen = EKE_rechunk.coarsen({'latitude':4,'longitude':4}).mean()<jupyter_output><empty_output><jupyter_text>Roll over 12 months:<jupyter_code>EKE_rolled = EKE_coarsen.rolling(time=365,center=True).mean().compute() 
# This computation requires ~ 50 GB of RAM, to decrease the usage of RAM, 
# reduce the size of the chunks.
EKE_rolled = EKE_rolled.to_dataset(name="EKE").rename({'latitude':'lat','longitude':'lon'})
EKE_rolled<jupyter_output><empty_output><jupyter_text>Add metadata<jupyter_code>EKE_rolled.attrs['title'] = "Eddy Kinetic Energy"
EKE_rolled.attrs['Description'] = """Eddy Kinetic Energy computed from AVISO+ altimetry products."""
EKE_rolled.attrs['Publication'] = "Dataset created for Martínez-Moreno, J. et. al. 2020: \n 'Global changes in oceanic mesoscale currents over the satellite altimetry record'"
EKE_rolled.attrs['Author'] = "<NAME>"
EKE_rolled.attrs['Contact'] = "<EMAIL>"

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

counter = 0
units = [r"$m^2s^{-2}$"]
names = ["EKE"]
long_names = ["Eddy Kinetic Energy"]

EKE_rolled['EKE'].attrs['units'] = units[counter]
EKE_rolled['EKE'].attrs['name'] = names[counter]
EKE_rolled['EKE'].attrs['long_name'] = long_names[counter]

EKE_rolled['EKE'].attrs['missing_value'] = np.nan
EKE_rolled['EKE'].attrs['valid_min'] = np.nanmin(EKE_rolled['EKE'])
EKE_rolled['EKE'].attrs['valid_max'] = np.nanmax(EKE_rolled['EKE'])
EKE_rolled['EKE'].attrs['valid_range'] = [np.nanmin(EKE_rolled['EKE']),np.nanmax(EKE_rolled['EKE'])]<jupyter_output><empty_output><jupyter_text>Store netCDF<jupyter_code>comp = dict(zlib=True, complevel=5)
encoding = {var: comp for var in EKE_rolled.data_vars}

EKE_rolled.to_netcdf('../datasets/EKE_timeseries.nc', encoding=encoding)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup