This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from random import random | |
| # function to optimize: takes in a list of decision variables, returns an objective value | |
| # this is the Rosenbrock function: http://en.wikipedia.org/wiki/Rosenbrock_function | |
| # the global minimum is located at x = (1,1) where f(x) = 0 | |
| def my_function(x): | |
| return (1-x[0])**2 + 100*(x[1] - x[0]**2)**2 | |
| # function to perform (a very crude, stupid) optimization | |
| # bounds = lower and upper bounds for each decision variable (2D list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| bsondump database.bson > database.json | |
| # replace ObjectId("50f330869178b31dde000001") | |
| # with just the string | |
| sed -re 's/ObjectId\((.*)\)/\1/g' database.json > test.json | |
| # then in python |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // utility functions for boost matrices/vectors | |
| #include <fstream> | |
| namespace ublas = boost::numeric::ublas; | |
| using namespace std; | |
| // create matrix: | |
| // ublas::matrix<double> my_matrix(num_rows, num_columns); | |
| // loadtxt("/path/to/file", my_matrix); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| DIR=current | |
| TYPE=tmean | |
| RES=5m | |
| pwd | |
| for MONTH in {1..12} | |
| do | |
| gdalwarp -cutline states_shape/states.shp \ |