Skip to content

Instantly share code, notes, and snippets.

View rabernat's full-sized avatar

Ryan Abernathey rabernat

View GitHub Profile
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.
@rabernat
rabernat / xarray_anomaly_calculations.ipynb
Created November 27, 2019 16:34
Xarray Anomaly Calculations
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rabernat
rabernat / detrend_xarray.py
Last active December 18, 2024 05:21
Detrend xarray DataArrays using polyfit
import xarray as xr
def detrend_dim(da, dim, deg=1):
# detrend along a single dimension
p = da.polyfit(dim=dim, deg=deg)
fit = xr.polyval(dim, p.polyfit_coefficients)
return da - fit
def detrend(da, dims, deg=1):
# detrend along multiple dimensions
import xarray as xr
url = "https://www.ncei.noaa.gov/thredds-ocean/dodsC/woa23/DATA/temperature/netcdf/decav/1.00/woa23_decav_t16_01.nc"
ds = xr.open_dataset(url, decode_times=False)
t_diff = ds.t_an - ds.t_an.isel(depth=0)
t_diff.sel(lat=0, method="nearest").plot(x="lon", ylim=(5000, 0), vmax=0, vmin=-25)
t_diff.sel(lat=0, method="nearest").squeeze().plot.contour(levels=[-22], ylim=(5000, 0), colors='w')
@rabernat
rabernat / vector-accessor.ipynb
Created June 25, 2023 03:37
Xarray as an embedded vector database
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rabernat
rabernat / Ocean_Meridional_Heat_Transport.ipynb
Created October 17, 2019 17:19
Using WOA Ocean Basin Masks
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

Pangeo OSN Data Guide

This is a rough guide to using OSN with Pangeo tools.

Background Information

Open Storage Network

Open Storage Network (OSN) is a distributed data service to support active data sharing and transfer between academic institutions, leveraging existing NSF-funded resources. It is funded by NSF and the Schmidt Futures Foundation.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.