Skip to content

Instantly share code, notes, and snippets.

Ben Fasoli benfasoli

Block or report user

Report or block benfasoli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@benfasoli
benfasoli / chpc_r_configuration.sh
Last active Sep 19, 2019
Configure R for user-scoped package management
View chpc_r_configuration.sh
#!/bin/bash
mkdir -p /uufs/chpc.utah.edu/common/home/$(whoami)/.Rpackages && \
echo "system('source /uufs/chpc.utah.edu/common/home/$(whoami)/.bashrc')
.libPaths(
c(
'/uufs/chpc.utah.edu/common/home/$(whoami)/.Rpackages',
.libPaths()
)
@benfasoli
benfasoli / matrix_distance_weighting.r
Last active Jul 25, 2019
Normalized inverse distance weighting applied over a grid
View matrix_distance_weighting.r
#!/usr/bin/env Rscript
n <- 5
# fill matrix of distances
d <- matrix(nrow = n, ncol = n)
d[1:n, 1] <- 0:(n-1)
d[1, 1:n] <- 0:(n-1)
@benfasoli
benfasoli / gaussian_weighted_interpolation.r
Last active Jul 9, 2019
Weighted interpolation of sparse STILT footprints
View gaussian_weighted_interpolation.r
#!/usr/bin/env Rscript
# Ben Fasoli
#
# Interpolation utilities for STILT footprints to predict footprints for
# finely gridded receptors using coarse STILT-calculated footprints for
# intermediate receptor locations.
#
# Uses weights derived from 2d Gaussian kernels to average footprints from
# the surrounding spatial area
#
@benfasoli
benfasoli / parallel_apply.py
Last active Jul 9, 2019
Split-apply-combine strategy for data mining in parallel with Pandas DataFrames
View parallel_apply.py
#!/usr/bin/env python
from multiprocessing import cpu_count, Pool
import pandas as pd
def parallel_apply(df, fun, n_chunks: int = None):
"""Apply function to batches of dataframe rows
Parameters
----------
@benfasoli
benfasoli / adc_worker.ino
Created Mar 28, 2019
Arduino template for polling analog voltages at given interval
View adc_worker.ino
// Ben Fasoli
const int n = 6;
const int pins[n] = {A0, A1, A2, A3, A4, A5};
const float slope[n] = {1, 1, 1, 1, 1, 1};
const float intercept[n] = {0, 0, 0, 0, 0, 0};
// Board reference voltage measured on aref pin
const float refVoltage = 4.93; // V
@benfasoli
benfasoli / raster_interpolation.r
Created Mar 20, 2019
Bilinearly interpolate raster to a different resolution
View raster_interpolation.r
#!/usr/bin/env Rscript
library(raster)
# Create gridded example data
xyz <- expand.grid(x = seq(-112.4, -111.6, by = 0.03),
y = seq(40.3, 40.9, by = 0.03))
xyz$z <- with(xyz, abs(x * y))
r_coarse <- rasterFromXYZ(xyz, crs = '+proj=longlat')
r_coarse
View process_egts.r
#!/usr/bin/env Rscript
# Ben Fasoli
library(ncdf4)
library(raster)
files <- dir('raw', full.names = T)
data <- 0
for (file in files) {
View parallel_function.r
#!/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 Jul 9, 2019
Backup of lin-group CHPC resources to remote location
View chpc_rclone_backup.py
#!/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 Aug 14, 2018
R KMZ mapping function for points and lines
View make_kmz.r
#' 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'
You can’t perform that action at this time.