Skip to content

Instantly share code, notes, and snippets.

View richpsharp's full-sized avatar

Richard Sharp richpsharp

View GitHub Profile
@richpsharp
richpsharp / pollination_simulations.py
Created February 26, 2021 23:42
Running a batch of pollination runs.
"""Run pollination model on a variety of scenarios
All data should be in a "data" subdirectory in the same directory as this
script.
Run it with docker as the following:
docker container run -it --rm --name pollination_kelley -v `pwd`:/usr/local/workspace therealspring/inspring:latest pollination_simulations.py
"""
@richpsharp
richpsharp / ndr_plus_scenario.py
Last active March 1, 2021 20:44
NDR plus scenario example
"""Tracer for NDR watershed processing."""
import argparse
import glob
import logging
import multiprocessing
import os
import shutil
import subprocess
import threading
import urllib
@richpsharp
richpsharp / example_stream_subwatershed_script.py
Created February 13, 2021 21:11
Demo of how to extract streams and subwatersheds
"""Tracer for floodplain extraction function with custom parameters."""
import logging
import os
import sys
import pygeoprocessing
import pygeoprocessing.routing
import numpy
logging.basicConfig(
@richpsharp
richpsharp / example_floodplain_custom_params_call.py
Created February 13, 2021 21:06
Floodplain extraction with custom power parameters
"""Tracer for floodplain extraction function with custom parameters."""
import logging
import os
import sys
from inspring.floodplain_extraction.floodplain_extraction import floodplain_extraction_custom_power_params
logging.basicConfig(
level=logging.DEBUG,
@richpsharp
richpsharp / example_floodplain_call.py
Last active February 12, 2021 18:56
Demo showing how to invoke the `floodplain_extraction` function
"""Tracer for floodplain extraction function"""
"""
def floodplain_extraction(
t_return_parameter,
min_flow_accum_threshold,
dem_path,
stream_gauge_vector_path,
gauge_table_path,
gauge_id_field,
@richpsharp
richpsharp / time_slice.py
Created February 4, 2021 06:58
Time different kinds of slicing.
import time
import numpy
def mask_op(array_a, array_b, nodata):
result = numpy.full(array_a.shape, nodata, dtype=numpy.float)
valid_mask = numpy.ones(array_a.shape, dtype=numpy.bool)
valid_mask &= (array_a != nodata) & (array_b != nodata)
result[valid_mask] = array_a[valid_mask]+array_b[valid_mask]
return result
@richpsharp
richpsharp / flow_accum_study.py
Created February 4, 2021 02:13
Script to test many flow accumulation threshold values on a DEM while taking advantage of multiprocessing and avoided reexecution
"""TFA script for Stacie to experiment with TFAs."""
import logging
import os
import pygeoprocessing.routing
import multiprocessing
import sys
import taskgraph
WORKSPACE_DIR = 'workspace'
@richpsharp
richpsharp / datetime64_safe_serialization.py
Last active November 18, 2020 21:28
Example of pickleless numpy serialization
# coding=UTF-8
import io
import multiprocessing
import numpy
def numpy_dumps(numpy_array):
"""Safely pickle numpy array to string.
@richpsharp
richpsharp / pgp_entry_point.py
Created October 16, 2020 20:00
Entry point for base pygeoprocessing script
"""These calculations are for the Critical Natural Capital paper."""
import pygeoprocessing
gdal.SetCacheMax(2**27)
logging.basicConfig(
level=logging.DEBUG,
format=(
'%(asctime)s (%(relativeCreated)d) %(levelname)s %(name)s'
' [%(funcName)s:%(lineno)d] %(message)s'))
@richpsharp
richpsharp / eo_test.py
Created October 11, 2020 23:15
EO Pollination Test script
"""
EO Pollination test script.
docker run --rm -it -v "%CD%":/usr/local/workspace therealspring/inspring:latest eo_test.py
"""
import logging
import sys
import multiprocessing
import inspring
from osgeo import gdal