Skip to content

Instantly share code, notes, and snippets.

View rBatt's full-sized avatar

Ryan Batt rBatt

  • Newell
  • Philadelphia, PA
View GitHub Profile
@rBatt
rBatt / gist:7ae49c0f216d430906ca
Last active August 29, 2015 14:20
Lake Metabolizer Latex Scripts
% ===============
% = Bookkeeping =
% ===============
% Equation 3: average respiration
R_{\mu} = \frac{\sum\limits_{i=1}^{n} \Delta DO_i - F_i}{n \Delta t}
NEP = \frac{NEP_t (\text{mg O}_2 \text{ L}^{\text{-}1} \Delta t)} {1}
@rBatt
rBatt / fig.setup.R
Last active January 11, 2016 20:37
png(file="~/Desktop/figure.png", width=3.5, height=3.5, res=150, units="in") # open / setup device
par(
mar=c(1.75, 1.75, 0.1, 0.1), # panel magin size in "line number" units
mgp=c(1, 0.1, 0), # default is c(3,1,0); line number for axis label, tick label, axis
tcl=-0.1, # size of tick marks as distance INTO figure (negative means pointing outward)
cex=1, # character expansion factor; keep as 1; if you have a many-panel figure, they start changing the default!
ps=8, # point size, which is the font size
family="sans"
@rBatt
rBatt / gist:b4bfba056e7cf1bec55a
Last active September 22, 2015 16:20
multiply 2d kernel by this
# this is what 'test' looks like:
# > test
# s.reg year num nameID stratum lon lat btemp depth N Nsite spp Z u.a0 a1 a2
# 1: ebs 1982 12 ebs_1982_12 -158.5 57.5 -158.5 57.5 -0.16 34.4 919.4999 83 Acantholithodes hispidus 0 -2.807526 0.60290095 -0.1560553
# 2: ebs 1982 12 ebs_1982_12 -158.5 57.5 -158.5 57.5 -0.16 34.4 919.4999 83 Acantholumpenus mackayi 0 -4.294548 0.66363085 -0.1244255
# 3: ebs 1982 12 ebs_1982_12 -158.5 57.5 -158.5 57.5 -0.16 34.4 919.4999 83 Actinauge verrilli 0 -2.763588 0.67887606 -0.1261046
# 4: ebs 1982 12 ebs_1982_12 -158.5 57.5 -158.5 57.5 -0.16 34.4 919.4999 83 Admete regina 0 -3.658542 0.66688800 -0.1661476
# 5: ebs 1982 12 ebs_1982_12 -158.5 57.5 -158.5 57.5 -0.16 34.4 919.4999 83 Aforia circinata 0 -9.954288 0.67970755 -0.1168343
# ---
@rBatt
rBatt / zCol
Created November 23, 2015 22:04
add heat map colors to plot
zCol <- function(nCols, Z){
cols <- colorRampPalette(c("#000099", "#00FEFF", "#45FE4F", "#FCFF00", "#FF9400", "#FF3100"))(nCols)
colVec_ind <- cut(Z, breaks=nCols)
colVec <- cols[colVec_ind]
}
# Example
X <- rnorm(1E3)
Y <- rnorm(1E3)
Z <- X*Y
plot(crop(subset(soda.annMax, 5:51), extent(c(-76, -65, 36, 46))), maxnl=200, bigplot=bgplt, smallplot=smplt, axis.args=axargs, col=tim.colors(), zlim=range(values(crop(subset(soda.annMax, 5:51), extent(c(-76, -65, 36, 46)))),na.rm=T))
export PATH=$HOME/bin:$PATH
source ~/.bashrc
export PATH=$PATH:/usr/include
source ~/.bashrc
echo $PATH
cd
mkdir src
@rBatt
rBatt / trawlData.yml
Last active December 15, 2015 00:43
trawlData yml
## All R files that are used must be listed here:
packages:
- data.table
- LaF
- bit64
- stringr
- stringi
- PBSmapping
- devtools
# for Eva (foreva eva)
eg <- structure(c(608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
608416320, 608416320, 608416320, 608416320, 608416320, 608416320,
df <- data.frame(x = rnorm(20, mean=20, sd = 10))
threshold <- 25
replace_val <- 0
df[,"x2"] <- df[,"x"] # make them the same to start
df[df[,"x"] >= threshold, "x2"] <- replace_val # replace values at or above threshold with replacement value
@rBatt
rBatt / read_jho.R
Created March 31, 2016 18:07
How to read a data file with 2 dimensional data interspersed with comments, in R
#' Read JHo
#'
#' Read in a file formatted like Jennifer's data sets
#'
#' @param file a character indicating the file name (and possibly path)
#' @param n_nrows integer indicating number of rows for each matrix
#' @param n_matrices integer indicating number of matrices in the file
#' @param n_comment integer indicating the number of comment lines preceding each matrix of data; should include blank lines
#' @param n_top_comment integer indicating the number of comment lines that are unique to the start of the file; default is 0 lines
#' @param ... arguments to be passed to \code{scan}, such as \code{what=numeric()} and \code{sep=","}