Skip to content

Instantly share code, notes, and snippets.

View benfasoli's full-sized avatar

Ben Fasoli benfasoli

View GitHub Profile
#!/usr/bin/env Rscript
library(parallel)
fun <- function(x) {
x^2
}
cl <- makeForkCluster(nnodes = 2, outfile = '')
out <- parSapply(cl, 1:2, fun)
@benfasoli
benfasoli / chpc_rclone_backup.py
Last active July 9, 2019 16:34
Backup of lin-group CHPC resources to remote location
#!/usr/bin/env python3
# Automated backup of lin-group CHPC resources
# Ben Fasoli
#
# Requires rclone to be installed
# Depends on access_token found in ~/.config/rclone/rclone.conf
# To create an access token, run
# module load rclone
# rclone config
# Name: {anything short, e.g. gcloud}
@benfasoli
benfasoli / make_kmz.r
Last active August 14, 2018 13:47
R KMZ mapping function for points and lines
#' Generates a KMZ file
#' @author Ben Fasoli
#'
#' \code{make_kmz} generates a KMZ representation of surface observations.
#'
#' @param data to be plotted on Z axis
#' @param time vector of times for data observations
#' @param lat latitude, in dd.dddd
#' @param lon longitude, in dd.dddd
#' @param filepath character path to output file, ending in '.kmz'
@benfasoli
benfasoli / test_slurm_apply_listarg.r
Created May 30, 2018 01:08
Verify that a list column of a data frame is passed through rslurm::slurm_apply to mapped function
# Ben Fasoli
# Check that rslurm::slurm_apply accepts a list as a dataframe column
library(rslurm)
slurm_options <- list(
time = '300:00:00',
account = 'lin-kp',
partition = 'lin-kp'
)
@benfasoli
benfasoli / test_find_met_files.r
Created May 29, 2018 17:25
Test STILT's met file identification function
# Ben Fasoli
# Testing for met file identification
rm(list = ls())
# Source find_met_files()
# https://github.com/uataq/stilt/blob/master/r/src/find_met_files.r
source('https://raw.githubusercontent.com/uataq/stilt/master/r/src/find_met_files.r')
# Create pseudo-met files
system('touch ex_d01.arl ex_d02.arl ex_d03.arl')
@benfasoli
benfasoli / wait_for_slurm.r
Created May 16, 2018 21:50
Wait for rslurm::slurm_apply to complete
# Ben Fasoli
# Wait for rslurm::slurm_apply to complete
library(rslurm)
fun <- function(x) {
Sys.sleep(x)
return(T)
}
@benfasoli
benfasoli / read_grimm.py
Last active June 29, 2019 01:00
Parse GRIMM particle counts and estimate mass concentrations
#!/usr/bin/env python3
import numpy as np
import os
import pandas as pd
DATA_PATH = '/home/data/alta_udot/grimm_1109/'
BIN_SIZE_UPPER = np.array([0.25,
0.28,
<form action="https://formspree.io/info@wwtrek.com" method="POST">
<input type="text" name="name" placeholder="Name">
<input type="email" name="_replyto" placeholder="Email Address">
<textarea name="message" placeholder="Message"></textarea>
<input type="submit" value="Send">
</form>
@benfasoli
benfasoli / map-raster-to-google-terrain.r
Last active January 25, 2018 20:45
Overlay partial transparency gridded raster to grayscale Google Map terrain layer
library(ggmap)
library(tidyverse)
# Fetch SLC-centric grayscale Google Map terrain layer
basemap <- get_googlemap(center = c(lon = -112.0, lat = 40.6), zoom = 10,
scale = 2, maptype = 'terrain', color = 'bw')
# Display downloaded map
ggmap(basemap)
@benfasoli
benfasoli / extract-coordinates-from-polygons.r
Last active November 1, 2023 11:28
Methods for extracting coordinates from spatial objects (e.g. SpatialPolygonsDataFrame)
# Ben Fasoli
library(sp)
library(rgdal)
shape <- readOGR(dsn = 'data', layer = 'four_samples')
head(shape@polygons[[1]]@Polygons[[1]]@coords)
# [,1] [,2]
# [1,] -111.6227 40.75247