Skip to content

Instantly share code, notes, and snippets.

View cversek's full-sized avatar

Craig Versek cversek

  • Northeastern University
  • Boston, MA
View GitHub Profile
@cversek
cversek / stuporblue_ndvi.py
Last active December 17, 2015 13:19
Compute NDVI from StuporBlue Image
################################################################################
# this is code to compute NDVI from Blue (Visible channel) and Red (Infrared)
# such as pictures taken with "SuperBlue" camera
from PIL import Image
import numpy
img = Image.open("IMG_0512.JPG")
imgR, imgG, imgB = img.split() #get channels
#convert to double precision floating point..is this overkill? probably, could try 'float32' or 'float16'
arrR = numpy.asarray(imgR).astype('float64')
@cversek
cversek / jeffs_HSV_colormap_demo.py
Last active December 17, 2015 13:29
Jeff's HSV Colormap in Matplotlib
from pylab import *
cdict = {
'red' : ((0.00, 0.00, 0.00),
(0.20, 0.00, 0.00),
(0.40, 0.00, 0.00),
(0.60, 0.00, 0.00),
(0.80, 1.00, 1.00),
(1.00, 1.00, 1.00)),
'green': ((0.00, 0.00, 0.00),
(0.20, 0.00, 0.00),
@cversek
cversek / cmap_gaussianHSV.py
Last active December 17, 2015 14:09
Tunable Gaussian HSV Colormap
import numpy as np
import matplotlib
def make_cmap_guassianHSV( num_segs = 100, #number of segments
bandwidth = 0.25,
red_center = 1.00,
green_center = 0.75,
blue_center = 0.50,
name = "gaussianHSV"
):
import time, socket
doc = """
<!DOCTYPE html>
<html>
<head> <title>ESP8266 Pins</title> </head>
<body> <h1>ESP8266 Pins</h1>
<table border="1"> <tr><th>Pin</th><th>Value</th></tr> s </table>
@cversek
cversek / setup.sh
Created February 8, 2017 23:47
Notes on building open-eio/circuitpython firmware with pawpaw outside of Vagrant machine
#!/bin/bash -x
#FIRST TIME SETUP
#install esp-open-sdk, Espressif ESP-IDF, and micropython dependencies
echo "Installing esp-open-sdk, Espressif ESP-IDF, and micropython dependencies..."
sudo apt-get update
sudo apt-get install -y build-essential git make unrar-free unzip \
autoconf automake libtool libtool-bin gcc g++ gperf \
flex bison texinfo gawk ncurses-dev libexpat-dev \
python sed libreadline-dev libffi-dev pkg-config \
help2man python-dev python-serial wget linux-image-extra-$(uname -r)
import numpy as np
def speedx(sound_array, factor):
""" Multiplies the sound's speed by some `factor` """
indices = np.round( np.arange(0, len(sound_array), factor) )
indices = indices[indices < len(sound_array)].astype(int)
return sound_array[ indices.astype(int) ]
def stretch(sound_array, f, window_size, h):
""" Stretches the sound by a factor `f` """
@cversek
cversek / code.py
Last active December 29, 2017 04:02
Start of a Morse Code lab... I basically smashed two Adafruit guide demos together. Transition state machine approach now calls sample.play and sample.stop at the right times.
from digitalio import DigitalInOut, Direction, Pull
import audioio
import board
import array
import time
import math
FREQUENCY = 440 # 440 Hz middle 'A'
SAMPLERATE = 8000 # 8000 samples/second, recommended!
@cversek
cversek / code.py
Last active December 31, 2017 07:14
This is a modified CircuitPlayground demo, original is here: https://learn.adafruit.com/adafruit-circuit-playground-express/playground-sound-meter. The main modification is to only "detect" when the current magnitude of the mic is above a running average value by some multiplier > 1 (here we used 2.0).
# The MIT License (MIT)
#
# Copyright (c) 2017 Dan Halbert for Adafruit Industries
# Copyright (c) 2017 Kattni Rembor, Tony DiCola for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
@cversek
cversek / gen_polar_checks.py
Last active February 23, 2018 05:26
Simple python script to generate polar checked stimuli patterns.
import numpy as np
from scipy.misc import imsave
PIXELS_X = 256
PIXELS_Y = PIXELS_X
COLOR_SOLID_WHITE = (255,255,255,255)
COLOR_SOLID_BLACK = (0,0,0,255)
COLOR_FULLY_TRANSPARENT_BLACK = (0,0,0,0)
@cversek
cversek / anagrams.py
Created December 24, 2020 07:06
Anagram generator
from operator import mul
from functools import reduce
PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
67, 71, 73, 79, 83, 89, 97, 101]
LETTERS_BY_FREQ = list('esiarntolcdupmghbyfvkwzxqj')
LETTER_TO_PRIME = dict(zip(LETTERS_BY_FREQ,PRIMES))
def ppencode(letter_str):
return reduce(mul,map(lambda l: LETTER_TO_PRIME.get(l,1),letter_str))