lgrcia / prose

Modular image processing pipelines with Python. Built for Astronomy.
https://prose.readthedocs.io
MIT License
54 stars 11 forks source link

Importing FITS file error #101

Closed dan-adi closed 1 year ago

dan-adi commented 1 year ago

Bug Report

## How To Reproduce I tried to load a fits file, but I get an error probably related to WCS ### Code sample ``` image = FITSImage("C:\\Users\\dan\\Desktop\\notebook\\FWHM\\abell.fits") ``` ### Environment Windows 10 ``` python 3.11.2 ``` ### A part of my fits header: ``` DATE-OBS= '2023-05-10T19:50:04.641600' /UT date of Observation UT = '19:50:04.64 ' /UT begining of observation EXPOSURE= 300.00000 /Exposure time seconds XPIXELSZ= 6.00 /X pixel size microns CDELTM1 = 6.00000000000000012E-003 /Size of a pixel (x) in mm** XPIXSZ = 6.0 /X Binned pixel size as microns YPIXELSZ= 6.00 /Y pixel size microns CDELTM2 = 6.00000000000000012E-003 /Size of a pixel (y) in mm** YPIXSZ = 6.0 /X Binned pixel size as microns INSTRUME= 'ASCOM_Moravian Instruments, G3-16200' /Camera which created data FILTERS = 'Green ' /Filters CVF = 5.000 /Conversion factor (e-/adu) READOUTT= 23.40 /Image readout time (sec) X1 = 1 /X1 image windowing Y1 = 1 /Y1 image windowing X2 = 4524 /X2 image windowing Y2 = 3624 /Y2 image windowing ``` ### Error: ``` --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[42], line 1 ----> 1 image = FITSImage("C:\\Users\\dan\\Desktop\\notebook\\FWHM\\abell.fits") File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\prose\core\image.py:718, in FITSImage(filepath_or_hdu, verbose, load_units, load_data, telescope) 716 image.metadata["jd"] = Time(image.date).jd 717 image.fits_header = header --> 718 image.wcs = WCS(header) 719 image.telescope = telescope 721 return image File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\astropy\wcs\wcs.py:612, in WCS.__init__(self, header, fobj, key, minerr, relax, naxis, keysel, colsel, fix, translate_units, _do_set) 609 self.fix(translate_units=translate_units) 611 if _do_set: --> 612 self.wcs.set() 614 for fd in close_fds: 615 fd.close() ValueError: ERROR 5 in wcsset() at line 2775 of file cextern\wcslib\C\wcs.c: Invalid parameter value. ERROR 4 in linset() at line 737 of file cextern\wcslib\C\lin.c: Failed to initialize distortion functions. ERROR 3 in dssset() at line 2697 of file cextern\wcslib\C\dis.c: Coefficient scale for DSS on axis 1 is zero.. ``` ### Attached FITS file [abell.fits.zip](https://github.com/lgrcia/prose/files/11580766/abell.fits.zip)
lgrcia commented 1 year ago

Hi @dan-adi and thanks for reporting this bug! I can reproduce it.

Would a skip_wcs keyword argument to the FITSImage help? Like

image = FITSImage("C:\\Users\\dan\\Desktop\\notebook\\FWHM\\abell.fits", skip_wcs=True)

Or do you need something fancier? The downside is that an Image.wcs object will not be available but it seems you error is rather from the astropy.wcs module, so you might need to build a new WCS solution anyway.

Whatever solution we agree on, we can make that part of the 3.2.0 (next minor release).

dan-adi commented 1 year ago

Hi @dan-adi and thanks for reporting this bug! I can reproduce it.

Would a skip_wcs keyword argument to the FITSImage help? Like

image = FITSImage("C:\\Users\\dan\\Desktop\\notebook\\FWHM\\abell.fits", skip_wcs=True)

Or do you need something fancier? The downside is that an Image.wcs object will not be available but it seems you error is rather from the astropy.wcs module, so you might need to build a new WCS solution anyway.

Whatever solution we agree on, we can make that part of the 3.2.0 (next minor release).

Hello, thanks for replying.

I did try:

image = FITSImage("C:\\Users\\dan\\Desktop\\notebook\\FWHM\\abell.fits", skip_wcs=True)

But got:

TypeError: FITSImage() got an unexpected keyword argument 'skip_wcs'
dan-adi commented 1 year ago

I think you meant insert the option

skip_wcs=True

with the next minor release.. Yes it will be just fine. Thank you

lgrcia commented 1 year ago

I released this feature as a patch, available in 3.1.1 (documented here)

Thanks a lot for this issue and please do not hesitate to open more in the future!

Cheers

dan-adi commented 1 year ago

I released this feature as a patch, available in 3.1.1 (documented here)

Thanks a lot for this issue and please do not hesitate to open more in the future!

Cheers

Thank you very much