Skip to content

Instantly share code, notes, and snippets.

View phaustin's full-sized avatar

Philip Austin phaustin

  • University of British Columbia
  • Vancouver, BC Canada
View GitHub Profile
@phaustin
phaustin / 00README.rst
Created December 25, 2011 17:35 — forked from GaelVaroquaux/00README.rst
Copy-less bindings of C-generated arrays with Cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

@phaustin
phaustin / checkipnb.py
Created June 9, 2012 17:07 — forked from minrk/checkipnb.py
run python notebooks
#!/usr/bin/env python
"""
simple example script for running notebooks and reporting exceptions.
Usage: `checkipnb.py foo.ipynb [bar.ipynb [...]]`
Each cell is submitted to the kernel, and checked for errors.
"""
import os,sys,time
@phaustin
phaustin / ipnbdoctest.py
Created June 9, 2012 17:07 — forked from minrk/ipnbdoctest.py
simple example script for running and testing notebooks.
#!/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
@phaustin
phaustin / 00README.rst
Created February 17, 2013 22:17 — forked from GaelVaroquaux/00README.rst
passing arrays to cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

@phaustin
phaustin / git_toc.org
Created February 6, 2015 22:43
git commands

git hints

@phaustin
phaustin / argparse.py
Last active November 1, 2016 17:05
Python snippets
"""
test docstring
https://docs.python.org/3/library/argparse.html#nargs
"""
import argparse, textwrap
if __name__ == '__main__':
linebreaks=argparse.RawTextHelpFormatter
descrip=textwrap.dedent(globals()['__doc__'])
@phaustin
phaustin / b_a.txt
Last active August 29, 2015 14:15
swap answer key for eosc340
1 18 c
2 19 c
3 20 a
4 4 e
5 1 a
6 9 b
7 15 a
8 2 a
9 3 e
10 5 c
@phaustin
phaustin / read_excel.py
Last active August 29, 2015 14:15
read_excel.py
#[[file:/pip_raid/phil/gcm_e340/read_names.py]]
import xlrd
filename='standard_output.xls'
workbook = xlrd.open_workbook(filename)
worksheet = workbook.sheet_by_name('Amon')
twod_fields=[]
headers=worksheet.row(14)
colnames=[item.value for item in headers]
for rownum in np.arange(16,66):
@phaustin
phaustin / openpyxl.py
Last active August 29, 2015 14:15
openpyxl to pandas with bad values
# -*- coding: utf-8 -*-
from __future__ import print_function
from builtins import next
from openpyxl import load_workbook
import glob,os
import pandas as pd
import numpy as np
import logging
logging.basicConfig(level=logging.DEBUG)
@phaustin
phaustin / read_grades.py
Created February 17, 2015 01:11
barplot and histogram
fig, ax = plt.subplots(1, 1, figsize = (12, 12) )
height,bins=np.histogram(group,bins=marks,normed=True)
out = ax.bar(bins[:-1],height*len(group),width=np.diff(bins))
ax.set_title('group')
ax.set_xlim([60,100])