diff --git a/models/background.py b/models/background.py index a1d2a78f..ee9ab001 100644 --- a/models/background.py +++ b/models/background.py @@ -294,8 +294,9 @@ def save( self, filename=None, **kwargs ): f"Variance shape {self.variance.shape} does not match image shape {self.image_shape}" ) - bggrp.create_dataset( 'counts', data=self.counts, compression='gzip', compression_opts=9 ) - bggrp.create_dataset( 'variance', data=self.variance, compression='gzip', compression_opts=9 ) + opts = dict(compression='gzip', compression_opts=1, chunks=(128, 128)) + bggrp.create_dataset( 'counts', data=self.counts, **opts ) + bggrp.create_dataset( 'variance', data=self.variance, **opts ) elif self.format == 'polynomial': raise NotImplementedError('Currently we do not support a polynomial background model. ') bggrp.create_dataset( 'coeffs', data=self.counts ) diff --git a/tests/models/test_background.py b/tests/models/test_background.py index fc58d3b6..313eeb68 100644 --- a/tests/models/test_background.py +++ b/tests/models/test_background.py @@ -1,3 +1,8 @@ +import os + +import sep +import time + import pytest import numpy as np import h5py @@ -72,10 +77,15 @@ def test_save_load_backgrounds(decam_raw_image, code_version): with pytest.raises(RuntimeError, match='Counts shape .* does not match image shape .*'): b2.save() - b2.counts = np.random.normal(bg_mean, 1, size=image.data.shape) - b2.variance = np.random.normal(bg_var, 1, size=image.data.shape) - b2.save() + # use actual background measurements so we can get a realistic estimate of the compression + back = sep.Background(image.data) + b2.counts = back.back() + b2.variance = back.rms() ** 2 + t0 = time.perf_counter() + b2.save() + print(f'Background save time: {time.perf_counter() - t0:.3f} s') + print(f'Background file size: {os.path.getsize(b2.get_fullpath()) / 1024 ** 2:.3f} MB') # check the filename contains the provenance hash assert prov.id[:6] in b2.get_fullpath()