Closed devanshkv closed 3 years ago
The last file is empty, which's causing this issue.
Yes, the last file is causing this. It has 0 subints. Just running your_header on it gives the following. Need to find a better way to catch this error.
your_header.py -f /hyrule/data/users/dagarwal/SGR1935/L_Band/vegas_59261_60229_J1934+2145_0011_0026.fits -v
[02/22/21 11:52:41] DEBUG 2021-02-22 11:52:41,419 - __init__ -your.your - DEBUG - Reading the file(s): ['/hyrule/data/users/dagarwal/SGR1935/L_Band/vegas_59261_60229_J1934+2145_0011_0026.fits'] your.py:70
WARNING: non-ASCII characters are present in the FITS file header and have been replaced by "?" characters [astropy.io.fits.util]
WARNING 2021-02-22 11:52:41,450 - _showwarning -astropy - WARNING - non-ASCII characters are present in the FITS file header and have been replaced by "?" characters logger.py:204
WARNING: non-ASCII characters are present in the FITS file header and have been replaced by "?" characters [astropy.io.fits.util]
[02/22/21 11:52:42] WARNING 2021-02-22 11:52:42,333 - _showwarning -astropy - WARNING - non-ASCII characters are present in the FITS file header and have been replaced by "?" characters logger.py:204
Traceback (most recent call last):
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/hdulist.py", line 1111, in _try_while_unread_hdus
return func(*args, **kwargs)
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/base.py", line 406, in _readfrom_internal
header_str, header = _BasicHeader.fromfile(data)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/header.py", line 2077, in fromfile
header_str, cards = parse_header(fileobj)
File "astropy/io/fits/_utils.pyx", line 38, in astropy.io.fits._utils.parse_header
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd5 in position 1: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/kshitij/anaconda3/envs/grbfrb/bin/your_header.py", line 4, in <module>
__import__('pkg_resources').run_script('your==0.6.3', 'your_header.py')
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/pkg_resources/__init__.py", line 650, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1446, in run_script
exec(code, namespace, namespace)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/your-0.6.3-py3.6.egg/EGG-INFO/scripts/your_header.py", line 104, in <module>
read_header(values.files, values.no_table)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/your-0.6.3-py3.6.egg/EGG-INFO/scripts/your_header.py", line 55, in read_header
y = Your(f)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/your-0.6.3-py3.6.egg/your/your.py", line 72, in __init__
self.formatclass.__init__(self, self.your_file)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/your-0.6.3-py3.6.egg/your/formats/psrfits.py", line 112, in __init__
self.specinfo = SpectraInfo(psrfitslist)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/your-0.6.3-py3.6.egg/your/formats/psrfits.py", line 462, in __init__
self.hdu_names = [hdu.name for hdu in hdus]
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/your-0.6.3-py3.6.egg/your/formats/psrfits.py", line 462, in <listcomp>
self.hdu_names = [hdu.name for hdu in hdus]
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/hdulist.py", line 261, in __iter__
yield self[idx]
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/hdulist.py", line 314, in __getitem__
self._positive_index_of(key))
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/hdulist.py", line 1113, in _try_while_unread_hdus
if self._read_next_hdu():
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/hdulist.py", line 1154, in _read_next_hdu
hdu = _BaseHDU.readfrom(fileobj, **kwargs)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/base.py", line 327, in readfrom
**kwargs)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/hdu/base.py", line 414, in _readfrom_internal
endcard=not ignore_missing_end)
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/header.py", line 514, in fromfile
padding)[1]
File "/home/kshitij/anaconda3/envs/grbfrb/lib/python3.6/site-packages/astropy/io/fits/header.py", line 596, in _from_blocks
raise OSError('Header missing END card.')
OSError: Header missing END card.
I have a possible fix:
adding ignore_missing_end=True
to the pyfits.open
statements
and an hdus.verify() after this:
https://github.com/thepetabyteproject/your/blob/a678c8da7894d1ee9bfcab9250920a66772007c6/your/formats/psrfits.py#L459
and an if condition to catch is self.num_subint[ii] == 0
https://github.com/thepetabyteproject/your/blob/a678c8da7894d1ee9bfcab9250920a66772007c6/your/formats/psrfits.py#L539
We would have to change the number of files, fitslist, etc if the last file is found to have 0 subints. What if the user is reading just that file with 0 subints? and what if some file in between has 0 subints?
Also, we use pyfits.open multiple times in psrfits.py, so before deploying this change we need to think of better ways to test if this breaks something else.
First attempt at fixing this: 42e10ff511d63e96ed46b5857c0cf9211bb99026
Added tests for this too: 45d212e8bb9425375647b41edf4d78d54dc92a9d I think this issue is resolved now.
Describe the bug Can't read a bunch of fits files together for some reason?
To Reproduce