def test_wcs_keyword_removal_for_wcs_test_files(): """ Test, for the WCS test files, that keyword removall works as expected. Those cover a much broader range of WCS types than test_wcs_keywords_removed_from_header """ from astropy.nddata.ccddata import _generate_wcs_and_update_header from astropy.nddata.ccddata import _KEEP_THESE_KEYWORDS_IN_HEADER keepers = set(_KEEP_THESE_KEYWORDS_IN_HEADER) wcs_headers = get_pkg_data_filenames('../../wcs/tests/data', pattern='*.hdr') for hdr in wcs_headers: # Skip the files that are expected to be bad... if 'invalid' in hdr or 'nonstandard' in hdr or 'segfault' in hdr: continue header_string = get_pkg_data_contents(hdr) wcs = WCS(header_string) header = wcs.to_header(relax=True) new_header, new_wcs = _generate_wcs_and_update_header(header) # Make sure all of the WCS-related keywords have been removed. assert not (set(new_header) & set(new_wcs.to_header(relax=True)) - keepers) # Check that the new wcs is the same as the old. new_wcs_header = new_wcs.to_header(relax=True) for k, v in new_wcs_header.items(): if isinstance(v, str): assert header[k] == v else: np.testing.assert_almost_equal(header[k], v)
def test_wcs_keyword_removal_for_wcs_test_files(): """ Test, for the WCS test files, that keyword removall works as expected. Those cover a much broader range of WCS types than test_wcs_keywords_removed_from_header """ from astropy.nddata.ccddata import _generate_wcs_and_update_header from astropy.nddata.ccddata import _KEEP_THESE_KEYWORDS_IN_HEADER keepers = set(_KEEP_THESE_KEYWORDS_IN_HEADER) wcs_headers = get_pkg_data_filenames('../../wcs/tests/data', pattern='*.hdr') for hdr in wcs_headers: # Skip the files that are expected to be bad... if 'invalid' in hdr or 'nonstandard' in hdr or 'segfault' in hdr: continue header_string = get_pkg_data_contents(hdr) wcs = WCS(header_string) header = wcs.to_header(relax=True) new_header, new_wcs = _generate_wcs_and_update_header(header) # Make sure all of the WCS-related keywords have been removed. assert not (set(new_header) & set(new_wcs.to_header(relax=True)) - keepers) # Check that the new wcs is the same as the old. new_wcs_header = new_wcs.to_header(relax=True) for k, v in new_wcs_header.items(): if isinstance(v, str): assert header[k] == v else: np.testing.assert_almost_equal(header[k], v)
def test_wcs_keyword_removal_for_wcs_test_files(): """ Test, for the WCS test files, that keyword removal works as expected. Those cover a much broader range of WCS types than test_wcs_keywords_removed_from_header. Includes regression test for #8597 """ from astropy.nddata.ccddata import _generate_wcs_and_update_header from astropy.nddata.ccddata import (_KEEP_THESE_KEYWORDS_IN_HEADER, _CDs, _PCs) keepers = set(_KEEP_THESE_KEYWORDS_IN_HEADER) wcs_headers = get_pkg_data_filenames('../../wcs/tests/data', pattern='*.hdr') for hdr in wcs_headers: # Skip the files that are expected to be bad... if ('invalid' in hdr or 'nonstandard' in hdr or 'segfault' in hdr or 'chandra-pixlist-wcs' in hdr): continue header_string = get_pkg_data_contents(hdr) header = fits.Header.fromstring(header_string) wcs = WCS(header_string) header_from_wcs = wcs.to_header(relax=True) new_header, new_wcs = _generate_wcs_and_update_header(header) new_wcs_header = new_wcs.to_header(relax=True) # Make sure all of the WCS-related keywords generated by astropy # have been removed. assert not (set(new_header) & set(new_wcs_header) - keepers) # Check that new_header contains no remaining WCS information. # Specifically, check that # 1. The combination of new_header and new_wcs does not contain # both PCi_j and CDi_j keywords. See #8597. # Check for 1 final_header = new_header + new_wcs_header final_header_set = set(final_header) if _PCs & final_header_set: assert not (_CDs & final_header_set) elif _CDs & final_header_set: assert not (_PCs & final_header_set) # Check that the new wcs is the same as the old. for k, v in new_wcs_header.items(): if isinstance(v, str): assert header_from_wcs[k] == v else: np.testing.assert_almost_equal(header_from_wcs[k], v)
def test_hdul_fromstring(self): """ Test creating the HDUList structure in memory from a string containing an entire FITS file. This is similar to test_hdu_fromstring but for an entire multi-extension FITS file at once. """ # Tests HDUList.fromstring for all of Astropy's built in test files def test_fromstring(filename): with fits.open(filename) as hdul: orig_info = hdul.info(output=False) with open(filename, 'rb') as f: dat = f.read() hdul2 = fits.HDUList.fromstring(dat) assert orig_info == hdul2.info(output=False) for idx in range(len(hdul)): assert hdul[idx].header == hdul2[idx].header if hdul[idx].data is None or hdul2[idx].data is None: assert hdul[idx].data == hdul2[idx].data elif (hdul[idx].data.dtype.fields and hdul2[idx].data.dtype.fields): # Compare tables for n in hdul[idx].data.names: c1 = hdul[idx].data[n] c2 = hdul2[idx].data[n] assert (c1 == c2).all() elif (any(dim == 0 for dim in hdul[idx].data.shape) or any(dim == 0 for dim in hdul2[idx].data.shape)): # For some reason some combinations of Python and Numpy # on Windows result in MemoryErrors when trying to work # on memmap arrays with more than one dimension but # some dimensions of size zero, so include a special # case for that return hdul[idx].data.shape == hdul2[idx].data.shape else: np.testing.assert_array_equal(hdul[idx].data, hdul2[idx].data) for filename in get_pkg_data_filenames('data', pattern='*.fits'): if sys.platform == 'win32' and filename.endswith('zerowidth.fits'): # Running this test on this file causes a crash in some # versions of Numpy on Windows. See ticket: # https://aeon.stsci.edu/ssb/trac/pyfits/ticket/174 continue elif filename.endswith( ('variable_length_table.fits', 'theap-gap.fits')): # Comparing variable length arrays is non-trivial and thus # skipped at this point. # TODO: That's probably possible, so one could make it work. continue test_fromstring(filename) # Test that creating an HDUList from something silly raises a TypeError pytest.raises(TypeError, fits.HDUList.fromstring, ['a', 'b', 'c'])
def test_wcs_keyword_removal_for_wcs_test_files(): """ Test, for the WCS test files, that keyword removal works as expected. Those cover a much broader range of WCS types than test_wcs_keywords_removed_from_header. Includes regression test for #8597 """ from astropy.nddata.ccddata import _generate_wcs_and_update_header from astropy.nddata.ccddata import (_KEEP_THESE_KEYWORDS_IN_HEADER, _CDs, _PCs) keepers = set(_KEEP_THESE_KEYWORDS_IN_HEADER) wcs_headers = get_pkg_data_filenames('../../wcs/tests/data', pattern='*.hdr') for hdr in wcs_headers: # Skip the files that are expected to be bad... if 'invalid' in hdr or 'nonstandard' in hdr or 'segfault' in hdr: continue header_string = get_pkg_data_contents(hdr) header = fits.Header.fromstring(header_string) wcs = WCS(header_string) header_from_wcs = wcs.to_header(relax=True) new_header, new_wcs = _generate_wcs_and_update_header(header) new_wcs_header = new_wcs.to_header(relax=True) # Make sure all of the WCS-related keywords generated by astropy # have been removed. assert not (set(new_header) & set(new_wcs_header) - keepers) # Check that new_header contains no remaining WCS information. # Specifically, check that # 1. The combination of new_header and new_wcs does not contain # both PCi_j and CDi_j keywords. See #8597. # Check for 1 final_header = new_header + new_wcs_header final_header_set = set(final_header) if _PCs & final_header_set: assert not (_CDs & final_header_set) elif _CDs & final_header_set: assert not (_PCs & final_header_set) # Check that the new wcs is the same as the old. for k, v in new_wcs_header.items(): if isinstance(v, str): assert header_from_wcs[k] == v else: np.testing.assert_almost_equal(header_from_wcs[k], v)
def copy_ginga_files(verbose=False): """Copy Ginga configuration files to HOME directory. Parameters ---------- verbose : bool Print info to screen. """ # NOTE: There is no need to copy plugins here anymore. # # Copy configuration files. dstpath = os.path.join(_home, '.ginga') if not os.path.exists(dstpath): os.makedirs(dstpath) for filename in get_pkg_data_filenames('config', pattern='*.*'): _do_copy(filename, os.path.join(dstpath, os.path.basename(filename)), verbose=verbose)
def copy_ginga_files(verbose=False): """Copy Ginga configuration files to HOME directory. Parameters ---------- verbose : bool Print info to screen. """ # NOTE: There is no need to copy plugins here anymore. # # Copy configuration files. dstpath = os.path.join(_home, '.ginga') if not os.path.exists(dstpath): os.makedirs(dstpath) for filename in get_pkg_data_filenames('config', pattern='*.*'): _do_copy(filename, os.path.join(dstpath, os.path.basename(filename)), verbose=verbose)
def get_path_to_file(*data_name: str, package=None): """Get path to file. Similar to :func:`~astropy.utils.data.get_pkg_data_filename`, but only gets the path to the file, does not check if the file exists. The package directory must exist. Parameters ---------- *data_name : tuple of str the path, without folder delimiters (which are platform specific) relative to `package`. One of the following: * The name of a directory included in the source distribution. The path is relative to the module calling this function. For example, if calling from ``astropy.pkname``, use ``'data'`` to get the files in ``astropy/pkgname/data``. * Remote URLs are not currently supported. package : str, optional If specified, look for a file relative to the given package, rather than the default of looking relative to the calling module's package. Returns ------- filename : str A file path on the local file system corresponding to the data requested in ``data_name``. """ # TODO more robust system fps = list(get_pkg_data_filenames(".", package=package)) filename = pathlib.Path(fps[0]).parent.joinpath(*data_name) return str(filename)
def setup(self): self._file_list = list(get_pkg_data_filenames("data/spectra", pattern="*.hdr"))
def setup(self): # get the list of the hdr files that we want to test self._file_list = list(get_pkg_data_filenames("data/maps", pattern="*.hdr"))
def test_open_files(): for filename in get_pkg_data_filenames('data', pattern='*.xml'): if filename.endswith('custom_datatype.xml'): continue parse(filename)
def test_read(): # Check that all test files including reference files are readable files = get_pkg_data_filenames('data') for f in files: with open(f) as f: DS9Parser(f.read(), errors='warn')
def test_open_files(): for filename in get_pkg_data_filenames('data', pattern='*.xml'): if filename.endswith('custom_datatype.xml'): continue parse(filename, pedantic=False)
import os import pytest import numpy as np from astropy.utils.data import get_pkg_data_filenames, get_pkg_data_contents from astropy.utils.misc import NumpyRNGContext from astropy import wcs from astropy.wcs.wcs import FITSFixedWarning # use the base name of the file, because everything we yield # will show up in the test name in the pandokia report hdr_map_file_list = [ os.path.basename(fname) for fname in get_pkg_data_filenames("data/maps", pattern="*.hdr") ] # Checking the number of files before reading them in. # OLD COMMENTS: # AFTER we tested with every file that we found, check to see that we # actually have the list we expect. If N=0, we will not have performed # any tests at all. If N < n_data_files, we are missing some files, # so we will have skipped some tests. Without this check, both cases # happen silently! def test_read_map_files(): # how many map files we expect to see n_map_files = 28
def test_read(): # Check that all test files including reference files are readable files = get_pkg_data_filenames('data') for f in files: with open(f) as f: DS9Parser(f.read(), errors='warn')
def test_read(): # Check that all test files including reference files are readable files = get_pkg_data_filenames('data') for f in files: read_ds9(f)
def test_read(): # Check that all test files including reference files are readable files = get_pkg_data_filenames('data') for f in files: read_ds9(f, errors='warn')
def setup(self): # get the list of the hdr files that we want to test self._file_list = list(get_pkg_data_filenames( "data/maps", pattern="*.hdr"))
def setup(self): self._file_list = list(get_pkg_data_filenames("data/spectra", pattern="*.hdr"))
import os import pytest import numpy as np from astropy.utils.data import get_pkg_data_filenames, get_pkg_data_contents from astropy.utils.misc import NumpyRNGContext from astropy import wcs # hdr_map_file_list = list(get_pkg_data_filenames("maps", pattern="*.hdr")) # use the base name of the file, because everything we yield # will show up in the test name in the pandokia report hdr_map_file_list = [os.path.basename(fname) for fname in get_pkg_data_filenames("data/maps", pattern="*.hdr")] # Checking the number of files before reading them in. # OLD COMMENTS: # AFTER we tested with every file that we found, check to see that we # actually have the list we expect. If N=0, we will not have performed # any tests at all. If N < n_data_files, we are missing some files, # so we will have skipped some tests. Without this check, both cases # happen silently! def test_read_map_files(): # how many map files we expect to see n_map_files = 28 assert len(hdr_map_file_list) == n_map_files, (