Menu

#148 Generation of unreadable header when not specifying all header cards

v3.83+
open
nobody
None
5
2025-05-19
2025-05-19
Anonymous
No

Hi all,

We in Oslo are encountering a problem when we write maps with TFIELDS > 3 where we don't specify all the additional header cards. We are writing maps (in Fortran) that contain, for example (T_1, T_2, T_3, T_4, Q, U) or something similar, which is obviously non-standard but doesn't crash.

The problem arises when we then try to open these maps in healpy, which fails with a message that looks like this:

File "/mn/stornext/d5/data/mathewg/mathew/cosmoglobe-papers/HFI/01_mapmaking/figs/plot_nplus2.py", line 12, in <module>
    map_in = hp.read_map(chainsdir + '/tod_' + det + '_map_c0001_k000002.fits', field=(0,1,2))
  File "/astro/local/mamba/envs/py310/lib/python3.10/site-packages/astropy/utils/decorators.py", line 603, in wrapper
    return function(*args, **kwargs)
  File "/mn/stornext/u3/mathewg/.local/lib/python3.10/site-packages/healpy/fitsfunc.py", line 444, in read_map
    m = fits_hdu.data.field(ff).ravel()
  File "/astro/local/mamba/envs/py310/lib/python3.10/site-packages/astropy/utils/decorators.py", line 836, in __get__
    val = self.fget(obj)
  File "/astro/local/mamba/envs/py310/lib/python3.10/site-packages/astropy/io/fits/hdu/table.py", line 407, in data
    data = self._get_tbdata()
  File "/astro/local/mamba/envs/py310/lib/python3.10/site-packages/astropy/io/fits/hdu/table.py", line 193, in _get_tbdata
    raw_data = self._get_raw_data(self._nrows, columns.dtype, self._data_offset)
  File "/astro/local/mamba/envs/py310/lib/python3.10/site-packages/astropy/utils/decorators.py", line 836, in __get__
    val = self.fget(obj)
  File "/astro/local/mamba/envs/py310/lib/python3.10/site-packages/astropy/io/fits/column.py", line 1729, in dtype
    return np.dtype({"names": self.names, "formats": formats, "offsets": offsets})
ValueError: name already used as a name or title

It looks (to me) like the problem is that all TTYPES get set to 'simulation' when generating the header, and then never overwritten because we aren't bothering to set the header properly (these are just debug outputs). I think the culprit is here:

https://sourceforge.net/p/healpix/code/HEAD/tree/trunk/src/f90/mod/fits_template.F90#l1002

where the comment "will be updated" ends up not happening.

Ideally, I think healpix shouldn't be able to generate non-compliant headers even if the users are idiots, so it should either raise an error in this case or it should generate unique TTYPES ("simulation1", simulation2"...) so that the files can always be opened.

Thanks,
-Mathew Galloway

Discussion

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB