Skip to content

Instantly share code, notes, and snippets.

@kuchaale
kuchaale / cartopy_wrap_example.ipynb
Created June 15, 2016 11:13 — forked from darothen/cartopy_wrap_example.ipynb
Example of adding cyclic points to DataArrays for plotting with Cartopy
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import xarray as xr
import numpy as np
# create an example dataset
da = xr.DataArray(np.random.rand(10,30,40), dims=['time', 'lat', 'lon'])
# define a function to compute a linear trend of a timeseries
def linear_trend(x):
pf = np.polyfit(x.time, x, 1)
# we need to return a dataarray or else xarray's groupby won't be happy
@kuchaale
kuchaale / jypyter_init.ipynb
Last active October 10, 2016 13:33
Gist for initialization of packages in jypyter
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kuchaale
kuchaale / MOLA_datashader.ipynb
Created October 6, 2016 21:50 — forked from kidpixo/MOLA_datashader.ipynb
MOLA_datashader.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kuchaale
kuchaale / composite_construction.py
Last active December 5, 2016 12:28
Script for calculation of SSW composites (split of displacement)
def open_date_file(file_path):
df = pd.read_csv(file_path, index_col=0, parse_dates=True)
df['BeginDate'] = df.BeginDate.apply(lambda t: pd.to_datetime(t, format='%Y-%m-%d'))
return df
var = sys.argv[1]
path = ''
max_lag = 30
type_ls = ['split', 'displ']
@kuchaale
kuchaale / aggregate.py
Created January 27, 2017 08:55 — forked from rabernat/aggregate.py
aggregation routines for coarse graining
# implement my own aggregation downsampling function
from itertools import product
import numpy as np
import xarray as xr
def aggregate(data, factor=2, mean=True):
ndim = data.ndim
shape = data.shape
# promote single value to list
@kuchaale
kuchaale / xr_utilities.py
Last active February 23, 2017 11:19
My xarray utilities
def longest_com_period_possible(xa_list):
"""Determine the longest common period for list of xarrays
Parameters
----------
xa_list: list of xarray dataarrays
Returns
-------
period: slice
@kuchaale
kuchaale / bretherton_correlation.py
Created February 23, 2017 11:46
Pearson correlation coefficient calculation according to Bretherton's effective sample size
def autocorr(x, t=1):
"""Calculates autocorrelation with lag = 1.
Parameters
----------
x: numpy.array
Input
Returns
-------
@kuchaale
kuchaale / xarray_correlation_testing.ipynb
Created February 23, 2017 16:52
Testing the possibility of xarray dot product of two DataArrays along their shared dims.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.