Skip to content

Instantly share code, notes, and snippets.

View richpsharp's full-sized avatar

Richard Sharp richpsharp

View GitHub Profile
@richpsharp
richpsharp / beta_tests.py
Created April 12, 2021 20:53
is beta/m broken?
import numpy
import matplotlib.pyplot
slope_in_radians_list = numpy.linspace(0.089, 0.785, 100)
beta_list = []
m_list = []
for slope_in_radians in slope_in_radians_list:
beta = ((numpy.sin(slope_in_radians) / 0.0896) /
(3 * numpy.sin(slope_in_radians)**0.8 + 0.56))
m_list.append(beta/(1+beta))
@richpsharp
richpsharp / sdr.py
Created April 10, 2021 18:34
Modified LS factor Python code from rafa
"""InVEST Sediment Delivery Ratio (SDR) module.
The SDR method in this model is based on:
Winchell, M. F., et al. "Extension and validation of a geographic
information system-based method for calculating the Revised Universal
Soil Loss Equation length-slope factor for erosion risk assessments in
large watersheds." Journal of Soil and Water Conservation 63.3 (2008):
105-111.
"""
import os
@richpsharp
richpsharp / LS_from_DEM.m
Created April 10, 2021 18:32
LS code in matlab from rafa
clear all
close all
addpath(genpath(pwd))
% channel init threshold [km2]
Ad_ini=1;
% length threshold [m]
@richpsharp
richpsharp / models.py
Created April 2, 2021 15:51
SQLAlchamy example from STAC Geoserver
"""SQLAlchemy models for STAC view."""
from ..db import db
class Job(db.Model):
"""Stores info about a non-trivial running job invoked from the API."""
__tablename__ = "job_table"
job_id = db.Column(db.String, primary_key=True)
@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