Skip to content

Instantly share code, notes, and snippets.

View mbjoseph's full-sized avatar

Max Joseph mbjoseph

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbjoseph
mbjoseph / small-sample-weibull.R
Created November 22, 2016 20:47
Exploring how sample size affects the estimates of Weibull shape and scale parameters
# Script to evaluate small sample behavior of Weibull parameter MLEs --------
library(fitdistrplus)
library(dplyr)
library(tidyr)
library(gridExtra)
library(parallel)
library(ggplot2)
library(viridis)
@mbjoseph
mbjoseph / parallel-loop-unroll.R
Last active December 9, 2016 17:38
How to unroll a nested for-loop in R so that it can be run in parallel
library(parallel)
# Create matrix to store result -------------------------------------------
M <- 4
N <- 6
A <- matrix(0, nrow = M, ncol = N)
list <- list(3, 4, 6)
# Serial version ----------------------------------------------------------
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbjoseph
mbjoseph / main.ipynb
Created January 16, 2017 21:41
sad error
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mbjoseph
mbjoseph / HDF_to_TIF.R
Created March 10, 2017 20:36
Setting raster projections, extent, and computing annual summaries
library(rgdal)
library(rgeos)
library(raster)
library(gdalUtils)
# gdalinfo("GFED40_MQ_199506_BA.hdf")
# sds <- get_subdatasets("GFED40_MQ_199506_BA.hdf")
# sds
@mbjoseph
mbjoseph / get_lsat.rasters.R
Last active June 7, 2017 19:51
Fetch rasters from USGS server
library(RCurl)
# Fetching burn rasters ---------------------------------------------------
# get and read the file listing from the usgs server
prefix <- 'https://rmgsc.cr.usgs.gov/outgoing/baecv/BAECV_CONUS_v1_2017/'
download.file(prefix, destfile = 'listing.txt')
out <- readLines('listing.txt')
# now create paths to each tar.gz file by processing the html
@mbjoseph
mbjoseph / read_ams_data.R
Created March 29, 2017 20:24
Parse and read ams data
# Importing data from USDA into large data file ---------------------------
library(stringr)
library(tidyverse)
convert_to_df <- function(file) {
# takes a text file as input and parses the file to generate a data.frame
lines <- readLines(file)
# identify blank lines which denote separate files
@mbjoseph
mbjoseph / boulder-weather-basis.R
Created May 19, 2017 19:39
Using basis functions to predict weather in Boulder, CO
library(raster)
library(tidyverse)
library(lubridate)
library(mgcv)
# Boulder temperature prediction ------------------------------------------
# Goal: use historical temperature data to predict the weather a week from today
# Fetch raw data from NOAA
data_url <- "https://www.esrl.noaa.gov/psd/boulder/data/boulderdaily.complete"
@mbjoseph
mbjoseph / hello-world.R
Created June 5, 2017 20:24
Hello world in R
print("Hello, world!")