This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
# Define the x and y coordinates | |
x = [0, 1, 2, 3] | |
y = [0, 1, 2, 3] | |
# Define the u and v components of the currents | |
u = [1, 2, 3, 4] | |
v = [0, 1, 0, -1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
file = 'path/to/file.nc' | |
data = xr.open_dataset(file) | |
data.OHC_0_200_emean.isel(time=0).plot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# define preprocess drop function - this unfortunately removes useful information like areau that's missing from 2015 files | |
def drop_not_in_2015(ds): | |
if 'latu_bounds' in ds.data_vars: | |
ds = ds.drop(['latu_bounds']) | |
if 'lonu_bounds' in ds.data_vars: | |
ds = ds.drop(['lonu_bounds']) | |
if 'latv_bounds' in ds.data_vars: | |
ds = ds.drop(['latv_bounds']) | |
if 'lonv_bounds' in ds.data_vars: | |
ds = ds.drop(['lonv_bounds']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def calc_EKE(u, v): | |
''' | |
Author1 = {"name": "Thomas Moore", "affiliation": "CSIRO", "email": "thomas.moore@csiro.au", "orcid": "0000-0003-3930-1946"} | |
u,v are x and y currents as an xarray data array | |
''' | |
u_mean = u.mean('time') | |
v_mean = v.mean('time') | |
MKE = 0.5*(u_mean**2 + v_mean**2).rename('MKE') # currents | |
EKE = ( 0.5 * ((u-u_mean)**2 + (v-v_mean)**2) ).rename('EKE') # eddies | |
return EKE, MKE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
file_list =[] | |
# get regex range from web generator - https://3widgets.com/ | |
# find range of files from filename_1981.nc to filename_2018.nc | |
regexp = re.compile('filename_(198[1-9]|199[0-9]|200[0-9]|201[0-8]).nc') | |
ROOT_DIR ='/root/path/to/files/' | |
for root, dirs, files in os.walk(ROOT_DIR): | |
for file in files: | |
if regexp.search(file): | |
file_list.append(os.path.join(root, file)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is specific to needs outlined in this repo: | |
# https://github.com/Thomas-Moore-Creative/NCI-CCiA-ARD | |
import xarray as xr | |
import numpy as np | |
import datetime | |
import intake | |
NCI_catalog = intake.open_catalog('/g/data/hh5/public/apps/nci-intake-catalogue/catalogue.yaml') | |
# build CCiA catalog subset | |
CCiA_catalog = NCI_catalog.esgf.cmip5.search(variable=['psl','pr'], | |
realm=['atmos'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import intake | |
import xarray as xr | |
NCI_catalog = intake.open_catalog('/g/data/hh5/public/apps/nci-intake-catalogue/catalogue.yaml') | |
CCiA_catalog = NCI_catalog.esgf.cmip5.search(variable=['psl','pr'], | |
realm=['atmos'], | |
time_frequency='mon', | |
experiment=['rcp85','historical'], | |
ensemble=['r1i1p1'], | |
model=['ACCESS1.0', | |
'CESM1(CAM5)', |