def test_LabelMapperArray_str(tmpdir): a = np.array([["label1", "", "label2"], ["label1", "", ""], ["label1", "label2", "label2"]]) mask = selector.LabelMapperArray(a) tree = {'model': mask} helpers.assert_roundtrip_tree(tree, tmpdir, extensions=GWCSExtension())
def test_assert_roundtrip_with_extension(tmpdir): called_custom_assert_equal = [False] class CustomType(dict, asdftypes.CustomType): name = 'custom_flow' organization = 'nowhere.org' version = (1, 0, 0) standard = 'custom' @classmethod def assert_equal(cls, old, new): called_custom_assert_equal[0] = True class CustomTypeExtension(CustomExtension): @property def types(self): return [CustomType] tree = { 'custom': CustomType({'a': 42, 'b': 43}) } def check(ff): assert isinstance(ff.tree['custom'], CustomType) with pytest.warns(None) as warnings: helpers.assert_roundtrip_tree( tree, tmpdir, extensions=[CustomTypeExtension()]) assert len(warnings) == 0, helpers.display_warnings(warnings) assert called_custom_assert_equal[0] is True
def test_table_inline(tmpdir): table = np.array( [(0, 1, (2, 3)), (4, 5, (6, 7))], dtype=[(str('MINE'), np.int8), (str(''), np.float64), (str('arr'), '>i4', (2,))]) tree = {'table_data': table} def check_raw_yaml(content): tree = yaml.load( re.sub(br'!core/\S+', b'', content)) assert tree['table_data'] == { 'datatype': [ {'datatype': 'int8', 'name': 'MINE'}, {'datatype': 'float64', 'name': 'f1'}, {'datatype': 'int32', 'name': 'arr', 'shape': [2]} ], 'data': [[0, 1.0, [2, 3]], [4, 5.0, [6, 7]]], 'shape': [2] } helpers.assert_roundtrip_tree(tree, tmpdir, raw_yaml_check_func=check_raw_yaml, write_options={'auto_inline': 64})
def test_sharing(tmpdir): x = np.arange(0, 10, dtype=np.float) tree = { 'science_data': x, 'subset': x[3:-3], 'skipping': x[::2] } def check_asdf(asdf): tree = asdf.tree assert_array_equal(tree['science_data'], x) assert_array_equal(tree['subset'], x[3:-3]) assert_array_equal(tree['skipping'], x[::2]) assert tree['science_data'].ctypes.data == tree['skipping'].ctypes.data assert len(list(asdf.blocks.internal_blocks)) == 1 assert next(asdf.blocks.internal_blocks)._size == 80 tree['science_data'][0] = 42 assert tree['skipping'][0] == 42 def check_raw_yaml(content): assert b'!core/ndarray' in content helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check_asdf, raw_yaml_check_func=check_raw_yaml)
def test_frame_from_model(tmpdir): """ Tests creating a frame from a data model. """ # Test CompositeFrame initialization (celestial and spectral) im = _create_model_3d() frame = pointing.frame_from_model(im) radec, lam = frame.coordinates(1, 2, 3) utils.assert_allclose(radec.spherical.lon.value, 1) utils.assert_allclose(radec.spherical.lat.value, 2) assert_quantity_allclose(lam, 3 * u.um) # Test CompositeFrame initialization with custom frames im.meta.wcsinfo.ctype1 = 'ALPHA1A' im.meta.wcsinfo.ctype2 = 'BETA1A' frame = pointing.frame_from_model(im) assert frame.frames[1].name == 'ALPHA1A_BETA1A' assert frame.frames[1].axes_names == ('ALPHA1A', 'BETA1A') tree = {'frame': frame} helpers.assert_roundtrip_tree(tree, tmpdir) # Test 2D spatial custom frame im = _create_model_2d() frame = pointing.frame_from_model(im) assert frame.name == "sky" assert frame.axes_names == ("RA", "DEC") tree = {'frame': frame} helpers.assert_roundtrip_tree(tree, tmpdir)
def test_table_nested_fields(tmpdir): table = np.array( [(0, (1, 2)), (4, (5, 6)), (7, (8, 9))], dtype=[(str('A'), np.int64), (str('B'), [(str('C'), np.int64), (str('D'), np.int64)])]) tree = {'table_data': table} def check_raw_yaml(content): tree = yaml.load( re.sub(br'!core/\S+', b'', content)) assert tree['table_data'] == { 'datatype': [ {'datatype': 'int64', 'name': 'A', 'byteorder': 'little'}, {'datatype': [ {'datatype': 'int64', 'name': 'C', 'byteorder': 'little'}, {'datatype': 'int64', 'name': 'D', 'byteorder': 'little'} ], 'name': 'B', 'byteorder': 'big'}], 'shape': [3], 'source': 0, 'byteorder': 'big' } helpers.assert_roundtrip_tree(tree, tmpdir, raw_yaml_check_func=check_raw_yaml)
def test_frames(tmpdir): tree = { 'frames': create_test_frames() } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_earthlocation_quantity(tmpdir): location = EarthLocation(lat=34.4900*u.deg, lon=-104.221800*u.deg, height=40*u.km) tree = dict(location=location) assert_roundtrip_tree(tree, tmpdir)
def test_string(tmpdir): tree = { 'ascii': np.array([b'foo', b'bar', b'baz']), 'unicode': np.array(['სამეცნიერო', 'данные', 'வடிவம்']) } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_hcrs_basic(tmpdir): ra = Longitude(25, unit=units.deg) dec = Latitude(45, unit=units.deg) tree = {'coord': ICRS(ra=ra, dec=dec)} assert_roundtrip_tree(tree, tmpdir)
def test_table(tmpdir): table = np.array( [(0, 1, (2, 3)), (4, 5, (6, 7))], dtype=[(str('MINE'), np.int8), (str(''), np.float64), (str('arr'), '>i4', (2,))]) tree = {'table_data': table} def check_raw_yaml(content): tree = yaml.load( re.sub(br'!core/\S+', b'', content)) assert tree['table_data'] == { 'datatype': [ {'byteorder': 'big', 'datatype': 'int8', 'name': 'MINE'}, {'byteorder': 'little', 'datatype': 'float64', 'name': 'f1'}, {'byteorder': 'big', 'datatype': 'int32', 'name': 'arr', 'shape': [2]} ], 'shape': [2], 'source': 0, 'byteorder': 'big' } helpers.assert_roundtrip_tree(tree, tmpdir, raw_yaml_check_func=check_raw_yaml)
def test_earthlocation(position, tmpdir): x, y, z = EarthLocation.from_geodetic(*position).to_geocentric() geocentric = EarthLocation(x, y, z) tree = dict(location=geocentric) assert_roundtrip_tree(tree, tmpdir)
def test_icrs_compound(tmpdir): icrs = ICRS(ra=[0, 1, 2]*units.deg, dec=[3, 4, 5]*units.deg) tree = {'coord': icrs} assert_roundtrip_tree(tree, tmpdir)
def test_isot_array(tmpdir): tree = { 'time': time.Time(['2001-01-02T12:34:56', '2001-02-03T00:01:02']) } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_ndarray_mixin(tmpdir): t = table.Table() t['a'] = [1, 2] t['b'] = ['x', 'y'] t['c'] = table.NdarrayMixin([5, 6]) helpers.assert_roundtrip_tree({'table': t}, tmpdir)
def test_complex_structure(tmpdir): with fits.open(os.path.join( os.path.dirname(__file__), 'data', 'complex.fits'), memmap=False) as hdulist: tree = { 'fits': hdulist } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_icrs_basic(tmpdir): wrap_angle = Angle(1.5, unit=units.rad) ra = Longitude(25, unit=units.deg, wrap_angle=wrap_angle) dec = Latitude(45, unit=units.deg) tree = {'coord': ICRS(ra=ra, dec=dec)} assert_roundtrip_tree(tree, tmpdir)
def test_labelMapperArray_int(tmpdir): a = np.array([[1, 0, 2], [1, 0, 0], [1, 2, 2]]) mask = selector.LabelMapperArray(a) tree = {'model': mask} helpers.assert_roundtrip_tree(tree, tmpdir, extensions=GWCSExtension())
def test_simple_object_array(tmpdir): # See https://github.com/spacetelescope/asdf/issues/383 for feature # request dictdata = np.empty((3, 3), dtype=object) for i, _ in enumerate(dictdata.flat): dictdata.flat[i] = {'foo': i*42, 'bar': i**2} helpers.assert_roundtrip_tree({'bizbaz': dictdata}, tmpdir)
def test_timedelta(fmt, tmpdir): t1 = Time(Time.now()) t2 = Time(Time.now()) td = TimeDelta(t2 - t1, format=fmt) tree = dict(timedelta=td) assert_roundtrip_tree(tree, tmpdir)
def test_skycoord_extra_attribute(tmpdir): sc = SkyCoord(10*u.deg, 20*u.deg, equinox="2011-01-01T00:00", frame="fk4") tree = dict(coord=sc.transform_to("icrs")) def check_asdf(asdffile): assert hasattr(asdffile['coord'], 'equinox') assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check_asdf)
def test_roundtrip(tmpdir): tree = { 'a': 0+0j, 'b': 1+1j, 'c': -1+1j, 'd': -1-1j } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_time(tmpdir): time_array = time.Time( np.arange(100), format="unix") tree = { 'large_time_array': time_array } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_isot(tmpdir): tree = { 'time': time.Time('2000-01-01T00:00:00.000') } helpers.assert_roundtrip_tree(tree, tmpdir) ff = asdf.AsdfFile(tree) tree = yamlutil.custom_tree_to_tagged_tree(ff.tree, ff) assert isinstance(tree['time'], str)
def test_earthlocation_mixin(tmpdir): t = table.Table() t['a'] = [1, 2] t['b'] = ['x', 'y'] t['c'] = EarthLocation(x=[1, 2] * u.km, y=[3, 4] * u.km, z=[5, 6] * u.km) def check(ff): assert isinstance(ff['table']['c'], EarthLocation) helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_tagged_object_array(tmpdir): # See https://github.com/spacetelescope/asdf/issues/383 for feature # request astropy = pytest.importorskip('astropy') from astropy.units.quantity import Quantity objdata = np.empty((3, 3), dtype=object) for i, _ in enumerate(objdata.flat): objdata.flat[i] = Quantity(i, 'angstrom') helpers.assert_roundtrip_tree({'bizbaz': objdata}, tmpdir)
def test_transforms_compound(tmpdir): tree = { 'compound': astmodels.Shift(1) & astmodels.Shift(2) | astmodels.Sky2Pix_TAN() | astmodels.Rotation2D() | astmodels.AffineTransformation2D([[2, 0], [0, 2]], [42, 32]) + astmodels.Rotation2D(32) } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_time_mixin(tmpdir): t = table.Table() t['a'] = [1, 2] t['b'] = ['x', 'y'] t['c'] = Time(['2001-01-02T12:34:56', '2001-02-03T00:01:02']) def check(ff): assert isinstance(ff['table']['c'], Time) helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_quantity_mixin(tmpdir): t = table.QTable() t['a'] = [1, 2, 3] t['b'] = ['x', 'y', 'z'] t['c'] = [2.0, 5.0, 8.2] * u.m def check(ff): assert isinstance(ff['table']['c'], u.Quantity) helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_timedelta_mixin(tmpdir): t = table.Table() t['a'] = [1, 2] t['b'] = ['x', 'y'] t['c'] = TimeDelta([1, 2] * u.day) def check(ff): assert isinstance(ff['table']['c'], TimeDelta) helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_naming_of_compound_model(tmpdir): """Issue #87""" def asdf_check(ff): assert ff.tree['model'].name == 'compound_model' offx = astmodels.Shift(1) scl = astmodels.Scale(2) model = (offx | scl).rename('compound_model') tree = { 'model': model } helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=asdf_check)
def test_auto_inline_recursive(tmpdir): astropy = pytest.importorskip('astropy') from astropy.modeling import models aff = models.AffineTransformation2D(matrix=[[1, 2], [3, 4]]) tree = {'test': aff} def check_asdf(asdf): assert len(list(asdf.blocks.internal_blocks)) == 0 helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check_asdf, write_options={'auto_inline': 64})
def test_generic_projections(tmpdir): from astropy.io.misc.asdf.tags.transform import projections for tag_name, (name, params, version) in projections._generic_projections.items(): tree = { 'forward': util.resolve_name( f'astropy.modeling.projections.Sky2Pix_{name}')(), 'backward': util.resolve_name( f'astropy.modeling.projections.Pix2Sky_{name}')() } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_structured_array_columns(tmpdir): a = np.array([((1, 'a'), 2.0, 'x'), ((4, 'b'), 5.0, 'y'), ((5, 'c'), 8.2, 'z')], dtype=[('a', [('a0', '<i4'), ('a1', '|S1')]), ('b', '<f8'), ('c', '|S1')]) t = table.Table(a, copy=False) def check(ff): assert len(ff.blocks) == 1 helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_fix_inputs_type(): with pytest.raises(TypeError): tree = { 'compound': fix_inputs(3, {'x': 45}) } helpers.assert_roundtrip_tree(tree, tmpdir) with pytest.raises(AttributeError): tree = { 'compound': astmodels.Pix2Sky_TAN() & {'x': 45} } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_inverse_transforms(tmpdir): rotation = astmodels.Rotation2D(32) rotation.inverse = astmodels.Rotation2D(45) real_rotation = astmodels.Rotation2D(32) tree = {'rotation': rotation, 'real_rotation': real_rotation} def check(ff): assert ff.tree['rotation'].inverse.angle == 45 helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check)
def test_time_with_location_1_0_0(tmpdir): from astropy import units as u from astropy.coordinates.earth import EarthLocation location = EarthLocation(x=6378100*u.m, y=0*u.m, z=0*u.m) t = time.Time('J2000.000', location=location, format='jyear_str') tree = {'time': t} # The version refers to ASDF Standard 1.0.0, which includes time-1.0.0 helpers.assert_roundtrip_tree(tree, tmpdir, init_options={"version": "1.0.0"})
def test_frames(tmpdir, version): # Version 1.0.0 test currently fails. It may be the case that some of the # frame types simply weren't supported in version 1.0.0. if version == '1.0.0': pytest.xfail() tree = { 'frames': create_test_frames() } write_options = dict(version=version) helpers.assert_roundtrip_tree(tree, tmpdir, write_options=write_options)
def test_array_inline_threshold_recursive(tmpdir): models = pytest.importorskip('astropy.modeling.models') aff = models.AffineTransformation2D(matrix=[[1, 2], [3, 4]]) tree = {'test': aff} def check_asdf(asdf): assert len(list(asdf.blocks.internal_blocks)) == 0 with asdf.config_context() as config: config.array_inline_threshold = 100 helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check_asdf)
def test_time_with_location(tmpdir): # See https://github.com/spacetelescope/asdf/issues/341 from astropy import units as u from astropy.coordinates.earth import EarthLocation location = EarthLocation(x=[1,2]*u.m, y=[3,4]*u.m, z=[5,6]*u.m) t = time.Time([1,2], location=location, format='cxcsec') tree = {'time': t} helpers.assert_roundtrip_tree(tree, tmpdir)
def test_array_columns(tmpdir): a = np.array([([[1, 2], [3, 4]], 2.0, 'x'), ([[5, 6], [7, 8]], 5.0, 'y'), ([[9, 10], [11, 12]], 8.2, 'z')], dtype=[('a', '<i4', (2, 2)), ('b', '<f8'), ('c', '|S1')]) t = table.Table(a, copy=False) assert t.columns['a'].shape == (3, 2, 2) def check(ff): assert len(ff.blocks) == 1 helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_fits_table(tmpdir): a = np.array( [(0, 1), (2, 3)], dtype=[('A', int), ('B', int)]) h = fits.HDUList() h.append(fits.BinTableHDU.from_columns(a)) tree = {'fits': h} def check_yaml(content): assert b'!<tag:astropy.org:astropy/table/table-1.0.0>' in content helpers.assert_roundtrip_tree(tree, tmpdir, raw_yaml_check_func=check_yaml)
def test_gwa_to_slit(tmpdir): transforms = [m1, m2] s0 = Slit("s0", 1, 2, 3, 4, 5, 6, 7, 8) s1 = Slit("s1", 10, 20, 30, 40, 50, 60, 70, 80) slits = [s0, s1] m = Gwa2Slit(slits, transforms) tree = {'model': m} helpers.assert_roundtrip_tree(tree, tmpdir, extensions=jwextension.JWSTExtension()) slits = [1, 2] m = Gwa2Slit(slits, transforms) tree = {'model': m} helpers.assert_roundtrip_tree(tree, tmpdir, extensions=jwextension.JWSTExtension())
def test_vector_spectralcoord(tmpdir): sc = SpectralCoord([100, 200, 300] * u.GHz) tree = dict(spectralcoord=sc) def check(asdffile): assert isinstance(asdffile['spectralcoord'], SpectralCoord) assert_quantity_allclose(asdffile['spectralcoord'].quantity, [100, 200, 300] * u.GHz) assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check, tree_match_func=assert_quantity_allclose)
def test_tabular_model(tmpdir): points = np.arange(0, 5) values = [1., 10, 2, 45, -3] model = astmodels.Tabular1D(points=points, lookup_table=values) tree = {'model': model} helpers.assert_roundtrip_tree(tree, tmpdir) table = np.array([[ 3., 0., 0.], [ 0., 2., 0.], [ 0., 0., 0.]]) points = ([1, 2, 3], [1, 2, 3]) model2 = astmodels.Tabular2D(points, lookup_table=table, bounds_error=False, fill_value=None, method='nearest') tree = {'model': model2} helpers.assert_roundtrip_tree(tree, tmpdir)
def test1(tmpdir, ret=False): obs = Observer(name='Dummy Name Jr.', institution='Harvaard', address='Harvard Square, Cambridge, MA 02121', email='*****@*****.**', PI=True, meta={ 'drink_of_choice': 'hemlock', 'students': ['Peter', 'Paul', 'Mary'] }) tree = {'observer': obs} if ret: return obs helpers.assert_roundtrip_tree(tree, tmpdir)
def test_regions_selector(tmpdir): m1 = Mapping([0, 1, 1]) | Shift(1) & Shift(2) & Shift(3) m2 = Mapping([0, 1, 1]) | Scale(2) & Scale(3) & Scale(3) sel = {1: m1, 2: m2} a = np.zeros((5, 6), dtype=np.int32) a[:, 1:3] = 1 a[:, 4:5] = 2 mask = selector.LabelMapperArray(a) rs = selector.RegionsSelector(inputs=('x', 'y'), outputs=('ra', 'dec', 'lam'), selector=sel, label_mapper=mask) tree = {'model': rs} helpers.assert_roundtrip_tree(tree, tmpdir, extensions=GWCSExtension())
def test2(tmpdir, ret=False): loc = fl_test1(None, ret=True) tel = Telescope(name='VLA', location=loc, location_name="Plains of Saint Augustine", telescope_type=['Radio'], org_url='nrao.edu', telescope_url='https://public.nrao.edu/telescopes/vla/', meta={'fines': 'hitting cows'}) tree = {'telescope': tel} if ret: return tel helpers.assert_roundtrip_tree(tree, tmpdir)
def test_fix_inputs(tmpdir): with warnings.catch_warnings(): # Some schema files are missing from asdf<=2.4.2 which causes warnings if LooseVersion(asdf.__version__) <= '2.4.2': warnings.filterwarnings('ignore', 'Unable to locate schema file') model = astmodels.Pix2Sky_TAN() | astmodels.Rotation2D() tree = { 'compound': fix_inputs(model, {'x': 45}), 'compound1': fix_inputs(model, {0: 45}) } helpers.assert_roundtrip_tree(tree, tmpdir)
def test_create_wcs(tmpdir): m1 = models.Shift(12.4) & models.Shift(-2) m2 = models.Scale(2) & models.Scale(-2) icrs = cf.CelestialFrame(name='icrs', reference_frame=coord.ICRS()) det = cf.Frame2D(name='detector', axes_order=(0, 1)) gw1 = wcs.WCS(output_frame='icrs', input_frame='detector', forward_transform=m1) gw2 = wcs.WCS(output_frame='icrs', forward_transform=m1) gw3 = wcs.WCS(output_frame=icrs, input_frame=det, forward_transform=m1) tree = {'gw1': gw1, 'gw2': gw2, 'gw3': gw3} helpers.assert_roundtrip_tree(tree, tmpdir)
def test_table(tmpdir): data_rows = [(1, 2.0, 'x'), (4, 5.0, 'y'), (5, 8.2, 'z')] t = table.Table(rows=data_rows, names=('a', 'b', 'c'), dtype=('i4', 'f8', 'S1')) t.columns['a'].description = 'RA' t.columns['a'].unit = 'degree' t.columns['a'].meta = {'foo': 'bar'} t.columns['c'].description = 'Some description of some sort' def check(ff): assert len(ff.blocks) == 3 helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_table_row_order(tmpdir): a = np.array([(1, 2.0, 'x'), (4, 5.0, 'y'), (5, 8.2, 'z')], dtype=[('a', '<i4'), ('b', '<f8'), ('c', '|S1')]) t = table.Table(a, copy=False) t.columns['a'].description = 'RA' t.columns['a'].unit = 'degree' t.columns['a'].meta = {'foo': 'bar'} t.columns['c'].description = 'Some description of some sort' def check(ff): assert len(ff.blocks) == 1 helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check)
def test_generic_projections(tmpdir): from astropy.io.misc.asdf.tags.transform import projections for tag_name, (name, params, version) in projections._generic_projections.items(): tree = { 'forward': util.resolve_name( f'astropy.modeling.projections.Sky2Pix_{name}')(), 'backward': util.resolve_name( f'astropy.modeling.projections.Pix2Sky_{name}')() } with warnings.catch_warnings(): # Some schema files are missing from asdf<=2.4.2 which causes warnings if LooseVersion(asdf.__version__) <= '2.5.1': warnings.filterwarnings('ignore', 'Unable to locate schema file') helpers.assert_roundtrip_tree(tree, tmpdir)
def test_LabelMapperRange(tmpdir): m = [] for i in np.arange(9) * .1: c0_0, c1_0, c0_1, c1_1 = np.ones((4, )) * i m.append(Polynomial2D(2, c0_0=c0_0, c1_0=c1_0, c0_1=c0_1, c1_1=c1_1)) keys = np.array([[4.88, 5.64], [5.75, 6.5], [6.67, 7.47], [7.7, 8.63], [8.83, 9.96], [10.19, 11.49], [11.77, 13.28], [13.33, 15.34], [15.56, 18.09]]) rmapper = {} for k, v in zip(keys, m): rmapper[tuple(k)] = v sel = selector.LabelMapperRange(('x', 'y'), rmapper, inputs_mapping=Mapping((0, ), n_inputs=2)) tree = {'model': sel} helpers.assert_roundtrip_tree(tree, tmpdir, extensions=GWCSExtension())
def test_create_fitwcs(tmpdir): """ Test GWCS vs FITS WCS results. """ im = _create_model_3d() w3d = pointing.create_fitswcs(im) gra, gdec, glam = w3d(1, 1, 1) ff = fits_support.to_fits(im._instance, im._schema) hdu = fits_support.get_hdu(ff._hdulist, "SCI") w = wcs.WCS(hdu.header) wcel = w.sub(['celestial']) ra, dec = wcel.all_pix2world(1, 1, 1) utils.assert_allclose((ra, dec), (gra, gdec)) # test serialization tree = {'wcs': w3d} helpers.assert_roundtrip_tree(tree, tmpdir)
def test_isot(tmpdir): isot = time.Time('2000-01-01T00:00:00.000') tree = {'time': isot} helpers.assert_roundtrip_tree(tree, tmpdir) ff = asdf.AsdfFile(tree) tree = yamlutil.custom_tree_to_tagged_tree(ff.tree, ff) if isinstance(tree['time'], str): assert str(tree['time']) == isot.value elif isinstance(tree['time'], dict): assert str(tree['time']['value']) == isot.value assert str(tree['time']['base_format']) == "isot" else: assert False
def test_mask_roundtrip(tmpdir): x = np.arange(0, 10, dtype=np.float) m = ma.array(x, mask=x > 5) tree = {'masked_array': m, 'unmasked_array': x} def check_asdf(asdf): tree = asdf.tree m = tree['masked_array'] print(m) print(m.mask) assert np.all(m.mask[6:]) assert len(asdf.blocks) == 2 helpers.assert_roundtrip_tree(tree, tmpdir, asdf_check_func=check_asdf)
def test_composite_frame(tmpdir): icrs = coord.ICRS() fk5 = coord.FK5() cel1 = cf.CelestialFrame(reference_frame=icrs) cel2 = cf.CelestialFrame(reference_frame=fk5) spec1 = cf.SpectralFrame(name='freq', unit=(u.Hz, ), axes_order=(2, )) spec2 = cf.SpectralFrame(name='wave', unit=(u.m, ), axes_order=(2, )) comp1 = cf.CompositeFrame([cel1, spec1]) comp2 = cf.CompositeFrame([cel2, spec2]) comp = cf.CompositeFrame( [comp1, cf.SpectralFrame(axes_order=(3, ), unit=(u.m, ))]) tree = {'comp1': comp1, 'comp2': comp2, 'comp': comp} helpers.assert_roundtrip_tree(tree, tmpdir)
def test_skycoord_mixin(tmpdir): t = table.Table() t['a'] = [1, 2] t['b'] = ['x', 'y'] t['c'] = SkyCoord([1, 2], [3, 4], unit='deg,deg', frame='fk4', obstime='J1990.5') def check(ff): assert isinstance(ff['table']['c'], SkyCoord) def tree_match(old, new): NDArrayType.assert_equal(new['a'], old['a']) NDArrayType.assert_equal(new['b'], old['b']) assert skycoord_equal(new['c'], old['c']) helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check_func=check, tree_match_func=tree_match)
def test_table_inline(tmpdir): data_rows = [(1, 2.0, 'x'), (4, 5.0, 'y'), (5, 8.2, 'z')] t = table.Table(rows=data_rows, names=('a', 'b', 'c'), dtype=('i4', 'f8', 'S1')) t.columns['a'].description = 'RA' t.columns['a'].unit = 'degree' t.columns['a'].meta = {'foo': 'bar'} t.columns['c'].description = 'Some description of some sort' def asdf_check(ff): assert len(list(ff.blocks.internal_blocks)) == 0 helpers.assert_roundtrip_tree({'table': t}, tmpdir, asdf_check, write_options={'auto_inline': 64})