コード例 #1
0
    def test_image_loading_fitshdu(self, disk_cache):
        n = 10
        d = np.ones((10, 10))
        l = [fits.PrimaryHDU(d) for i in range(n)]

        logs = []
        lh = log_to_list(logger, logs, full_record=True)
        comb = ImCombiner(use_disk_cache=disk_cache)
        comb._load_images(l)

        # check if the logging is properly being emitted.
        log = [
            i for i in logs if i.msg == 'The images to combine are not '
            'FrameData. Some features may be disabled.'
        ]
        assert_equal(len(log), 1)
        assert_equal(log[0].levelname, 'WARNING')
        logger.removeHandler(lh)

        assert_equal(len(comb._images), n)
        assert_is_none(comb._buffer)
        for i, v in enumerate(comb._images):
            assert_is_instance(v, FrameData)
            if disk_cache:
                assert_true(v._memmapping)

        comb._clear()
        # must start empty
        assert_equal(len(comb._images), 0)
        assert_is_none(comb._buffer)
コード例 #2
0
 def test_extract_header_nowcs(self):
     header = fits.Header.fromstring(_base_header, sep='\n')
     h, wcs = extract_header_wcs(header)
     assert_is_none(wcs)
     assert_is_instance(h, fits.Header)
     assert_equal(h, header)
     assert_false(h is header)
コード例 #3
0
    def test_image_loading_fitsfile(self, tmpdir, disk_cache):
        tmp = tmpdir.strpath
        n = 10
        d = np.ones((10, 10))
        l = [os.path.join(tmp, f'fits_test{i}') for i in range(n)]
        for f in l:
            fits.PrimaryHDU(d).writeto(f)

        logs = []
        lh = log_to_list(logger, logs, full_record=True)
        comb = ImCombiner(use_disk_cache=disk_cache)
        comb._load_images(l)

        # check if the logging is properly being emitted.
        log = [
            i for i in logs if i.msg == 'The images to combine are not '
            'FrameData. Some features may be disabled.'
        ]
        assert_equal(len(log), 1)
        assert_equal(log[0].levelname, 'WARNING')

        assert_equal(len(comb._images), n)
        assert_is_none(comb._buffer)
        for i, v in enumerate(comb._images):
            assert_is_instance(v, FrameData)
            if disk_cache:
                assert_true(v._memmapping)

        comb._clear()
        # must start empty
        assert_equal(len(comb._images), 0)
        assert_is_none(comb._buffer)
コード例 #4
0
    def test_extract_invalid_wcs_header(self):
        # It should no raise, just return empty wcs
        # No header change too
        header = fits.Header.fromstring(_base_header + _invalid_wcs, sep='\n')
        del header['']
        h, wcs = extract_header_wcs(header)

        assert_is_none(wcs)
        assert_is_instance(h, fits.Header)
        assert_equal(h, header)
        assert_false(h is header)
コード例 #5
0
    def test_image_loading_framedata(self, tmpdir, disk_cache):
        tmp = tmpdir.strpath
        n = 10
        d = np.ones((10, 10))
        l = [
            FrameData(d,
                      unit='adu',
                      uncertainty=d,
                      cache_folder=tmp,
                      cache_filename=f'test{i}') for i in range(n)
        ]

        comb = ImCombiner(use_disk_cache=disk_cache)
        # must start empty
        assert_equal(len(comb._images), 0)
        assert_is_none(comb._buffer)
        comb._load_images(l)
        assert_equal(len(comb._images), n)
        assert_is_none(comb._buffer)
        for i, v in enumerate(comb._images):
            fil = os.path.join(tmp, f'test{i}')
            assert_is_instance(v, FrameData)
            if disk_cache:
                assert_true(v._memmapping)
                # assert_path_exists(fil+'_copy_copy.data')
                # assert_path_exists(fil+'_copy_copy.unct')
                # assert_path_exists(fil+'_copy_copy.mask')

        comb._clear()
        # must start empty
        assert_equal(len(comb._images), 0)
        assert_is_none(comb._buffer)

        # ensure tmp files cleaned
        if disk_cache:
            for i in range(n):
                fil = os.path.join(tmp, f'test{i}')
                assert_path_not_exists(fil + '_copy_copy.data')
                assert_path_not_exists(fil + '_copy_copy.unct')
                assert_path_not_exists(fil + '_copy_copy.mask')
コード例 #6
0
def test_qfloat_unit_property_none():
    # Check None and dimensionless_unscaled
    c = DummyClass(None)
    assert_is_none(c._unit)
    assert_equal(c.unit, units.dimensionless_unscaled)
