Skip to content

Instantly share code, notes, and snippets.

View benfasoli's full-sized avatar

Ben Fasoli benfasoli

View GitHub Profile
@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 / 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 / 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'
#!/usr/bin/env Rscript
library(parallel)
fun <- function(x) {
x^2
}
cl <- makeForkCluster(nnodes = 2, outfile = '')
out <- parSapply(cl, 1:2, fun)
#!/usr/bin/env Rscript
# Ben Fasoli
library(ncdf4)
library(raster)
files <- dir('raw', full.names = T)
data <- 0
for (file in files) {
@benfasoli
benfasoli / raster_interpolation.r
Created March 20, 2019 22:46
Bilinearly interpolate raster to a different resolution
#!/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
@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,
@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 / read_grimm.py
Last active July 9, 2019 17:20
GRIMM 1.109 data logging interface
#!/usr/bin/python
# GRIMM data collection script
# Ben Fasoli
import serial as ser # serial port use
import datetime # time stamps (UTC)
import re # regular expression matching
# Path to serial device ID
serialpath = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0'
@benfasoli
benfasoli / gaussian_weighted_interpolation.r
Last active July 9, 2019 21:32
Weighted interpolation of sparse STILT footprints
#!/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
#