Skip to content

Instantly share code, notes, and snippets.

View lzkelley's full-sized avatar

Luke Zoltan Kelley lzkelley

View GitHub Profile
import numpy as np
import scipy as sp
import scipy.stats
import matplotlib as mpl
import matplotlib.pyplot as plt
size = 1e4
aa = 10**np.random.normal(-2.0, size=int(size))
aa = np.clip(aa, 1e-5, 1.0)
bb = 10**np.random.uniform(-4, 0, size=aa.size)
@lzkelley
lzkelley / gist:716d728a489e62973d0a9426a9ca1aa3
Last active July 8, 2020 22:26
Draw an Arepo mesh and (optional) scalar variable
def voronoi_mesh(path, snap_num, ndim=2, int_type=np.int32, double_type=np.float32):
"""Load an Arepo voronoi mesh from the 2D `voronoi_mesh_###` files.
"""
# fname = _snap_file_from_path(fname, "voronoi_mesh_{:03d}", snap_num=snap_num)
fname = os.path.join(path, "voronoi_mesh_{:03d}".format(snap_num))
mesh = dict()
with open(fname, 'rb') as data:
# Read header
import numpy as np
import matpotlib.pyplot as plt
import corner # From: https://github.com/dfm/corner.py
SKIP = 100 # Only plot 1/SKIP data points
fname = "./lzk-gw-data_cornish-becsy.npz"
data = np.load(fname)
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)
@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
fig, ax = plt.subplots(figsize=[8, 5])
ax.set_xscale('log')
# Construct a log-normal distribution
dist = sp.stats.lognorm(1)
@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:
# 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 / 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
#!/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