Skip to content

Instantly share code, notes, and snippets.

@timothydmorton
timothydmorton / find_existing_dataId.py
Created March 15, 2020 06:54
Get all dataIds for existing datasets in a repo (gen2)
from pathlib import Path
from difflib import SequenceMatcher
import re
# Some example dataset templates from policy/datasets.yaml in obs_base
templates = {'deepCoadd_obj': 'deepCoadd-results/merged/%(tract)d/%(patch)s/obj-%(tract)d-%(patch)s.parq',
'deepCoadd_qa': 'deepCoadd-results/qa/%(tract)d/%(patch)s/qa-%(tract)d-%(patch)s.parq',
'analysisVisitTable': 'plots/%(filter)s/tract-%(tract)d/visit-%(visit)d/%(tract)d_%(visit)d.parq',
'analysisVisitTable_commonZp': 'plots/%(filter)s/tract-%(tract)d/visit-%(visit)d/%(tract)d_%(visit)d_commonZp.parq',
'analysisCoaddTable_forced': 'plots/%(filter)s/tract-%(tract)d/%(tract)d_forced.parq',
@timothydmorton
timothydmorton / isochrones_dynesty_test.py
Last active January 24, 2019 02:55
Multinest vs. dynesty for isochrones fit
# Need to run this with 'bolo' branch from github.com/timothydmorton/isochrones
from isochrones.mist.isochrone import MIST_BasicIsochrone
from isochrones import StarModel
iso = MIST_BasicIsochrone()
iso.initialize() # This will take a few minutes the first time you run this.
mags = {'J': (10.14, 0.02),
'H': (9.81, 0.02),
@timothydmorton
timothydmorton / test_big_app.py
Created January 11, 2018 16:57
Holoviews/bokeh app that crashes because of too much data
import numpy as np
import holoviews as hv
from bokeh.io import curdoc
from bokeh.layouts import layout
from bokeh.models.widgets import Panel, Tabs
import holoviews as hv
renderer = hv.renderer('bokeh').instance(mode='server')
@timothydmorton
timothydmorton / scattersky-operation-demo.py
Created September 26, 2017 16:55
Playing with custom operations in holoviews
import holoviews as hv
hv.notebook_extension('bokeh')
import param
from holoviews.operation.datashader import datashade, dynspread
import colorcet as cc
import datashader
import numpy as np
import pandas as pd
@timothydmorton
timothydmorton / test_app.py
Created August 8, 2017 14:52
A bokeh/holoviews/datashader/parambokeh test app
import numpy as np
import holoviews as hv
import pandas as pd
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.io import show
from bokeh.layouts import layout
from bokeh.plotting import curdoc
from scipy.optimize import root
import numpy as np
from scipy.special import spherical_jn
import matplotlib.pyplot as plt
def spherical_jn_sensible_grid(n, m, ngrid=100):
"""Returns a grid of x values that should contain the first m zeros, but not too many.
"""
return np.linspace(n, n + 2*m*(np.pi * (np.log(n)+1)), ngrid)
def model(p, x):
"""
p are parameters of the model, in this case C, alpha
where y = C*x^alpha
"""
return p[0]*x**p[1]
def lnlike(p, xdata, ydata, yerr=1.):