Skip to content

Instantly share code, notes, and snippets.

@paleolimbot
paleolimbot / deconvolution.R
Created January 12, 2020 19:55
Bayesian deconvolution
gaussian_fun <- function(x, mu = 0, sigma = 1, height = 1) {
height * exp(-0.5 * ((x - mu) / sigma) ^ 2)
}
# error function:
## (see Abramowitz and Stegun 29.2.29)
skewed_gaussian_error <- function(x) {
2 * pnorm(x * sqrt(2)) - 1
}
library(ggplot2)
library(grid)
# in real life, this would be a reference to a large (scary) raster file
big_scary_raster <- tibble::tibble(raster = list(matrix(1:9, nrow = 3)))
# -------- typical ggplot2 approach --------
StatMatrixList <- ggproto(
library(tidyverse)
tbl <- tribble(
~RECORDER.ID, ~ymdh, ~scaled_load,
52210, "2017-01-01 01:00:00", 0.347,
52210, "2017-01-01 02:00:00", 0.308,
53610, "2017-01-01 01:00:00", 0.938,
53610, "2017-01-01 02:00:00", 0.902
) %>%
mutate(ymdh = lubridate::ymd_hms(ymdh))
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# learn this at https://r4ds.had.co.nz/ and https://rstudio.cloud/
# basic set of tools you can direct folks to to learn more
# very well done and has exellent learning material!
library(tidyverse)
# in this ccase, simplifyVector = TRUE does the conversion you're looking for
activities <- jsonlite::read_json(
"https://awqms.goldsystems.com/api/ResultsVer1?OrganizationIdentifiersCsv=FortPeck&MonitoringLocationType=River/Stream&MonitoringLocationIdentifiersCsv=PR-R-PR-041&ContentType=json",
simplifyVector = TRUE,
)
# use "tidyphreeqc" not "easyphreeqc"!
# remotes::install_github("paleolimbot/tidyphreeqc")
library(tidyphreeqc)
# for utility functions
library(tidyverse)
# use your own DB...
# my_custom_db <- readLines("path/to/my/db.dat")
# phr_use_db(my_custom_db)
library(tidyverse)
files <- crossing(
tibble(station_id = 42583, timeframe = 1),
tibble(year = 2018:2019),
tibble(month = 1:12)
) %>%
mutate(
url = glue::glue(
"http://climate.weather.gc.ca/climate_data/bulk_data_e.html?format=csv&Month={month}&stationID={station_id}&submit=Download%20Data&timeframe=1&Year={year}"
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
library(tidyverse)
# best case: your data is already in the right form
perfect_data <- tibble(
day_in_year = c(1, 101, 201, 1, 101, 201, 1, 101, 201),
depth = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
temp = c(15, 16, 17, 14, 15, 16, 13, 14, 15)
)
ggplot(perfect_data, aes(x = day_in_year, y = depth, fill = temp)) +