Skip to content

Instantly share code, notes, and snippets.

### Plot length summary
data=read.csv("plotBAincr.csv",stringsAsFactors=F)
data$Date.start=as.Date(data$Date.start)
data$Date.end=as.Date(data$Date.end)
plotlist=unique(data$Plot)
out_frame=data.frame(Plot="",Date.start="",Date.end="",length=0,stringsAsFactors=F)
@ozjimbob
ozjimbob / engine.r
Created December 11, 2012 23:55
SPAM Model
# Run model simulation with given values for:
# initial cull, maintenance cull, cell target density, allocated budget,
# area to cull, and "control area" (area for which proportional population is calculated)
# (last two are kept separate for the spatial optimisation, where we may choose to cull a subset
# of the target control area for efficiency)
run.sim = function(curr.init.cull, curr.maint.cull, curr.target.density, budget, C.mask, ctrl.mask)
{
Nx = ncol(K); Ny = nrow(K); # gauge size of map
IC = K # note - initial population is set to carrying capacity
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am ozjimbob on github.
  • I am jimbob (https://keybase.io/jimbob) on keybase.
  • I have a public key whose fingerprint is 7ABC 13B3 C2B3 2583 C3A2 C03C EC2D AA9F 5376 6533

To claim this, I am signing this object:

@ozjimbob
ozjimbob / demiowa.r
Created February 2, 2016 02:39
R Dem Iowa Caucus Graph
library(rjson)
library(httr)
turl="https://iowadems-caucussitecdn-prod2.azureedge.net/api/statecandidateresults"
a=GET(turl)
arr=c(content(a)$StateResults[[1]]$WinPercentage,content(a)$StateResults[[2]]$WinPercentage,content(a)$StateResults[[3]]$WinPercentage)
nam=c(content(a)$StateResults[[1]]$Candidate$DisplayName,content(a)$StateResults[[2]]$Candidate$DisplayName,content(a)$StateResults[[3]]$Candidate$DisplayName)
colr=c(content(a)$StateResults[[1]]$Candidate$Color,content(a)$StateResults[[2]]$Candidate$Color,content(a)$StateResults[[3]]$Candidate$Color)
rar=round(arr,3)*100
barplot(arr,names.arg=nam,col=colr)
@ozjimbob
ozjimbob / sph_hillshade.r
Last active August 16, 2016 05:44
Example code to great a hillshade raster from a DEM in R using spherical environment mapping for the colour scheme.
library(raster)
library(jpeg)
# Spherical environment mapping hillshade function
getv=function(i,a,s){
ct = dim(i)[1:2]/2
sx = values(s)/90 * ct[1]
sy = values(s)/90 * ct[2]
a = values(a) * 0.01745
px = floor(ct[1] + sx * -sin(a))
@ozjimbob
ozjimbob / blitz.r
Last active November 29, 2017 01:09
## Load required packages
# you will need to install these, first do
# eg. install.packages("tidyverse")
# etc. to install them one by one
library(tidyverse)
library(httr)
library(sf)
library(tmap)
data = tibble(foo=c("Bah","Fuzz"))
my_column="foo"
data %>% filter(!!my_column := "Bah")
library("reticulate")
library(tidyverse)
library(purrr)
# We use the python "holidays" package for the basic holidays
# Installed it using pip first
holidays <- import("holidays")
tas_holidays <- holidays$Australia(prov="TAS")
# List of all dates from 2000 to 2018
@ozjimbob
ozjimbob / access.r
Last active November 21, 2018 10:47
Example of downloading and plotting ACCESS met model data in R
# Demonstration - Downloading and animating ACCESS forecast data
# grant.williamson@utas.edu.au
# General functions, including str_replace, map
library(tidyverse)
# threddscrawler is a useful package for parsing THREDDS data servers
# Install it with:
# devtools::install_github("BigelowLab/threddscrawler")
library(threddscrawler)