import numpy as np
import proplot as pplt
from matplotlib import pyplot as plt
import cartopy.geodesic
def add_ticks(ax, labelpad=None):
"""
Only works for major ticks on the left and bottom.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from astropy import units as u | |
| (0 * u.ABmag).to(u.erg/u.s/u.cm**2/u.Hz) | |
| # 0 ABmag corresponsds to 3.6307805477010035e-20 erg / (cm2 Hz s) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import np | |
| def kern_smooth(x, xp, yp, bw=1, return_std=False): | |
| w = np.exp(-0.5 * ((xp - x.reshape(-1, 1)) / bw)**2) | |
| w = w / w.sum(1, keepdims=True) | |
| y = (yp * w).sum(1) | |
| if not return_std: | |
| return y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getdist_colors(): | |
| "return getdist color table" | |
| # taken from getdist, https://github.com/cmbant/getdist | |
| return ['#006FED', '#E03424', 'gray', '#009966', '#000866', '#336600', '#006633', 'm', 'r'] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scipy import optimize | |
| from scipy import stats | |
| def gaussian(x, p): | |
| n = len(p) // 2 | |
| return np.add.reduce([p[i] * stats.norm.pdf(x, scale=p[n + i]) for i in range(n)]) | |
| def fit_gauss_sym(x, y, n=2, origin=True, full=True, positive=True): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%This is often best used in a latex file in two-column mode. To do that, do: | |
| %% | |
| %%\usepackage{multicol} % before \begin{document} | |
| %% ... document ... | |
| %%\begin{multicols}{2} | |
| %%\bibliography{filename}{} | |
| %%\bibliographystyle{apj_short_prop} | |
| %%\end{multicols} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def interp_orbit(ix, snap_list, npts=51, rtol=1e-5): | |
| ns = len(snap_list) - 1 | |
| ts = np.array([si.t for si in snap_list.values()]) | |
| t_list = np.empty((ns, npts)) | |
| xv_list = np.empty((len(ix), ns, npts, 6)) | |
| for i, si in enumerate(snap_list.values()): | |
| print(i, end=',', flush=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import sys | |
| import json | |
| for file in sys.argv[1:]: | |
| print('# file: %s' % file) | |
| print('# vi: filetype=python') | |
| print('') | |
| code = json.load(open(file)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CubicSplineExtrap(CubicSpline): | |
| def __init__(self, x, y, bc_type='not-a-knot', extrapolate='linear'): | |
| """ | |
| Linearly extrapolate outside the range | |
| extrapolate: False, float, 'const', 'linear', 'cubic', or a 2-tuple of them | |
| Example | |
| ------- | |
| from scipy.interpolate import PchipInterpolator, CubicSpline |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # create env and install dependency | |
| conda create -n agama python=3.8 numpy gsl glpk eigen cvxopt | |
| conda activate agama | |
| # download files | |
| cd $HOME/src | |
| wget https://github.com/GalacticDynamics-Oxford/Agama/archive/master.zip -O agama.zip | |
| wget https://github.com/GalacticDynamics-Oxford/unsio/archive/master.zip -O unsio.zip | |
| wget https://github.com/cvxopt/cvxopt/archive/master.zip -O cvxopt.zip | |
| unzip agama.zip |