Skip to content

Instantly share code, notes, and snippets.

View syrte's full-sized avatar

Zhaozhou Li syrte

View GitHub Profile
@syrte
syrte / example_eagle_halo.py
Last active March 8, 2023 06:34
virgo_query
from virgo_query import virgo_query
simu = 'RefL0100N1504'
name = 'Eagle' + simu
snap = 28
file_save = 'data/{}_s{}_group.fits'.format(name, snap)
print('saving %s' % file_save)
query = """
@syrte
syrte / binorm.py
Last active April 24, 2021 05:21
points to points
import numpy as np
from numba import njit, prange
import numba
numba.config.NUMBA_NUM_THREADS = 20
numba.set_num_threads(20)
@njit(parallel=True, fastmath=True)
def binorm(xj, yj, x, y, xsig, ysig, nsig2_min=9.):
r = np.zeros_like(x)
import glob
import numpy as np
import healpy
from astropy.io import fits
LEVEL_HPIX = 12
NSIDE_HPIX = 2**LEVEL_HPIX
@syrte
syrte / read_NearbyGalaxies.py
Last active September 12, 2020 03:26
Loading data from Nearby Dwarf Database
from astropy.io import ascii
table = ascii.read('http://www.astro.uvic.ca/~alan/Nearby_Dwarf_Database_files/NearbyGalaxies.dat', delimiter=' ', guess=False, fast_reader=False, header_start=None, data_start=31, names="GalaxyName RA_h RA_m RA_s Dec_d Dec_m Dec_s E(B-V) distmod E_distmod e_distmod vh E_vh e_vh Vmag E_Vmag e_Vmag PA E_PA e_PA eps E_eps e_eps muV E_muV e_muV rh E_rh e_r vsig E_vsig e_vsig vrot E_vrot e_vrot MHI gvsig E_gvsig e_gvsig gvrot E_gvrot e_gvrot FeH E_FeH e_FeH Flag References".split())
@syrte
syrte / gpy_kernel_cheatsheet.py
Created May 25, 2020 12:48 — forked from rikrd/gpy_kernel_cheatsheet.py
GPy Kernel Cheatsheet:: All the kernels in GPy (example realizations, covariance matrix, kernel equation)
%pylab inline
import numpy as np
import pylab as plt
import GPy
import re
def get_equation(kern):
match = re.search(r'(math::)(\r\n|\r|\n)*(?P<equation>.*)(\r\n|\r|\n)*', kern.__doc__)
return '' if match is None else match.group('equation').strip()
#!/usr/bin/env python3
# encoding=utf8
import os
import re
import unicodedata
def slugify(value, max_length=50):
"""
@syrte
syrte / README.md
Last active October 17, 2022 07:49
tomboy2markdown

tomboy2markdown: Convert Tomboy/Gnote notes to Markdown files.

It uses Markdown formatting when possible and creates subdirectories for notebooks.

This is a rewritten script of tomboy2text by Johannes H. Jensen with improved Markdown compatibility and customizability. Several known issues reported for tomboy2text are fixed. The output files are tested with Typora.

Usage

def wstd(x, weights=None, axis=None, keepdims=False):
x = np.asarray(x)
if weights is not None:
weights = np.asarray(weights)
if weights.shape != x.shape:
raise ValueError("weights must have same shape with x")
else:
weights = np.ones_like(x)
w = weights / np.sum(weights, axis=axis, keepdims=True)
@syrte
syrte / HeteroNoise.py
Last active May 24, 2020 12:53
Custom GPy noise model
import GPy
import numpy as np
class HeteroNoise(GPy.kern.Kern):
"""
heteroscedastic white noise as function of X
"""
def __init__(self, input_dim, variance_function=1., active_dims=None):
@syrte
syrte / test.py
Last active April 28, 2020 16:44
Make transformation to a cKDTree object without rebuilding the tree.
from scipy.spatial import cKDTree
transform = {0: lambda x: -x}
a = np.random.randn(1000, 2)
b = a.copy()
for k in transform:
b[:, k] = transform[k](b[:, k])
c = np.random.randn(1000, 2)