Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision issues for high resolution images #72

Open
astrofrog opened this issue Feb 23, 2024 · 0 comments
Open

Precision issues for high resolution images #72

astrofrog opened this issue Feb 23, 2024 · 0 comments

Comments

@astrofrog
Copy link

I'm running into precision issues for images that are in the 0.01" resolution regime (ALMA, JWST, etc.). Here is a minimal example to reproduce. First, generate test images with the following Python code:

import numpy as np
from astropy.wcs import WCS
from astropy.io import fits

for label, res in [('high', 3e-6), ('low', 1e-3)]:

    wcs1 = WCS()
    wcs1.wcs.ctype = 'RA---TAN', 'DEC--TAN'
    wcs1.wcs.crval = 13, 20
    wcs1.wcs.crpix = 10.1, 10.2
    wcs1.wcs.cdelt = res, res

    wcs2 = WCS()
    wcs2.wcs.ctype = 'RA---TAN', 'DEC--TAN'
    wcs2.wcs.crval = 13, 20
    wcs2.wcs.crpix = 3, 3
    wcs2.wcs.cdelt = 3 * res, 3 * res

    array = np.zeros((19, 19))
    array[9, 9] = 1

    fits.writeto(f'data1_{label}.fits', array, wcs1.to_header(), overwrite=True)
    fits.writeto(f'data2_{label}.fits', array, wcs2.to_header(), overwrite=True)

then run Montage with e.g.:

#!/bin/bash

Montage/bin/mGetHdr data2_high.fits header2_high.hdr
Montage/bin/mProject data1_high.fits data3_high.fits header2_high.hdr

Montage/bin/mGetHdr data2_low.fits header2_low.hdr
Montage/bin/mProject data1_low.fits data3_low.fits header2_low.hdr

(I could also have used the Python API but just doing it the simplest way to minimize any potential issues)

Finally, check the results in Python - as the resolution has changed by a factor of 3, the total flux in the image should be changed by a factor of 9, so the following should return 1:

from astropy.io import fits

result_high = fits.getdata('data3_high.fits')
result_low = fits.getdata('data3_low.fits')

print(result_high.sum() * 9)
print(result_low.sum() * 9)

However, this gives:

0.84375
0.9999990280958064

The result for the low resolution is as expected, but for the high resolution is significantly wrong (and diverges fast as the resolution is lowered further).

I tried to dig into the C code but I couldn't determine what might be going wrong. All the calculations are done in double precision but there must be some loss of precision in one of the calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant