Skip to content

Instantly share code, notes, and snippets.

View alpha-beta-soup's full-sized avatar
🌏

Richard Law alpha-beta-soup

🌏
View GitHub Profile
@alpha-beta-soup
alpha-beta-soup / github_issues_to_docx.md
Last active September 12, 2024 22:48 — forked from toraritte/github_issues_to_docx.md
A long and stupid way to save GitHub issues in Word DOCX format

The long and stupid way is listed below, but hoping that someone has a way quicker and nicer solution. (Didn't have time to come up with a proper Node or Deno solution, so I spent better part of the day on this abomination.[quote][1])

  1. "Install" [GitHub CLI][gh] and [Pandoc]

    nix-shell -p gh pandoc
    
  2. Export GitHub issues in JSON

@alpha-beta-soup
alpha-beta-soup / raster-benchmarks.py
Created May 8, 2024 22:42
Generating random raster landscapes for generating performance benchmarking cases
import numpy as np
import random
import sys
from nlmpy import nlmpy
np.random.seed(0) # So that the same NLMs are produced each time
nRow = 100 # Number of rows
nCol = 100 # Number of columns
@alpha-beta-soup
alpha-beta-soup / download-qeii.sh
Last active October 6, 2023 03:22
Experiments with a commit time modification in a Kart archive for pre-existing geospatial data
#!/bin/bash
CLEAR='\033[0m'
RED='\033[0;31m'
function usage() {
if [ -n "$1" ]; then
echo -e "${RED}👉 $1${CLEAR}\n";
fi
@alpha-beta-soup
alpha-beta-soup / stratified_sample.py
Last active April 2, 2023 22:52
Stratified random sampling of GPKG files
import sys
from pathlib import Path
import pandas as pd
import geopandas as gpd
def stratified_sample(df: pd.DataFrame, groupby_column: str, sampling_rate: float = 0.01) -> pd.DataFrame:
assert 0.0 < sampling_rate <= 1.0
assert groupby_column in df.columns
num_rows = int((df.shape[0] * sampling_rate) // 1)
@alpha-beta-soup
alpha-beta-soup / simplify.py
Created October 10, 2022 20:45
Geometry simplification script (GPKG, Snakemake, geopandas, pygeos)
import logging
from pathlib import Path
import sys
import warnings
smk = snakemake # type: ignore
logging.basicConfig(filename=Path(str(smk.log)), level=smk.params.get('logLevel', logging.INFO))
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout)) # Log to stdout as well
@alpha-beta-soup
alpha-beta-soup / chalet-demo-may-2022.ipynb
Created May 8, 2022 22:34
Demonstration of Uber's H3 DGGS which I did at the Palmerston North Regional GIS Forum (May 2022)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@alpha-beta-soup
alpha-beta-soup / h3_raster_windows.py
Created April 30, 2021 05:13
Utility functions for converting from a row/column index of a raster window, to longitude/latitude or an H3 index. Useful for H3-indexing raster data read with rasterio.
#!/usr/bin/env python3
import pyproj
import h3.api.basic_int as h3
# A window_transformation is the affine transformation of a window, see https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html?highlight=window_transform#window-transforms
# Transformer
transformer = lambda s_srs, t_srs: pyproj.Transformer.from_proj(pyproj.Proj(s_srs), pyproj.Proj(t_srs), always_xy=True)
# Row/column conversion to lon, lat; given a window transformation and pyproj.Transformer
rc2lonlat = lambda r, c, window_transformation, transformer: transformer.transform(*(window_transformation * (c, r)))
@alpha-beta-soup
alpha-beta-soup / sample-crontab
Last active January 8, 2020 04:23
Sets GNOME wallpaper to latest Himawari image
# Update wallpaper every 15 minutes
15 * * * * /bin/bash /home/richard/scripts/set-wallpaper.sh
@alpha-beta-soup
alpha-beta-soup / cartopy-nztm.py
Created August 29, 2019 21:32
Cartopy CRS definition for NZTM2000
import cartopy
import shapely.geometry as sgeom
class NZTM(cartopy.crs.TransverseMercator):
def __init__(self):
'''
https://epsg.io/2193
https://www.linz.govt.nz/data/geodetic-system/datums-projections-and-heights/geodetic-datums/new-zealand-geodetic-datum-2000-nzgd2000
'''
inverse_flattening = 298.257222101
@alpha-beta-soup
alpha-beta-soup / geojson-stringify.js
Last active July 5, 2019 02:50
GeoJSON serialiser that doesn't explode your nested coordinate arrays
const replacerWrapper = val => val.replace(/\"\[/g, '[').replace(/\]\"/g,']')
const replacer = (name, val) => {
console.log({name, val})
if (name === 'coordinates' && Array.isArray(val)) {
val = JSON.stringify(val)
}
return val
}
module.exports = {
replacer, replacerWrapper,