Skip to content

Instantly share code, notes, and snippets.

@jdherman
jdherman / download-data-caiso.py
Last active January 23, 2018 01:54
Download CAISO hourly renewables data
# this runs in python 3 as of Jan. 2018
import pandas as pd
import time
import urllib
from bs4 import BeautifulSoup
import numpy as np
from io import StringIO
import matplotlib.pyplot as plt
dates = pd.date_range(start='4/20/2010', end='1/20/2018')
@jdherman
jdherman / folsom-data.csv
Last active October 5, 2016 15:36
really simple reservoir simulation
datetime storage elevation outflow inflow precip evap tocs
2000-10-01 659.258 435.01 1849.0 1107.0 0.0 9.0
2000-10-02 658.149 434.89 1991.0 1432.0 0.0 0.0
2000-10-03 656.208 434.68 2327.0 1357.0 0.0 9.0
2000-10-04 653.436 434.38 2020.0 631.0 0.0 9.0
2000-10-05 651.034 434.12 2110.0 908.0 0.0 9.0
2000-10-06 650.295 434.04 1871.0 1507.0 0.0 9.0
2000-10-07 647.632 433.75 2046.0 712.0 0.0 9.0
2000-10-08 644.331 433.39 2241.0 586.0 0.0 9.0
2000-10-09 641.671 433.1 1886.0 554.0 0.0 9.0
# Leaf River Mississippi, 40 years of daily data
# Precip (mm/day) PET (mm/day) Q (mm/day)
0.0000000e+000 4.6004000e+000 2.8995124e-001
0.0000000e+000 4.3092000e+000 2.4476064e-001
0.0000000e+000 4.3286000e+000 2.1338209e-001
0.0000000e+000 4.7777000e+000 1.9329787e-001
0.0000000e+000 2.9110000e+000 1.8325798e-001
0.0000000e+000 3.5714000e+000 1.7447252e-001
1.3518000e+000 1.4499000e+000 1.7195922e-001
0.0000000e+000 4.6986000e+000 1.6694149e-001
@jdherman
jdherman / exstatic.py
Created December 9, 2015 18:24
exstatic syllabi keyword analysis
import glob
kw = ['climate', 'decision theory', 'dynamic', 'economics', 'game theory', 'heuristic', 'hydrology',
'integer', 'linear', 'model', 'nonlinear', 'policy', 'probability', 'statistics',
'stochastic','quality', 'simulation', 'optimization']
files = glob.glob('*.txt')
courses_including = {}
avg_count = {}
@jdherman
jdherman / plotstyle.py
Created October 10, 2015 22:44
plot style python
def init_plotting():
sns.set_style('whitegrid')
plt.rcParams['figure.figsize'] = (5, 4)
plt.rcParams['font.size'] = 13
plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
# plt.rcParams['font.weight'] = 'bold'
plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
@jdherman
jdherman / taccvietnam.md
Last active August 29, 2015 14:26
tacc vietnam notes for Julie

###First Clone the latest version of the model from bitbucket.

###Upload code to TACC You can use scp, rsync, even git, whatever. I use rsync:

rsync -raz . jdh33@stampede.tacc.utexas.edu:~/projects/emodps

when you're in the highest level directory of the project (the dot .) the nice thing about rsync is that it only transfers files that were added or modified relative to the destination.

@jdherman
jdherman / cawater-links.md
Last active December 30, 2020 23:05
links for california water data
@jdherman
jdherman / random-search-example.py
Last active May 15, 2023 10:43
example of pure random search in python
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)
@jdherman
jdherman / convert.sh.py
Created December 22, 2014 21:50
convert BSON to valid json, then parse it in python
#!/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
@jdherman
jdherman / boostutil.h
Created December 9, 2014 20:09
boost utility functions for dealing with files
// 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);