Skip to content

Handle non-ASCII characters in FITS header #6074

Closed

Description

@saimn

Opening this issue about non-ASCII (e.g. UTF-8) characters in FITS header, which is a quite common issue with many duplicates (if I'm not mistaken), but I cannot find an issue to gather all (related: #2887 #5732 #5396 #3497). #2887 has a test file, other test files are welcome.

This is not standard but it should be possible to display these headers and to allow fixing them. Quoting @embray (#2887 (comment)):

It's probably a relatively easy fix. If nothing else the header parser needs to catch non-ASCII bytes and either replace them with a replacement character (e.g. '?' and/or raise an error--perhaps depending on a setting).

Activity

  1. mcara commented on May 16, 2017

    @mcara
    Contributor

    #5093 seems to be somewhat related to this issue too (though for header padding I think parser could safely ignore non ASCII characters).

  2. saimn commented on May 16, 2017

    @saimn
    ContributorAuthor

    @mcara - Indeed. Do you still have the problematic files ?

  3. added a commit that references this issue on May 16, 2017
    2d07272
  4. mcara commented on May 17, 2017

    @mcara
    Contributor

    @saimn https://stsci.box.com/s/v2szxbpazaxu2y4f2h7et9wkykmghw5h (link set to expire on August 31st, 2017).

    In my opinion non-ASCII characters should not be supported. From the section 3.2 of https://fits.gsfc.nasa.gov/standard40/fits_standard40draft1.pdf:

    The primary HDU and every extension HDU shall consist of one or more 2880-byte header blocks immediately followed by an optional sequence of associated 2880-byte data blocks. The header blocks shall contain only the restricted set of ASCII text characters, decimal 32 through 126 (hexadecimal 20 through 7E). The ASCII control characters with decimal values less than 32 (including the null, tab, carriage return, and line feed charac- ters), and the delete character (decimal 127 or hexadecimal 7F) must not appear anywhere within a header block.

    In section 3.3.2 of the same document, it says:

    The last header block must contain the END keyword (defined in Sect. 4.4.1) which marks the logical end of the header. Keyword records without information (e.g., following the END keyword) shall be filled with ASCII spaces (decimal 32 or hexadecimal 20).

    I do not think that astropy should be facilitating use of non-standard FITS files.

  5. saimn commented on May 17, 2017

    @saimn
    ContributorAuthor

    @mcara - Thanks for the file. About "facilitating use of non-standard FITS files", the goal here is not to allow writing non-standard FITS files, but just to read them, to be able to fix the problematic cards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions