SHARE
TWEET

Untitled

a guest May 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def _insert_in_metadata_fits_safe(meta, key, value):
  2.     """Helper function to insert key-value pair into metadata in a way that
  3.        FITS can serialize
  4.     Parameters
  5.     ----------
  6.     key : str
  7.         Key to be inserted in the dictionary
  8.     value : str or None
  9.         Value to be inserted
  10.     Notes
  11.     -----
  12.     This addresses a shortcoming of the FITS standard. There are length
  13.         restrictions on both the ``key`` (8 characters) and ``value`` (72
  14.         characters) in the FITS standard. There is a convention for handling
  15.         long keywords and a convention for handling long values, but the
  16.         two conventions cannot be used at the same time.
  17.         This addresses that case by checking the length of the ``key`` and
  18.         ``value`` and, if necessary, shortening the key.
  19.     Reference
  20.     ---------
  21.     This helper method is taken from `astropy.nddata.cddata`. Not imported
  22.     as this is a private method, subject to change
  23.     """
  24.  
  25.     if len(key) > 8 and len(value) > 72:
  26.         short_name = key[:8]
  27.         meta['HIERARCH {0}'.format(key.upper())] = (short_name, "Shortened name for {}".format(key))
  28.         meta[short_name] = value
  29.     else:
  30.         meta[key] = value
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top