def model(st, flux, index, beta, pivot, cutoff, b): if st == 'PowerLaw': return Models.PowerLaw(p=[flux, index], e0=pivot) elif st == 'PLSuperExpCutoff': prefactor = flux * np.exp((pivot / cutoff)**b) return Models.PLSuperExpCutoff(p=[prefactor, index, cutoff, b], e0=pivot) elif st == 'PLExpCutoff': prefactor = flux * np.exp((pivot / cutoff)) return Models.PLSuperExpCutoff( p=[prefactor, index, cutoff, 1.0], e0=pivot) elif st == 'LogParabola': return Models.LogParabola(p=[flux, index, beta, pivot]) elif st == 'PowerLaw2': ### same as PowerLaw in table return Models.PowerLaw(p=[flux, index], e0=pivot) else: raise Exception( 'unexpected spectrum type {}, source name {}'.format( st, name))
def pmodel(source): """ create a pointlike model from a Series object from DataFrame row """ expandbits = lambda x: [(x & 2**i) != 0 for i in range(4)] modelname, freebits, e0, norm, norm_unc, pindex, pindex_unc, index2,index2_unc, cutoff, cutoff_unc=\ [source[x] for x in 'modelname freebits e0 flux flux_unc pindex pindex_unc index2 index2_unc cutoff cutoff_unc'.split()] free = expandbits(freebits) errors = [norm_unc, pindex_unc] if modelname == 'LogParabola': if np.abs(index2) < 2e-3: modelname = 'PowerLaw' model = Models.PowerLaw(p=[norm, pindex], e0=e0) else: # if index2<0: # print 'Source %s has beta (%.2f) <0: setting to 0.' % ( source.name, index2, ) # index2=0 model = Models.LogParabola(p=[norm, pindex, index2, e0]) model.free[-1] = False errors.append(index2_unc) elif modelname == 'PLSuperExpCutoff': prefactor = np.exp(-(e0 / cutoff)**index2) model = Models.PLSuperExpCutoff( p=[norm / prefactor, pindex, cutoff, index2], e0=e0) errors[0] /= prefactor errors += [cutoff_unc, index2_unc] elif modelname == 'ExpCutoff': prefactor = np.exp(-(e0 / cutoff)) model = Models.PLSuperExpCutoff( p=[norm / prefactor, pindex, cutoff, 0.], e0=e0) model.free[3] == False errors[0] /= prefactor errors += [cutoff_unc] else: raise Exception('model "%s" not recognized' % modelname) map(model.set_error, range(len(errors)), errors) model.free[:] = free[:model.len()] return model
def PowerLaw(*pars, **kw): return Models.PowerLaw(p=pars, **kw)
def PowerLaw(*pars): model = Models.PowerLaw(p=pars) sources.set_default_bounds(model) return model
def PowerLaw(*pars): model = Models.PowerLaw(p=pars) return model