Skip to content

Commit

Permalink
Merge pull request #324 from punch-mission/faster-uncertainty-unpacking
Browse files Browse the repository at this point in the history
Unpack uncertainties faster
  • Loading branch information
svank authored Nov 25, 2024
2 parents 2561669 + 25d6388 commit 3903207
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 4 additions & 1 deletion punchbowl/data/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def _pack_uncertainty(cube: NDCube) -> np.ndarray:

def _unpack_uncertainty(uncertainty_array: np.ndarray, data_array: np.ndarray) -> np.ndarray:
"""Uncompress the uncertainty when reading from a file."""
return (1/uncertainty_array) * data_array
# This is (1/uncertainty_array) * data_array, but this way we save time on memory allocation
np.divide(1, uncertainty_array, out=uncertainty_array)
np.multiply(data_array, uncertainty_array, out=uncertainty_array)
return uncertainty_array


def _update_statistics(cube: NDCube) -> None:
Expand Down
2 changes: 0 additions & 2 deletions punchbowl/level3/tests/test_celestial_intermediary.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ def test_shift_image_onto_fill_value(tmp_path):
for hdu in hdul[1:]:
hdu.header['CRVAL1A'] += 10
hdu.header['CRVAL2A'] += 10
# Cut down to one Stokes component to speed up the test
hdu.data = hdul[1].data[0]
hdul.writeto(file2)

cube1 = io.load_ndcube_from_fits(file1, key='A')
Expand Down

0 comments on commit 3903207

Please sign in to comment.