Skip to content

Instantly share code, notes, and snippets.

View calebrob6's full-sized avatar

Caleb Robinson calebrob6

View GitHub Profile
@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.
@calebrob6
calebrob6 / running_stats_in_torch.py
Last active July 7, 2024 08:48
A class for computing online mean and variance of multi-dimensional arrays in PyTorch (i.e. for computing per-channel stats over large image datasets).
import torch
class RunningStatsButFast(torch.nn.Module):
def __init__(self, shape, dims):
"""Initializes the RunningStatsButFast method.
A PyTorch module that can be put on the GPU and calculate the multidimensional
mean and variance of inputs online in a numerically stable way. This is useful
for calculating the channel-wise mean and variance of a big dataset because you
don't have to load the entire dataset into memory.
@calebrob6
calebrob6 / area.ipynb
Created May 8, 2024 02:23
How do the areas of a set of polygons and their rasterized equivalents differ as a function of spatial resolution of the rasterized versions?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@calebrob6
calebrob6 / sam_inference.py
Last active May 22, 2024 02:20
Runs inference on large satellite image scenes with SAM models
# Requires the `segment-geospatial` package https://samgeo.gishub.org/
import argparse
import os
import cv2
import numpy as np
import rasterio
import rasterio.features
import rasterio.transform
import rasterio.windows
@calebrob6
calebrob6 / jaccard_test.ipynb
Created February 22, 2024 00:01
Verify the behavior of `smp.losses.JaccardLoss`.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@calebrob6
calebrob6 / landcover_analysis_tutorial.ipynb
Created November 14, 2023 23:25
Tutorial notebook showing how to calculate the land cover distribution around a point.
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_object_detection_example.ipynb
Created October 13, 2023 04:10
Short example of object detection training in TorchGeo.
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_rasterdataset_cog.ipynb
Created October 2, 2023 22:27
Demo that shows how to use TorchGeo to do windowed reading from remote COGs.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.