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)
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)
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')