Skip to content

Instantly share code, notes, and snippets.

View jnhansen's full-sized avatar

Johannes Hansen jnhansen

  • Sylvera
  • Edinburgh
View GitHub Profile
@jnhansen
jnhansen / gridlines_with_labels.py
Last active June 7, 2021 09:19
This is a fix for cartopy `ax.gridlines()` that allows adding labels even for non-rectangular projections
import numpy as np
import cartopy
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
def gridlines_with_labels(ax, top=True, bottom=True, left=True,
right=True, **kwargs):
"""
Like :meth:`cartopy.mpl.geoaxes.GeoAxes.gridlines`, but will draw
@jnhansen
jnhansen / xr_auto_merge.py
Created August 3, 2018 18:59
Auto-merge xarray datasets along multiple dimensions
import glob
import xarray as xr
import itertools
import numpy as np
def auto_merge(datasets):
"""
Automatically merge a split xarray Dataset. This is designed to behave like
`xarray.open_mfdataset`, except it supports concatenation along multiple