Beispiel #1
0
    def test_compare_gpu(self):
        psfdata = self.psfdata
        meta = psfdata['PSF'].meta
        wavelengths = np.linspace(meta['WAVEMIN'], meta['WAVEMAX'], 30)
        psfparams = evalcoeffs(psfdata, wavelengths)

        psfparams_gpu = gpu_evalcoeffs(psfdata, wavelengths)

        self.assertTrue(np.allclose(psfparams['X'], psfparams_gpu['X']))
        self.assertTrue(np.allclose(psfparams['Y'], psfparams_gpu['Y']))

        common_keys = set(psfparams.keys() & set(psfparams_gpu.keys()))
        self.assertTrue(len(common_keys) > 0)

        for key in common_keys:
            # print(f'Comparing {key}')
            ok = np.allclose(psfparams[key], psfparams_gpu[key])
            self.assertTrue(ok, key)

        for i in range(psfparams['GH'].shape[0]):
            for j in range(psfparams['GH'].shape[1]):
                # print(f'Comparing GH-{i}-{j}')
                ok = np.allclose(psfparams['GH'][i, j], psfparams_gpu['GH'][i,
                                                                            j])
                self.assertTrue(ok, f'GH-{i}-{j}')
Beispiel #2
0
    def test_compare_specter(self):
        #- gpu_specter version
        psfdata = self.psfdata
        meta = psfdata['PSF'].meta
        wavelengths = np.linspace(meta['WAVEMIN'], meta['WAVEMAX'], 30)
        psfparams = evalcoeffs(psfdata, wavelengths)

        #- specter version
        psf = specter.psf.load_psf(self.psffile)
        iispec = np.arange(500)

        # print('Comparing X and Y')
        self.assertTrue(np.allclose(psf.x(iispec, wavelengths),
                                    psfparams['X']))
        self.assertTrue(np.allclose(psf.y(iispec, wavelengths),
                                    psfparams['Y']))

        common_keys = sorted(set(psfparams.keys()) & set(psf.coeff.keys()))
        self.assertTrue(len(common_keys) > 0)

        for key in common_keys:
            # print(f'Comparing {key}')
            ok = np.allclose(psfparams[key],
                             psf.coeff[key].eval(iispec, wavelengths))
            self.assertTrue(ok, key)

        for i in range(psfparams['GH'].shape[0]):
            for j in range(psfparams['GH'].shape[1]):
                # print(f'Comparing GH-{i}-{j}')
                ok = np.allclose(
                    psfparams['GH'][i, j],
                    psf.coeff[f'GH-{i}-{j}'].eval(iispec, wavelengths))
                self.assertTrue(ok, f'GH-{i}-{j}')
Beispiel #3
0
 def setUpClass(cls):
     cls.psffile = find_test_file('psf')
     cls.psfdata = read_psf(cls.psffile)
     meta = cls.psfdata['PSF'].meta
     nwave = 15
     cls.wavelengths = np.linspace(meta['WAVEMIN'] + 100,
                                   meta['WAVEMAX'] - 100, nwave)
     cls.psfparams = evalcoeffs(cls.psfdata, cls.wavelengths)
Beispiel #4
0
 def setUpClass(cls):
     cls.psffile = pkg_resources.resource_filename(
         'gpu_specter', 'test/data/psf-r0-00051060.fits')
     cls.psfdata = read_psf(cls.psffile)
     meta = cls.psfdata['PSF'].meta
     nwave = 15
     cls.wavelengths = np.linspace(meta['WAVEMIN'] + 100,
                                   meta['WAVEMAX'] - 100, nwave)
     cls.psfparams = evalcoeffs(cls.psfdata, cls.wavelengths)
Beispiel #5
0
    def test_basics(self):
        psfdata = self.psfdata
        for key in ('XTRACE', 'YTRACE', 'PSF'):
            self.assertTrue(key in psfdata.keys(), f'{key} is not in psfdata')
            meta = psfdata[key].meta
            self.assertTrue('WAVEMIN' in meta.keys(),
                            f'{key}.meta missing WAVEMIN')
            self.assertTrue('WAVEMAX' in meta.keys(),
                            f'{key}.meta missing WAVEMAX')

        #- wavelengths outside original range are allowed
        meta = psfdata['PSF'].meta
        nspec = psfdata['PSF']['COEFF'].shape[1]
        nwave = 30
        wavelengths = np.linspace(meta['WAVEMIN'] - 10, meta['WAVEMAX'] + 10,
                                  nwave)
        psfparams = evalcoeffs(psfdata, wavelengths)
        self.assertEqual(psfparams['X'].shape, (nspec, nwave))
        psfparams = evalcoeffs(psfdata, wavelengths, specmin=0, nspec=25)
        self.assertEqual(psfparams['X'].shape, (25, nwave))
        psfparams = evalcoeffs(psfdata, wavelengths, specmin=25, nspec=5)
        self.assertEqual(psfparams['Y'].shape, (5, nwave))
Beispiel #6
0
    def test_compare_gpu(self):
        psfdata = self.psfdata
        meta = psfdata['PSF'].meta
        wavelengths = np.linspace(meta['WAVEMIN'], meta['WAVEMAX'], 30)
        psfparams = evalcoeffs(psfdata, wavelengths)

        psfparams_gpu = gpu_evalcoeffs(psfdata, wavelengths)

        self.assertTrue(
            np.array_equal(psfparams['X'], cp.asnumpy(psfparams_gpu['X'])))
        self.assertTrue(
            np.array_equal(psfparams['Y'], cp.asnumpy(psfparams_gpu['Y'])))

        common_keys = set(psfparams.keys() & set(psfparams_gpu.keys()))
        self.assertTrue(len(common_keys) > 0)

        eps_double = np.finfo(np.float64).eps

        for key in common_keys:
            # print(f'Comparing {key}')
            if key == 'GH':
                continue
            ok = np.allclose(psfparams[key],
                             cp.asnumpy(psfparams_gpu[key]),
                             rtol=1e2 * eps_double,
                             atol=0)
            self.assertTrue(ok, key)

        for i in range(psfparams['GH'].shape[0]):
            for j in range(psfparams['GH'].shape[1]):
                # print(f'Comparing GH-{i}-{j}')
                ok = np.allclose(psfparams['GH'][i, j],
                                 cp.asnumpy(psfparams_gpu['GH'][i, j]),
                                 rtol=1e5 * eps_double,
                                 atol=0)
                self.assertTrue(ok, f'GH-{i}-{j}')