Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View emanuelhuber's full-sized avatar

Emanuel Huber emanuelhuber

View GitHub Profile
@emanuelhuber
emanuelhuber / BHETemp.R
Last active September 6, 2022 15:01
Function to calculate temperature change around borehole heat exchanger as a function of depth and time, based on the Finite Line Source (Eskilson, 1987).
library("sf")
library("terra")
library("viridis")
# Finite Line Source (Eskilson, 1987)
# FLS
# s = term to be integrated, ranges from D to D+L (m)
# aB = temperaturleitfähigkeit (m2/s)
# D = Überdeckung der Sonde (m)
# L = Sondenlänge (m)
library(sf)
library(deldir)
require(igraph)
# require(gstat)
require(smoothr)
require(tripack)
require(spatstat)
library(fields)
library(gstat)
library(xts)
library(lubridate)
# Write time-series for FEFLOW
# userunit = m^3/d, l/min, m, ^0C
writeTS <- function(fPath, x,
option = c("linear", "cyclic"),
type = c("Polylined", "Constant"),
unitclass = c("PUMP_RATE", "TEMPERATURE", "LENGTH", "VELOCITY", "PUMP_HEAT_RATE"),
userunit,
# Add a logo at the bottom left of a plot (outside plot area).
# obj = raster image
# wight = width in % of figure width
# shift in inch (x, y)
# interpolate Raster (=smooth)
#---
# inspiration: https://stackoverflow.com/a/56018973/16599100
addLogo <- function(obj, width = 0.25, shift = c(0,0), interpolate = TRUE){
xsign <- ifelse(diff(par()$usr[1:2]) > 0, 1, -1)
ysign <- ifelse(diff(par()$usr[3:4]) > 0, 1, -1)
if(!require("openxlsx")) install.packages("openxlsx")
library("openxlsx")
# this function open an explorer window.
# select the file you want to split
# the file is split into files according to the values
# in the column "Projektleitung"
splitExcelFile <- function(fpath = NULL, fpathold = TRUE, startRow = 1){
@emanuelhuber
emanuelhuber / addPolySeq.R
Created February 11, 2021 15:13
Add colored rectangle as background to a xts time-series (R language)
addPolySeq <- function(tval, y, ylim, ...){
i <- seq(1, by = 2, to = length(tval)- 1)
tval_p <- cbind(tval[i], tval[i + 1])
u <- (apply(tval_p, 1, FUN, y = y, ylim = ylim, ...))
u
}
FUN <- function(x, y, ylim, ...){
ynew <- y[paste0(c(as.Date(x[1]), as.Date(x[2])), collapse = "/")]
nr <- nrow(ynew)
if(nr > 0){
@emanuelhuber
emanuelhuber / R_tips_and_tricks.md
Last active May 8, 2020 08:11
R tips and tricks
% Encoding: UTF-8
@Article{affolter&al:2010,
Title = {Adaptives Grundwassermanagement in urbanen Gebieten},
Author = {A. Affolter and P. Huggenberger and S. Scheidler and J. Epting},
Journal = {Grundwasser},
Year = {2010},
Month = {jun},
Number = {3},
@emanuelhuber
emanuelhuber / perpendicularPoints.R
Last active November 2, 2019 20:21
Compute the points perpendicular to a polyline (usefull to compute perpendicular profiles/transects)
# Exemple
# #
# a <- locator()
# xy0 <- do.call(cbind, a)
# lat <- transect(xy0, d = c(0.00001, -0.000003))
# plot(xy0, asp = 1, type = "o", pch = 20)
# segments(xy0[, 1], xy0[, 2], lat$x[, 1], lat$y[, 1], col = "blue")
# segments(xy0[, 1], xy0[, 2], lat$x[, 2], lat$y[, 2], col = "red")
#' Points perdicular to a polyline
@emanuelhuber
emanuelhuber / r2jekyll.R
Last active October 5, 2022 17:51
From Rmarkdown to github markdown while preserving latex equations
#!/usr/bin/env Rscript
#-----------------------------------------------------------------------------
# How to run?
# In terminal enter: Rscript --vanilla r2jekyll.R my_RMarkdownFile.Rmd
#-----------------------------------------------------------------------------
# Problem while rendering Rmarkdown files with latex equation into markdown file
# -> Rmarkdown try to convert the equation into markdown instead of leaving them
# as latex equation. In consequences, the equations within the mardown file