Skip to content

Instantly share code, notes, and snippets.

View jlehtoma's full-sized avatar

Joona Lehtomäki jlehtoma

  • Helsinki
View GitHub Profile
@jlehtoma
jlehtoma / batchreplace.sh
Created March 24, 2014 08:17
Batch replace ASCII rasters with GeoTIFF rasters
#!/bin/bash
for FILE in *.asc
do
BASENAME=$(basename $FILE .asc)
OUTFILE=${BASENAME}.tif
echo "Processing: ${BASENAME}.asc"
gdal_translate -of GTiff -co COMPRESS=DEFLATE $FILE $OUTFILE
@jlehtoma
jlehtoma / convert.sh
Last active August 29, 2015 14:00
Pandoc table conversion
#!/bin/bash
pandoc in.md -o out.pdf
pandoc in.md -o out.tex
pandoc out.tex -o out2.pdf
@jlehtoma
jlehtoma / check_list_of_lists_null.R
Created August 26, 2014 19:41
Check if any of the elements in a list within a list is NULL
library(rlist)
x <- list(list("ID"=1, "var1"="B", "var2"="D"),
list("ID"=2, "var1"="F", "var2"="H"),
list("ID"=3, "var1"="I", "var2"=NULL))
# rlist approach - returns FALSE
list.any(x, l ~ is.null(l))
# 2-level lapply - returns TRUE

Keybase proof

I hereby claim:

  • I am jlehtoma on github.
  • I am jlehtoma (https://keybase.io/jlehtoma) on keybase.
  • I have a public key whose fingerprint is CCCE BB9B C821 8250 74F4 28BA B49C 7E97 E9C2 A513

To claim this, I am signing this object:

# Tell all slaves to return a message identifying themselves.
mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size()))
mpi.remote.exec(paste(mpi.comm.get.parent()))
# Send execution commands to the slaves
x <- 5
x <- mpi.remote.exec(rnorm, x)
x
mpi.close.Rslaves()
@jlehtoma
jlehtoma / join_and_update.R
Last active August 29, 2015 14:18
Join and update transect
library(dplyr)
library(magrittr)
museum_transects <- read.table("data/museon_linjat.csv", as.is = TRUE,
sep = ";", header = TRUE)
standard_transects <- read.table("data/vakioreitit_lista_suojelualueet.csv",
as.is = TRUE, sep = ";", header = TRUE)
# Select only columns Reitti and Suojelualue form standard_transects
@jlehtoma
jlehtoma / massage_data.R
Last active August 29, 2015 14:18
Massaging data
library(dplyr)
library(tidyr)
dat <- data.frame(laji=c("accgen", "accnis", "accgen", "accnis" , "accgen",
"accnis", "accgen", "accnis"),
lkm=c(2, 2, 1, 4, 3, 2, 2, 6),
linja_P_E = c("P", "P", "E", "E", "P", "P", "E", "E"))
dat_agg <- dat %>%
# Group by both laji and linja_P_E
@jlehtoma
jlehtoma / scrape_urls.R
Created April 29, 2015 09:51
Scrape bird transect lines urls
library("dplyr")
library("magrittr")
library("rvest")
urls <- c("http://koivu.luomus.fi/seurannat/linjalaskenta/vakiolinjat.php")
site <- html(urls)
linjat_table <- site %>%
html_node("table") %>%
html_nodes("tr")
@jlehtoma
jlehtoma / map_europe.R
Created June 29, 2015 13:42
Map Europe
install.packages(c("maptools", "rworldmap", "rworldxtra"))
# Load required packages
library(maptools)
library(rworldmap)
# Define LAEA projection for Europe
crs.laea <- CRS("+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +units=m +no_defs") # Lambert Azimuthal Equal Area
# Grab the whole world, NOTE that you will also need package rworldextra
@jlehtoma
jlehtoma / rmpi_script.R
Created September 14, 2015 09:59
Run simple R/MPI example on CSC Taito
# Tell all slaves to return a message identifying themselves.
mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size()))
mpi.remote.exec(paste(mpi.comm.get.parent()))
# Send execution commands to the slaves
x <- 5
x <- mpi.remote.exec(rnorm,x)
length(x)
x