Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / circular
Created April 14, 2015 15:45
circular lost
{
"metadata": {
"name": "",
"signature": "sha256:9e9b8e73d2e084ca27d4015fe246597f8a1595a35b0bee658170be3636d8c30a"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@cpelley
cpelley / 2stage_regrid.py
Last active August 29, 2015 14:23
2-stage-regrid - different coord system regrid
import warnings
import iris
import biggus
from iris.analysis._area_weighted import AreaWeightedRegridder \
as _AreaWeightedRegridder
from iris.experimental.regrid import regrid_weighted_curvilinear_to_rectilinear
import iris.experimental.regrid as eregrid
from iris.analysis._regrid import RectilinearRegridder
import numpy as np
@cpelley
cpelley / extract_overlap.py
Last active August 29, 2015 14:24
extract_overlap
import iris
import numpy as np
from shapely.geometry import Polygon
def horizontal_grid(cube):
return cube.coord(axis='x'), cube.coord(axis='y')
def transform_bbox(points, src_crs, tgt_crs):
@cpelley
cpelley / svn
Created October 22, 2015 08:27
svn wrapper
#!/usr/bin/env python2.7
import subprocess
import sys
DEBUG = False
SVN_EXEC = '/usr/bin/svn'
class SVNError(Exception):
@cpelley
cpelley / nump_mask_view_bug.txt
Created October 27, 2015 20:53
numpy masked array bug
>>> import numpy as np
>>> arr = np.ma.array([1, 2, 3, 4], mask=[False, True, False, True])
>>> arr2 = arr.reshape((2, 2))
>>> arr2
masked_array(data =
[[1 --]
[3 --]],
mask =
[[False True]
[False True]],