spacetelescope / drizzle

A package for combining dithered images into a single image
https://spacetelescope-drizzle.readthedocs.io/en/latest/
Other
51 stars 26 forks source link

Changes to drizzle to switch from single to double precision. #68

Closed WilliamJamieson closed 9 months ago

WilliamJamieson commented 3 years ago

These are changes that should switch drizzle's C library from computing in single precision to double precision. The C code currently builds, but with additional warnings (at least on my machine).

The only changes I made were searching files in src and changing float declarations to double declarations until the code would build successfully.

WilliamJamieson commented 3 years ago

There are also lots of test failures right now. To summarize:

FAILED drizzle/tests/test_drizzle.py::test_square_with_point - assert 1.940925471596618 < 1e-06
FAILED drizzle/tests/test_drizzle.py::test_square_with_grid - ValueError: cannot convert float NaN to integer
FAILED drizzle/tests/test_drizzle.py::test_turbo_with_grid - ValueError: cannot convert float NaN to integer
FAILED drizzle/tests/test_drizzle.py::test_gaussian_with_grid - ValueError: cannot convert float NaN to integer
FAILED drizzle/tests/test_drizzle.py::test_lanczos_with_grid - ValueError: cannot convert float NaN to integer
FAILED drizzle/tests/test_drizzle.py::test_tophat_with_grid - assert 1.4318166877429803 < 1e-06
FAILED drizzle/tests/test_drizzle.py::test_point_with_grid - assert 1.4318166878003353 < 1e-06
FAILED drizzle/tests/test_drizzle.py::test_blot_with_point - assert 2.1828068579991102 < 1e-06
FAILED drizzle/tests/test_drizzle.py::test_blot_with_default - ValueError: cannot convert float NaN to integer
FAILED drizzle/tests/test_drizzle.py::test_blot_with_lan3 - ValueError: cannot convert float NaN to integer
FAILED drizzle/tests/test_drizzle.py::test_blot_with_lan5 - assert 2.717604582302542 < 1e-06
FAILED drizzle/tests/test_file_io.py::test_add_file - assert nan == 0.0
FAILED drizzle/tests/test_file_io.py::test_blot_file - assert nan == 0.0
jdavies-st commented 3 years ago

Re the test failures, there's probably some specific python calling code that sends dtype=np.float32 arrays specifically to tdriz and tblot, and I suspect that might need to be changed as well.

$ grep -r np.float32 drizzle
drizzle/drizzle.py:                    self.outsci = hdu.data.copy().astype(np.float32)
drizzle/drizzle.py:                    self.outwht = hdu.data.copy().astype(np.float32)
drizzle/drizzle.py:                                   dtype=np.float32)
drizzle/drizzle.py:                                   dtype=np.float32)
drizzle/drizzle.py:        insci = insci.astype(np.float32)
drizzle/drizzle.py:            inwht = inwht.astype(np.float32)
drizzle/doblot.py:    _outsci = np.zeros(blot_wcs.pixel_shape[::-1], dtype=np.float32)
drizzle/dodrizzle.py:    if (insci.dtype > np.float32):
drizzle/dodrizzle.py:        insci = insci.astype(np.float32)
WilliamJamieson commented 3 years ago

Changing np.float32 this line: https://github.com/spacetelescope/drizzle/blob/3d8ba08d84583d7689288fcfcc9e1d77242b39aa/drizzle/doblot.py#L66 to np.float64 causes a segmentation fault.