Skip to content

Instantly share code, notes, and snippets.

View dhhagan's full-sized avatar
🙀
Building @quant-aq

David H Hagan dhhagan

🙀
Building @quant-aq
View GitHub Profile
@dhhagan
dhhagan / print-timestamp-arduino
Created January 6, 2015 21:27
Print a timestamp to SD card on Arduino
/*
print_time() returns a string in the format mm-dd-yyyy hh:mm:ss
*/
#include "RTClib.h"
#include <SD.h>
#include <SPI.h>
RTC_DS1307 rtc;
const int chipSelect = 10;
@dhhagan
dhhagan / bacharach.py
Created February 2, 2015 00:40
Log serial data from a Bacharach ECA450 Combustion Analyzer in real-time or post-collection.
'''
Written by David Hagan
January 8, 2015
This script reads data from the Bacharach ECA 450 Combustion analyzer through the serial interface and
logs the data to a file
In the future (If I ever use the Bacharach again), I aim to convert this into a GUI for ease of use.
Description of Columns:
@dhhagan
dhhagan / run-opc.py
Created June 16, 2015 20:36
Run Alphasense OPC-N2
'''
This is an example script displaying how to easily run the
Alphasense OPC-N2 from a Raspberry Pi using the py-opc library.
Author: David H Hagan
Email: david@davidhhagan.com
Date: 2015-06-16
'''
from opc import OPCN2
@dhhagan
dhhagan / timeplot.py
Created August 15, 2015 04:34
Make pretty x-axis labels for Time series data
fig, ax = plt.subplots(1, 1)
with sns.axes_style('white'):
ax.plot(final.index, final['AFE1_X2-01_degC'], label = 'T RTD-X2-01')
ax.plot(final.index, final['AFE2_X2-01_degC'], label = 'T RTD-X2-01b')
ax.plot(final.index, final['AFE1_X2-02_degC'], label = 'T RTD-X2-02')
ax.plot(final.index, final['AFE2_X2-02_degC'], label = 'T RTD-X2-02b')
ax.set_title("X2-Series RTD Intercomparison")
ax.set_xlabel("Local Time (EST)")
ax.set_ylabel("T degC")
@dhhagan
dhhagan / gist:c36ce965a679e8889513
Last active September 12, 2015 12:51 — forked from maximebf/gist:3986659
Jinja2 macro to render WTForms fields with Twitter Bootstrap
{% macro form_field(field) -%}
{% set with_label = kwargs.pop('with_label', False) %}
{% set placeholder = '' %}
{% if not with_label %}
{% set placeholder = field.label.text %}
{% endif %}
<div class="control-group {% if field.errors %}error{% endif %}">
{% if with_label %}
<label for="{{ field.id }}" class="control-label">
{{ field.label.text }}{% if field.flags.required %} *{% endif %}:
import requests
import json
class API(object):
def __init__(self, **kwargs):
self._key = kwargs.pop('key', '')
self._pswd = kwargs.pop('pswd', '')
self._version = kwargs.pop('version', None)
self._baseurl = kwargs.pop('baseurl', None)
self._headers = {'content-type': 'application/json'}
@dhhagan
dhhagan / opc.py
Created March 16, 2016 19:58
opc.py
import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
import seaborn as sns
import warnings
class DataError(TypeError):
pass
@dhhagan
dhhagan / alphasense-example.py
Created March 24, 2016 15:30
Run the Alphasense OPC-N2 for 10 seconds in a loop.
"""
Simple script to run the Alphasense OPC-N2 using the py-opc library.
Written by David H Hagan | March 24, 2016
"""
import spidev
import opc
from time import sleep
@dhhagan
dhhagan / run_opcn2_usbiss.py
Created December 2, 2016 15:57
run_opcn2_usbiss
"""
This script runs the Alphasense OPC-N2 via the USB-ISS adapter and logs
every X seconds
Written by David H Hagan | Dec. 2016
Contact: dhagan@mit.edu
"""
import usbiss
import opc
@dhhagan
dhhagan / datetime_axis_magic.py
Created April 19, 2017 22:22
autofmt_datetime_axis
"""
This function accepts a matplotlib axis object with a datetime x-axis
and performs magical things to it to make it look not like total shit.
"""
import matplotlib.dates as dates
import matplotlib.ticker as mtick
import datetime
def label_july_only(x, pos=None):