'Insert key/value pair into metadata in a way that FITS can serialize.
Parameters
key : str
Key to be inserted in dictionary.
value : str or None
Value to be inserted.
Notes
This addresses a shortcoming of the FITS standard. There are length
restrictions on both the ``key`` (8 characters) and ``value`` (72
characters) in the FITS standard. There is a convention for handling
long keywords and a convention for handling long values, but the
two conventions cannot be used at the same time.
This addresses that case by checking the length of the ``key`` and
``value`` and, if necessary, shortening the key.'

def _insert_in_metadata_fits_safe(self, key, value):

    if ((len(key) > 8) and (len(value) > 72)):
        short_name = key[:8]
        self.meta[u'HIERARCH    {0}'.format(key.upper())] = (short_name, u'Shortened    name    for    {}'.format(key))
        self.meta[short_name] = value
    else:
        self.meta[key] = value
