Skip to content

Instantly share code, notes, and snippets.

View robintw's full-sized avatar

Robin Wilson robintw

View GitHub Profile
@robintw
robintw / Build stderr
Created October 21, 2014 15:18
Py6S RtD build notes
html
-----
/var/build/user_builds/py6s/checkouts/stable/doc/source/helpers.rst:59: WARNING: autodoc: failed to import class u'Wavelengths' from module u'Py6S.SixSHelpers'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/py6s/envs/stable/local/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 335, in import_object
__import__(self.modname)
ImportError: No module named Py6S.SixSHelpers
/var/build/user_builds/py6s/checkouts/stable/doc/source/helpers.rst:77: WARNING: autodoc: failed to import class u'Angles' from module u'Py6S.SixSHelpers'; the following exception was raised:
Traceback (most recent call last):
@robintw
robintw / gist:abc9a33d54c1d40c6f01
Created December 31, 2014 20:08
SQL for status duration Stack Overflow question
CREATE TABLE `data` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`set_point` float DEFAULT NULL,
`temp` float DEFAULT NULL,
`on` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `data` (`id`, `timestamp`, `set_point`, `temp`, `on`)
@robintw
robintw / gist:3df1464e5c8a7ee8835e
Last active August 13, 2024 14:22
Duplicate slide in python-pptx
def duplicate_slide(pres, index):
source = pres.slides[index]
try:
blank_slide_layout = pres.slide_layouts[6]
except:
blank_slide_layout = pres.slide_layouts[len(pres.slide_layouts) - 1]
dest = pres.slides.add_slide(blank_slide_layout)
for shp in source.shapes:
el = shp.element
@robintw
robintw / pywatts.py
Last active August 28, 2024 08:56
Code to read data from a CurrentCost EnviR electricity usage meter
import untangle
import serial
def get_data(port='/dev/ttyUSB1', verbose=False):
"""Gets temperature and power usage data from an attached CurrentCost meter.
Parameters:
- port: the port that the CurrentCost meter is attached to. Somthing like /dev/ttyUSB0 or COM1
Returns:
@robintw
robintw / apache2-graphite.conf
Last active August 29, 2015 14:21
Apache2 VirtualHost configuration for Graphite on Port 81
<VirtualHost *:81>
WSGIDaemonProcess _graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 user=_graphite group=_graphite
WSGIProcessGroup _graphite
WSGIImportScript /usr/share/graphite-web/graphite.wsgi process-group=_graphite application-group=%{GLOBAL}
WSGIScriptAlias / /usr/share/graphite-web/graphite.wsgi
Alias /content/ /usr/share/graphite-web/static/
<Location "/content/">
SetHandler None
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@robintw
robintw / vanHOzone.py
Created September 3, 2015 16:59
Code to calculate atmospheric ozone concentrations based upon the van Heuklon (1979) ozone model. In numpy and without numpy.
import numpy as np
from dateutil.parser import parse
import math
def get_ozone_conc(lat, lon, timestamp):
"""Returns the ozone contents in matm-cm for the given latitude/longitude
and timestamp (provided as either a datetime object or a string in any sensible format
- I strongly recommend using an ISO 8601 format of yyyy-mm-dd) according to van Heuklon's
Ozone model.
@robintw
robintw / orthoregress.py
Created November 1, 2015 12:01
Orthogonal distance regression in Python, with the same interface as the linregress function
# Copyright (c) 2013, Robin Wilson
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
import random
import numpy as np
from MonteCarloRegression import MonteCarloRegression
mcr = MonteCarloRegression('LAL7_v10_RemoveBrookhaven.csv', 'B1', 'B3')
random.seed(123456789)
np.random.seed(123456789)
mcr.run_from_metadata('/Users/robin/HOTBAR/Test/Inputs/LE71230322001091EDC00_MTL.txt')