Skip to content

Instantly share code, notes, and snippets.

View phargogh's full-sized avatar

James Douglass phargogh

View GitHub Profile
@phargogh
phargogh / convert_taudem_d8_flow_dir_to_pygeoprocessing.py
Created May 6, 2022 19:01
Pygeoprocessing raster_calculator call to convert from a TauDEM D8 flow direction to pygeoprocessing D8 flow direction.
import numpy
import pygeoprocessing
from osgeo import gdal
def convert_taudem_flow_dir_to_pygeoprocessing(
taudem_flow_dir_raster_path, target_flow_dir_raster_path):
source_nodata = pygeoprocessing.get_raster_info(
taudem_flow_dir_raster_path)['nodata'][0]
dest_nodata = 128 # Matches pygeoprocessing-produced flow dir nodata.
@phargogh
phargogh / routing-example.py
Created April 12, 2022 22:42
Example of weighted flow accumulation for NCI NOXN work using pygeoprocessing.routing.
import logging
import os
import pygeoprocessing
import pygeoprocessing.routing
from osgeo import gdal
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)
@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.