Skip to content

Instantly share code, notes, and snippets.

View phargogh's full-sized avatar

James Douglass phargogh

View GitHub Profile
@phargogh
phargogh / branchfind.sh
Created February 13, 2020 18:21
Script to merge multiple heads on closed mercurial branches
#!/bin/bash
# NOTE: This version of this script was adapted from
# https://gist.github.com/FernFerret/3178035, with a few minor revisions
# for efficiency and clarity of output.
# This simple script will look at all named branches in a given repository
# and print out any branch that contains multiple open heads. This is useful
# to see if your repository is clean or if someone has pushed multiple
# anonymous branches.
@phargogh
phargogh / invest-autotest.yml
Created February 27, 2020 17:52
GitHub Actions YML to run the InVEST autotest suite
name: Run InVEST Autotest
steps:
windows-invest-autotest:
name: Run InVEST-autotest (windows)
needs: build-windows-binaries
runs-on: windows-latest
env:
PYTHON_VERSION: 3.7
PYTHON_ARCH: x64
steps:
@phargogh
phargogh / zip.ps1
Created March 10, 2020 17:40
Powershell shim for replicating zip -r
# A wrapper around the powershell equivalent of zipping functionality.
# This script takes 3 parameters:
# --> whether to recurse (this is ignored, but we have to take it anyways for compatibility)
# --> The target archive path
# --> The folder to zip.
#
param (
[Parameter(Mandatory=$false, ValueFromPipeline=$false, ParameterSetName='r')]
[switch]
$recurse,
@phargogh
phargogh / cython-updates.patch
Created March 10, 2020 23:38
Getting linetracing to work with cython
diff --git a/setup.py b/setup.py
index 46be1b36..67b5a1df 100644
--- a/setup.py
+++ b/setup.py
@@ -96,6 +96,8 @@ setup(
Extension(
name="natcap.invest.sdr.sdr_core",
sources=['src/natcap/invest/sdr/sdr_core.pyx'],
+ define_macros=[('CYTHON_TRACE', '1')],
+ compiler_directives={'linetrace': True},
@phargogh
phargogh / writeblockindex.py
Created March 12, 2020 19:49
Write raster block/tile indexes to a new raster
import os
import logging
logging.basicConfig(level=logging.DEBUG)
import pygeoprocessing
from osgeo import gdal
import numpy
def doit():
@phargogh
phargogh / printflowdirection.py
Created March 12, 2020 20:17
Print Multiple Flow Direction weights to the CLI when given a packed weight
import sys
def doit():
packed_flow_dir = int(sys.argv[1])
weights = [(packed_flow_dir >> 4*i) & 0xF for i in range(8)]
weights = [str(w).rjust(2, ' ') for w in weights]
print(weights)
@phargogh
phargogh / time-mfd-aspect.py
Last active March 23, 2020 21:51
Time MFD aspect calculations
# encoding=UTF-8
"""time-mfd-aspect.py
Time MFD mean aspect ratio generation routine over 100 runs.
Requires:
- pygeoprocessing==1.9.2
- git+https://github.com/phargogh/invest.git@8ac2575#egg=natcap.invest
"""
@phargogh
phargogh / github_sha_on_master.sh
Created April 4, 2020 00:57
Getting the latest SHA on master for a GitHub repository
#!/bin/sh
# jq -r prints the 'raw' value.
curl https://api.github.com/repos/natcap/invest.users-guide/commits/master | jq -r .sha
@phargogh
phargogh / convert.sh
Created April 25, 2020 01:14
Archiving mercurial repositories from bitbucket: project natcap-archive
REPO_DIR=$(pwd)/repos
OUT_DIR=$(pwd)/bundles
mkdir -p $OUT_DIR $REPO_DIR
for sshrepo in `cat repos.txt`
do
REPONAME=$(echo $sshrepo | cut -d '/' -f 5-)
TARGETDIR=$REPO_DIR/$REPONAME
hg clone $sshrepo --noupdate $TARGETDIR
pushd $OUT_DIR
@phargogh
phargogh / model_stats.py
Created June 3, 2020 22:47
InVEST model stats per model, with aliasing and separate stats for model runs and n study areas
# Usage: python model_stats.py <path to model stats GeoJSON
import sys
import collections
from osgeo import ogr
ALIASES = {
'natcap.invest.blue_carbon.blue_carbon_preprocessor': 'CBC-preprocessor',
'natcap.invest.coastal_blue_carbon.preprocessor': 'CBC-preprocessor',
'natcap.invest.coastal_blue_carbon.coastal_blue_carbon': 'CBC',