Convert lpd to noaa keys for this one section
        :param str header: Section header
        :param dict d: Metadata
        :return dict:  Metadata w/ converted keys
188041
def __convert_keys_2(header, d):
        
        d_out = {}
        try:
            for k, v in d.items():
                try:
                    noaa_key = LIPD_NOAA_MAP_BY_SECTION[header][k]
                    d_out[noaa_key] = v
                except Exception:
                    logger_lpd_noaa.warn("lpd_noaa: convert_keys_section: ran into an error converting {}".format(k))
        except KeyError:
            logger_lpd_noaa.warn("lpd_noaa: convert_keys_section: KeyError: header key {} is not in NOAA_ALL_DICT".format(header))
        except AttributeError:
            logger_lpd_noaa.warn("lpd_noaa: convert_keys_section: AttributeError: metdata is wrong data type".format(header))
            return d
        return d_out
1225874
def get_header_by_name(self, hdrname):
        '''
        
        '''
        for hdr in self._headers:
            if hdr.__class__.__name__ == hdrname:
                return hdr
        return None
1271705
def getheader(self, header, default=None):
        '''
        
        '''
        if isinstance(header, str):
            return self.headers.get(header.lower(), default)
        return self.__rawheaders.get(header, default)
1369918
def get_header(self, key):
        
        key = canonicalize_header(key)
        if key in self.header:
            return self.header[key]
        return ''
9755
def _encode_header(key: str, pdict: Dict[str, str]) -> str:
    
    if not pdict:
        return key
    out = [key]
    # Sort the parameters just to make it easy to test.
    for k, v in sorted(pdict.items()):
        if v is None:
            out.append(k)
        else:
            # TODO: quote if necessary.
            out.append("%s=%s" % (k, v))
    return "; ".join(out)
152445
def headers_as_dict(cls, resp):
        """"""
        if six.PY2:
            pairs = [header.split(':', 1) for header in resp.msg.headers]
            return dict([(k, v.strip()) for k, v in pairs])
        else:
            return dict([(k, v.strip()) for k, v in resp.msg._headers])
63448
def get_header(self, individual=-1):
        
        type_map = dict([(val,key) for key,val in self.meta.type_map.iteritems()])
        extra = '\n'.join(['##{0}'.format(i) for i in self.meta.extra])
        info = '\n'.join(['##INFO=<ID={0},Number={1},Type={2},Description={3}>'.format(key, val.get('num_entries','.'), type_map.get(val.get('type', '')), val.get('description')) for key,val in self.meta.info.iteritems()])
        filter = '\n'.join(['##FILTER=<ID={0},Description={1}>'.format(key, val.get('description','.')) for key,val in self.meta.filter.iteritems()])
        format = '\n'.join(['##FORMAT=<ID={0},Number={1},Type={2},Description={3}>'.format(key, val.get('num_entries','.'), type_map.get(val.get('type', '')), val.get('description')) for key,val in self.meta.format.iteritems()])
        alt = '\n'.join(['##ALT=<ID={0},Description={1}>'.format(key, val.get('description','.')) for key,val in self.meta.alt.iteritems()])
        header = '\t'.join(['#CHROM','POS','ID','REF','ALT','QUAL','FILTER','INFO','FORMAT'])
        if individual is not None:
            if individual == -1:
                individual = '\t'.join(self.individuals.keys())
            else:
                if isinstance(individual, int):
                    for i, v in self.individuals.iteritems():
                        if v == individual:
                            individual = i
                            break
            header += '\t'+individual
        return '\n'.join([extra, info, filter, format, alt, header])
398771
def mk_set_headers(self, data, columns):
        
        columns = tuple(columns)
        lens = []

        for key in columns:
            value_len = max(len(str(each.get(key, ''))) for each in data)
            # account for header lengths
            lens.append(max(value_len, len(self._get_name(key))))

        fmt = self.mk_fmt(*lens)
        return fmt
170605
def get_hdrs(flds_all, **kws):
    """"""
    # Return Headers if the user explicitly lists them.
    hdrs = kws.get('hdrs', None)
    if hdrs is not None:
        return hdrs
    # User may specify a subset of fields or a column order using prt_flds
    if 'prt_flds' in kws:
        return kws['prt_flds']
    # All fields in the namedtuple will be in the headers
    return flds_all
