This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Get your climate data.. | |
usmex <- c(273:284,328:365) | |
usmex.basin <- create_map_df(usmex) | |
temp.dat <- get_historical_temp(usmex, "decade" ) | |
temp.dat <- subset(temp.dat,temp.dat$year == 2000 ) | |
usmex.map.df <- climate_map(usmex.basin,temp.dat,return_map=F) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_datatype<- function(datastype,term){ | |
results <- noaa_datatypes(dataset=datatype) | |
s_parse <- function(x){ | |
if(sum(grep(term,x[2],ignore.case=TRUE)) > 0){ | |
return(c(x[1],x[2])) | |
} | |
} | |
out <- unlist(lapply(results$dataTypeCollection$dataType,s_parse)) | |
out <- data.frame(matrix(out,ncol=2,nrow=(length(out)/2),byrow=T)) | |
colnames(out) <- c("ID","Description") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### Doesn't work... | |
map <- map_data('world') | |
ggplot(data = map, aes(long, lat, group=group)) + geom_path() +coord_map(xlim=c(-170, -40), ylim=c(20, 83)) | |
### Does work | |
test <- map | |
test <- subset(test,test$long > -170 & test$long < -40) | |
test <- subset(test,test$lat > 20 & test$lat < 83) | |
ggplot(data = test, aes(long, lat, group=group)) + geom_path() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(twitteR) | |
require(ggplot2) | |
library(ROAuth) | |
library(plyr) | |
### See this post on how to get your key and secret to put | |
### in below as strings: https://dev.twitter.com/discussions/631 | |
reqURL <- "https://api.twitter.com/oauth/request_token" | |
accessURL <- "http://api.twitter.com/oauth/access_token" | |
authURL <- "http://api.twitter.com/oauth/authorize" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### NLS multiple starting points search | |
### formula: a standard R formula that you want to include in the nls() call | |
### inits: is a list of 2x1 vectors giving the upper and lower bounds of a uniform distribution to pull random starting values from | |
### The list should have names that correspond to the names of your parameters, similar to the way you would call them in nls() | |
### e.g. a good starting list would be: starts <- list(a=c(0,50),b=c(0,50)) | |
### miter The maximum time to try and find a solution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import requests | |
import re | |
import sys | |
import os | |
def download_file(url,path): | |
if path[-1] == "/": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Extract % variance explained from a multiple regression model for each parameter | |
## Inputs: a fitted model object | |
## Details: Uses a simple formula for each parameter as SSparam / SST | |
## Returns: a p x 2 dataframe with parameters as rows and name and % explained are the two columns | |
per_exp <- function(mod){ | |
## Get sums of squares total (SSt) | |
squares <- anova(mod) | |
sst <- sum(squares$Sum) | |
var_exp <- vector() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clean up old installs, removing old RMendeley and old ROAuth | |
install.packages("devtools") | |
library(devtools) | |
install_github("ROAuth","duncantl") | |
install_github("RMendeley","ropensci") | |
mc <- mendeley_auth() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function (d, colClasses) | |
{ | |
colClasses <- rep(colClasses, len = length(d)) | |
d[] <- lapply(seq_along(d), function(i) switch(colClasses[i], | |
numeric = as.numeric(d[[i]]), character = as.character(d[[i]]), | |
Date = as.Date(d[[i]], origin = "1970-01-01"), POSIXct = as.POSIXct(d[[i]], | |
origin = "1970-01-01"), factor = as.factor(d[[i]]), | |
as(d[[i]], colClasses[i]))) | |
d | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### "Smart brute force" algorithm. Works in most mortal situations. | |
### Works by looping through a matrix that is m by k and putting numbers in | |
### Is aware of the top and left cell, and works by sampling based on the probabilities of | |
### numbers that are left in the set of valid possible numbers, e.g. those not excluded by the neighborhood rules (von Neumann) | |
### Parameters: | |
### k -- The number of rows | |
### m -- The number of columns | |
### n -- 1:N vector of desired outcomes (plants in the blog post), e.g. if N = 3, your n parameter would be n <- 1:3 | |
### maxiter -- The maximum number of iterations you want to use in the algorithm (default is 100. |