Skip to content

Instantly share code, notes, and snippets.

@scottstanie
scottstanie / export_to_qgis.py
Last active February 6, 2025 01:57
Export dolphin, or DISP, time series rasters to a GeoParquet format ingestible by QGIS
#!/usr/bin/env python3
# /// script
# dependencies = ["geopandas", "rioxarray", "tyro", "opera_utils"]
# ///
"""Create a GeoParquet file from multi-date InSAR displacement GeoTIFFs.
Optionally mask by similarity and coherence thresholds.
Example CLI usage (with tyro):
@scottstanie
scottstanie / validate_pysolid_conversion.py
Created December 19, 2024 00:56
Validation script to compare PySolid Python and Fortran implementations
#!/usr/bin/env python3
"""
Validation script to compare Python and Fortran implementations
of solid earth tide calculations across different times and locations.
"""
import datetime as dt
import numpy as np
import pandas as pd
from pathlib import Path
@scottstanie
scottstanie / midas.py
Last active December 6, 2024 21:57
Python conversion of MIDAS velocity calculation for GPS time series data
"""Python conversion of MIDAS velocity calculation.
Original code: http://geodesy.unr.edu/MIDAS_release.tar
Original author: Geoff Blewitt. Copyright (C) 2015.
When using these velocities in publications please cite:
Blewitt, G., C. Kreemer, W.C. Hammond, and J. Gazeaux (2016). MIDAS robust trend
estimator for accurate GPS station velocities without step detection, Journal
@scottstanie
scottstanie / disp-s1-frame-temporal-gaps.ipynb
Created October 21, 2024 21:58
Plot the maximum gap in time of DISP-S1 frames
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@scottstanie
scottstanie / download_coherence_mosaics.sh
Last active October 9, 2024 13:51
Download and analyze the global sentinel-1 coherence mosaics for each DISP-S1 frames
for item in COH12 COH24 COH36 rho tau; do
s5cmd --numworkers 10 --no-sign-request cp "s3://sentinel-1-global-coherence-earthbigdata/data/mosaics/*vv*${item}*" .
done
@scottstanie
scottstanie / view-changelog.sh
Created August 14, 2024 17:46
Get a view of all release notes in your terminal, pipe-able to other programs
git tag --list | sort --version-sort | xargs -n1 gh release view
@scottstanie
scottstanie / tau-uklg.py
Created July 8, 2024 14:34
Print a random chapter from Ursula Le Guin's Tao
import requests
import re
import random
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
url = "https://raw.githubusercontent.com/nrrb/tao-te-ching/master/Ursula%20K%20Le%20Guin.md"
def get_random_chapter():
@scottstanie
scottstanie / app.py
Created January 30, 2024 13:57
On-the-fly conversion of interferogram complex values to phase for Titiler
from starlette import responses
from titiler.core.algorithm import algorithms as default_algorithms
from titiler.core.errors import DEFAULT_STATUS_CODES, add_exception_handlers
from titiler.core.factory import TilerFactory
from fastapi import FastAPI
from .titiler_algorithms import Phase
app = FastAPI(title="Bowser")
@scottstanie
scottstanie / boi.py
Last active January 23, 2024 22:33
Burst Overlap Interferometry with geocoded SLCs
from os import fspath
import numpy as np
from osgeo import gdal
from dolphin import io, stitching, utils
def compute_boi(ifg_file1: str, ifg_file2: str, looks: tuple[int, int] = (1, 1)) -> np.ndarray:
assert io.get_raster_crs(ifg_file1) == io.get_raster_crs(ifg_file2)
(left, bottom, right, top), nodata = stitching.get_combined_bounds_nodata(
ifg_file1, ifg_file2
@scottstanie
scottstanie / demo_cache_locality.py
Last active January 7, 2024 18:40
Show timing variations from poor data access patterns
#!/usr/bin/env python3
from numba import njit
@njit
def f(arr):
s = 0
i = 0
while i < len(arr):
s += arr[i]