def test_ccds_generator_does_not_support_overwrite(self, triage_setup): """ CCDData objects have several attributes that make it hard to reliably support overwriting. For example in what extension should mask, uncertainty be written? Also CCDData doesn't explicitly support in-place operations so it's to easy to create a new CCDData object inadvertantly and all modifications might be lost. """ ic = ImageFileCollection(triage_setup.test_dir) with pytest.raises(NotImplementedError): ic.ccds(overwrite=True) with pytest.raises(NotImplementedError): ic.ccds(clobber=True)
def test_multiple_extensions(self, triage_setup, extension): ext1 = fits.PrimaryHDU() ext1.data = np.arange(1, 5) # It is important than the name used for this test extension # NOT be MASK or UNCERT because both are treated in a special # way by the FITS reader. test_ext_name = 'TESTEXT' ext2 = fits.ImageHDU(name=test_ext_name) ext2.data = np.arange(6, 10) hdulist = fits.hdu.hdulist.HDUList([ext1, ext2]) hdulist.writeto(os.path.join(triage_setup.test_dir, 'multi-extension.fits')) ic2 = ImageFileCollection( triage_setup.test_dir, keywords='*', filenames=['multi-extension.fits'], ext=extension) ic1 = ImageFileCollection( triage_setup.test_dir, keywords='*', filenames=['multi-extension.fits'], ext=0) assert ic1.ext == 0 assert ic2.ext == extension column2 = ic2.summary.colnames column1 = ic1.summary.colnames assert column1 != column2 list1 = [key.lower() for key in ext2.header] list2 = ic2.summary.colnames[1:] assert list1 == list2 ccd_kwargs = {'unit': 'adu'} for data, hdr, hdu, ccd in zip(ic2.data(), ic2.headers(), ic2.hdus(), ic2.ccds(ccd_kwargs)): np.testing.assert_array_equal(data, ext2.data) assert hdr == ext2.header # Now compare that the generators each give the same stuff np.testing.assert_array_equal(data, ccd.data) np.testing.assert_array_equal(data, hdu.data) assert hdr == hdu.header assert hdr == ccd.meta
def test_ccds_generator_in_different_directory(self, triage_setup, tmpdir): """ Regression test for https://github.com/astropy/ccdproc/issues/421 in which the ccds generator fails if the current working directory is not the location of the ImageFileCollection. """ coll = ImageFileCollection(triage_setup.test_dir) # The temporary directory below should be different that the collection # location. os.chdir(tmpdir.strpath) # Let's make sure it is. assert not os.path.samefile(os.getcwd(), coll.location) # This generated an IOError before the issue was fixed. for _ in coll.ccds(ccd_kwargs={'unit': 'adu'}): pass
def test_generator_ccds(self, triage_setup): collection = ImageFileCollection( location=triage_setup.test_dir, keywords=['imagetyp']) ccd_kwargs = {'unit': 'adu'} for ccd in collection.ccds(ccd_kwargs=ccd_kwargs): assert isinstance(ccd, CCDData)
def test_generator_ccds_without_unit(self, triage_setup): collection = ImageFileCollection( location=triage_setup.test_dir, keywords=['imagetyp']) with pytest.raises(ValueError): ccd = next(collection.ccds())