Skip to content

Instantly share code, notes, and snippets.

Avatar

Carl Boettiger cboettig

View GitHub Profile
View col_versions.R
library(tidyverse)
# 2017 monthly
x <- tempfile("col")
dir.create(x)
download.file("https://download.catalogueoflife.org/col/monthly/2017-02-27_dwca.zip", file.path(x, "dwca.zip"))
unzip(file.path(x, "dwca.zip"), exdir = x)
fs::dir_ls(x)
taxa <- readr::read_tsv(file.path(x, "taxa.txt"), guess_max=1e6, quote="", col_types = readr::cols(.default = "c"))
taxa %>% filter(specificEpithet == "sapiens", taxonomicStatus == "accepted name", genus=="Homo")
@cboettig
cboettig / ppo.py
Last active Jun 4, 2021
ppo puzzle
View ppo.py
import numpy as np
import stable_baselines3 as sb3
from stable_baselines3.common.env_util import make_vec_env
from torch import nn as nn
import os
import gym
import gym_fishing
seed = 24
np.random.seed(seed)
View README.md

Reproducibility problems

Install precise dependencies indicated:

pip install -r requirements.txt

Download the cached agent (alternately, skip this and re-train agent by uncommenting the learn and save steps above):

View forecast-eml.xml
<?xml version="1.0" encoding="UTF-8"?>
<eml:eml xmlns:eml="https://eml.ecoinformatics.org/eml-2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.2" packageId="hash://sha256/0feec451332bc465a03fb15a0351fd34bf896e8221226cdfe6bd812bfa6f5dec" system="hash-uri" xsi:schemaLocation="https://eml.ecoinformatics.org/eml-2.2.0 https://eml.ecoinformatics.org/eml-2.2.0/eml.xsd">
<dataset>
<title>NEON Carabid Species Richness and Abundance Forecast</title>
<creator id="http://orcid.org/0000-0002-1642-628X">
<individualName>
<givenName>Carl</givenName>
<surName>Boettiger</surName>
</individualName>
</creator>
@cboettig
cboettig / as_efi.R
Last active Mar 16, 2021
Format fable timeseries, fbl_ts, to EFI flat-file format
View as_efi.R
## Helper functions to turn a fable timeseries, which uses a special "distribution" column,
## into a flat-file format. efi_statistic_format uses a 'statistic' column (indicating either mean or sd),
## while efi_ensemble_format uses an 'ensemble' column, drawing `n` times from the distribution.
efi_statistic_format <- function(df){
## determine variable name
var <- attributes(df)$dist
## Normal distribution: use distribution mean and variance
df %>%
dplyr::mutate(sd = sqrt( distributional::variance( .data[[var]] ) ) ) %>%
dplyr::rename(mean = .mean) %>%
View noaa_stack.R
library(tidync)
library(aws.s3)
download_noaa <- function(siteID,
interval = "6hr",
date = Sys.Date()-2,
cycle = "00",
dir = file.path(neon_dir(), "noaa")){
dir.create(dir, FALSE, TRUE)
prefix <- paste("noaa", paste0("NOAAGEFS_", interval),
@cboettig
cboettig / tidync-noaa.Rmd
Created Mar 3, 2021
access EFI NOAA data
View tidync-noaa.Rmd
```{r setup}
library(tidync)
```
Today's (2021-03-03) 16-day forecast made for ABBY NEON site at 6h-intervals: (other intervals and older forecasts also possible)
```{r}
download.file("https://data.ecoforecast.org/drivers/noaa/NOAAGEFS_6hr/ABBY/2021-03-03/12/NOAAGEFS_6hr_ABBY_2021-03-03T00_2021-03-19T12_ens00.nc", "~/NOAAGEFS_6hr_ABBY_2021-03-03T00_2021-03-19T12_ens00.nc")
```
```{r}
@cboettig
cboettig / forecast-eml-debug.Rmd
Last active Feb 3, 2021
forecast-eml-debug.Rmd
View forecast-eml-debug.Rmd
---
title: "Example metadata for a Lotka-Volterra population growth forecast"
output: rmarkdown::html_document
vignette: >
%\VignetteIndexEntry{Logistic Growth Simulation}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
#### Code {.tabset}
View Bug Report.Rmd
---
title: "bug report"
output: github_document
---
```{r}
stopifnot(file.exists("Bug Report.Rmd"))
```
@cboettig
cboettig / prov.json
Created Aug 31, 2020
DCAT2 Provenance (JSON-LD)
View prov.json
{
"@context": {
"dcat": "http://www.w3.org/ns/dcat#",
"prov": "http://www.w3.org/ns/prov#",
"dct": "http://purl.org/dc/terms/",
"id": "@id",
"type": "@type",
"identifier": "dct:identifier",
"title": "dct:title",
"description": "dct:description",