@@ -0,0 +1,1731 @@
+#- Utility functions for testing%0A%0Afrom __future__ import division, print_function%0A%0Aimport numpy as np%0Aimport scipy.sparse%0A%0Afrom redrock.dataobj import Template, Spectrum, Target%0A%0Adef get_template():%0A    '''%0A    Returns fake template PCA eigenvectors to use for testing%0A    '''%0A    redshifts = np.linspace(0, 1, 20)%0A    wave = np.arange(1000, 9001, 5)%0A    flux = np.zeros((3, len(wave)))%0A    flux%5B0%5D = 1.0%0A    flux%5B1%5D = np.arange(len(wave)) / len(wave)%0A    flux%5B2%5D = np.exp(-(wave-4000)**2/(2*20**2))%0A    %0A    return Template('test', redshifts, wave, flux)%0A    %0Adef get_target(z=0.5):%0A    '''Returns a fake target at redshift z to use for testing'''%0A    template = get_template()%0A    c = np.random.normal(size=template.nbasis)%0A    c = %5B1,2,3%5D%0A    spectra = list()%0A    for wave in %5Bnp.arange(4000, 6700, 5), np.arange(6502, 9001, 5)%5D:%0A        flux = template.eval(c, wave, z)%0A        sigma = np.random.normal(loc=1, scale=0.1, size=len(wave)).clip(0.5, 1.5)%0A        ivar = 1/sigma**2%0A        R = _getR(len(wave), 2.0)%0A        for i in range(2):%0A            noisyflux = flux + np.random.normal(scale=sigma)%0A            spectra.append(Spectrum(wave, noisyflux, ivar, R))%0A%0A    return Target(123, spectra)%0A%0A#- Return a normalized sampled Gaussian (no integration, just sampling)%0Adef _norm_gauss(x, sigma):%0A    y = np.exp(-x**2/(2.0*sigma))%0A    return y / np.sum(y)%0A%0A#- Utility function to create a resolution matrix with a given sigma in pixel units%0Adef _getR(n, sigma):%0A    '''Returns a (n,n) sized sparse Resolution matrix with constant sigma'''%0A    x = np.arange(-5, 6)%0A    y = _norm_gauss(x, sigma)%0A    data = np.zeros((11, n))%0A    for i in range(n):%0A        data%5B:,i%5D = y%0A    return scipy.sparse.dia_matrix((data, x), shape=(n,n))%0A%0A

add missing util.py