Ejemplo n.º 1
0
 def test_SNRdocumentPSF(self):
     fwhm_in = 0.3
     pixel_scale = 0.2
     psf_gen = SNRdocumentPSF(fwhm=fwhm_in, pixel_scale=pixel_scale)
     psf = psf_gen._getPSF()
     image = galsim.ImageD(256, 256, scale=pixel_scale)
     image = psf.drawImage(image)
     self.verify_analytic_fwhm(fwhm_in, pixel_scale, image.array)
Ejemplo n.º 2
0
class StarTimer(object):
    def __init__(self, obs_md, seed, nxy=64, pixel_scale=0.2):
        self.psf = SNRdocumentPSF(obs_md.OpsimMetaData['FWHMgeom'])
        self._rng = galsim.UniformDeviate(seed)
        self.nxy = nxy
        self.pixel_scale = pixel_scale

        fratio = 1.234
        obscuration = 0.606
        angles = galsim.FRatioAngles(fratio, obscuration, self._rng)

        self.bandpass = gs_bandpasses(obs_md.bandpass)
        self.sed = galsim.SED(lambda x: 1, 'nm',
                              'flambda').withFlux(1., self.bandpass)
        waves = galsim.WavelengthSampler(sed=self.sed, bandpass=self.bandpass,
                                         rng=self._rng)
        self.surface_ops = (waves, angles)

    def get_sensor(self, nrecalc):
        return galsim.SiliconSensor(rng=self._rng, nrecalc=nrecalc)

    def timing(self, flux, sensor=None):
        point = galsim.DeltaFunction(flux=flux)
        star = galsim.Convolve(point*self.sed, self.psf._getPSF())

        image = galsim.Image(self.nxy, self.nxy)
        surface_ops = self.surface_ops if sensor is not None else ()
        t0 = time.clock()
        image = star.drawImage(method='phot', bandpass=self.bandpass,
                               image=image, scale=self.pixel_scale,
                               rng=self._rng, sensor=sensor,
                               surface_ops=surface_ops)
        return time.clock() - t0

    def flux_loop_timing(self, apply_model, nrecalc=10000, flux_min=10,
                         flux_max=1e5, nflux=8):
        sensor = self.get_sensor(nrecalc) if apply_model else None
        timing = OrderedDict()
        for flux in np.logspace(np.log10(flux_min), np.log10(flux_max), nflux):
            timing[flux] = self.timing(flux, sensor=sensor)
        return timing