Skip to content

Instantly share code, notes, and snippets.

Actual Collaboration Scale:

  • 100+ prompts from you across yesterday and today
  • Intensive iterative process with extensive back-and-forth
  • Deep scientific debugging requiring many rounds of refinement
  • Much more substantial effort than I initially estimated

What This Actually Represents:

  • Your time investment: Probably 6-8+ hours of active engagement across the two days
@cboettig
cboettig / module-2-full-claude-4-log.md
Created July 27, 2025 21:08
claude full module log

cboettig: Help me complete the assignment in this repo

GitHub Copilot: I'll help you complete the fisheries assignment. Let me first examine the current state of the notebook and understand what needs to be done. Let me also check the requirements and rubric to understand what exactly needs to be completed: Now I understand the assignment! This is a fisheries data analysis assignment using the Ibis framework and RAM Legacy Stock Assessment Database. There are two main exercises:

  1. Exercise 1: Investigating North-Atlantic Cod - replicating a figure from the Millennium Ecosystem Assessment
  2. Exercise 2: Global Fisheries Stock Collapses - replicating trends from Worm et al 2006

Let me configure the notebook environment and start implementing the solutions: Let me first run the imports cell to set up the environment: Great! Now let me start working on Exercise 1. I need to add code to connect to the RAM database and extract North Atlantic Cod data. Let me add code to the first empty Python cell:

Ma

@cboettig
cboettig / duckdb-filtering-join.py
Last active June 9, 2025 00:17
ibis-geospatial-filtering-joins
# same thing in pure duckdb / SQL
import duckdb as ddb
con = ddb.connect('test4.db', config=dict(max_memory='500MB')) # Create a DuckDB connection
con.install_extension("spatial")
con.load_extension("spatial")
con.sql(f"""
CREATE OR REPLACE VIEW fires AS (
@cboettig
cboettig / ecmwf-gdal.R
Created May 13, 2025 00:08
ECMWF land-cover ncdf examples
library(gdalcubes)
library(dplyr)
library(sf)
library(spData)
aoi <- spData::world |> filter(name_long=="United States")
gdalcubes_options(parallel = 100) # can be way more than "real" cpus.
# netcdf is an inconsistent format where auto-detection of layers and CRS doesn't always work. We specify this crap in the URL:
@cboettig
cboettig / raster_to_hex.R
Last active May 12, 2025 19:37
Convert rasters to approximate corresponding h3geo.org hex index
unlink("mobi.xyz")
remotes::install_github("cboettig/duckdbfs")
library(duckdbfs)
library(dplyr)
library(sf)
tracts_z8 = open_dataset("https://minio.carlboettiger.info/public-social-vulnerability/2022-tracts-h3-z8.parquet", recursive = FALSE) |>
mutate(h8 = tolower(h8))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cboettig
cboettig / polygon-to-h3.R
Created February 4, 2025 23:28
polygon-to-h3
# get the h0 hexes covering a polygon.
library(duckdbfs)
library(dplyr)
library(sf)
library(spData)
duckdbfs::load_h3()
duckdbfs::load_spatial()
@cboettig
cboettig / pmtiles-filter.R
Created January 5, 2025 00:13
Dynamically filter pmtiles and plot with maplibre in R
library(mapgl)
library(dplyr)
library(duckdbfs)
# This test file demonstrates that given a SQL query on the parquet version
# of the data, we can identify all the features included in the response and
# construct a maplibre filter that filters the corresponding features in
# the pmtiles vesion.
pmtiles <- "https://data.source.coop/cboettig/social-vulnerability/svi2020_us_tract.pmtiles"
@cboettig
cboettig / ibis-duckdb-udfs.py
Created December 11, 2024 03:39
ibis pyarrow UDFs
import ibis
from ibis import _
import leafmap.maplibregl as leafmap
con = ibis.duckdb.connect(extensions=["spatial"])
states = con.read_geo("https://raw.githubusercontent.com/PublicaMundi/MappingAPI/master/data/geojson/us-states.json")
## Add a fill-color column
import matplotlib.cm as cm
import matplotlib.colors as mcolors
@cboettig
cboettig / h3_filter.py
Created November 26, 2024 21:30
filter data using h3 indices
park = (con
.read_geo("/vsicurl/https://huggingface.co/datasets/cboettig/biodiversity/resolve/main/data/NPS.gdb")
.filter(_.UNIT_NAME == "Yosemite National Park")
.select(_.SHAPE)
.mutate(SHAPE = _.SHAPE.convert('EPSG:3857', 'EPSG:4326'))
.mutate(lng = _.SHAPE.centroid().x(), lat = _.SHAPE.centroid().y())
.mutate(h1 = h3_latlng_to_cell(_.lat, _.lng, 1) )
.mutate(neighbors = h3_grid_disk(_.h1, 1))
#.mutate(cells = h3_polygon_wkt_to_cells_string(_.SHAPE.as_text(),1))
)