Skip to content

Instantly share code, notes, and snippets.

View phargogh's full-sized avatar

James Douglass phargogh

View GitHub Profile
@phargogh
phargogh / extract_model_inputs.py
Created March 26, 2021 15:56
A script to extract ARGS_SPEC inputs information and write it to a directory, one CSV per model.
import json
import sys
import os
import importlib
import pkgutil
import natcap.invest
module_stack = list(pkgutil.iter_modules(
natcap.invest.__path__, natcap.invest.__name__ + '.'))
@phargogh
phargogh / average-comparison.py
Created April 14, 2021 04:30
Comparing two approaches to raster averaging, based off the task/stormwater branch, rev b8974c7286d5ebaf68f4596ffb264132e5b5a04e
import time
import os
from natcap.invest import stormwater
import pygeoprocessing
from osgeo import gdal, osr
import numpy
import numpy.random
@phargogh
phargogh / numpy-array-filling-test.py
Created April 19, 2021 15:21
Timing various numpy array creation routines
import timeit
SETUP = 'import numpy'
SHAPE = 10000
ZEROS = (
'a=numpy.zeros(10000, dtype={dtype}); '
'b=numpy.zeros(10000, dtype={dtype}); x=a+b')
ONES = (
'a=numpy.zeros(10000, dtype={dtype}); '
'b=numpy.zeros(10000, dtype={dtype}); x=a+b')
@phargogh
phargogh / pygeoprocessing-average.py
Created April 19, 2021 22:14
Using pygeoprocessing's convolve_2d as an averaging function
import os
import pygeoprocessing
import numpy
from osgeo import gdal, osr
_PROJECTION_SRS = osr.SpatialReference()
_PROJECTION_SRS.ImportFromEPSG(26910) # UTM Zone 10N
PROJECTION_WKT = _PROJECTION_SRS.ExportToWkt()
# taken from https://spatialreference.org/ref/epsg/26910/
ORIGIN = (224215.8977, 3810589.9220)
@phargogh
phargogh / sed-manpage-to-epub.sh
Created April 29, 2021 20:52
Convert the sed manpage to EPUB
mandoc -Tmarkdown /usr/share/man/man1/sed.1 | pandoc -f markdown -t epub --metadata title="Man 1 Sed" > man1sed.epub
@phargogh
phargogh / numba-jit-experiment.py
Created August 12, 2021 18:20
Numba speed comparison with pure python
import time
import numpy.random
from numba import njit
@njit
def function():
size = 10000
arrays = [numpy.random.rand(size, size) for i in range(5)]
@phargogh
phargogh / rotate.py
Created September 1, 2021 16:13
NatCap software team office hours rotations for September, 2021 trial period
"""Randomly generate office hours rotations for the defined dates.
This was brought up as a possible way of randomly picking office hours
assignments during the original trial run of office hours in September, 2021.
"""
import random
# Group Wednesday-to-following-Monday
# This is because of the labor day holiday on Monday the 6th that offsets the
@phargogh
phargogh / README.md
Created September 8, 2021 19:19
Unzip all files downloaded from github actions for a release

To use this:

  1. Download all of the pygeoprocessing archives from github actions.
  2. Place all downloads into a single folder.
  3. Open a bash shell in this new folder that contains the archives.
  4. Run the find command noted in this gist.
  5. Proceed with the wheel/sdist upload via twine.
@phargogh
phargogh / Makefile
Last active September 16, 2021 23:49
Experiment with different line-iteration methods in node.js
.PHONY: all clean
WITHREADLINE := withreadline.txt
WITHOUTREADLINE := withoutreadline.txt
WITHOUTREADLINEBYLINE := withoutreadlinebyline.txt
SAMPLE := sample.txt
all: $(WITHREADLINE) $(WITHOUTREADLINE) $(WITHOUTREADLINEBYLINE)
clean:
@phargogh
phargogh / numpy-wheels-for-py310.sh
Created December 1, 2021 18:09
Get all numpy wheels available for python 3.10
#!/bin/bash
curl https://pypi.org/pypi/numpy/json | jq '..|.filename?' | grep \.whl | grep 310