Skip to content

Instantly share code, notes, and snippets.

@brews
brews / fire_stacker.R
Last active October 6, 2015 20:03
Combine multiple FHX files for Ellis.
#! /usr/bin/env Rscript
# 2015-02-25 S. B. Malevich
# Combine all FHX files in the current working directory and try to output it
# as a single FHX file (`OUTFILE`). You need to have "firehistory.R" in the
# same directory, too.
ARGS <- commandArgs(TRUE)
source("firehistory.R")
@brews
brews / .vimrc
Last active December 3, 2016 18:40
My vimrc file
call plug#begin('~/.vim/plugged')
Plug 'sickill/vim-monokai'
Plug 'dikiaap/minimalist'
Plug 'w0ng/vim-hybrid'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
"Plug 'scrooloose/nerdtree'
Plug 'scrooloose/syntastic'
Plug 'scrooloose/nerdcommenter'
Plug 'ctrlpvim/ctrlp.vim'
@brews
brews / animate_bignetcdf.py
Last active November 14, 2015 17:06
Big netCDF animation example for Goddard
#! /usr/bin/env python3
# 2015-11-13
# S. B. Malevich <malevich@email.arizona.edu>
# Animate netCDF files. Can use in shell like:
#
# ./animate_bignetcdf.py SSH 5days_SSH_Brewster.nc ./plots/
#
# This is ./animate_bignetcdf.py [variable_name] [netCDF_file] [output_dir]
#! /usr/bin/env bash
# 2016-04-28
# Download everything from a specific directory in the ITRDB.
TARGET_URL="ftp://ftp.ncdc.noaa.gov/pub/data/paleo/treering/measurements/northamerica/usa/*"
WAIT_SECONDS=1
wget -r -nH --cut-dirs=7 -w $WAIT_SECONDS --tries=10 $TARGET_URL -o log.txt
@brews
brews / fire_season_plot.R
Last active May 25, 2016 15:50
firescar season plot example
plot_season <- function(x, binwidth=10) {
# Plot seasonality of fire scars through time.
#
# Args:
# x : An fhx object.
# binwidth : Integer. The bin-size (number of years in each bar) for the
# output plot. Default is 10.
#
# Returns:
# A ggplot2 object.
@brews
brews / parse_itrdb_example.R
Last active October 6, 2016 15:30
Example for someone on how to parse everything from the ITRDB.
require(dplR)
# setwd ("/you/had/your/path/here")
# Global variables. We'll use these below. I put them here so we can easily
# change them, if need be.
PATH_ITRDB <- 'itrdb.csv'
GREP_PATTERN <- '/usa/.*?\\.rwl' # matches strings that end in "/usa/*.rwl"
# 2011-04-04
# v0.2
# Copyright 2011 C. Guiterman & S. B. Malevich <malevich@email.arizona.edu>
# Based on dplR spag.plot function - by A. Bunn.
# Function to add a spline to dplR's spagetti plot.
require(dplR)
#source('ffcsaps.R')
spag.spline <- function(rwl, zfac=1, spline.nyrs=32, f=0.5, spline.col=2,
@brews
brews / matern.py
Created July 14, 2017 17:56
Python Matérn correlation function for given distances and parameters. Comparable to `geoR`'s `matern()`
import scipy
import numpy as np
def matern(u, phi, kappa):
"""Computes Matérn correlation function for given distances and parameters
Roughly based on the matern function from Ribeiro and Diggle's 'geoR'
package for R.
Parameters:
@brews
brews / scrape_IMPD_example.R
Last active July 14, 2017 22:25
How to pull hyperlinks and FHX files from an html directory, read with read_fhx() in an somewhat error-resistant way
# 2017-07-14
# S. Brewster Malevich <malevich@email.arizona.edu>
# How to pull hyperlinks from an html directory, read with read_fhx() in a
# somewhat error-resistant way.
# There are a couple ways to do this. Python or `wget` would be far
# better options, but let's do this with R.
# Another thing, this pesters the poor NCDC server every time you run this.
@brews
brews / make_comparison.sh
Created February 1, 2018 16:16
compare CCSM3 TraCE21ka TS with regridded TOS
#! /usr/bin/env bash
# 2018-01-12
# Make a netCDF file that's diff between TS and TOS (TS - TOS).
cp data/regrid/tos_sfc_Odec_CCSM3_TraCE21ka_TSREGRID.nc data/combined_tmp.nc
ncks -A data/ts_sfc_Adec_CCSM3_TraCE21ka.nc data/combined_tmp.nc
ncap2 -s 'tdif=(ts-tos)' data/combined_tmp.nc data/combined.nc
# Cleanup