radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
98 stars 65 forks source link

KeyError in test_lmv_fits() on big endian systems #903

Open olebole opened 9 months ago

olebole commented 9 months ago

On Debian's big endian architecture (s390x), we observe the following test failure:

________________________________ test_lmv_fits _________________________________

    def test_lmv_fits():
        c1 = SpectralCube.read(path('example_cube.fits'))
>       c2 = SpectralCube.read(path('example_cube.lmv'))

/usr/lib/python3/dist-packages/spectral_cube/tests/test_io.py:20: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3/dist-packages/spectral_cube/io/core.py:118: in __call__
    return registry.read(BaseSpectralCube, filename, *args, **kwargs)
/usr/lib/python3/dist-packages/astropy/io/registry/compat.py:52: in wrapper
    return getattr(registry, method_name)(*args, **kwargs)
/usr/lib/python3/dist-packages/astropy/io/registry/core.py:221: in read
    data = reader(*args, **kwargs)
/usr/lib/python3/dist-packages/spectral_cube/io/class_lmv.py:263: in load_lmv_cube
    hdu = read_lmv_tofits(fileobj)
/usr/lib/python3/dist-packages/spectral_cube/io/class_lmv.py:246: in read_lmv_tofits
    data,header = read_lmv(fileobj)
/usr/lib/python3/dist-packages/spectral_cube/io/class_lmv.py:81: in read_lmv
    return read_lmv_type1(lf)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

lf = <_io.FileIO [closed]>

    def read_lmv_type1(lf):
        […]
        # Copied from the type 2 reader:
        # Use the appropriate projection type
        ptyp = header['PTYP']
        for kw in header:
            if 'CTYPE' in kw:
                if header[kw].strip() in cel_types:
                    n_dashes = 5-len(header[kw].strip())
>                   header[kw] = header[kw].strip()+ '-'*n_dashes + _proj_dict[ptyp]
E                   KeyError: 50331648

/usr/lib/python3/dist-packages/spectral_cube/io/class_lmv.py:210: KeyError

The number in the key error (0x3000000) has probably the wrong byte order.

Full test log here.