Skip to content

Instantly share code, notes, and snippets.

View deeplycloudy's full-sized avatar

Eric Bruning deeplycloudy

  • Lubbock, TX
View GitHub Profile
@deeplycloudy
deeplycloudy / audioplayer.py
Created March 21, 2012 20:37
Simple Python audio player with matplotlib and pyaudio
""" Play an audio file with pyaudio while concurrently showing audio playhead
on a matplotlib plot of the audio time series and spectrogram.
Adjust duration and filename in the script below to reflect your audio file.
v. 0.1
21 Mar 2012
Eric Bruning
"""
@deeplycloudy
deeplycloudy / gist:7009692
Last active December 25, 2015 16:59
Profile matplotlib scatter plots in the agg backend using yep and gperftools
"""
This script uses yep (https://pypi.python.org/pypi/yep) and its dependency
gperftools (https://code.google.com/p/gperftools/) to profile rendering in
matplotlib's agg backend. Hopefully this hits the relevant drawing parts
within the profiler start/stop block. It is meant to try to figure out where
the time is spent doing a 100,000 point color-mapped scatterplot.
To build gperftools against my 32 bit Python on 64 bit Mac OS X, I had to:
./configure CFLAGS="-arch i386 -m32" CXXFLAGS="-arch i386 -m32" LDFLAGS="-arch
i386 -m32"
@deeplycloudy
deeplycloudy / ipynb-highlights
Last active September 25, 2015 02:48
While grading homework assignments turned in as IPython notebooks, I wanted to insert my remarks as highlighted text in a Markdown cell. You can use the following CSS style and markup to do it. In fact,
In a code cell at the beginning of your notebook, enter:
%%html
<style type="text/css">
span.ecb { background: yellow; }
</style>
Then in any other markdown cell you can put:
@deeplycloudy
deeplycloudy / Harvest Collaborators.scpt
Created March 13, 2015 04:05
Get a list of collaborators on all papers in the last N years
-- This script is meant for use with BibDesk.
-- I wrote it to automate generation of a list of collaborators for the NSF biographical sketch.
-- You'll need to edit this list, but it automates the first step.
-- Usage: Highlight all of publications of interest
-- (e.g., search for your name in the search field and select all) and then run this script.
set thisYear to the year of (current date)
set namelist to {}
set yearlist to {}
@deeplycloudy
deeplycloudy / Radar projection timing test.ipynb
Created September 22, 2015 02:05
Geodesic vs. map projection timing for radar data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@deeplycloudy
deeplycloudy / derivatives.py
Created July 1, 2016 17:30
Gradient (4th order accuracy) and laplacian (3rd order accuracy) functions for numpy arrays.
import numpy as np
#4th order accurate gradient function based on 2nd order version from http://projects.scipy.org/scipy/numpy/browser/trunk/numpy/lib/function_base.py
def gradientO4(f, *varargs):
"""Calculate the fourth-order-accurate gradient of an N-dimensional scalar function.
Uses central differences on the interior and first differences on boundaries
to give the same shape.
Inputs:
@deeplycloudy
deeplycloudy / extract_unique_el_sweep.py
Created December 7, 2018 21:59
Eliminate duplicate elevation angles in a pyart radar object (e.g., 88D SAILS)
def get_vcp(radar):
""" Return a list of elevation angles representative of each sweep.
These are the median of the elevation angles in each sweep, which are
more likely to be identical than the mean due to change of elevation angle
at the beginning and end of each sweep.
"""
vcp = [np.median(el_this_sweep) for el_this_sweep in radar.iter_elevation()]
return np.asarray(vcp, dtype=radar.elevation['data'].dtype)
def unique_sweeps_by_elevation_angle(radar, tol=0.05):
@deeplycloudy
deeplycloudy / iem_nexrad_wms_cartopy.py
Last active March 7, 2019 18:57
Overlay IEM NEXRAD composite on Cartopy
""" Overlay IEM NEXRAD composite on Cartopy for any date or time in the
long-running IEM archive. This works for any target projection, with the
reprojection handled by the Cartopy WMS functionality.
If you don't enter a time on an even 5 min boundary, you will get a blank map.
"""
iem_wms_nexrad = 'https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi?'
layers = ["nexrad-n0r-wmst"]
wms_kw = {"time":"2017-10-22T05:15:00Z", "transparent":'true'}
@deeplycloudy
deeplycloudy / getbib.sh
Created March 24, 2020 16:47
Use dx.doi.org service to get a BibTeX-formatted reference from a DOI.
#!/bin/bash
# | pbcopy; pbpaste are mac-only commands; delete to simply print to the shell.
# Use: getbib $DOI where $DOI is something like 10.xxx/xxxxxx
getbib(){
curl -LH "Accept:text/bibliography; style=bibtex" http://dx.doi.org/$1 2>/dev/null | cut -c 2- | pbcopy ; pbpaste
}
@deeplycloudy
deeplycloudy / lidar3dep.py
Created May 28, 2020 02:19
USGS 3DEP Lidar elevation data with xarray, rasterio, and matplotlib
import matplotlib.pyplot as plt
import xarray as xr
import glob
# The code below is for 4 DEMs that cover the Montford Dam that forms Lake Alan Henry.
# Download geotiffs here.
: https://viewer.nationalmap.gov/basic/?basemap=b1&category=ned,nedsrc&q=&zoom=4&bbox=-139.74609375,10.14193169,-54.22851563,61.14323525&preview=&avail=&refpoly=
fns = glob.glob('/Users/ebruning/Downloads/*.tif')
# ds=xr.open_rasterio('/Users/ebruning/Downloads/USGS_one_meter_x31y366_TX_West_Central_B12_2018.tif')