Exemple #1
0
 def assert_equal(cls, old, new):
     from asdf.tests import helpers
     assert old.name == new.name  # nosec
     assert len(old.available_frames) == len(new.available_frames)  # nosec
     for old_step, new_step in zip(old.pipeline, new.pipeline):
         helpers.assert_tree_match(old_step.frame, new_step.frame)
         helpers.assert_tree_match(old_step.transform, new_step.transform)
Exemple #2
0
def _test_defragment(tmpdir, codec):
    x = np.arange(0, 1000, dtype=np.float)

    tree = {
        'science_data': x,
        'subset': x[3:-3],
        'skipping': x[::2],
        'not_shared': np.arange(100, 0, -1, dtype=np.uint8)
        }

    path = os.path.join(str(tmpdir), 'original.asdf')
    out_path = os.path.join(str(tmpdir), 'original.defragment.asdf')
    ff = AsdfFile(tree)
    ff.write_to(path)
    assert len(ff.blocks) == 2

    result = main.main_from_args(
        ['defragment', path, '-o', out_path, '-c', codec])

    assert result == 0

    files = get_file_sizes(str(tmpdir))

    assert 'original.asdf' in files
    assert 'original.defragment.asdf' in files

    assert files['original.defragment.asdf'] < files['original.asdf']

    with asdf.open(os.path.join(str(tmpdir), 'original.defragment.asdf')) as ff:
        assert_tree_match(ff.tree, tree)
        assert len(list(ff.blocks.internal_blocks)) == 2
Exemple #3
0
 def assert_equal(cls, old, new):
     assert old.name == new.name
     assert len(old.available_frames) == len(new.available_frames)
     for (old_frame, old_transform), (new_frame, new_transform) in zip(
             old.pipeline, new.pipeline):
         helpers.assert_tree_match(old_frame, new_frame)
         helpers.assert_tree_match(old_transform, new_transform)
Exemple #4
0
def test_extract(tmpdir):
    hdulist = HDUList()

    image = ImageHDU(np.random.random((25, 25)))
    hdulist.append(image)

    tree = {
        'some_words': 'These are some words',
        'nested': {
            'a': 100,
            'b': 42
        },
        'list': [x for x in range(10)],
        'image': image.data
    }

    asdf_in_fits = str(tmpdir.join('asdf.fits'))
    with AsdfInFits(hdulist, tree) as aif:
        aif.write_to(asdf_in_fits)

    pure_asdf = str(tmpdir.join('extract.asdf'))
    extract.extract_file(asdf_in_fits, pure_asdf)

    assert os.path.exists(pure_asdf)

    with asdf.open(pure_asdf) as af:
        assert not isinstance(af, AsdfInFits)
        assert_tree_match(tree, af.tree)
Exemple #5
0
 def assert_equal(cls, old, new):
     assert old.name == new.name
     assert len(old.available_frames) == len(new.available_frames)
     for (old_frame, old_transform), (new_frame, new_transform) in zip(
             old.pipeline, new.pipeline):
         helpers.assert_tree_match(old_frame, new_frame)
         helpers.assert_tree_match(old_transform, new_transform)
Exemple #6
0
    def _assert_equal(cls, old, new):
        assert old.name == new.name
        assert old.axes_order == new.axes_order
        assert old.axes_names == new.axes_names
        assert type(old.reference_frame) == type(new.reference_frame)
        assert old.unit == new.unit

        if old.reference_frame is not None:
            for name in old.reference_frame.get_frame_attr_names().keys():
                helpers.assert_tree_match(getattr(old.reference_frame, name),
                                          getattr(new.reference_frame, name))
