Skip to content

Instantly share code, notes, and snippets.

View syrte's full-sized avatar

Zhaozhou Li syrte

View GitHub Profile
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):
@syrte
syrte / apj_short_prop.bst
Created July 30, 2022 06:14 — forked from eteq/apj_short_prop.bst
A modified version of the apj latex/bibtex bst file for funding/observing proposals where there is very little space.
%%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}
@syrte
syrte / orbit_interp.py
Created March 26, 2022 18:31
Interp orbit using agama between snapshots
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)
#!/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))
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
@syrte
syrte / sky_map.md
Last active January 16, 2022 12:28
Sky map with proplot
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.
@syrte
syrte / install_agama.sh
Last active November 18, 2021 13:31
Manual installation of agama in a plain conda enviroment
# 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
"""
Add exponentiated variance (EV) acquisition function to skopt.
Author:
Zhaozhou Li ([email protected])
"""
import numpy as np
import warnings
import skopt.acquisition
"""
author:
Zhaozhou Li ([email protected])
history:
This code is taken from my project mw_mass3.
"""
import numpy as np
from scipy.interpolate import CubicSpline
@syrte
syrte / Nemo_IO.py
Last active February 2, 2022 18:14
"""
Python IO for nemo snapshot
Author: syrte ([email protected])
Example:
file = '../data/N1e6_d0.22_g0.16_0.00_f0.00.snap'
snap = open_nemo(file, file_meta=False)
print(snap.History.data, end='\n\n')