Advertisement
Guest User

Untitled

a guest
May 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement