Skip to content

Instantly share code, notes, and snippets.

@cpelley
cpelley / lazy_netcdf_save_bug
Created March 31, 2015 12:48
Lazy NetCDF save bug
{
"metadata": {
"name": "",
"signature": "sha256:1ccaf1d6efde449dc4d273823364434c19bdd068d41587570ffde0a5be796216"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@cpelley
cpelley / iris_plot.py
Created February 6, 2015 17:12
Quick visualisation
def plot_data(*args, **kwargs):
save = kwargs.pop('save', False)
import matplotlib.pyplot as plt
import iris.plot as iplt
markers = ('+', 'x', 's')
if save is True:
plt.switch_backend('Agg')
@cpelley
cpelley / mem_bang_netcdf.py
Last active August 29, 2015 14:12
netcdf memory_blow-up
from netCDF4 import Dataset
import numpy as np
import os
def process_usage():
fnme = os.path.join('/', 'proc', str(os.getpid()), 'status')
usage = {}
with open(fnme, 'r') as fh:
for line in fh:
@cpelley
cpelley / mem_bang_iris.py
Last active August 29, 2015 14:12
iris memory_blow-up
import os
import biggus
import iris
import numpy as np
print iris.__file__, iris.__version__
print biggus.__file__, biggus.__version__
@cpelley
cpelley / stat.py
Last active August 29, 2015 14:11
process statistics
from functools import wraps
import os
def proc_stat():
pid = os.getpid()
fnme = os.path.join('/', 'proc', str(pid), 'status')
fields = ['VmSize', 'VmRSS', 'VmPeak', 'VmHWM']
with open(fnme, 'r') as fh:
@cpelley
cpelley / BUG_save_load_coord_system
Created November 3, 2014 09:38
Bug with save-load sequence. Inverse flattening representation changes between save-load, resulting in a failled equality condition. Also demonstrates the lack of support for a scalar cube.
{
"metadata": {
"name": "",
"signature": "sha256:563b350202cce7ea8c83bbb25c227c1bdcef905445af72e7b040121fc52884b8"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@cpelley
cpelley / mosaic.py
Created September 26, 2014 12:24
Generator of slices which represent a mosaic indexing of an iterable object
def mosaic(iterable_shape, subdivided_shape):
"""
Return a generator of slices that represent a subdivided indexing of an iterable of specified shape.
"""
shape = subdivided_shape
if len(iterable_shape) != len(shape):
raise ValueError('Array shape and resulting shape mismatch, broadcasting not supported.')
# iterate through this array with shape (shape)
@cpelley
cpelley / regrid_performance.ipynb
Created September 24, 2014 13:33
Regrid performance
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cpelley
cpelley / temporary_directory.py
Created August 26, 2014 14:40
Support for temporary directories in python2.7 as context managers (already available in python3.2+)
import shutil
import tempfile
class TemporaryDirectory(object):
"""
Context manager for tempfile.mkdtemp().
This class is available in python +v3.2.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.