Skip to content

Commit

Permalink
find better compression parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
guynir42 committed Jul 5, 2024
1 parent 053002f commit a737cb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions models/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
16 changes: 13 additions & 3 deletions tests/models/test_background.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import os

import sep
import time

import pytest
import numpy as np
import h5py
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit a737cb7

Please sign in to comment.