Skip to content

Instantly share code, notes, and snippets.

@mattions
mattions / cyl_example.py
Created February 16, 2011 17:04
Drawing cylinders
#cyl_example.py
from enthought.tvtk.tools import visual
def draw_cyl(coords):
x_ax = coords['x1'] -coords['x0']
y_ax = coords['y1'] -coords['y0']
z_ax = coords['z1'] -coords['z0']
cyl = visual.Cylinder(pos=(coords['x0'],coords['y0'],coords['z0']),
axis=(x_ax,y_ax,z_ax), radius=1, length=10)
@mattions
mattions / cylinder_color_change.py
Created May 4, 2011 14:35
Using mlab to change a second scalar for the cilinders..
import numpy as np
from mayavi import mlab
class Animator(object):
def __init__(self):
self.scalar_active_attribute = None
def add_scalar_array(self, dataset, tube, scalar_data, scalar_data_name):
@mattions
mattions / a.param
Created June 27, 2011 13:13
Easy way to get params from external file in the main script (and work with them)
# Parameters file for simulation.
{
"dt" : 0.025, # integration dt [ms]
"dict_ampa_s1" :
{"t_stim" : 0.130, # t_stim [s]
"numbers" : 4, # number
"delay" : 0.1, # delay [s]
"type" : "ampa" # , type
},
"dict_ampa_s2" :
@mattions
mattions / offscreen_3D_Neuronvisio.py
Created September 12, 2011 12:43
Off screen rendering of a 3D window of Neuronvisio
import os
from shutil import copyfile
import numpy as np
# Getting the qt in before mayavi
from PyQt4 import QtGui
app = QtGui.QApplication.instance()
from enthought.mayavi import mlab
# Offscreen
@mattions
mattions / run_model_in_neuronvisio_example.py
Created September 12, 2011 15:07
run a downloaded model in Neuronvisio
def run_model_in_neuronvisio(model_dir):
if os.path.exists(os.path.join (model_dir, 'mosinit.hoc')):
os.chdir(model_dir)
#TODO: We should check if the file is already compiled,
# and call the right executable according to the system.
call(['nrnivmodl'])
from neuron import gui # to not freeze neuron gui
from neuron import h
from neuronvisio.controls import Controls
@mattions
mattions / patch_qstring_windows_pyqt.py
Created October 2, 2011 10:58
importing the right Qstring for Python 3 on windows
"""
This is a check to make sure the sip and the Qstrings play nicely in Windows,
where the PySide is using the new Python API (Python 3)
http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg19702.html
http://stackoverflow.com/questions/1400858/how-to-create-qstring-in-pyqt4
This could be easily removed when we move to Python 3
"""
if os.name == 'nt':
import sip
sip.setapi('QString', 2)
@mattions
mattions / neuronvisio_dev_reqs.txt
Created February 8, 2012 16:57
Requirements for version 0.8.0 of neuronvisio
-e git+https://mattions@github.com/mattions/mayavi.git@fix-21#egg=mayavi
-e git+https://github.com/enthought/traitsui.git#egg=traitsui
ipython==0.12
@mattions
mattions / protecting_with_braces.py
Created March 30, 2012 13:43
Initial work to protect the Capital letters in latex with braces. WARNING: Does not work, but it is a start
#!/usr/bin/env python
# -*- coding: utf8 -*-
import re
def protect_with_braces(title):
new_title = ''
words = title.split()
for w in words:
from pysam import VariantFile
import time
def count_oldvar_reg(vcffile_reg, labels=["OLDVARS", "OLDVARS_A", "OLDVARS_B"]):
t_start = time.time()
bcf_in = VariantFile(vcffile_reg)
total = 0
reg = 0
for rec in bcf_in:
@mattions
mattions / pr.md
Created August 30, 2012 23:26 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: