Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def as_scalar(value):
"""Like np.asscalar, but also works on scalar values (not just ndarrays)
"""
return np.array(value).item()
def to_str(value):
"""Convert a (possibly bytes) string to unicode, which is comparable to
strings on all Python versions
class partial_by_order(object):
"""
>>> f = partial_by_order(add, [(1, 10)])
>>> f(5)
15
"""
def __init__(self, op, other):
if (not isinstance(other, list) or
not all(isinstance(o, tuple) and len(o) == 2 for o in other)):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
resampled_xray = xray.open_dataset(
'COLA_data/resampled_tas_Amon_CCSM4_piControl_r3i1p1_000101-012012.nc')
climatology = resampled_xray.groupby('time.month').mean('time')
anomalies = resampled_xray.groupby('time.month') - climatology
@shoyer
shoyer / faster.txt
Created November 18, 2015 18:37
xray pcolormesh profiling
4099953 function calls (4093947 primitive calls) in 14.571 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
89302 4.795 0.000 5.585 0.000 linref.py:14(__call__)
722 2.353 0.003 2.355 0.003 {cartopy.trace.project_linear}
89302 1.491 0.000 1.781 0.000 point.py:188(geos_point_from_py)
480 0.439 0.001 9.527 0.020 crs.py:329(_attach_lines_to_boundary)
288301 0.439 0.000 0.439 0.000 base.py:209(empty)
@shoyer
shoyer / ipnbdoctest.py
Last active December 28, 2015 11:59 — forked from minrk/ipnbdoctest.py
#!/usr/bin/env python
"""
simple example script for running and testing notebooks.
Usage: `ipnbdoctest.py foo.ipynb [bar.ipynb [...]]`
Each cell is submitted to the kernel, and the outputs are compared with those stored in the notebook.
"""
import os,sys,time