Skip to content

Instantly share code, notes, and snippets.

View syrte's full-sized avatar

Zhaozhou Li syrte

View GitHub Profile
@syrte
syrte / gaussian_kernel_regression.py
Created November 5, 2025 14:38
Iterative Gaussian kernel smoothing .
import numpy as np
def gaussian_kernel_regression(
x, y, sigma, yerr=None, w=None, x_new=None, niter=20, atol=1e-6, rtol=1e-3
):
"""
Iterative Gaussian kernel smoothing.
Parameters
@syrte
syrte / smooth_piecewise_linear.py
Created April 30, 2025 06:50
fit gaussian process and smooth piecewise linear function
import numpy as np
import matplotlib.pyplot as plt
def fit_gp(x, y, y_err, y_avg=None, x_pred=None, scale=1):
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, ConstantKernel, Matern, WhiteKernel
from sklearn.exceptions import ConvergenceWarning
import warnings
import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import griddata
def add_label(x, y, x0=None, y0=None, dx=0, dy=0, s='', **kwargs):
"add label on the curve (x, y) at location specified by (x0, y0)"
if x0 is not None:
if x[-1] > x[0]:
y0 = np.interp(x0, x, y)
@syrte
syrte / arcs.py
Last active March 10, 2025 08:54
Plot a collection of patches (circles, ellipses, rectangles), similar to `plt.scatter` but the size of patches are in data unit.
from __future__ import division, print_function, absolute_import
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Arc
from matplotlib.collections import PatchCollection
__all__ = ['arcs']
def arcs(x, y, w, h=None, rot=0.0, theta1=0.0, theta2=360.0,
c='b', vmin=None, vmax=None, **kwargs):
@syrte
syrte / flip_AM.py
Last active December 7, 2024 13:46
flip angular momentum
import astropy.units as u
import numpy as np
from matplotlib.pylab import *
import agama
agama.setUnits(length=1, velocity=1, mass=1)
def sigmoid(x, fmax=1, scale=0.5):
"""
@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 / clean_latex.sh
Created June 4, 2024 21:27
copy from stackoverflow.
#!/bin/bash
for image_file in $(ls figs6/)
do
if grep $image_file */*.log -c > 1
then
echo "File $image_file is in use."
else
echo "File $image_file is not in use."
mv "figs6/$image_file" "figs6/moved.$image_file" # or any other action
@syrte
syrte / Sersic_Einasto_index.py
Created January 29, 2024 16:09
To compute the coefficient for Sersic or Einasto profile with half-mass radius
from scipy.special import gammaincinv
def b(n):
# 2 * n - 1 / 3 + 4 / (405 * n) + 46 / (25515 * n**2) + 131 / (1148175 * n**3)
return gammaincinv(2 * n, 0.5)
def d(n):
# 3 * n - 1 / 3 + 8 / (1215 * n) + 184 / (229635 * n**2) + 1048 / (31000725 * n**3)
return gammaincinv(3 * n, 0.5)
@syrte
syrte / sersic_lum.py
Created January 29, 2024 08:55 — forked from bamford/sersic_lum.py
Luminosity of Sérsic function in annulus
from numpy import pi, exp
from scipy.special import gamma, gammaincinv, gammainc
# Normalisation constant
def b(n):
return gammaincinv(2*n, 0.5)
# Total luminosity of a 2D Sérsic profile
def sersic_total_lum(Ie, re, n):
bn = b(n)
@syrte
syrte / parsec_query.py
Last active January 20, 2024 17:36
A handy script for querying the new parsec website of padova isochrones.
"""
A handy script for querying the new parsec website of padova isochrones.
author: syrte (http://github.com/syrte)
## Features
- Easy to use
- Flexibility
- Friendly error prompts
- Support latest also previous versions of parsec website