Skip to content

Instantly share code, notes, and snippets.

View calebrob6's full-sized avatar

Caleb Robinson calebrob6

View GitHub Profile
@calebrob6
calebrob6 / embed.py
Last active September 22, 2025 19:09
Create embeddings from an input GeoTIFF using DINOv3 and save results as an output GeoTIFF.
import argparse
import math
import os
import time
from typing import List, Optional, Sequence, Tuple
import numpy as np
import rasterio
import rasterio.windows
import torch
@calebrob6
calebrob6 / FTW demo application.ipynb
Created August 12, 2025 23:29
Notebook that shows end-to-end example of running a Fields of the World model on Sentinel-2 imagery and joining with CDL labels and MOSAIKS embeddings.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@calebrob6
calebrob6 / lbp.py
Created August 3, 2025 02:07
PyTorch local binary pattern histograms
def batch_histogram(data_tensor, num_classes=-1):
"""
From https://discuss.pytorch.org/t/batched-torch-histc/179741
Computes histograms of integral values, even if in batches (as opposed to torch.histc and torch.histogram).
Arguments:
data_tensor: a D1 x ... x D_n torch.LongTensor
num_classes (optional): the number of classes present in data.
If not provided, tensor.max() + 1 is used (an error is thrown if tensor is empty).
Returns:
@calebrob6
calebrob6 / benchmark_sieve.py
Created April 17, 2025 19:15
Script for benchmarking polygonization through gdal command line calls vs. in-memory with rasterio and friends.
#!/usr/bin/env python3
"""
benchmark_sieve.py
Benchmark sieving, polygonizing, and simplifying GeoTIFFs using two methods:
- "gdal": subprocess calls to gdal_sieve.py, gdal_polygonize.py, and ogr2ogr
- "python": pure Python using rasterio.features, shapely, and fiona
"""
import os
@calebrob6
calebrob6 / rcf_segmentation.py
Created March 13, 2025 03:26
A subclass of torchgeo's RCF model that averages features over a given mask instead of the whole input.
class RCFSegmentationFeatures(RCF):
def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
"""Forward pass of the RCF model.
Args:
x: a tensor with shape (C, H, W)
y: a tensor with shape (H, W)
Returns:
a tensor of size (``self.num_features``)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@calebrob6
calebrob6 / eurosat_few_shot.ipynb
Last active January 13, 2025 22:09
Small experiment showing KNN performance on EuroSAT with MOSAIKS features and different numbers of training samples per class.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@calebrob6
calebrob6 / torchgeo_indices.ipynb
Created December 3, 2024 18:51
Short notebook with an end to end example of using torchgeo's transforms.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@calebrob6
calebrob6 / check_if_scene_is_cloudy.py
Created November 13, 2024 23:42
Method for checking whether a bbox in a Sentinel 2 scene from the Planetary Computer is cloudy or not
def check_if_scene_is_cloudy_at_box(item: pystac.Item, box: shapely.geometry.Polygon):
"""Uses the S2 Scene Classification Layer (SCL) to determine if a S2 L2A scene is cloudy at a given bbox.
Args:
item (pystac.Item): The S2 L2A item to check
box (shapely.geometry.Polygon): The geometry to check (should be EPSG:4326)
Returns:
float: The fraction of the box that is classified as "Cloud medium probability" + "Cloud high probability"
"""
@calebrob6
calebrob6 / benchmarking_reprojecting_polygons.ipynb
Created October 25, 2024 05:20
A notebook for benchmarking `fiona.transform.transform_geom` vs. `pyproj.Transformer` for reprojecting polygons.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.