Skip to content

Instantly share code, notes, and snippets.

@jdherman
jdherman / backup.sh
Last active August 29, 2015 14:10
backup to dropbox
#!/bin/bash
declare -a arr=("professional" "phd" "presentations" "proposals")
for d in "${arr[@]}"
do
rsync -raz --progress --exclude=".git*" --delete ./"$d"/* Dropbox/jdh/"$d"
done
chown -R Administrators Dropbox/jdh/*
@jdherman
jdherman / generate-samples.py
Created November 18, 2014 20:42
SALib parameter samples into input file template
from SALib.sample import saltelli
from string import Template
# Generate samples for sensitivity analysis, and put them into an input file template
# This will generate N(2D+2) copies of the template with the values inserted
# The use case is for older models (like F77) where the input file something like below.
# Put dollar-sign variables where you want to replace with numbers, like so:
#
#C IWQVLIM = option for velocity limitation of macroalgae growth
#C = 0, macroalgae growth is not limited by stream velocity
@jdherman
jdherman / lake.py
Last active August 29, 2015 14:07
Lake problem (multiobjective) in python with Borg wrapper
from __future__ import division
import numpy as np
from scipy.optimize import brentq as root
from borg import *
nvars = 100 # decision variables: pollution for each timestep
nobjs = 4
nconstr = 1
nsamples = 100 # 100 scenarios of natural inflows
b = 0.42 # decay rate for P in lake (0.42 = irreversible)
@jdherman
jdherman / syllabus.py
Created October 14, 2014 14:50
syllabus keywords in python
import glob
kw = ['climate', 'decision theory', 'dynamic', 'economics', 'game theory', 'heuristic', 'hydrology',
'integer', 'linear', 'model', 'nonlinear', 'policy', 'probability', 'statistics',
'stochastic','quality']
files = glob.glob('*.txt')
courses_including = {}
avg_count = {}
@jdherman
jdherman / raster-point.py
Created October 7, 2014 18:16
Extract raster data value at a point
from __future__ import division
from osgeo import gdal
from geopy.geocoders import Nominatim
def get_value_at_point(rasterfile, pos):
gdata = gdal.Open(rasterfile)
gt = gdata.GetGeoTransform()
data = gdata.ReadAsArray().astype(np.float)
gdata = None
x = int((pos[0] - gt[0])/gt[1])
@jdherman
jdherman / map-raster.py
Created October 3, 2014 16:54
plotting raster data with shapefile in python+basemap
from osgeo import gdal
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap
# Plotting 2070 projected August (8) precip from worldclim
gdata = gdal.Open("D:/jon/datasets/worldclim/future/pr/gf45pr70_usa/gf45pr708.tif")
geo = gdata.GetGeoTransform()
data = gdata.ReadAsArray()
@jdherman
jdherman / clipusa.sh
Last active August 29, 2015 14:07
clip raster data with shapefile example
#!/bin/bash
DIR=current
TYPE=tmean
RES=5m
pwd
for MONTH in {1..12}
do
gdalwarp -cutline states_shape/states.shp \
@jdherman
jdherman / run_program.c
Created July 31, 2014 20:50
run any program in parallel
#include <mpi.h>
#include <stdio.h>
int main (argc, argv)
int argc;
char *argv[];
{
int rank,size;
char cmd[1000];
MPI_Init (&argc, &argv); /* starts MPI */
@jdherman
jdherman / pip-update-all-outdated.sh
Created July 14, 2014 18:43
upgrade windows python packages from cmd
for /F "delims===" %i in ('pip freeze -l') do pip install -U %i
# from http://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip
@jdherman
jdherman / journals_rss.txt
Last active August 24, 2017 22:57
journal RSS feeds
Water Resources Research (WRR)
http://onlinelibrary.wiley.com/rss/journal/10.1002/(ISSN)1944-7973
Journal of Water Resources Planning & Management (JWRPM)
http://ascelibrary.org/action/showFeed?type=etoc&feed=rss&jc=jwrmd5
Environmental Modelling & Software (EMS)
http://rss.sciencedirect.com/publication/science/13648152
Advances in Water Resources (AWR)