Skip to content

Instantly share code, notes, and snippets.

View syrte's full-sized avatar

Zhaozhou Li syrte

View GitHub Profile
@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)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@syrte
syrte / mandc.py
Last active July 10, 2023 15:26
exec and load Zhao+2009 model, see http://202.127.29.4/dhzhao/mandc.html
"""
exec and load Zhao+2009 model
cf http://202.127.29.4/dhzhao/mandc.html
"""
import os
from astropy.io import ascii
# -*- coding:utf-8 -*-
from __future__ import division
from numpy import sqrt, exp, log, abs, diff, sin, cos, linspace, interp
from numpy import empty_like, atleast_1d, asarray
from numpy.testing import assert_almost_equal
from scipy.optimize import bisect as root
from numpy import e, pi
from scipy.integrate import romberg
mid = lambda x: (x[1:] + x[:-1]) / 2.
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)
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
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']
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}