Skip to content

Instantly share code, notes, and snippets.

Syrtis Major syrte

Block or report user

Report or block syrte

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@syrte
syrte / weighted_kde.ipynb
Created May 9, 2019 — forked from tillahoffmann/weighted_kde.ipynb
Weighted kernel density estimation based on `scipy.stats.gaussian_kde`.
View weighted_kde.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View better_bibtex_setting.md

citation key

citation key format

[auth][year]

Force citation key to plain text

export

Export Unicode

@syrte
syrte / AdapKDE.py
Created Jan 7, 2019
Not tested yet.
View AdapKDE.py
import numpy as np
from sklearn.neighbors import KDTree
from numba import vectorize
@vectorize(["float64(float64, float64, float64, float64, float64, float64, float64)"])
def binorm(xi, yi, x, y, xvar, yvar, xyvar=0):
X, Y = xi - x, yi - y
det = xvar * yvar - xyvar**2
p = (np.exp(-(X**2 * yvar + Y**2 * xvar - 2 * X * Y * xyvar) / (2 * det)) / (2 * np.pi * np.sqrt(det)))
View ModelParam.py
class ModelParam:
"""
p0 = ModelParam({'a': 1, 'b':2})
p1 = p0.free('a', 'b').fix(b=1, c=2)
"""
def __init__(self, param_fixed, names_free=[]):
"""
param_fixed: dict
names_free: list
View make_gauss_kernel.py
def make_gauss_kernel(xsig, ysig, dx, dy, nsig=4):
"""nbin ~ nsig * xsig / dx
kernel shape: 2 * nbinx + 1 where nbinx + 0.5 >= nsig * xsig / dx
Examples
plt.imshow(make_gauss_kernel(0.05, 0.05, 0.01, 0.01, 3.5))
"""
from scipy.stats import norm
nbins_x = np.int32(np.ceil(nsig * xsig / dx - 0.5))
View cat_ipynb.py
#!/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))
View example_halo_growth.py
f = lambda x, a, b, c: 15 - exp(a * x**b) + a * c * x**b
xkcd()
figure(figsize=(5, 4))
plot(x, f(x, 1.75, 1.3, 0.95), label='early')
plot(x, f(x, 1.7, 1, 0.5), label='late')
xlim(1, 0)
ylim(10, 15)
xlabel(r'$\log\ (1+z)$')
@syrte
syrte / import_vars.py
Created Aug 23, 2018
What a useless snipet!
View import_vars.py
def import_vars(**dict_list):
"""
dict_list: namespaces to import
Examples
--------
dic1 = dict(x=1, y=1)
dic2 = dict(a=1, b=1)
exec(import_vars(dic1=dic1, dic2=dic2))
print(x, y, a, b)
View OMP_NUM_THREADS.py
import os
os.environ["OMP_NUM_THREADS"] = "3"
os.environ["MKL_NUM_THREADS"] = "3"
View find_root.py
@numba.jit
def find_root(x):
"""find the indexes where x>0, the sign of x change twice: ----++++----
"""
n1, n2, n0 = x.shape
ix_inn, ix_out = np.empty((2, n1, n2), dtype=int)
for i in range(n1):
for j in range(n2):
for k in range(n0):
if x[i, j, k] > 0:
You can’t perform that action at this time.