Skip to content

Instantly share code, notes, and snippets.

View sabrooks's full-sized avatar

Steve Brooks sabrooks

View GitHub Profile
import osmnx as ox
import geopandas as gpd
import matplotlib.pyplot as plt
from typing import Tuple
MAJOR = {
"motorway","trunk","primary","secondary",
"motorway_link","trunk_link","primary_link","secondary_link",
}
[{"current": 86.51745, "time": 298.8232, "fuse": "40T", "curve": "Melting "}, {"current": 86.95113, "time": 278.8996, "fuse": "40T", "curve": "Melting "}, {"current": 87.64952, "time": 252.3587, "fuse": "40T", "curve": "Melting "}, {"current": 88.35352, "time": 226.0716, "fuse": "40T", "curve": "Melting "}, {"current": 89.06317, "time": 203.9452, "fuse": "40T", "curve": "Melting "}, {"current": 90.40918, "time": 167.981, "fuse": "40T", "curve": "Melting "}, {"current": 91.59217, "time": 143.8614, "fuse": "40T", "curve": "Melting "}, {"current": 92.88347, "time": 121.3708, "fuse": "40T", "curve": "Melting "}, {"current": 94.28725, "time": 103.2186, "fuse": "40T", "curve": "Melting "}, {"current": 95.90382, "time": 86.21543, "fuse": "40T", "curve": "Melting "}, {"current": 97.54814, "time": 72.22954, "fuse": "40T", "curve": "Melting "}, {"current": 99.31992, "time": 61.05951, "fuse": "40T", "curve": "Melting "}, {"current": 101.225, "time": 51.15437, "fuse": "40T", "curve": "Melting "}, {"current": 102.8576, "t
@sabrooks
sabrooks / hzplt-full.js
Created January 28, 2016 23:16
Horizon plot (positive and negative) - xaxis time.
var height = 450,
width = 960,
margin = {top: 20, right:20, bottom: 30, left: 50},
layers = 4;
var parseTime = d3.timeParse("%m/%d/%Y");
var layerArray = d3.range(1, layers+1);
var x = d3.scaleTime()
@sabrooks
sabrooks / hzplt.js
Created January 24, 2016 17:14
Start of Horizon Plot in D3js
var height = 450,
width = 960,
layers = 4;
var layerArray = d3.range(layers);
var values =[
{"x": 1, "y": 28}, {"x": 2, "y": 55},
{"x": 3, "y": 43}, {"x": 4, "y": 91},
@sabrooks
sabrooks / gather.js
Created January 17, 2016 15:24
Tidyr:Gather in JS
//From Wide and Short to Narrow and Skinny,
var headers = ["hydro", "thermal"];
var layer = headers.map(function(header){
return data.map(d =>
({date: d.date, type: header, value:d[header]})
);
});
//vega-lite example of compile to vega spec and then parse the vega spec.
function parse(spec) {
vg.parse.spec(spec, function(chart) {
chart({el:"#vis"}).update(); });
}
var vlspec = {
"data": {
"values": [
{"a":"A", "b":28}, {"a":"B", "b":55}, {"a":"C", "b":43},
@sabrooks
sabrooks / Model-Parameter-Comparison.R
Created August 10, 2015 04:19
Compare the confidence intervals of two linear models
# Data a dataframe of Confidence Intervals around parameter estimates
params <- bind_rows(lm_for%>%
confint()%>%
as.data.frame(., rownames = rownames(.))%>%
add_rownames(var = "parameter")%>%
mutate(model = "Forecast"),
lm_back%>%
confint()%>%
as.data.frame(., rownames = rownames(.))%>%
add_rownames(var = "parameter")%>%
@sabrooks
sabrooks / confint-to-dataframe.R
Last active August 29, 2015 14:27
Convert output of confint (confidence intervals around lm parameters) to a dataframe
params <- bind_rows(lm_for%>%
confint()%>%
as.data.frame(., rownames = rownames(.))%>% # convert matrix to dataframe
add_rownames(var = "parameter")%>% # convert rownames to variable
mutate(model = "Forecast"),
lm_back%>%
confint()%>%
as.data.frame(., rownames = rownames(.))%>%
add_rownames(var = "parameter")%>%
mutate(model = "Backcast"))
@sabrooks
sabrooks / time.sequence.R
Created May 9, 2015 19:17
Create a sequence of times (points) at a uniform interval
df.int <- df.start.end$start[1]%--%df.start.end$end[1] # define interval
time.points <- int_start(df.int)+minutes(seq(0, df.int%/%minutes(1), by = 5 ))# 5 minutes
@sabrooks
sabrooks / Detect Holidays.R
Last active August 29, 2015 14:19
ML Holiday Detection
#Classify workdays and weekends
cs.df<- coldstorage%>%
mutate(dofw = wday(Date.Time, label = TRUE),
day.type = as.factor(ifelse(dofw == "Sun"|dofw == "Sat", "weekend", "workweek")))%>%
dplyr::select(-dofw)
#Train Model
model <- train(day.type ~., data = cs.df,
'nb', trControl=trainControl(method='cv',number=10))