astropy / astropy/specutils

Not able to read FITS with `format="iraf"`

Open
#960 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
204
Forks
134
Avg merge
12h 55m
Merged PRs (30d)
1

Description

Description:

I have a FITS file which is already wavelength calibrated and have spectral world coordinates in the Header. But when I try to read the file using this:
`Spectrum1D.read(specdata.any(), format="iraf") `
I get this error:
```
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
/Users/bhavesh/coding/MSc/mkep5/Ex8.ipynb Cell 7' in ()
----> [1](vscode-notebook-cell:/Users/bhavesh/coding/MSc/mkep5/Ex8.ipynb#ch0000028?line=0) Spectrum1D.read(specdata.any(), format="iraf")

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/astropy/nddata/mixins/ndio.py:59, in NDDataRead.__call__(self, *args, **kwargs)
58 def __call__(self, *args, **kwargs):
---> 59 return self.registry.read(self._cls, *args, **kwargs)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/astropy/io/registry/core.py:212, in UnifiedInputRegistry.read(self, cls, format, cache, *args, **kwargs)
208 format = self._get_valid_format(
209 'read', cls, path, fileobj, args, kwargs)
211 reader = self.get_reader(format, cls)
--> 212 data = reader(*args, **kwargs)
214 if not isinstance(data, cls):
215 # User has read with a subclass where only the parent class is
216 # registered. This returns the parent class, so try coercing
217 # to desired subclass.
218 try:

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/specutils/io/default_loaders/wcs_fits.py:259, in non_linear_wcs1d_fits(file_obj, **kwargs)
233 @data_loader('iraf', identifier=identify_iraf_wcs, dtype=Spectrum1D, extensions=['fits'])
234 def non_linear_wcs1d_fits(file_obj, **kwargs):
235 """Load Spectrum1D with WCS spectral axis from FITS files written by IRAF
236
...
540 "method, required for mode '{}'.".format(self.mode))
542 # Any mode except for 'ostream' requires readability
543 if self.mode != 'ostream' and not hasattr(self._file, 'read'):

OSError: File-like object does not have a 'write' method, required for mode 'ostream'.
```

I am also attaching the file which I'm trying to import.
[arc_lapm_wav.fits.zip](https://github.com/astropy/specutils/files/8943131/arc_lapm_wav.fits.zip)

I really don't want to do the calibration again. Therefore, any help resolving this issue would be really appreciated.

------------------
System Details:
```
'platform': 'Darwin',
'platform-release': '21.5.0',
'platform-version': 'Darwin Kernel Version 21.5.0,
'architecture': 'arm64',
'processor': 'M1 Pro',
'ram': '16 GB'
'os': 'macOS Montery 12.4'
```

Kernel Details:
```
Python: 3.10.4 64bit
Specutils: 1.7.0
Astropy: 5.1
Numpy: 1.22.4
Matplotlib: 3.5.2
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing Spectrum1D.read(specdata.any(), format="iraf") with the attached arc_lapm_wav.fits file and the reported Python, specutils, and Astropy versions. Trace the IRAF FITS reader at the location shown in the traceback; done means the file loads successfully while retaining its spectral world coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.