871731
def headers(self):
        '''  '''
        self.__dict__['headers'] = hdict = HeaderDict()
        hdict.dict = self._headers
        return hdict
719186
def _clean_header_df(self, df):
        """"""
        if self.suffix == '-drvd.txt':
            df.units = {'release_time': 'second',
                        'precipitable_water': 'millimeter',
                        'inv_pressure': 'hPa',
                        'inv_height': 'meter',
                        'inv_strength': 'Kelvin',
                        'mixed_layer_pressure': 'hPa',
                        'mixed_layer_height': 'meter',
                        'freezing_point_pressure': 'hPa',
                        'freezing_point_height': 'meter',
                        'lcl_pressure': 'hPa',
                        'lcl_height': 'meter',
                        'lfc_pressure': 'hPa',
                        'lfc_height': 'meter',
                        'lnb_pressure': 'hPa',
                        'lnb_height': 'meter',
                        'lifted_index': 'degC',
                        'showalter_index': 'degC',
                        'k_index': 'degC',
                        'total_totals_index': 'degC',
                        'cape': 'Joule / kilogram',
                        'convective_inhibition': 'Joule / kilogram'}

        else:
            df.units = {'release_time': 'second',
                        'latitude': 'degrees',
                        'longitude': 'degrees'}

        return df
583148
def headerData(self, index, orientation, role):
        
        d = self.declaration
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            try:
                return d.horizontal_headers[index] \
                    if d.horizontal_headers else index
            except IndexError:
                return index
        elif orientation == Qt.Vertical and role == Qt.DisplayRole:
            try:
                return d.vertical_headers[index] \
                    if d.vertical_headers else index
            except IndexError:
                return index
        return None
1213752
def _get_header_keys(row):
    
    # Swap out NOAA keys for LiPD keys
    for idx, key in enumerate(row):
        key_low = key.value.lower()

        # Simple case: Nothing fancy here, just map to the LiPD key counterpart.
        if key_low in EXCEL_LIPD_MAP_FLAT:
            row[idx] = EXCEL_LIPD_MAP_FLAT[key_low]

        # Nested data case: Check if this is a calibration, interpretation, or some other data that needs to be nested.
        # elif key_low:
        #     pass

        # Unknown key case: Store the key as-is because we don't have a LiPD mapping for it.
        else:
            try:
                row[idx] = key.value
            except AttributeError as e:
                logger_excel.warn("excel_main: get_header_keys: unknown header key, unable to add: {}".format(e))

    # Since we took a whole row of cells, we have to drop off the empty cells at the end of the row.
    header_keys = _rm_cells_reverse(row)
    return header_keys
1282495
def with_headers(self, headers):
        
        for key, value in headers.items():
            self.with_header(key, value)
        return self
1259769
def header(args):
    
    from jcvi.formats.base import DictFile

    p = OptionParser(header.__doc__)
    p.add_option("--prefix", default="",
                 help="Prepend text to line number [default: %default]")
    p.add_option("--ids", help="Write ids to file [default: %default]")
    opts, args = p.parse_args(args)

    if len(args) != 2:
        sys.exit(not p.print_help())

    mstmap, conversion_table = args
    data = MSTMap(mstmap)
    hd = data.header
    conversion = DictFile(conversion_table)
    newhd = [opts.prefix + conversion.get(x, x) for x in hd]

    print("\t".join(hd))
    print("--->")
    print("\t".join(newhd))

    ids = opts.ids
    if ids:
        fw = open(ids, "w")
        print("\n".join(newhd), file=fw)
        fw.close()
167014
def _read_header(filename):
    
    with filename.open('rb') as f:
        h = f.read(HDR_LENGTH).decode()

        header = {}
        for line in h.split('\n'):
            if '=' in line:
                key, value = line.split(' = ')
                key = key.strip()[7:]
                value = value.strip()[:-1]
                header[key] = value

    return header
3740
def _encode_message_header(cls, client_id, correlation_id, request_key,
                               api_version=0):
        
        return (struct.pack('>hhih',
                            request_key,          # ApiKey
                            api_version,          # ApiVersion
                            correlation_id,       # CorrelationId
                            len(client_id)) +     # ClientId size
                client_id)