Skip to content

Instantly share code, notes, and snippets.

View drheinheimer's full-sized avatar

David Rheinheimer drheinheimer

View GitHub Profile
@drheinheimer
drheinheimer / douglasPeucker.js
Created November 8, 2022 20:59 — forked from adammiller/douglasPeucker.js
Javascript implementation of the Douglas Peucker path simplification algorithm
var simplifyPath = function( points, tolerance ) {
// helper classes
var Vector = function( x, y ) {
this.x = x;
this.y = y;
};
var Line = function( p1, p2 ) {
this.p1 = p1;
import os
import win32com.client as client # get win32com from Python package pywin32
# See WEAP API at https://www.weap21.org/WebHelp/WEAPApplication.htm
WEAP = client.Dispatch('WEAP.WEAPApplication') # create WEAP object
# Open the area
WEAP.Areas("my area").Open()
# Set the expression
import requests
import json
class Hydra(object):
"""
Example:
# Set up the class
hydra = Hydra('https://www.openagua.org/hydra', api_key=os.environ['OPENAGUA_SECRET_KEY'])
@drheinheimer
drheinheimer / simplify_pywr_json.py
Last active October 22, 2019 19:46
Simplify Pywr json file
def simplify_network(m, delete_gauges=False):
# simplify the network
mission_complete = False
obsolete_gauges = []
while not mission_complete:
mission_complete = True
up_nodes = []
down_nodes = []
up_edges = {}
down_edges = {}
from graphviz import Digraph
import json
with open('./pywr_model.json') as f:
model = json.load(f)
dot = Digraph(comment='System')
dot.edges(model['edges'])
dot.render('system.gv', view=True)
import os
from itertools import product
import win32com.client as client # get win32com from Python package pywin32
# See WEAP API at https://www.weap21.org/WebHelp/WEAPApplication.htm
WEAP = client.Dispatch('WEAP.WEAPApplication') # create WEAP object
WEAP.Areas("Shire_ZAMCOM_v27_AB_ROR").Open() # open the model
realizations = [1,2,3]
import win32com.client as client
weap = client.Dispatch('WEAP.WEAPApplication')
print weap.ActiveArea.Name
# script to run the HHLSM model
import os, os.path
import win32com.client
# install win32com with "pip install pywin32"
HHLSM = "HHSM_2008_v3.1_PEIR_BD_VULNERABILITY.xlsm"
MACRO = "{}!HHSM_2008_v2.HHSM_2008_v2".format(HHLSM)
scenarios = [1,2,3]
@drheinheimer
drheinheimer / read_paradox_table.py
Last active October 4, 2018 18:14
Read a Paradox database table (for example from WEAP)
import os
from pypxlib import Table
def db(dir, name):
filelist = os.listdir(dir)
dbname = '{}.db'.format(name)
dbname = dbname if dbname in filelist else dbname.replace('.db', '.DB')
if dbname not in filelist:
return
mbname = dbname.replace('.db', '.MB').replace('.DB', '.MB')
if mbname not in filelist:
import pandas as pd
from math import ceil
for region in ['CherryEleanor', 'DonPedro', 'Hetchy']:
# define input and output paths
inpath = 'baserun/{}/statvar.csv'.format(region)
outpath = 'baserun/{}/10day.csv'.format(region)
# read in the original csv
df = pd.read_csv(inpath, index_col=0, parse_dates=True)