Skip to content

Instantly share code, notes, and snippets.

@d1manson
d1manson / monobrow.py
Last active August 29, 2015 13:58
wrap matplotlib for piping to main process from subprocess (incomplete) http://stackoverflow.com/q/22819254/2399799
# -*- coding: utf-8 -*-
"""
The purpose of this module is to do monoprocessing for a single package when using multiprocessing.
It is designed with matplotlib in mind, but most of it is pretty general.
The idea is that you may have a block of code that you want to run in parallel
processes, but because of some "small" thing (i.e. something that isn't computationally expensive)
you can't do it easily without some major, ugly, alterations to your existing code. Monobrow.py
injects all the ugly stuff for you at the point you launch the processes, so you don't need to
alter your base code at all.
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 25 13:26:15 2014
@author: daniel
"""
from functools import partial
class LazyDictProperty(object):
"""
@d1manson
d1manson / exception_aggregator.py
Last active August 29, 2015 14:08
Collect exceptions & warnings together with custom state string, and print an aggregated summary at the end
# -*- coding: utf-8 -*-
"""
This works but it's pretty ugly in places, the html/str representation specifically.
"""
from __future__ import print_function
import sys
import warnings
from traceback import format_list, extract_tb, extract_stack
@d1manson
d1manson / theta_mle_climer.py
Last active August 29, 2015 14:14
Python impl. of Climer et al. 2014, a max-likelihood estimation of temporal autocorrelogram parameters (for in vivo neuronal spiking)
# -*- coding: utf-8 -*-
"""
Adapted from the Matlab code acompanying the following paper:
Climer, J. R., DiTullio, R., Newman, E. L., Hasselmo, M. E., Eden, U. T.
(2014), Examination of rhythmicity of extracellularly recorded neurons
in the entorhinal cortex. Hippocampus, Epub ahead of print.
doi: 10.1002/hipo.22383.
Matlab code take from: github.com/jrclimer/mle_rhythmicity, on 02-feb-2015.
@d1manson
d1manson / accumarray.py
Last active August 29, 2015 14:15
[!!!SUPERSEDED BY ACTUAL REPOSITORY - https://github.com/ml31415/accumarray !!!] Matlab-like accumarray in Python
"""
!!!!!!SUPERSEDED BY ACTUAL REPOSITORY!!!!!!
https://github.com/ml31415/accumarray
!!!!!!SUPERSEDED BY ACTUAL REPOSITORY!!!!!!
"""
import numpy as np
@d1manson
d1manson / pearsonr_confidence.py
Last active August 29, 2015 14:15
compute pearson p-value using permutations and/or resampling rather than analytically
# -*- coding: utf-8 -*-
"""
Module contents:
# pearsonr_permutations
# pearsonr_sign_bootstrap
# permute_multi <-- used by pearsonr_permutations
DM, Feb 2015.
"""
import numpy as np
@d1manson
d1manson / np_indexing_tools.py
Last active August 29, 2015 14:15
numpy indexing/labeling tools
import numpy as np
def repeat_ind(n):
"""By example:
# 0 1 2 3 4 5 6 7 8
n = [0, 0, 3, 0, 0, 2, 0, 2, 1]
res = [2, 2, 2, 5, 5, 7, 7, 8]
That is the input specifies how many times to repeat the given index.
@d1manson
d1manson / list_views.py
Created February 27, 2015 23:09
a couple of classes for creating read/write views onto a list/array ...you cant do this in numpy
# -*- coding: utf-8 -*-
"""
Module contents:
# index_view
# masked_list
@author: daniel
"""
@d1manson
d1manson / append_docstring.py
Created March 5, 2015 17:01
decorator for appending docstring of one or more objects to a function
import inspect
def append_docstring(*others):
"""
Appends one or more other objects' docstrings to the decorated function.
Title, location and args info is provided in addition to basic docstring.
TODO: Compare the location of `other` to `foo` and only show the
neccessary suffix. Also, try and get the args/kwargs and
type printed nicely like spyder does.
<html>
<head>
<script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="bower_components/polymer/polymer.html">
<dom-module id="x-child">
<template>
<div style="background:#ccc;display: inline-block;">
prop_read_write: <span>[[prop_read_write]]</span><br>
prop_read_only: <span>[[prop_read_only]]</span><br>