Skip to content

Commit

Permalink
RCAL-861: by default compress all arrays (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Dec 18, 2024
1 parent 5380646 commit 2f6c46f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/440.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change default compression to lz4. The previous default was no compression.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers = [
]
dependencies = [
"asdf >=3.3.0",
"lz4 >= 4.3.0",
"asdf-astropy >=0.5.0",
"gwcs >=0.19.0",
"numpy >=1.24",
Expand Down
3 changes: 2 additions & 1 deletion src/roman_datamodels/datamodels/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,11 @@ def open_asdf(self, init=None, **kwargs):
return asdf.AsdfFile(init, **kwargs)

def to_asdf(self, init, *args, **kwargs):
all_array_compression = kwargs.pop("all_array_compression", "lz4")
with validate.nuke_validation(), _temporary_update_filename(self, Path(init).name):
asdf_file = self.open_asdf(**kwargs)
asdf_file["roman"] = self._instance
asdf_file.write_to(init, *args, **kwargs)
asdf_file.write_to(init, *args, all_array_compression=all_array_compression, **kwargs)

def get_primary_array_name(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/roman_datamodels/maker_utils/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ def save_node(node, filepath=None):

af = asdf.AsdfFile()
af.tree = {"roman": node}
af.write_to(filepath)
af.write_to(filepath, all_array_compression="lz4")

return node
25 changes: 25 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,3 +1109,28 @@ def test_model_assignment_access_types(model_class):
assert type(model["meta"]["filename"]) == type(model2.meta["filename"]) # noqa: E721
assert type(model["meta"]["filename"]) == type(model2.meta.filename) # noqa: E721
assert type(model.meta.filename) == type(model2.meta["filename"]) # noqa: E721


def test_default_array_compression(tmp_path):
"""
Test that saving a model results in compressed arrays
for default options.
"""
fn = tmp_path / "foo.asdf"
model = utils.mk_datamodel(datamodels.ImageModel)
model.save(fn)
with asdf.open(fn) as af:
assert af.get_array_compression(af["roman"]["data"]) == "lz4"


@pytest.mark.parametrize("compression", [None, "bzp2"])
def test_array_compression_override(tmp_path, compression):
"""
Test that providing a compression argument changes the
array compression.
"""
fn = tmp_path / "foo.asdf"
model = utils.mk_datamodel(datamodels.ImageModel)
model.save(fn, all_array_compression=compression)
with asdf.open(fn) as af:
assert af.get_array_compression(af["roman"]["data"]) == compression

0 comments on commit 2f6c46f

Please sign in to comment.