The default unit when there is no BUNIT in the FITS file (CCDData.read)
- Dominant language
- Python
- Stars
- 5.3k
- Forks
- 2.2k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 74
Description
### Description
Currently, if a FITS file is missing ``BUNIT``, ``CCDData.read(fpath)`` raises ValueError
```
ValueError: a unit for CCDData must be specified.
```
This is because (1) the reader couldn't find ``BUNIT`` and (2) user did not specify the unit.
However, in most cases when we load **CCD** data, it is very natural to assume the unit is in ADU when ``BUNIT`` is not there.
Moreover, if the FITS file has ``BUNIT = "ADU"``, the following ``INFO`` is printed regardless of using ``unit='adu'`` or ``unit=u.adu``:
```
>>> CCDData.read("test.fits", unit='adu')
INFO: using the unit adu passed to the FITS reader instead of the unit adu in the FITS file. [astropy.nddata.ccddata]
```
Currently, to avoid annoying errors and INFO strings, and to make the code run without redundant line of ``unit='adu'``, I am using the following lines in a convenience function:
```python
def load_ccd(path, extension=0, unit=None, hdu_uncertainty="UNCERT",
use_wcs=True, hdu_mask='MASK', hdu_flags=None,
key_uncertainty_type='UTYPE', memmap=False,
**kwd):
[.....]
try:
ccd = CCDData.read(path, unit=unit, **reader_kw)
except ValueError: # e.g., user did not give unit and there's no BUNIT
ccd = CCDData.read(path, unit='adu', **reader_kw)
```
So my suggestion is to let ``CCDData.read`` to assume ADU when ``unit=None`` && ``BUNIT`` is not found, because it's quite natural to assume so as we are dealing with **CCD** data, not general ND data. How do you think?
Contributor guide
Research direction
Start at the CCDData.read entry point and trace FITS handling when BUNIT is absent or when a unit is explicitly supplied. Resolve the intended default and INFO behavior for unit=None with no BUNIT, while preserving the existing behavior when BUNIT is present; done means the resulting read behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100