def test_local_data_obj(filename): from astropy.utils.data import get_pkg_data_fileobj if (not HAS_BZ2 and 'bz2' in filename) or (not HAS_XZ and 'xz' in filename): with pytest.raises(ValueError) as e: with get_pkg_data_fileobj(os.path.join('data', filename), encoding='binary') as f: f.readline() # assert f.read().rstrip() == b'CONTENT' assert ' format files are not supported' in str(e) else: with get_pkg_data_fileobj(os.path.join('data', filename), encoding='binary') as f: f.readline() assert f.read().rstrip() == b'CONTENT'
def test_local_data_obj(filename): from astropy.utils.data import get_pkg_data_fileobj if (not HAS_BZ2 and 'bz2' in filename) or (not HAS_XZ and 'xz' in filename): with pytest.raises(ValueError) as e: with get_pkg_data_fileobj(os.path.join('data', filename), encoding='binary') as f: f.readline() # assert f.read().rstrip() == b'CONTENT' assert ' format files are not supported' in str(e) else: with get_pkg_data_fileobj(os.path.join('data', filename), encoding='binary') as f: f.readline() assert f.read().rstrip() == b'CONTENT'
def test_read_through_table_interface2(): from astropy.table import Table with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd: t = Table.read(fd, format='votable', table_id='last_table') assert len(t) == 0
def test_read_through_table_interface2(): with np.errstate(over="ignore"): # https://github.com/astropy/astropy/issues/13341 with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd: t = Table.read(fd, format='votable', table_id='last_table') assert len(t) == 0
def test_header_parse(): from astropy.io import fits with get_pkg_data_fileobj( 'data/header_newlines.fits', encoding='binary') as test_file: hdulist = fits.open(test_file) w = wcs.WCS(hdulist[0].header) assert w.wcs.ctype[0] == 'RA---TAN-SIP'
def test_header_parse(): from astropy.io import fits with get_pkg_data_fileobj('data/header_newlines.fits', encoding='binary') as test_file: hdulist = fits.open(test_file) w = wcs.WCS(hdulist[0].header) assert w.wcs.ctype[0] == 'RA---TAN-SIP'
def test_read_through_table_interface2(): from astropy.table import Table with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd: t = Table.read(fd, format='votable', table_id='last_table') assert len(t) == 0
def test_table_read_with_unnamed_tables(): """ Issue #927 """ with get_pkg_data_fileobj('data/names.xml', encoding='binary') as fd: t = Table.read(fd, format='votable') assert len(t) == 1
def test_explicit_ids(): with get_pkg_data_fileobj('data/names.xml', encoding='binary') as fd: votable = parse(fd) table = votable.get_first_table().to_table(use_names_over_ids=False) assert table.colnames == [ 'col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9', 'col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17']
def test_get_pkg_data_contents(): from astropy.utils.data import get_pkg_data_fileobj, get_pkg_data_contents with get_pkg_data_fileobj('data/local.dat') as f: contents1 = f.read() contents2 = get_pkg_data_contents('data/local.dat') assert contents1 == contents2
def test_explicit_ids(): with get_pkg_data_fileobj('data/names.xml', encoding='binary') as fd: votable = parse(fd) table = votable.get_first_table().to_table(use_names_over_ids=False) assert table.colnames == [ 'col1', 'col2', 'col3', 'col4', 'col5', 'col6', 'col7', 'col8', 'col9', 'col10', 'col11', 'col12', 'col13', 'col14', 'col15', 'col16', 'col17']
def test_get_pkg_data_contents(): from astropy.utils.data import get_pkg_data_fileobj, get_pkg_data_contents with get_pkg_data_fileobj('data/local.dat') as f: contents1 = f.read() contents2 = get_pkg_data_contents('data/local.dat') assert contents1 == contents2
def test_names_over_ids(): with get_pkg_data_fileobj('data/names.xml', encoding='binary') as fd: votable = parse(fd) table = votable.get_first_table().to_table(use_names_over_ids=True) assert table.colnames == [ 'Name', 'GLON', 'GLAT', 'RAdeg', 'DEdeg', 'Jmag', 'Hmag', 'Kmag', 'G3.6mag', 'G4.5mag', 'G5.8mag', 'G8.0mag', '4.5mag', '8.0mag', 'Emag', '24mag', 'f_Name']
def test_names_over_ids(): with get_pkg_data_fileobj('data/names.xml', encoding='binary') as fd: votable = parse(fd) table = votable.get_first_table().to_table(use_names_over_ids=True) assert table.colnames == [ 'Name', 'GLON', 'GLAT', 'RAdeg', 'DEdeg', 'Jmag', 'Hmag', 'Kmag', 'G3.6mag', 'G4.5mag', 'G5.8mag', 'G8.0mag', '4.5mag', '8.0mag', 'Emag', '24mag', 'f_Name']
def test_table_read_with_unnamed_tables(): """ Issue #927 """ from astropy.table import Table with get_pkg_data_fileobj('data/names.xml', encoding='binary') as fd: t = Table.read(fd, format='votable') assert len(t) == 1
def test_sip2(): with get_pkg_data_fileobj(os.path.join("data", "sip2.fits"), encoding='binary') as test_file: hdulist = fits.open(test_file, ignore_missing_end=True) wcs1 = wcs.WCS(hdulist[0].header) assert wcs1.sip is not None s = pickle.dumps(wcs1) wcs2 = pickle.loads(s) with NumpyRNGContext(123456789): x = np.random.rand(2**16, wcs1.wcs.naxis) world1 = wcs1.all_pix2world(x, 1) world2 = wcs2.all_pix2world(x, 1) assert_array_almost_equal(world1, world2)
def test_read_through_table_interface(tmpdir): from astropy.table import Table with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd: t = Table.read(fd, format='votable', table_id='main_table') assert len(t) == 5 fn = os.path.join(str(tmpdir), "table_interface.xml") t.write(fn, table_id='FOO', format='votable') with open(fn, 'rb') as fd: t2 = Table.read(fd, format='votable', table_id='FOO') assert len(t2) == 5
def test_sip2(): with get_pkg_data_fileobj( os.path.join("data", "sip2.fits"), encoding='binary') as test_file: hdulist = fits.open(test_file, ignore_missing_end=True) wcs1 = wcs.WCS(hdulist[0].header) assert wcs1.sip is not None s = pickle.dumps(wcs1) wcs2 = pickle.loads(s) with NumpyRNGContext(123456789): x = np.random.rand(2 ** 16, wcs1.wcs.naxis) world1 = wcs1.all_pix2world(x, 1) world2 = wcs2.all_pix2world(x, 1) assert_array_almost_equal(world1, world2)
def __init__(self): self._primary = set() self._secondary = set() self._descriptions = {} self._capitalization = {} with data.get_pkg_data_fileobj("data/ucd1p-words.txt", encoding='ascii') as fd: for line in fd.readlines(): type, name, descr = [x.strip() for x in line.split('|')] name_lower = name.lower() if type in 'QPEV': self._primary.add(name_lower) if type in 'QSEV': self._secondary.add(name_lower) self._descriptions[name_lower] = descr self._capitalization[name_lower] = name
def test_dist(): with get_pkg_data_fileobj(os.path.join("data", "dist.fits"), encoding='binary') as test_file: hdulist = fits.open(test_file) # The use of ``AXISCORR`` for D2IM correction has been deprecated with pytest.warns(AstropyDeprecationWarning): wcs1 = wcs.WCS(hdulist[0].header, hdulist) assert wcs1.det2im2 is not None s = pickle.dumps(wcs1) wcs2 = pickle.loads(s) with NumpyRNGContext(123456789): x = np.random.rand(2**16, wcs1.wcs.naxis) world1 = wcs1.all_pix2world(x, 1) world2 = wcs2.all_pix2world(x, 1) assert_array_almost_equal(world1, world2)
def __init__(self): self._primary = set() self._secondary = set() self._descriptions = {} self._capitalization = {} with data.get_pkg_data_fileobj( "data/ucd1p-words.txt", encoding='ascii') as fd: for line in fd.readlines(): type, name, descr = [ x.strip() for x in line.split('|')] name_lower = name.lower() if type in 'QPEV': self._primary.add(name_lower) if type in 'QSEV': self._secondary.add(name_lower) self._descriptions[name_lower] = descr self._capitalization[name_lower] = name
def test_read_through_table_interface(tmpdir): from astropy.table import Table with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd: t = Table.read(fd, format='votable', table_id='main_table') assert len(t) == 5 # Issue 8354 assert t['float'].format is None fn = os.path.join(str(tmpdir), "table_interface.xml") t.write(fn, table_id='FOO', format='votable') with open(fn, 'rb') as fd: t2 = Table.read(fd, format='votable', table_id='FOO') assert len(t2) == 5
def test_read_through_table_interface(tmpdir): with get_pkg_data_fileobj('data/regression.xml', encoding='binary') as fd: t = Table.read(fd, format='votable', table_id='main_table') assert len(t) == 5 # Issue 8354 assert t['float'].format is None fn = os.path.join(str(tmpdir), "table_interface.xml") # W39: Bit values can not be masked with pytest.warns(W39): t.write(fn, table_id='FOO', format='votable') with open(fn, 'rb') as fd: t2 = Table.read(fd, format='votable', table_id='FOO') assert len(t2) == 5
def test_sali(self): tbls = [] with get_pkg_data_fileobj('hh.sali') as f: d = f.read() blocks = d.split("\n\n") for block in blocks: tbls.append(np.loadtxt(stringio.StringIO(block))) integrator = DOPRI853Integrator(self.F_spec, func_args=self.par) for ii,w0 in enumerate(self.w0s): s, t, ws = sali(w0, integrator, dt=self.dt, nsteps=self.nsteps) plt.clf() plt.loglog(t, s, marker=None) plt.loglog(tbls[ii][:,0], tbls[ii][:,1], marker=None, alpha=0.4) plt.savefig(os.path.join(plot_path,"hh_sali_{}.png".format(ii))) plt.clf() plt.plot(ws[...,0], ws[...,1], marker=None) plt.savefig(os.path.join(plot_path,"hh_orbit_sali_{}.png".format(ii)))