def sncosmoFit(datacat_name='sncosmo_SN2018kp.txt'): """ z = 0.007166 ; NED """ import sncosmo data = ascii.read(datacat_name) magsys = sncosmo.CompositeMagSystem( bands={ 'standard::b': ('ab', 9.851778333549941), 'standard::v': ('ab', 10.165691850734973), 'standard::r': ('ab', 9.780891653643735), 'standard::i': ('ab', 10.00617773098994) }) dust1 = sncosmo.F99Dust(r_v=3.1) dust = sncosmo.F99Dust(r_v=1.766) model = sncosmo.Model(source='salt2', effects=[dust, dust1], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) model.set(z=0.010142) #model.set_source_peakabsmag(-19,'standard::b', 'ab') model.param_names model.parameters print('Set the model like this;', model) #source = sncosmo.SALT2Source(modeldir='/home/lim9/.astropy/cache/sncosmo/models/salt2/salt2-4') ### Applying cuts minsnr = 3 tl = data['mjd'][0] tu = data['mjd'][0] + 50. #mask = (data['mjd'] >= tl) & (data['mjd'] < tu) #mask = (data['mjd'] >= tl) & (data['mjd'] < tu) & (data['flux'] / data['fluxerr'] > minsnr) #data = data[mask] params_to_fit = ['t0', 'x0', 'x1', 'c', 'hostebv', 'mwebv'] bounds = {'hostebv': (0, 1.0), 't0': (58158, 58160), 'mwebv': (0, 1.0)} #bounds = { 't0':(58618, 58620), 'x0':(0.01,0.05), 'x1':(-2,-0.5), 'c':(0.0, 0.15), 'hostebv':(0, 0.1)} result, fitted_model = sncosmo.fit_lc(data, model, params_to_fit, guess_amplitude=False, guess_t0=True, guess_z=False, bounds=bounds, method='minuit', modelcov=True, phase_range=(-20, 75), verbose=True) print("Number of chi^2 function calls :", result.ncall) print("Number of degrees of freedom in fit :", result.ndof) print("Chi^2 value at minimum :", result.chisq) print("Reduced Chi^2 :", result.chisq / result.ndof) print("Model parameters :", result.param_names) print("Best-fit values :", result.parameters) print("The result contains the following attributes:\n", result.keys()) sncosmo.plot_lc(data, model=fitted_model, errors=result.errors, pulls=True, figtext='SN 2018kp; SALT2', show_model_params=True)
def extinction(self, eb_v, dust_law, r_v=3.1): """ Given eb-v and r-v return the dust extinction in a particular BAND It can use: Cardelli dust law (CCM), ODonneal (OD94) Fitzpatrick (F99) KEEP IN MIND: _minwave = 909.09 _maxwave = 33333.33 """ if dust_law == 'OD94': dust = sncosmo.OD94Dust() elif dust_law == 'CCM': dust = sncosmo.CCM89Dust() elif dust_law == 'F99': dust = sncosmo.F99Dust() else: print('Add this dust law! I dont know it') dust.parameters = [eb_v, r_v] w = self.wave t = self.transmission ext = dust.propagate(w, t) correction_extinction = np.trapz((ext)[1:-1], w[1:-1]) / np.trapz( (t)[1:-1], w[1:-1]) return correction_extinction
def lnprob(p, x, y, yerr): # p is ebv and r_v f99 = sncosmo.F99Dust(r_v=p[1]) f99.set(ebv=p[0]) A_ = f99.propagate(x, 1.) / f99.propagate(numpy.array([5287.48667023]), 1.)[0] A_ = -2.5 * numpy.log10(A_) dum = y - A_ ans = -0.5 * numpy.sum((dum / yerr)**2) return ans
def update_sncosmo_model(salt2par, lcpar_map): model = sncosmo.Model(source='salt2', effects=[sncosmo.F99Dust()], effect_names=['mw'], effect_frames=['obs']) lcpardict = {} sncosmo_parlist = ['x0', 'x1', 'c', 't0', 'z', 'mwebv'] for p in sncosmo_parlist: lcpardict[p] = salt2par[lcpar_map[p]] model.update(lcpardict) return model
def get_saltmodel(mwebv=None): """ """ import sncosmo dust = sncosmo.F99Dust() model = sncosmo.Model("salt2", effects=[dust], effect_names=['mw'], effect_frames=['obs']) if mwebv is not None: model.set(mwebv=mwebv) return model
def model(self): model = sncosmo.Model(source=self.source, effects=[self.dust_type(), sncosmo.F99Dust()], effect_names=['host', 'mw'], effect_frames=['rest', 'obs']) model.set(z=self.z) model.set(mwebv=self.mwebv) model.set(hostr_v=self.rv) model.set(hostebv=self.ebv) model.set(t0=0.) model.set_source_peakabsmag(-19.0, 'bessellb', 'ab') return model
def mwebv_corr(ra, dec, band): mwebv = get_mwebv(ra, dec) model_nomw = sncosmo.Model(source='salt2') model_mw = sncosmo.Model(source='salt2', effects=[sncosmo.F99Dust()], effect_names=['mw'], effect_frames=['obs']) model_mw.set(mwebv=mwebv) try: bandpass = sncosmo.get_bandpass('ztf' + band) except: register_ztf_bandpass(band) bandpass = sncosmo.get_bandpass('ztf' + band) mag_nomw = model_nomw.bandmag(bandpass, 'ab', 0.) mag_mw = model_mw.bandmag(bandpass, 'ab', 0.) mwebv_corr = mag_mw - mag_nomw return mwebv_corr
def fit_salt2(SN_det, z, mwebv): model = sncosmo.Model(source='salt2', effects=[sncosmo.F99Dust()], effect_names=['mw'], effect_frames=['obs']) model.set(z=z) model.set(mwebv=mwebv) filt_map = {1: 'g', 2: 'r'} zp = 27.5 SN_det['flux'] = np.power(10., -0.4 * (SN_det.magpsf - zp)) SN_det['fluxerr'] = np.absolute(0.921 * SN_det.flux * SN_det.sigmapsf) SN_det['zp'] = zp SN_det['zpsys'] = 'ab' SN_det['filter'] = ['ztf' + filt_map[x] for x in SN_det.fid] SN = Table.from_pandas(SN_det) res, fitmodel = sncosmo.fit_lc(SN, model, ['t0', 'x0', 'x1', 'c'], bounds={ 'x0': (0, 1.), 'x1': (-5., 5.), 'c': (-3., 3.) }) return res
def A_X(r_v=3.1, ebv=1.): dust = sncosmo.F99Dust(r_v=r_v) dust.set(ebv=ebv) model = sncosmo.Model(source='salt2', effects=[dust], effect_names=['host'], effect_frames=['rest']) return -2.5*numpy.log10(model.bandflux(synbands,0.)/flux_nodust)
def analyze(): pkl_file = open('fitz.pkl', 'r') amed = pickle.load(pkl_file) pkl_file.close() synlam = numpy.array([[3300.00, 3978.02], [3978.02, 4795.35], [4795.35, 5780.60], [5780.60, 6968.29], [6968.29, 8400.00]]) synname = ['U', 'B', 'V', 'R', 'I'] synbands = [] for name, lams in zip(synname, synlam): synbands.append(sncosmo.Bandpass(lams, [1., 1.], name='tophat' + name)) model_nodust = sncosmo.Model(source='salt2') print model_nodust flux_nodust = model_nodust.bandflux(synbands, 0.) shit = -2.5 * numpy.log10(flux_nodust) print shit - shit[2] shit = model_nodust.bandmag(synbands, 'vega', 0.) print shit - shit[2] wetw av = numpy.exp( numpy.arange(numpy.log(0.005), numpy.log(1.8) + 0.001, numpy.log(1.8 / 0.005) / 25)) av = numpy.concatenate((-av[16::-1], av)) rv = numpy.exp( numpy.arange(numpy.log(2.1), numpy.log(6.9) + 0.001, numpy.log(6.9 / 2.1) / 50)) avs = [] ebvs = [] rvs = [] AX = [] for a in av: for r in rv: dust = sncosmo.F99Dust(r_v=r) dust.set(ebv=a / r) model = sncosmo.Model(source='hsiao', effects=[dust], effect_names=['host'], effect_frames=['rest']) AX.append(-2.5 * numpy.log10(model.bandflux(synbands, 0.) / flux_nodust)) avs.append(a) ebvs.append(a / r) rvs.append(r) avs = numpy.array(avs) ebvs = numpy.array(ebvs) AX = numpy.array(AX) print AX[400] rvs = numpy.array(rvs) diff = AX - (amed[0][None,:]*avs[:,None]+ amed[1][None,:] * avs[:,None]**2 \ +amed[2][None,:]*ebvs[:,None]+ amed[3][None,:] * ebvs[:,None]**2 \ +amed[4][None,:] * (avs*ebvs)[:,None] \ +amed[5][None,:] * (avs**3)[:,None] \ +amed[6][None,:] * (ebvs**3)[:,None] \ +amed[7][None,:] * ((avs**2)*ebvs)[:,None] \ +amed[8][None,:] * (avs*(ebvs**2))[:,None] \ ) fdiff = (AX - (amed[0][None,:]*avs[:,None]+ amed[1][None,:] * avs[:,None]**2 \ +amed[2][None,:]*ebvs[:,None]+ amed[3][None,:] * ebvs[:,None]**2 \ +amed[4][None,:] * (avs*ebvs)[:,None] \ +amed[5][None,:] * (avs**3)[:,None] \ +amed[6][None,:] * (ebvs**3)[:,None] \ +amed[7][None,:] * ((avs**2)*ebvs)[:,None] \ +amed[8][None,:] * (avs*(ebvs**2))[:,None] \ ))/AX temp = (amed[0][None,:]*avs[:,None]+ amed[1][None,:] * avs[:,None]**2 \ +amed[2][None,:]*ebvs[:,None]+ amed[3][None,:] * ebvs[:,None]**2 \ +amed[4][None,:] * (avs*ebvs)[:,None] \ +amed[5][None,:] * (avs**3)[:,None] \ +amed[6][None,:] * (ebvs**3)[:,None] \ +amed[7][None,:] * ((avs**2)*ebvs)[:,None] \ +amed[8][None,:] * (avs*(ebvs**2))[:,None] \ ) print numpy.max(numpy.abs(fdiff)) arg = numpy.argmax(numpy.abs(fdiff)) print avs[arg / 5], ebvs[arg / 5] print diff[arg / 5] print avs.max() wav = numpy.isclose(avs, -0.21627365) for i in xrange(5): # plt.plot(rvs[wav],fdiff[wav,i],label=synname[i]) plt.plot(rvs[wav], AX[wav, i], label=synname[i]) plt.plot(rvs[wav], temp[wav, i]) plt.ylabel(r'$\Delta A$') plt.xlabel(r'$R$') plt.legend() pp = PdfPages('output18/dfitz.pdf') plt.savefig(pp, format='pdf') pp.close() plt.close()
from pprint import pprint import sncosmo import snfitio # to read snfit results REGEX = re.compile('jla_light_curves/lc-(.+)\.list') def snname_from_fname(fname): return re.match(REGEX, fname).groups()[0] if __name__ == "__main__": model = sncosmo.Model(source='salt2', effects=[sncosmo.F99Dust()], effect_names=['mw'], effect_frames=['obs']) fnames = glob.glob("jla_light_curves/lc-SDSS19230.list") for fname in fnames[0:1]: snname = snname_from_fname(fname) data = sncosmo.read_lc(fname, format='salt2', read_covmat=True) model.set(mwebv=data.meta['MWEBV'], z=data.meta['Z_HELIO']) t0 = time.time() result, m = sncosmo.fit_lc(data, model, ['t0', 'x0', 'x1', 'c'], modelcov=True, phase_range=(-15., 45.), wave_range=(3000., 7000.), verbose=True) print("time:", time.time() - t0, 's')
def light_curves_salt2(z: float, filters: list, peak: float = None, days: Union[tuple, list, np.ndarray] = (0, 85), show: bool = True, rise_time: float = None, ebv_mw: float = 0, ebv_host: float = 0., x1: float = None, output_path: str = None, output_title: str = None, day_markers: list = None, fil_peak='bessellb', r_v: float = 2.3): """ Produces light curves, in the provided filters, for a Type Ia supernova using the SALT2 models as implemented in sncosmo. :param z: Redshift of source. :param filters: Filters to obtain light curves in. Must be in the sncosmo Registry. :param peak: Peak (ie lowest) absolute magnitude, in the filter given by fil_peak, to calibrate curves to. :param days: Either an array of times (in days) to calculate the light curves over, or a tuple describing the range of days, ie (first_day, last_day) :param show: Show plot onscreen? :param rise_time: Rest-frame time, from beginning of SN to peak magnitude, in days. :param ebv_mw: Reddening parameter E(B-V), using S&F11 law, for the Milky Way along the SN's line-of-sight. :param ebv_host: Reddening parameter E(B-V), using S&F11 law, for the host galaxy. :param x1: SALT2 light curve stretch parameter. See SALT2 documentation for further information. :param output_path: Path to which to save output. If None, does not save. :param output_title: Title to give output plot and table. :param day_markers: List of times (in days) to mark on plot, eg observation dates. :param fil_peak: Filter in which to set the peak absolute magnitude; usually reported in B or V. :return: mag_table, model mag_table: an astropy.table.Table with the times, in days, and the magnitudes in each filter. model: the entire sncosmo model instance. """ if output_path is not None and output_path[-1] != '/': output_path += '/' u.mkdir_check(output_path) # Find time at which model begins and time of peak. t_first, t_peak = find_model_times(source='salt2-extended', z=z, fil=fil_peak, show=False) # If both are None, the model is invalid over these wavelengths if t_first is t_peak is None: return None, None # Set up model in sncosmo. dust_mw = sncosmo.F99Dust() dust_host = sncosmo.CCM89Dust() model = sncosmo.Model(source='salt2-extended', effects=[dust_mw, dust_host], effect_names=['mw', 'host'], effect_frames=['obs', 'rest']) model.set(x1=x1) # If a rise time is not given, allow the model to determine this itself. if rise_time is None: if t_peak <= 0: model.set(z=z, t0=-t_first, mwebv=ebv_mw, hostebv=ebv_host, hostr_v=r_v) else: model.set(z=z, t0=0, mwebv=ebv_mw, hostebv=ebv_host, hostr_v=r_v) elif rise_time == -1: model.set(z=z, t0=t_first, mwebv=ebv_mw, hostebv=ebv_host, hostr_v=r_v) else: # Correct rise time to observer frame rise_time_obs = rise_time * (1 + z) model.set(z=z, t0=rise_time_obs - t_peak, mwebv=ebv_mw, hostebv=ebv_host, hostr_v=r_v) print(model) # Set peak absolute magnitude of model. if peak is not None: model.set_source_peakabsmag(peak, fil_peak, 'ab') if type(days) is tuple: # Set up array of times. days = np.arange(days[0], days[1] + 1, 0.1) mags_filters = table.Table() mags_filters['days'] = days maxes = [] t_peaks = [] peaks = [] for f in filters: # Get light curve. mags = model.bandmag(f, 'ab', days) # If the light curve is mostly flat, the model has probably broken down. if np.sum(mags == mags[0]) < 0.9 * len(mags): # If this is False, the entire light curve must be nan, and we'll get nothing useful out of it. if not np.isnan(np.nanmax(mags)): # Collect peak (lowest) magnitudes, peak times, and maximum (faintest) magnitudes for each filter. maxes.append(np.nanmax(mags[mags != np.inf])) peaks.append(np.nanmin(mags[mags != np.inf])) t_peaks.append(days[np.nanargmin(mags)]) # Write light curve to table. mags_filters[f] = mags if output_path is not None or show: # Plot curve. plt.plot(days, mags, label=f) # If we have no maxima, the model has broken down. if len(maxes) > 0: # Collect this for plotting purposes. max_mag = np.nanmax(maxes) min_mag = np.nanmin(peaks) else: return None, None # If an output_path directory is not given and 'show' is not True, there's no point doing the plot. if output_path is not None or show: for i, t_peak in enumerate(t_peaks): # Plot blue lines marking the peak of each filter light curve. plt.plot([t_peak, t_peak], [max_mag + 1, min_mag - 1], c='blue') if day_markers is not None: for other_day in day_markers: # Plot red lines marking the observation dates. plt.plot([other_day, other_day], [max_mag + 1, min_mag - 1], c='red') plt.xlabel('Time (days)') plt.ylabel('Magnitude') plt.ylim(max_mag + 1, min_mag - 1) plt.legend() if output_path is not None: # Save figure. plt.savefig(output_path + output_title + '.png') # Save table to csv. mags_filters.write(output_path + output_title + '.csv', format='ascii.csv') if show: # Show figure onscreen. plt.show() plt.close() return mags_filters, model
def task(filename, i, j, nrv, nebv, kind='mcmc'): lc = sncosmo.read_lc(filename, format='csp') model = sncosmo.Model(bump.BumpSource(), effect_names=['host', 'mw'], effect_frames=['rest', 'obs'], effects=[sncosmo.OD94Dust(), sncosmo.F99Dust()]) rv_prior = burns.get_hostrv_prior(lc.meta['name'], 'gmm', sncosmo.OD94Dust) host_ebv, err = burns.get_hostebv(lc.meta['name']) ebv_prior = TruncNorm(-np.inf, np.inf, host_ebv, err) rv_prior, low, high = burns.get_hostrv_prior(lc.meta['name'], 'gmm', sncosmo.OD94Dust, retlims=True) host_ebv, err = burns.get_hostebv(lc.meta['name']) rv = np.linspace(low if low >= 0 else 0, high, nrv)[i] ebvlo = host_ebv - err ebvhi = host_ebv + err ebv = np.linspace(ebvlo if ebvlo >= 0 else 0, ebvhi, nebv)[j] model.set(z=lc.meta['zcmb']) model.set(mwebv=burns.get_mwebv(lc.meta['name'])[0]) model.set(hostebv=ebv) model.set(hostr_v=rv) model.set(t0=burns.get_t0(lc.meta['name'])) vparams = filter(lambda x: 'bump' in x, model._param_names) vparams += ['t0', 's'] bounds = {b.name + "_bump_amp": (-1, 2) for b in model.source.bumps} #bounds['hostr_v'] = (rv_prior.mean - 0.5, rv_prior.mean + 0.5) #bounds['hostebv'] = (0, 0.2) bounds['s'] = (0, 3.) res, model = sncosmo.fit_lc(lc, model, ['amplitude'] + vparams, bounds=bounds) bounds['t0'] = (model.get('t0') - 2, model.get('t0') + 2) vparams.append('amplitude') bounds['amplitude'] = (0.5 * model.get('amplitude'), 2 * model.get('amplitude')) qualifier = '_ebv_%.2f_rv_%.2f' % (ebv, rv) if kind != 'fit': if kind == 'mcmc': result = sncosmo.mcmc_lc(lc, model, vparams, bounds=bounds, nwalkers=500, nburn=1000, nsamples=20) elif kind == 'nest': result = sncosmo.nest_lc(lc, model, vparams, bounds=bounds, method='multi', npoints=800) samples = result[0].samples.reshape(500, 20, -1) vparams = result[0].vparam_names plot_arg = np.rollaxis(samples, 2) plotting.plot_chains(plot_arg, param_names=vparams, filename='fits/%s_samples%s.pdf' % (lc.meta['name'], qualifier)) dicts = [ dict(zip(vparams, samp)) for samp in samples.reshape(500 * 20, -1) ] thinned = samples.reshape(500, 20, -1)[:, [0, -1]].reshape(1000, -1) pickle.dump( samples, open('fits/%s_samples%s.pkl' % (lc.meta['name'], qualifier), 'wb')) models = [copy(result[1]) for i in range(len(thinned))] for d, m in zip(dicts, models): m.set(**d) fig = sncosmo.plot_lc(data=lc, model=models, ci=(50 - 68 / 2., 50., 50 + 68 / 2.), model_label=lc.meta['name']) fig.savefig('fits/%s%s.pdf' % (lc.meta['name'], qualifier)) else: fitres, model = sncosmo.fit_lc(lc, model, vparams, bounds=bounds) fig = sncosmo.plot_lc(data=lc, model=model) fig.savefig('fits/%s_fit%s.pdf' % (lc.meta['name'], qualifier))
qual = f.split('__')[1].split('.pkl')[0] ebv = float(qual.split('_')[1]) rv = float(qual.split('_')[-1]) nvparams.append([ebv, rv]) dicts = [] for samps, (ebv, rv) in zip(samples, nvparams): dicts.append(make_dictionaries(snname, samps, ebv, rv)) dicts = list(chain(*dicts)) samples = np.vstack(samples) pruned = samples[np.random.choice(range(len(dicts)), replace=False, size=1000)] model = sncosmo.Model(bump.BumpSource(), effect_names=['host','mw'], effect_frames=['rest','obs'], effects=[sncosmo.OD94Dust(), sncosmo.F99Dust()]) mods = [copy(model) for sample in pruned] for d, mod in zip(dicts, mods): mod.set(**d) bolos = [bolometric(mod) for mod in mods] stack = bolo.LCStack(mod.source._phase, bolos) ax = stack.plot() m2 = sncosmo.Model(sncosmo.get_source('hsiao')) m2.set(z=mod.get('z'), amplitude=mod.get('amplitude')) m3 = copy(mod) m3.set(**{p:0 for p in m3._param_names if 'bump' in p}) ax.plot(m2.source._phase, bolometric(m2), ls='--') ax.plot(m3.source._phase, bolometric(m3), ls='-.') ax.figure.savefig('combined.pdf')
fmt='.', label='SN2014J', color='black') plt.errorbar(elam, gammam1 * ans[0] + deltam1 * ans[1], yerr=[fiterr, fiterr], label='Best-fit Model', color='red', fmt='.') lambdas = numpy.arange(3500., 8000, 100) rvs = [1.4] ebv = 1.37 for rv in rvs: f99 = sncosmo.F99Dust(r_v=rv) f99.set(ebv=ebv) A_ = f99.propagate(lambdas, 1.) / f99.propagate(numpy.array([5477]), 1.)[0] A_ = -2.5 * numpy.log10(A_) # A_ = sncosmo._extinction.ccm89(lambdas, 1.37, rv) - sncosmo._extinction.ccm89(numpy.array([5477.]), 1.37, rv)[0] # norm = sncosmo._extinction.ccm89(numpy.array([5477.]), 1., rv) # A_ = A_/norm[0]-1 plt.plot(lambdas, A_, label=r"Amanullah et al. (2014)") plt.legend() plt.xlim((3200, 8000)) plt.ylim((-2, 3)) plt.ylabel(r'$E_o(X-V)$') plt.xlabel(r'Wavelength (\AA)') pp = PdfPages('output11/sn2014j.pdf') plt.savefig(pp, format='pdf')
names168 = [line.split()[0] for line in open('table.txt')] dic_meta = cPickle.load(open("CABALLOv2/META.pkl")) ans = [] for sn in names168: meta = dic_meta[sn] for nm in meta['spectra']: spec = meta['spectra'][nm] if abs(spec['salt2.phase']) < 2.5: name = "CABALLOv2/" + spec['idr.spec_merged'] spectra = read_fits.read_fits_spectrum1d( name, dispersion_unit='angstrom') model0 = sncosmo.TimeSeriesSource(numpy.array([0.,1,2]), spectra.dispersion.value/(1+meta['salt2.Redshift']), \ numpy.tile(spectra.flux.value,(3,1))) dust = sncosmo.F99Dust(r_v=2.5) dust.set(ebv=0.01) model = sncosmo.Model(source=model0, effects=[dust], effect_names=['host'], effect_frames=['rest']) try: A = -2.5 * numpy.log10( model.bandflux(synbands, 0.) / model0.bandflux(synbands, 0.)) ans.append(A[1] / (A[0] - A[1])) except: pass ans = numpy.array(ans)
import glob import argparse from collections import OrderedDict import numpy as np import sncosmo delim = 61 * "-" # test data ndata = 100 # make divisible by 4! dates = np.linspace(-15., 40., ndata) bands = np.array((ndata // 4) * ['desg', 'desr', 'desi', 'sdssg']) niter = 100 # models f99dust = sncosmo.F99Dust(3.1) models = OrderedDict([('salt2', sncosmo.Model(source='salt2')), ('hsiao', sncosmo.Model(source='hsiao')), ('salt2+f99dust', sncosmo.Model(source='salt2', effects=[f99dust], effect_names=['mw'], effect_frames=['obs'])), ('hsiao+f99dust', sncosmo.Model(source='hsiao', effects=[f99dust], effect_names=['mw'], effect_frames=['obs']))]) print("\nbandflux(band_array, time_array) [4 des bands]:") print(delim)
rvs.append(r) avs = numpy.array(avs) ebvs = numpy.array(ebvs) AX = numpy.array(AX) rvs = numpy.array(rvs) data = {'D': avs.size, 'AV': avs, 'EBV': ebvs, 'AX': AX} av_ = numpy.array([0.01, 0.01, 0.01 + 1e-4]) ebv_ = numpy.array([0.01 / 2.5, 0.01 / 2.5 + 1e-4, 0.01 / 2.5]) rv_ = av_ / ebv_ ans_ = [] for av0, ebv0, rv0 in zip(av_, ebv_, rv_): dust = sncosmo.F99Dust(r_v=rv0) dust.set(ebv=ebv0) model = sncosmo.Model(source=snmod, effects=[dust], effect_names=['host'], effect_frames=['rest']) ans_.append(2.5 * numpy.log10(model.bandflux(synbands, 0.))) ans_ = numpy.array(ans_) dum1 = (ans_[0] - ans_[2]) / 1e-4 dum2 = (ans_[0] - ans_[1]) / 1e-4 init1 = { 'a': numpy.array([
def bump_model(dust_type): model = sncosmo.Model(BumpSource(), effect_names=['host','mw'], effect_frames=['rest','obs'], effects=[dust_type(), sncosmo.F99Dust()]) return model
def test_add_effect(self): nparams = len(self.model.parameters) self.model.add_effect(sncosmo.F99Dust(), 'host', 'rest') assert len(self.model.effects) == 2 assert 'hostebv' in self.model.param_names assert len(self.model.parameters) == nparams + 1
separate, collective sets. Function Documentation ---------------------- """ from copy import deepcopy import numpy as np import sncosmo from astropy.table import Table from matplotlib import pyplot from . import utils DUST = sncosmo.F99Dust() def create_empty_table(parameters, **kwargs): """Create an empty table for storing fit results Columns: - obj_id - band - source - pre_max - post_max - num_params - *parameters - *parameters + _err - chisq
matplotlib.use('Agg') from copy import copy import sncosmo import numpy as np from bolomc import bump from bolomc import burns from bolomc.distributions import TruncNorm lc = sncosmo.read_lc('../data/CSP_Photometry_DR2/SN2005elopt+nir_photo.dat', format='csp') model = sncosmo.Model(bump.BumpSource(), effect_names=['host', 'mw'], effect_frames=['rest', 'obs'], effects=[sncosmo.OD94Dust(), sncosmo.F99Dust()]) model2 = copy(model) model2.set( UV_bump_amp=1., #blue_bump_amp=0.2, blue_bump_amp=-0.2, i1_bump_amp=0.1, i2_bump_amp=-0.2, y1_bump_amp=-0.2, y2_bump_amp=0.2, y3_bump_amp=-0.1, j1_bump_amp=-0.2, j2_bump_amp=0.2, h1_bump_amp=-0.2, h2_bump_amp=0.2, k1_bump_amp=-0.2,