Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable compression #1085

Merged
merged 5 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,12 @@ def create_channel(
require_kwargs["dtype"] = values.dtype
if np.prod(require_kwargs["shape"]) == 1:
require_kwargs["chunks"] = None
if "compression" in kwargs:
require_kwargs["compression"] = kwargs["compression"]
if "compression_opts" in kwargs:
require_kwargs["compression_opts"] = kwargs["compression_opts"]
if "shuffle" in kwargs:
require_kwargs["shuffle"] = kwargs["shuffle"]
# create dataset
dataset_id = self.require_dataset(name=name, **require_kwargs).id
channel = Channel(self, dataset_id, units=units, **kwargs)
Expand Down Expand Up @@ -943,9 +949,18 @@ def create_variable(
shape = values.shape
dtype = values.dtype
fillvalue = None
require_kwargs = {"chunks": True}
if "compression" in kwargs:
require_kwargs["compression"] = kwargs["compression"]
if "compression_opts" in kwargs:
require_kwargs["compression_opts"] = kwargs["compression_opts"]
if "shuffle" in kwargs:
require_kwargs["shuffle"] = kwargs["shuffle"]
if np.prod(shape) == 1:
require_kwargs["chunks"] = None
# create dataset
id = self.require_dataset(
name=name, data=values, shape=shape, dtype=dtype, fillvalue=fillvalue
name=name, data=values, shape=shape, dtype=dtype, fillvalue=fillvalue, **require_kwargs
).id
variable = Variable(self, id, units=units, **kwargs)
# finish
Expand Down
9 changes: 9 additions & 0 deletions tests/data/dataset_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import numpy as np
import pytest

import os


def test_create_variable():
data = wt.Data()
Expand Down Expand Up @@ -31,6 +33,13 @@ def test_exception():
d.create_channel(name="w1")


def test_create_compressed_channel():
data = wt.Data()
child1 = data.create_channel("hi", shape=(1024, 1024), compression="gzip")

Check notice

Code scanning / CodeQL

Unused local variable

The value assigned to local variable 'child1' is never used.
data["hi"][:] = 0
assert os.path.getsize(data.filepath) < 1e6


if __name__ == "__main__":
test_create_variable()
test_create_channel()
Expand Down