Skip to content

Instantly share code, notes, and snippets.

@jdherman
jdherman / basemap-example.py
Created November 2, 2013 19:27
Example of plotting data on top of a shaded relief map in Basemap/Matplotlib
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from mpl_toolkits.basemap import Basemap
filename = 'vic_error_9p_1K.txt'
# Set up the map
# lat_ts is the latitude of true scale.
# resolution = 'c' means use crude resolution coastlines.
@jdherman
jdherman / spinning-globe-example.py
Created November 2, 2013 19:36
Example of spinning globe in Basemap/Matplotlib
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.cm as cm
from mpl_toolkits.basemap import Basemap, shiftgrid
from matplotlib.backends import backend_agg as agg # raster backend
filename = 'vic_error_9p_1K.txt'
# Set up the color data
@jdherman
jdherman / diffusion-2D.m
Created November 2, 2013 19:50
Diffusion in a 2D box - animation in Matlab
clc; clear all;
domain = -0.5:0.005:0.5;
[X,Y] = meshgrid(domain,domain);
Z = zeros(length(domain), length(domain));
cmap = hot;
cmap = flipud(cmap(:, [3 2 1]));
outfile = 'aaa.gif';
set(gcf,'renderer','zbuffer');
t_vals = [0:4:200];
@jdherman
jdherman / C_analytical.m
Created November 2, 2013 19:53
C(x,y,t) for diffusion 2D
function [C] = C_analytical(x,y,t)
mdot = 1; % kg/s
D = 10^-3;
L = 1;
outer_term = mdot./(4*pi*t*sqrt(D*D));
exp_sum = 0;
for m = -20:20
@jdherman
jdherman / borg_boilerplate.c
Last active January 3, 2016 09:29
Boilerplate for running parallel Borg (C)
// Optional settings:
// BORG_Debug_on();
// BORG_Algorithm_ms_max_time(0.008);
// BORG_Algorithm_output_aerovis();
char runtime[256];
char outputFilename[256];
FILE* outputFile = NULL;
BORG_Algorithm_ms_startup(&argc, &argv);
clc; clear all;
% Plot the feasible space for the Masonry LP
% max Z = 140*x1 + 160*x2
% subject to:
% 2*x1 + 4*x2 <= 28
% 5*x1 + 5*x2 <= 50
% x1 <= 8
% x2 <= 6
% x1, x2 >= 0
clc; clear all;
% Solve the Masonry LP
% max Z = 140*x1 + 160*x2
% subject to:
% 2*x1 + 4*x2 <= 28
% 5*x1 + 5*x2 <= 50
% x1 <= 8
% x2 <= 6
% x1, x2 >= 0
@jdherman
jdherman / submit_jobs_loop.sh
Last active August 29, 2015 13:58
job dependency in bash PBS submission
#!/bin/bash
# This submission will submit 200 jobs in "globs",
# Where one glob will not begin until the previous one finishes without errors
FILENUMS=$(seq 0 199)
MAX_SIMULT=7 # max number of simultaneous jobs
GLOBNUM=0
GLOBNUM_PREV=0
DEPEND=""
@jdherman
jdherman / txt2nc.py
Last active October 22, 2020 05:39
Convert ASCII data to NetCDF (Python)
from __future__ import division
from netCDF4 import Dataset
import numpy as np
import os
PATH = '.'
LL = np.loadtxt('%s/global_soils_default.txt' % PATH);
LL = LL[:,2:4]
OBS = np.loadtxt('%s/VIC_GRDC_Monthly_Climatology.txt' % PATH, delimiter=',', skiprows=1)
@jdherman
jdherman / txt2nc_cells.py
Created April 30, 2014 15:04
Convert a full lat-lon NetCDF dataset to a "list" representation
from __future__ import division
from netCDF4 import Dataset
import numpy as np
import os
import math
PATH = '.'
LL = np.loadtxt('%s/global_soils_default.txt' % PATH);
LL = LL[:,2:4]
OBS = np.loadtxt('%s/VIC_GRDC_Monthly_Climatology.txt' % PATH, delimiter=',', skiprows=1)