Skip to content

Instantly share code, notes, and snippets.

@cpelley
cpelley / iris masked regridding
Created August 29, 2012 13:41
Regridding a masked cube. The regridding method of a cube from iris
import numpy as np
import iris
def lat_lon_cube(x, mval, latgrid, longrid):
"""
Returns a masked cube with a latitude and longitude suitable for testing.
Args:
@cpelley
cpelley / gist:5781535
Last active December 18, 2015 12:18
Cartopy gridlines with labels on funky projections
import numpy as np
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
def workaround_gridlines(src_proj, labels=True):
# Workaround for plotting lines of constant latitude/longitude as gridlines
# labels not supported for this projection.
@cpelley
cpelley / gist:6351152
Created August 27, 2013 08:40
Plotting wind vectors (wind speed and direction)
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import iris
from iris.coord_systems import GeogCS
from iris.cube import Cube
@cpelley
cpelley / gist:6351252
Created August 27, 2013 08:55
Calculating the grate circle distance from a point
"""
Calculating the grate circle distance from a point
==================================================
This example demonstrates how we might use an external library (pyproj) to
calculate the distance from our points in a cube to a specific location,
using our cubes grid mapping. We then associate this information
onto our original cube as an auxiliary coordinate, since this relates to the
original phenomena.
@cpelley
cpelley / gist:6355283
Created August 27, 2013 15:45
Matplotlib colormap plotting (specified/all)
import numpy as np
import matplotlib.pyplot as plt
a = np.linspace(0, 1, 256).reshape(1,-1)
a = np.vstack((a,a))
plot_spec = None
if plot_spec is None:
# Get a list of the colormaps in matplotlib. Ignore the ones that end with
@cpelley
cpelley / gist:6377893
Last active December 21, 2015 22:49
Custom matplotlib colormap using an existing one
import copy
import matplotlib
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
def plot_colormap(cmapname='jet'):
"""
@cpelley
cpelley / .vimrc
Last active December 22, 2015 00:59
" ENABLE FILETYPE SPECIFIC VIM SETTINGS FILES
filetype plugin on
" language-dependent indenting.
filetype plugin indent on
" SET COLOUR
" mkdir -p ~/.vim/colors && cd ~/.vim/colors
" wget -O wombat256mod.vim http://www.vim.org/scripts/download_script.php?src_id=13400
set t_Co=256
@cpelley
cpelley / python.vim
Last active February 2, 2016 21:09
" setup wrapping
setlocal textwidth=79 " width of document
setlocal nowrap " don't automatically wrap on load
setlocal fo-=t " don't automatically wrap text when typing
" Colour column at 80char
if exists('+colorcolumn')
setlocal colorcolumn=80
else
autocmd BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
@cpelley
cpelley / Pyflakes monkeypatch
Last active December 22, 2015 14:09
Pyflakes monkey-patch to give appropriately formatted syntax error for vim
#!/usr/bin/env python
import sys
import pyflakes.reporter as reporter
from pyflakes.scripts.pyflakes import main
# Monkey patch syntax error method for suitability with vim
def vimhappy_syntaxError(self, filename, msg, lineno, offset, text):
line = text.splitlines()[-1]
#!/usr/bin/env python
import sys
import re
def main(fnme):
with open(fnme, 'r') as fh:
lines = fh.readlines()