Skip to content

Instantly share code, notes, and snippets.

View syrte's full-sized avatar

Zhaozhou Li syrte

View GitHub Profile
@syrte
syrte / arcs.py
Last active April 24, 2024 10:27
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 / 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
import glob
import numpy as np
import healpy
from astropy.io import fits
LEVEL_HPIX = 12
NSIDE_HPIX = 2**LEVEL_HPIX
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
Add exponentiated variance (EV) acquisition function to skopt.
Author:
Zhaozhou Li (lizz.astro@gmail.com)
"""
import numpy as np
import warnings
import skopt.acquisition
#!/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))
@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.