Skip to content

Instantly share code, notes, and snippets.

View phargogh's full-sized avatar

James Douglass phargogh

View GitHub Profile
@phargogh
phargogh / decay_types.py
Created March 22, 2022 22:30
Trying out decay types for my updated version of HRA
import matplotlib.pyplot as plt
import numpy
BUFFER_DIST = 500
DISTANCE = numpy.arange(BUFFER_DIST+100)
NONE = (DISTANCE < BUFFER_DIST)
LINEAR = numpy.maximum(1 - (DISTANCE / BUFFER_DIST), 0)
EXPONENTIAL = numpy.exp(-DISTANCE / BUFFER_DIST) * NONE
OLD_HRA_EXPONENTIAL = (1 - numpy.exp((numpy.log(1e-6) / DISTANCE))) * NONE
@phargogh
phargogh / convert-logfile-to-python-call.py
Created March 16, 2022 21:46
Convert a user's logfile and downloaded data to a functional args dict
import logging
import os
import pprint
import numpy
import pygeoprocessing
import pygeoprocessing.routing
from natcap.invest import datastack
from natcap.invest.seasonal_water_yield import seasonal_water_yield
from osgeo import gdal
@phargogh
phargogh / routing-example.py
Last active August 29, 2023 05:41
Example of pygeoprocessing-based D8 routing, including watershed delineation.
import os
import shutil
import numpy
import pygeoprocessing
import pygeoprocessing.routing
from osgeo import gdal
def doit(dem_path, flow_dir_weights, watershed_source_vector, workspace):
@phargogh
phargogh / experiment-raster-block-sizes.py
Created February 2, 2022 22:59
Experiment with when GDAL defaults to nonsquare block sizes
import logging
import os
import os.path
import numpy
import pygeoprocessing
from osgeo import gdal
from osgeo import osr
logging.basicConfig(level=logging.WARNING)
@phargogh
phargogh / dynaclue-pseudocode.txt
Created January 27, 2022 21:02
Dyna-CLUE Pseudocode
This gist reflects what I understand to be the workflow for Dyna-CLUE,
in the interest of getting the core algorithm down on paper.
This is based on :
* Verburg & Overmars (2009): https://link.springer.com/article/10.1007%2Fs10980-009-9355-7
* The CLUE Manual: http://environmentalgeography.nl/files/data/public/cluemanual
* The provided source code for CLUE: http://www.environmentalgeography.nl/files/data/public/dyna_clue
* The IEEM Dyna-CLUE manual: https://publications.iadb.org/publications/english/document/The-Integrated-Economic-Environmental-Modeling-IEEM-Platform-IEEM-Platform-Technical-Guides-User-Guide-for-the-IEEM-enhanced-Land-Use-Land-Cover-Change-Model-Dyna-CLUE.pdf
@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
@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 / 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 / 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 / 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)]