Skip to content

Instantly share code, notes, and snippets.

View lzkelley's full-sized avatar

Luke Zoltan Kelley lzkelley

View GitHub Profile
def some_task(catalog, ...):
...
data, changed = catalog.load_url(url, path)
# If the data is not changed, and we are updating... we're done
if not changed and catalog.args.update:
return
# Continue processing, update data blah blah blah
@lzkelley
lzkelley / label_line.py
Last active July 16, 2020 15:35
Add an annotation (label) to a matplotlib line. Position and Alignment is adjusted to match the line.
def label_line(ax, line, label, color='0.5', fs=14, halign='left'):
"""Add an annotation to the given line with appropriate placement and rotation.
Based on code from:
[How to rotate matplotlib annotation to match a line?]
(http://stackoverflow.com/a/18800233/230468)
User: [Adam](http://stackoverflow.com/users/321772/adam)
Arguments
---------
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=[10, 6])
ax.set(xscale='log', yscale='log')
ax.axis('off')
DURATION = 20.0
CADENCE = 0.1
#!/bin/bash
# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then # GNU `ls`
colorflag="--color"
else # OS X `ls`
colorflag="-G"
fi
# List all files colorized in long format
@lzkelley
lzkelley / rotation_station.py
Created January 26, 2019 00:09
Find principle axes of 3D collection of data, rotate positions to match those axes.
import sys
import os
import numpy as np
import scipy as sp
import scipy.stats
import matplotlib as mpl
import matplotlib.pyplot as plt
# Silence annoying numpy errors
# Initialize Auto-Reloading Magic
%reload_ext autoreload
%autoreload 2
import os
import sys
from importlib import reload
import astropy as ap
import numpy as np
@lzkelley
lzkelley / evolution_subclass.py
Last active March 27, 2019 21:29
Highly schematic pseudo-code showing thoughts on how to structure the evolution class and subclasses. This *very much* does not accurately reflect the existing structure of the code, but is just meant to convey the basic idea.
EVOLVE_ACCRETION_FLAG = True
def main():
mbhb, sets = run_init()
# ... do some check and logging and whatever ...
if EVOLVE_ACCRETION_FLAG:
import numpy as np
import scipy as sp
import scipy.stats
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=[8, 5])
ax.set_xscale('log')
# Construct a log-normal distribution
dist = sp.stats.lognorm(1)
@lzkelley
lzkelley / random-stuff.py
Created July 22, 2019 17:58
random-stuff
import numpy as np
import scipy as sp
import scipy.stats
import matplotlib.pyplot as plt
NUM = 100
xx = np.random.uniform(-1.0, 1.0, NUM)
plt.hist(xx)
import numpy as np
import scipy as sp
import scipy.stats
import matplotlib.pyplot as plt
def sf_rad(mm, aa, bb):
rs = aa + bb * (np.log10(mm) - 10.0)
return np.power(10.0, rs)