def task(lamb, f, e, m, fm, extLaw, **kwargs): """ Shortcut to compute the log likelihood of the SED with the models for a given extinction parameter set. INPUTS: lamb np.ndarray[float, ndim=1] array of wavelengths in AA f np.ndarray[float, ndim=1] array of fluxes e np.ndarray[float, ndim=1] array of flux errors m np.ndarray[bool, ndim=1] mask array to apply during the calculations mask.shape = flux.shape fm np.ndarray[float, ndim=2] array of modeled fluxes (Nfilters , Nmodels) extLaw extinction.ExtinctionLaw instance of extinction law KEYWORDS: **kwargs is forwarded to the getFluxAttenuation call OUTPUTS: ln(L) np.ndarray[float, ndim=1] array of ln(L) values (Nmodels) Note: this function is a copy of anased.job for clarity of the computations """ # get attetuation values #tau = extLaw.function( lamb * 1e-4, Alambda = False, **kwargs) tau = getFluxAttenuation(extLaw, lamb, **kwargs) #deredden the observed flux (faster than adding reddening to all models deredflux = f*exp(tau) #compute lnp lnp = computeLogLikelihood(deredflux, e, fm, normed=False, mask=m) return lnp
def generateFakeData(filters=filters, output='example.obs.csv', N=20, Av_min=0., Av_max=3., Rv=3.1, err=0.05): """ Function that generates fake data from the grid of models """ from anased import grid from anased.extinction import Cardelli from anased import getFluxAttenuation from anased.tools.vega import Vega import numpy with Vega() as v: vega_f, vega_mag, lamb = v.getMag(filters) g = grid.FileSpectralGrid('anased/libs/PHATSEDs_basel_padovaiso.fits') oAv = Cardelli() lamb = g.lamb fakein = numpy.random.randint(0, g.grid.nrows, N) Av0 = numpy.random.uniform(Av_min, Av_max, N) magerr = numpy.array( [0.05]*len(filters) ) d = g.grid[fakein] d.addCol(Av0, name='Av0') d.addCol(fakein, name='modelId') fakemag = numpy.empty((N, len(filters)),dtype=float) for k in range(N): fakesed = numpy.copy(g.seds[fakein[k],:]) tau = getFluxAttenuation(oAv, lamb, Av = Av0[k], Rv = Rv) fakesed *= exp(-tau) fakemag[k,:] = -2.5*numpy.log10(fakesed) - vega_mag for k in range(len(filters)): d.addCol( fakemag[:,k] , name=filters[k] ) d.addCol( err*numpy.ones(N,dtype=float), name=filters[k]+'err' ) d.header['NAME'] = 'Fake data' d.header['COMMENT'] = 'values are in Vega Magnitudes' d.write(output)