Exemple #7
0
    def _assert_equal(cls, old, new):
        from asdf.tests import helpers
        assert old.name == new.name  # nosec
        assert old.axes_order == new.axes_order  # nosec
        assert old.axes_names == new.axes_names  # nosec
        assert type(old.reference_frame) is type(new.reference_frame)  # nosec
        assert old.unit == new.unit  # nosec

        if old.reference_frame is not None:
            for name in old.reference_frame.get_frame_attr_names().keys():
                helpers.assert_tree_match(getattr(old.reference_frame, name),
                                          getattr(new.reference_frame, name))
Exemple #8
0
    def _assert_equal(cls, old, new):
        assert old.name == new.name
        assert old.axes_order == new.axes_order
        assert old.axes_names == new.axes_names
        assert type(old.reference_frame) == type(new.reference_frame)
        assert old.unit == new.unit

        if old.reference_frame is not None:
            for name in old.reference_frame.get_frame_attr_names().keys():
                helpers.assert_tree_match(
                    getattr(old.reference_frame, name),
                    getattr(new.reference_frame, name))
Exemple #9
0
def test_inline():
    x = np.arange(0, 10, dtype=np.float)
    tree = {'science_data': x, 'subset': x[3:-3], 'skipping': x[::2]}

    buff = io.BytesIO()

    ff = asdf.AsdfFile(tree)
    ff.blocks.set_array_storage(ff.blocks[tree['science_data']], 'inline')
    ff.write_to(buff)

    buff.seek(0)
    with asdf.open(buff, mode='rw') as ff:
        helpers.assert_tree_match(tree, ff.tree)
        assert len(list(ff.blocks.internal_blocks)) == 0
        buff = io.BytesIO()
        ff.write_to(buff)

    assert b'[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]' in buff.getvalue(
    )
Exemple #10
0
def test_inline():
    x = np.arange(0, 10, dtype=np.float)
    tree = {
        'science_data': x,
        'subset': x[3:-3],
        'skipping': x[::2]
        }

    buff = io.BytesIO()

    ff = asdf.AsdfFile(tree)
    ff.blocks.set_array_storage(ff.blocks[tree['science_data']], 'inline')
    ff.write_to(buff)

    buff.seek(0)
    with asdf.AsdfFile.open(buff, mode='rw') as ff:
        helpers.assert_tree_match(tree, ff.tree)
        assert len(list(ff.blocks.internal_blocks)) == 0
        buff = io.BytesIO()
        ff.write_to(buff)

    assert b'[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]' in buff.getvalue()
Exemple #11
0
 def assert_equal(cls, a, b):
     # TODO: If models become comparable themselves, remove this.
     TransformType.assert_equal(a, b)
     assert_tree_match(a.left, b.left)
     assert_tree_match(a.right, b.right)
Exemple #12
0
 def assert_equal(cls, a, b):
     # TODO: If models become comparable themselves, remove this.
     TransformType.assert_equal(a, b)
     assert_tree_match(a._tree.left.value, b._tree.left.value)
     assert_tree_match(a._tree.right.value, b._tree.right.value)
     assert a._tree.value == b._tree.value
Exemple #13
0
 def assert_equal(cls, a, b):
     # TODO: If models become comparable themselves, remove this.
     TransformType.assert_equal(a, b)
     assert_tree_match(a._tree.left.value, b._tree.left.value)
     assert_tree_match(a._tree.right.value, b._tree.right.value)
     assert a._tree.value == b._tree.value
Exemple #14
0
 def assert_equal(cls, old, new):
     from asdf.tests import helpers
     assert old.name == new.name  # nosec
     for old_frame, new_frame in zip(old.frames, new.frames):
         helpers.assert_tree_match(old_frame, new_frame)
Exemple #15
0
 def assert_equal(cls, old, new):
     assert old.name == new.name
     for old_frame, new_frame in zip(old.frames, new.frames):
         helpers.assert_tree_match(old_frame, new_frame)
Exemple #16
0
 def assert_equal(cls, old, new):
     assert old.name == new.name
     for old_frame, new_frame in zip(old.frames, new.frames):
         helpers.assert_tree_match(old_frame, new_frame)