Exemple #1
0
    def test_readwrite_tractor(self):
        tractorfile = io.list_tractorfiles(self.datadir)[0]
        sweepfile = io.list_sweepfiles(self.datadir)[0]
        data = io.read_tractor(sweepfile)
        self.assertEqual(len(data), 6)  # - test data has 6 objects per file
        data = io.read_tractor(tractorfile)
        self.assertEqual(len(data), 6)  # - test data has 6 objects per file
        data, hdr = io.read_tractor(tractorfile, header=True)
        self.assertEqual(len(data), 6)  # - test data has 6 objects per file

        # ADM check that input and output columns are the same.
        _, filename = io.write_targets(self.testdir, data, indir=self.datadir)
        # ADM use fits read wrapper in io to correctly handle whitespace.
        d2, h2 = io.whitespace_fits_read(filename, header=True)
        self.assertEqual(list(data.dtype.names), list(d2.dtype.names))

        # ADM check HPXPIXEL got added writing targets with NSIDE request.
        _, filename = io.write_targets(self.testdir,
                                       data,
                                       nside=64,
                                       indir=self.datadir)
        # ADM use fits read wrapper in io to correctly handle whitespace.
        d2, h2 = io.whitespace_fits_read(filename, header=True)
        self.assertEqual(
            list(data.dtype.names) + ["HPXPIXEL"], list(d2.dtype.names))
        for column in data.dtype.names:
            kind = data[column].dtype.kind
            # ADM whitespace_fits_read() doesn't convert string data
            # ADM types identically for every version of fitsio.
            if kind == 'U' or kind == 'S':
                self.assertTrue(
                    np.all(
                        data[column] == d2[column].astype(data[column].dtype)))
            else:
                self.assertTrue(np.all(data[column] == d2[column]))
Exemple #2
0
    def test_readwrite_tractor(self):
        tractorfile = io.list_tractorfiles(self.datadir)[0]
        sweepfile = io.list_sweepfiles(self.datadir)[0]
        data = io.read_tractor(sweepfile)
        self.assertEqual(len(data), 6)  #- test data has 6 objects per file
        data = io.read_tractor(tractorfile)
        self.assertEqual(len(data), 6)  #- test data has 6 objects per file
        data, hdr = io.read_tractor(tractorfile, header=True)
        self.assertEqual(len(data), 6)  #- test data has 6 objects per file

        #ADM check PHOTSYS got added in writing targets
        io.write_targets(self.testfile, data, indir=self.datadir)
        #ADM use fits read wrapper in io to correctly handle whitespace
        d2, h2 = io.whitespace_fits_read(self.testfile, header=True)
        self.assertEqual(
            list(data.dtype.names) + ["PHOTSYS"], list(d2.dtype.names))

        #ADM check PHOTSYS and HPXPIXEL got added writing targets with NSIDE request
        io.write_targets(self.testfile, data, nside=64, indir=self.datadir)
        #ADM use fits read wrapper in io to correctly handle whitespace
        d2, h2 = io.whitespace_fits_read(self.testfile, header=True)
        self.assertEqual(
            list(data.dtype.names) + ["HPXPIXEL", "PHOTSYS"],
            list(d2.dtype.names))

        for column in data.dtype.names:
            self.assertTrue(np.all(data[column] == d2[column]))