Skip to content

Instantly share code, notes, and snippets.

View drammock's full-sized avatar

Daniel McCloy drammock

View GitHub Profile
@drammock
drammock / 1s2d.R
Created September 20, 2014 12:32
phonR snippet for 1S2D
library(phonR)
# if you want to go straight to PDF, uncomment this line, and the "dev.off()" line at the end:
# cairo_pdf("myfile.pdf", width=6, height=6, pointsize=12)
# assuming that your dataframe is called "mydata":
# first, create columns for the normalized data:
z <- with(mydata, norm.vowels("lobanov", f1=f1, f2=f2, f3=f3, group=speaker))
colnames(z) <- paste(colnames(z), "z", sep="")
mydata <- cbind(mydata, z)
@drammock
drammock / BruneiVsChinaVowels.R
Last active August 29, 2015 14:12
Sample translation from phonR 0.4-2 to 1.0-0
# install the new version:
download.file("https://raw.githubusercontent.com/drammock/phonR/master/R/phonR.R", "phonR.R")
source("phonR.R")
# or, if you have devtools package, can use
# devtools::source_url("https://raw.githubusercontent.com/drammock/phonR/master/R/phonR.R")
# do the bark normalization before plotting:
BNF$f1bark <- normBark(BNF$f1)
BNF$f2bark <- normBark(BNF$f2)
@drammock
drammock / r-sig-clmm.R
Last active August 29, 2015 14:23
issues setting up cumulative-link mixed model
## "reduction" is the response variable (ordered factor, none < devoiced < deleted)
table(cleandata$reduction)
## none devoiced deleted
## 20776 360 420
## "speaker" is a nuisance predictor, which I intend to model as a random effect
with(cleandata, table(reduction, speaker))
## speaker
## reduction F1 F2 F3 M1 M2 M3
## none 3559 3482 3325 3569 3360 3481
@drammock
drammock / n_edges_draw_time_test.py
Created September 11, 2015 23:23
testing effect of number of vertices on expyfun circle draw times
import expyfun
import numpy as np
import matplotlib.pyplot as plt
plt.ioff()
n_iter = 10000
edges = np.arange(4, 17, dtype=int)
edges = [10, 100, 500]
times = np.zeros(n_iter)
with expyfun.ExperimentController('wait_test', output_dir=None,
@drammock
drammock / test-el-interactive.py
Created October 15, 2015 17:15
Test EyeLink connectivity within expyfun
# -*- coding: utf-8 -*-
"""
===============================================================================
Script 'test-eyelink-interactive.py'
===============================================================================
This script tests the connection to the EyeLink eye tracker.
"""
# @author: drmccloy
# Created on Thu Oct 15 09:11:04 2015
@drammock
drammock / test-ec-set-bg-col.py
Created October 16, 2015 19:49
test script for setting background color in ExperimentController
# -*- coding: utf-8 -*-
import numpy as np
from expyfun import ExperimentController
kwargs = dict(exp_name='test', session='000', participant='foo')
with ExperimentController(**kwargs) as ec:
ec.flip()
ec.set_background_color('red')
ec.screen_text('red', color='k')
@drammock
drammock / deconv.py
Created December 2, 2015 17:35 — forked from larsoner/deconv.py
# -*- coding: utf-8 -*-
# see:
# http://eeweb.poly.edu/iselesni/lecture_notes/least_squares/
# LeastSquares_SPdemos/deconvolution/html/deconv_demo.html
import numpy as np
from scipy import linalg, sparse
import matplotlib.pyplot as plt
from pyeparse.utils import pupil_kernel
@drammock
drammock / test_tdt.py
Created December 15, 2015 00:03
attempts to connect to TDT in PBB226
# -*- coding: utf-8 -*-
import expyfun as ef
import tdt
circuit = 'C:\\Users\\labuser\\Builds\\expyfun\\expyfun\\data\\expCircuitF32_RM1.rcx'
interface = 'USB'
model = 'RP2'
# approach #1
@drammock
drammock / write-utf8-df.R
Last active February 29, 2016 01:48
write R data.frame in UTF-8 on Windows
# sample data frame
df <- data.frame(zh=c("一", "二", "三", "四", "五", "六", "七", "八", "九", "十"),
pinyin=c("yī", "èr", "sān", "sì", "wǔ", "liù", "qī", "bā", "jiǔ", "shí"),
ipa=c("ji˥", "aɻ˥˩", "san˥", "sz̩˥˩", "wu˨˩˦", "ljoʊ˥˩", "tɕʰi˥", "pa˥", "tɕjoʊ˨˩˦", "ʂʐ̩˧˥"),
numbers=1:10, stringsAsFactors=FALSE)
print(df)
print(df$zh)
save.utf8 <- function(df, file, sep=",", quote=FALSE) {
@drammock
drammock / tricolor.R
Last active February 29, 2016 19:49
R function for weighted average of 3 colors
tricolor <- function(x, y, z, xcol=NA, ycol=NA, zcol=NA, plot=FALSE) {
if(length(unique(sapply(list(xcol, ycol, zcol), length))) != 1) {
stop("All colors (xcol, ycol, zcol) must be the same length")
}
cols <- c(xcol, ycol, zcol)
if(any(is.na(cols))) {
if(!all(is.na(cols))) warning('NAs detected in user-specified colors; ',
'falling back to defaults.')
## defaults
cols <- matrix(c(0, 120, 240, 100, 100, 100, 50, 50, 50, 1, 1, 1),