コード例 #7
0
    def test_chunk_yielder_f32(self):
        # using float32, the number of chunks are almost halved
        n = 100
        d = np.random.random((100, 100)).astype(np.float64)
        l = [FrameData(d, unit='adu') for i in range(n)]
        # data size = 4 000 000 = 4 bytes * 100 * 100 * 100
        # mask size = 1 000 000 = 1 bytes * 100 * 100 * 100
        # total size = 5 000 000

        comb = ImCombiner(max_memory=1e6, dtype=np.float32)
        comb._load_images(l)

        logs = []
        lh = log_to_list(logger, logs, False)
        level = logger.getEffectiveLevel()
        logger.setLevel('DEBUG')

        # for median, tot_size=5*4.5=22.5
        # xstep = 4, so n_chuks=25
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='median'):
            i += 1
            for k in chunk:
                assert_equal(k.shape, (4, 100))
                assert_almost_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 25)
        assert_in('Splitting the images into 25 chunks.', logs)
        logs.clear()

        # for mean and sum, tot_size=5*3=15
        # xstep = 6, so n_chunks=16+1
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='mean'):
            i += 1
            for k in chunk:
                assert_in(k.shape, [(6, 100), (4, 100)])
                assert_almost_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 17)
        assert_in('Splitting the images into 17 chunks.', logs)
        logs.clear()

        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='sum'):
            i += 1
            for k in chunk:
                assert_in(k.shape, [(6, 100), (4, 100)])
                assert_almost_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 17)
        assert_in('Splitting the images into 17 chunks.', logs)
        logs.clear()

        # this should not split into chunks
        comb = ImCombiner(max_memory=1e8, dtype=np.float32)
        comb._load_images(l)
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='median'):
            i += 1
            for k in chunk:
                assert_equal(k.shape, (100, 100))
                assert_almost_equal(k, d)
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 1)
        assert_equal(len(logs), 0)
        logs.clear()

        # this should split in 300 chunks!
        # total_size = 4.5*5e6=22.5e6 = 225 chunks
        # x_step = 1
        # y_step = 45
        comb = ImCombiner(max_memory=1e5, dtype=np.float32)
        comb._load_images(l)
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='median'):
            i += 1
            for k in chunk:
                assert_in(k.shape, ((1, 45), (1, 10)))
                assert_almost_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 300)
        assert_in('Splitting the images into 300 chunks.', logs)
        logs.clear()

        logger.setLevel(level)
        logger.removeHandler(lh)
コード例 #8
0
    def test_chunk_yielder_f64(self):
        n = 100
        d = np.random.random((100, 100)).astype(np.float64)
        l = [FrameData(d, unit='adu') for i in range(n)]
        # data size = 8 000 000 = 8 bytes * 100 * 100 * 100
        # mask size = 1 000 000 = 1 bytes * 100 * 100 * 100
        # total size = 9 000 000

        comb = ImCombiner(max_memory=1e6, dtype=np.float64)
        comb._load_images(l)

        logs = []
        lh = log_to_list(logger, logs, False)
        level = logger.getEffectiveLevel()
        logger.setLevel('DEBUG')

        # for median, tot_size=9*4.5=41
        # xstep = 2, so n_chuks=50
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='median'):
            i += 1
            for k in chunk:
                assert_equal(k.shape, (2, 100))
                assert_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 50)
        assert_in('Splitting the images into 50 chunks.', logs)
        logs.clear()

        # for mean and sum, tot_size=9*3=27
        # xstep = 3, so n_chunks=33+1
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='mean'):
            i += 1
            for k in chunk:
                assert_in(k.shape, [(3, 100), (1, 100)])
                assert_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 34)
        assert_in('Splitting the images into 34 chunks.', logs)
        logs.clear()

        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='sum'):
            i += 1
            for k in chunk:
                assert_in(k.shape, [(3, 100), (1, 100)])
                assert_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 34)
        assert_in('Splitting the images into 34 chunks.', logs)
        logs.clear()

        # this should not split into chunks
        comb = ImCombiner(max_memory=1e8)
        comb._load_images(l)
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='median'):
            i += 1
            for k in chunk:
                assert_equal(k.shape, (100, 100))
                assert_equal(k, d)
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 1)
        assert_equal(len(logs), 0)
        logs.clear()

        # this should split in 400 chunks!
        comb = ImCombiner(max_memory=1e5)
        comb._load_images(l)
        i = 0
        for chunk, unct, slc in comb._chunk_yielder(method='median'):
            i += 1
            for k in chunk:
                assert_equal(k.shape, (1, 25))
                assert_equal(k, d[slc])
                assert_is_none(unct)
                assert_is_instance(k, np.ma.MaskedArray)
        assert_equal(i, 400)
        assert_in('Splitting the images into 400 chunks.', logs)
        logs.clear()

        logger.setLevel(level)
        logger.removeHandler(lh)
コード例 #9
0
 def test_assert_is_none(self):
     a = None
     assert_is_none(a)
     with pytest.raises(AssertionError):
         assert_is_none(1)
コード例 #10
0
 def test_no_uncertainty(self):
     ccd = self.ccd
     ccd.uncertainty = None
     f = _extract_ccddata(ccd)
     assert_is_none(f['uncertainty'])
コード例 #11
0
 def test_no_mask(self):
     ccd = self.ccd
     ccd.mask = None
     f = _extract_ccddata(ccd)
     assert_is_none(f['mask'])