How to use the gsd.fl.open 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
schema_long = 'ijklmnop' * 100
    chunk_long = '12345678' * 100

    with gsd.fl.open(name=tmp_path / 'test_namelen.gsd',
                     mode=open_mode.write,
                     application=app_long,
                     schema=schema_long,
                     schema_version=[1, 2]) as f:
        assert f.application == app_long[0:63]
        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
with gsd.fl.open(name=tmp_path / 'test_gsd_v1.gsd',
                     mode='rb+',
                     application='test_gsd_v1',
                     schema='none',
                     schema_version=[1, 2]) as f:

        assert f.gsd_version == (1, 0)

        f.upgrade()

        # check that we can read the file contents after the upgrade in memory
        check_v1_file_read(f)

    # and the same tests again after closing and opening the file
    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)

    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)
github glotzerlab / gsd / tests / test_fl.py View on Github external
def test_zero_size(tmp_path, open_mode):
    """Test that zero-size data chunks are allowed."""
    data = numpy.array([], dtype=numpy.float32)

    with gsd.fl.open(name=tmp_path / 'test_zero.gsd',
                     mode=open_mode.write,
                     application='test_zero',
                     schema='none',
                     schema_version=[1, 2]) as f:

        f.write_chunk(name='data', data=data)
        f.end_frame()

    with gsd.fl.open(name=tmp_path / 'test_zero.gsd',
                     mode=open_mode.read,
                     application='test_zero',
                     schema='none',
                     schema_version=[1, 2]) as f:
        assert f.nframes == 1
        data_read = f.read_chunk(frame=0, name='data')
        assert data_read.shape == (0,)
github glotzerlab / gsd / tests / test_fl.py View on Github external
def test_namelen(tmp_path, open_mode):
    """Test that long names are truncated as documented."""
    app_long = 'abcdefga' * 100
    schema_long = 'ijklmnop' * 100
    chunk_long = '12345678' * 100

    with gsd.fl.open(name=tmp_path / 'test_namelen.gsd',
                     mode=open_mode.write,
                     application=app_long,
                     schema=schema_long,
                     schema_version=[1, 2]) as f:
        assert f.application == app_long[0:63]
        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:
github glotzerlab / gsd / tests / test_fl.py View on Github external
application='test_open',
                     schema='none',
                     schema_version=[1, 2]) as f:
        f.write_chunk(name='chunk1', data=data)
        f.end_frame()
        f.read_chunk(0, name='chunk1')

    with gsd.fl.open(name=tmp_path / 'test.gsd',
                     mode='ab',
                     application='test_open',
                     schema='none',
                     schema_version=[1, 2]) as f:
        f.write_chunk(name='chunk1', data=data)
        f.end_frame()

    with gsd.fl.open(name=tmp_path / 'test.gsd',
                     mode='rb',
                     application='test_open',
                     schema='none',
                     schema_version=[1, 2]) as f:
        f.read_chunk(0, name='chunk1')
        f.read_chunk(1, name='chunk1')

    with gsd.fl.open(name=tmp_path / 'test.gsd',
                     mode='rb+',
                     application='test_open',
                     schema='none',
                     schema_version=[1, 2]) as f:
        f.write_chunk(name='chunk1', data=data)
        f.end_frame()
        f.read_chunk(0, name='chunk1')
        f.read_chunk(1, name='chunk1')
github glotzerlab / gsd / tests / test_fl.py View on Github external
nframes = 1024

    with gsd.fl.open(name=tmp_path / 'test_append.gsd',
                     mode='ab',
                     application='test_append',
                     schema='none',
                     schema_version=[1, 2]) as f:
        assert f.mode == 'ab'
        for i in range(nframes):
            data[0] = i
            f.write_chunk(name='data1', data=data)
            data[0] = i * 10
            f.write_chunk(name='data10', data=data)
            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