How to use the gsd.pygsd.GSDFile function in gsd

To help you get started, we’ve selected a few gsd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glotzerlab / gsd / tests / test_fl.py View on Github external
f.write_chunk(name=str(value), data=data)
        f.end_frame()

        check_v1_file_read(f)

    # test opening again with the C implemantation
    with gsd.fl.open(name=tmp_path / 'test_gsd_v1.gsd',
                     mode=open_mode.read,
                     application='test_gsd_v1',
                     schema='none',
                     schema_version=[1, 2]) as f:

        check_v1_file_read(f)

    # and the pure python implementation
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path / 'test_gsd_v1.gsd'), mode='rb')) as f:

        assert f.gsd_version == (1, 0)

        check_v1_file_read(f)
github glotzerlab / gsd / tests / test_fl.py View on Github external
with gsd.fl.open(name=tmp_path / 'test_metadata.gsd',
                     mode=open_mode.read,
                     application='test_metadata',
                     schema='none',
                     schema_version=[1, 2]) as f:
        assert f.name == str(tmp_path / 'test_metadata.gsd')
        assert f.mode == open_mode.read
        assert f.application == 'test_metadata'
        assert f.schema == 'none'
        assert f.schema_version == (1, 2)
        assert f.nframes == 150
        assert f.gsd_version == (2, 0)

    # test again with pygsd
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path / 'test_metadata.gsd'), mode='rb')) as f:
        assert f.name == str(tmp_path / 'test_metadata.gsd')
        assert f.mode == 'rb'
        assert f.application == 'test_metadata'
        assert f.schema == 'none'
        assert f.schema_version == (1, 2)
        assert f.nframes == 150
        assert f.gsd_version == (2, 0)
github glotzerlab / gsd / tests / test_fl.py View on Github external
assert not f.chunk_exists(frame=0, name='test')
        with pytest.raises(Exception):
            read_data = f.read_chunk(frame=0, name='test')

        assert not f.chunk_exists(frame=2, name='chunk1')
        with pytest.raises(Exception):
            read_data = f.read_chunk(frame=2, name='chunk1')
        assert not f.chunk_exists(frame=0, name='abcdefg')
        with pytest.raises(Exception):
            read_data = f.read_chunk(frame=0, name='abcdefg')
        assert not f.chunk_exists(frame=1, name='test')
        with pytest.raises(Exception):
            read_data = f.read_chunk(frame=1, name='test')

    # test again with pygsd
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path / 'test_chunk_exists.gsd'), mode='rb')) as f:
        assert f.chunk_exists(frame=0, name='chunk1')
        read_data = f.read_chunk(frame=0, name='chunk1')
        assert f.chunk_exists(frame=1, name='abcdefg')
        read_data = f.read_chunk(frame=1, name='abcdefg')
        assert f.chunk_exists(frame=2, name='test')
        read_data = f.read_chunk(frame=2, name='test')

        assert not f.chunk_exists(frame=1, name='chunk1')
        with pytest.raises(Exception):
            read_data = f.read_chunk(frame=1, name='chunk1')
        assert not f.chunk_exists(frame=2, name='abcdefg')
        with pytest.raises(Exception):
            read_data = f.read_chunk(frame=2, name='abcdefg')
        assert not f.chunk_exists(frame=0, name='test')
        with pytest.raises(Exception):
github glotzerlab / gsd / tests / test_fl.py View on Github external
f.end_frame()

    data = numpy.array([1, 2, 3, 4, 5, 10012], dtype=numpy.int64)
    with gsd.fl.open(name=tmp_path / 'test_readonly_errors.gsd',
                     mode='rb',
                     application='test_readonly_errors',
                     schema='none',
                     schema_version=[1, 2]) as f:
        with pytest.raises(Exception):
            f.end_frame()

        with pytest.raises(Exception):
            f.write_chunk(name='chunk1', data=data)

    # test again with pygsd
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path
                          / 'test_readonly_errors.gsd'), mode='rb')) as f:
        with pytest.raises(Exception):
            f.end_frame()

        with pytest.raises(Exception):
            f.write_chunk(name='chunk1', data=data)
github glotzerlab / gsd / tests / test_fl.py View on Github external
assert f.schema == schema_long[0:63]

        data = numpy.array([1, 2, 3, 4, 5, 10012], dtype=numpy.int64)
        f.write_chunk(name=chunk_long, data=data)
        f.end_frame()

    with gsd.fl.open(name=tmp_path / 'test_namelen.gsd',
                     mode=open_mode.read,
                     application=app_long,
                     schema=schema_long,
                     schema_version=[1, 2]) as f:
        data_read = f.read_chunk(0, name=chunk_long)
        numpy.testing.assert_array_equal(data, data_read)

    # test again with pygsd
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path / 'test_namelen.gsd'), mode='rb')) as f:
        data_read = f.read_chunk(0, name=chunk_long)
        numpy.testing.assert_array_equal(data, data_read)
github glotzerlab / gsd / tests / test_fl.py View on Github external
f.end_frame()

    with gsd.fl.open(name=tmp_path / 'test_append.gsd',
                     mode=open_mode.read,
                     application='test_append',
                     schema='none',
                     schema_version=[1, 2]) as f:
        assert f.nframes == nframes
        for i in range(nframes):
            data1 = f.read_chunk(frame=i, name='data1')
            data10 = f.read_chunk(frame=i, name='data10')
            assert data1[0] == i
            assert data10[0] == i * 10

    # test again with pygsd
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path
                          / 'test_append.gsd'), mode=open_mode.read)) as f:
        assert f.nframes == nframes
        for i in range(nframes):
            data1 = f.read_chunk(frame=i, name='data1')
            data10 = f.read_chunk(frame=i, name='data10')
            assert data1[0] == i
            assert data10[0] == i * 10
github glotzerlab / gsd / tests / test_fl.py View on Github external
chunk_names = f.find_matching_chunk_names('')
        chunk_names.sort()
        assert chunk_names == values_str

    # test with the C implemantation
    with gsd.fl.open(name=test_path / 'test_gsd_v1.gsd',
                     mode=open_mode.read,
                     application='test_gsd_v1',
                     schema='none',
                     schema_version=[1, 2]) as f:

        check_v1_file_read(f)

    # and the pure python implementation
    with gsd.pygsd.GSDFile(
            file=open(str(test_path / 'test_gsd_v1.gsd'), mode='rb')) as f:

        assert f.gsd_version == (1, 0)

        check_v1_file_read(f)
github glotzerlab / gsd / tests / test_fl.py View on Github external
assert 'data/B' in all_chunks

        log_chunks = f.find_matching_chunk_names('log/')
        assert len(log_chunks) == 2
        assert 'log/A' in log_chunks
        assert 'log/chunk2' in log_chunks

        data_chunks = f.find_matching_chunk_names('data/')
        assert len(data_chunks) == 1
        assert 'data/B' in data_chunks

        other_chunks = f.find_matching_chunk_names('other/')
        assert len(other_chunks) == 0

    # test again with pygsd
    with gsd.pygsd.GSDFile(file=open(str(tmp_path
                                         / "test.gsd"), mode='rb')) as f:
        all_chunks = f.find_matching_chunk_names('')
        assert len(all_chunks) == 3
        assert 'log/A' in all_chunks
        assert 'log/chunk2' in all_chunks
        assert 'data/B' in all_chunks

        log_chunks = f.find_matching_chunk_names('log/')
        assert len(log_chunks) == 2
        assert 'log/A' in log_chunks
        assert 'log/chunk2' in log_chunks

        data_chunks = f.find_matching_chunk_names('data/')
        assert len(data_chunks) == 1
        assert 'data/B' in data_chunks
github glotzerlab / gsd / tests / test_fl.py View on Github external
application="test_dtype",
                     schema="none",
                     schema_version=[1, 2]) as f:
        read_data1d = f.read_chunk(frame=0, name='data1d')
        read_data2d = f.read_chunk(frame=0, name='data2d')
        read_data_zero = f.read_chunk(frame=0, name='data_zero')

        assert data1d.dtype == read_data1d.dtype
        numpy.testing.assert_array_equal(data1d, read_data1d)
        assert data2d.dtype == read_data2d.dtype
        numpy.testing.assert_array_equal(data2d, read_data2d)
        assert data_zero.dtype == read_data_zero.dtype
        assert data_zero.shape == (0,)

    # test again with pygsd
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path / "test_dtype.gsd"), mode='rb')) as f:
        read_data1d = f.read_chunk(frame=0, name='data1d')
        read_data2d = f.read_chunk(frame=0, name='data2d')

        assert data1d.dtype == read_data1d.dtype
        numpy.testing.assert_array_equal(data1d, read_data1d)
        assert data2d.dtype == read_data2d.dtype
        numpy.testing.assert_array_equal(data2d, read_data2d)
github glotzerlab / gsd / tests / test_fl.py View on Github external
check_v1_file_read(f)

    # test opening again with the C implemantation
    with gsd.fl.open(name=tmp_path / 'test_gsd_v1.gsd',
                     mode=open_mode.read,
                     application='test_gsd_v1',
                     schema='none',
                     schema_version=[1, 2]) as f:

        assert f.gsd_version == (2, 0)

        check_v1_file_read(f)

    # and the pure python implementation
    with gsd.pygsd.GSDFile(
            file=open(str(tmp_path / 'test_gsd_v1.gsd'), mode='rb')) as f:

        assert f.gsd_version == (2, 0)

        check_v1_file_read(f)