Skip to content

Instantly share code, notes, and snippets.

@guillochon
Created November 24, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillochon/5b80cebede8f51248fc9b654a8d8e4ac to your computer and use it in GitHub Desktop.
Save guillochon/5b80cebede8f51248fc9b654a8d8e4ac to your computer and use it in GitHub Desktop.
Fitting Ia data from OSC with SNCosmo
from astropy.table import Table
import sncosmo
import json
source = sncosmo.get_source('salt2', version='2.4')
model = sncosmo.Model(source=source)
with open('SNLS-05D4bm.json', 'r') as f:
data = json.loads(f.read())
photodat = []
data = data[list(data.keys())[0]]
for item in data['photometry']:
if 'counts' not in item or ('upperlimit' in item and item['upperlimit']):
continue
photodat.append((float(item['time']), 'sdss' + item['band'].strip("'"),
float(item['counts']), float(item['e_counts']),
float(item['zeropoint']), 'bd17'))
table = Table(rows=photodat, names=('time', 'band', 'flux', 'fluxerr',
'zp', 'zpsys'))
result, fm = sncosmo.fit_lc(table, model, ['z', 't0', 'x0', 'x1', 'c'],
bounds={'z':(0.25, 0.45)})
sncosmo.plot_lc(table, model=fm, errors=result.errors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment