Read FEI SFEG/HELIOS headers and return as dict.
173574
def read_fei_metadata(fh, byteorder, dtype, count, offsetsize):
    """"""
    result = {}
    section = {}
    data = bytes2str(stripnull(fh.read(count)))
    for line in data.splitlines():
        line = line.strip()
        if line.startswith('['):
            section = {}
            result[line[1:-1]] = section
            continue
        try:
            key, value = line.split('=')
        except ValueError:
            continue
        section[key] = astype(value)
    return result
1126775
def _read(self, fh, fname):
        """"""
        if fname in self._timers:
            raise self.Error("Cannot overwrite timer associated to: %s " % fname)

        def parse_line(line):
            """Parse single line."""
            name, vals = line[:25], line[25:].split()
            try:
                ctime, cfract, wtime, wfract, ncalls, gflops = vals
            except ValueError:
                # v8.3 Added two columns at the end [Speedup, Efficacity]
                ctime, cfract, wtime, wfract, ncalls, gflops, speedup, eff = vals

            return AbinitTimerSection(name, ctime, cfract, wtime, wfract, ncalls, gflops)

        data = {}
        inside, has_timer = 0, False
        for line in fh:
            #print(line.strip())
            if line.startswith(self.BEGIN_TAG):
                has_timer = True
                sections = []
                info = {}
                inside = 1
                line = line[len(self.BEGIN_TAG):].strip()[:-1]

                info["fname"] = fname
                for tok in line.split(","):
                    key, val = [s.strip() for s in tok.split("=")]
                    info[key] = val

            elif line.startswith(self.END_TAG):
                inside = 0
                timer = AbinitTimer(sections, info, cpu_time, wall_time)
                mpi_rank = info["mpi_rank"]
                data[mpi_rank] = timer

            elif inside:
                inside += 1
                line = line[1:].strip()

                if inside == 2:
                    d = dict()
                    for tok in line.split(","):
                        key, val = [s.strip() for s in tok.split("=")]
                        d[key] = float(val)
                    cpu_time, wall_time = d["cpu_time"], d["wall_time"]

                elif inside > 5:
                    sections.append(parse_line(line))

                else:
                    try:
                        parse_line(line)
                    except:
                        parser_failed = True

                    if not parser_failed:
                        raise self.Error("line should be empty: " + str(inside) + line)

        if not has_timer:
            raise self.Error("%s: No timer section found" % fname)

        # Add it to the dict
        self._timers[fname] = data
41463
def HDUCards(headers, hdu=0):
    '''
    

    '''

    if headers is None:
        return []

    if hdu == 0:
        # Get info from the TPF Primary HDU Header
        tpf_header = headers[0]
        entries = ['TELESCOP', 'INSTRUME', 'OBJECT', 'KEPLERID', 'CHANNEL',
                   'MODULE', 'OUTPUT', 'CAMPAIGN', 'DATA_REL', 'OBSMODE',
                   'TTABLEID', 'RADESYS', 'RA_OBJ', 'DEC_OBJ',  'EQUINOX',
                   'KEPMAG']
    elif (hdu == 1) or (hdu == 6):
        # Get info from the TPF BinTable HDU Header
        tpf_header = headers[1]
        entries = ['WCSN4P', 'WCAX4P', '1CTY4P', '2CTY4P',
                   '1CUN4P', '2CUN4P', '1CRV4P',
                   '2CRV4P', '1CDL4P', '2CDL4P', '1CRP4P',
                   '2CRP4P', 'WCAX4', '1CTYP4',
                   '2CTYP4', '1CRPX4', '2CRPX4', '1CRVL4',
                   '2CRVL4', '1CUNI4', '2CUNI4',
                   '1CDLT4', '2CDLT4', '11PC4', '12PC4',
                   '21PC4', '22PC4', 'WCSN5P',
                   'WCAX5P', '1CTY5P', '2CTY5P', '1CUN5P',
                   '2CUN5P', '1CRV5P', '2CRV5P',
                   '1CDL5P', '2CDL5P', '1CRP5P', '2CRP5P',
                   'WCAX5', '1CTYP5', '2CTYP5',
                   '1CRPX5', '2CRPX5', '1CRVL5', '2CRVL5',
                   '1CUNI5', '2CUNI5', '1CDLT5',
                   '2CDLT5', '11PC5', '12PC5', '21PC5',
                   '22PC5', 'WCSN6P', 'WCAX6P',
                   '1CTY6P', '2CTY6P', '1CUN6P', '2CUN6P',
                   '1CRV6P', '2CRV6P', '1CDL6P',
                   '2CDL6P', '1CRP6P', '2CRP6P', 'WCAX6',
                   '1CTYP6', '2CTYP6', '1CRPX6',
                   '2CRPX6', '1CRVL6', '2CRVL6', '1CUNI6',
                   '2CUNI6', '1CDLT6', '2CDLT6',
                   '11PC6', '12PC6', '21PC6', '22PC6',
                   'WCSN7P', 'WCAX7P', '1CTY7P',
                   '2CTY7P', '1CUN7P', '2CUN7P', '1CRV7P',
                   '2CRV7P', '1CDL7P', '2CDL7P',
                   '1CRP7P', '2CRP7P', 'WCAX7', '1CTYP7',
                   '2CTYP7', '1CRPX7', '2CRPX7',
                   '1CRVL7', '2CRVL7', '1CUNI7', '2CUNI7',
                   '1CDLT7', '2CDLT7', '11PC7',
                   '12PC7', '21PC7', '22PC7', 'WCSN8P',
                   'WCAX8P', '1CTY8P', '2CTY8P',
                   '1CUN8P', '2CUN8P', '1CRV8P', '2CRV8P',
                   '1CDL8P', '2CDL8P', '1CRP8P',
                   '2CRP8P', 'WCAX8', '1CTYP8', '2CTYP8',
                   '1CRPX8', '2CRPX8', '1CRVL8',
                   '2CRVL8', '1CUNI8', '2CUNI8', '1CDLT8',
                   '2CDLT8', '11PC8', '12PC8',
                   '21PC8', '22PC8', 'WCSN9P', 'WCAX9P',
                   '1CTY9P', '2CTY9P', '1CUN9P',
                   '2CUN9P', '1CRV9P', '2CRV9P', '1CDL9P',
                   '2CDL9P', '1CRP9P', '2CRP9P',
                   'WCAX9', '1CTYP9', '2CTYP9', '1CRPX9',
                   '2CRPX9', '1CRVL9', '2CRVL9',
                   '1CUNI9', '2CUNI9', '1CDLT9', '2CDLT9',
                   '11PC9', '12PC9', '21PC9',
                   '22PC9', 'INHERIT', 'EXTNAME', 'EXTVER',
                   'TELESCOP', 'INSTRUME',
                   'OBJECT', 'KEPLERID', 'RADESYS', 'RA_OBJ',
                   'DEC_OBJ', 'EQUINOX',
                   'EXPOSURE', 'TIMEREF', 'TASSIGN', 'TIMESYS',
                   'BJDREFI', 'BJDREFF',
                   'TIMEUNIT', 'TELAPSE', 'LIVETIME', 'TSTART',
                   'TSTOP', 'LC_START',
                   'LC_END', 'DEADC', 'TIMEPIXR', 'TIERRELA',
                   'INT_TIME', 'READTIME',
                   'FRAMETIM', 'NUM_FRM', 'TIMEDEL', 'DATE-OBS',
                   'DATE-END', 'BACKAPP',
                   'DEADAPP', 'VIGNAPP', 'GAIN', 'READNOIS',
                   'NREADOUT', 'TIMSLICE',
                   'MEANBLCK', 'LCFXDOFF', 'SCFXDOFF']
    elif (hdu == 3) or (hdu == 4) or (hdu == 5):
        # Get info from the TPF BinTable HDU Header
        tpf_header = headers[2]
        entries = ['TELESCOP', 'INSTRUME', 'OBJECT', 'KEPLERID', 'RADESYS',
                   'RA_OBJ', 'DEC_OBJ', 'EQUINOX', 'WCSAXES', 'CTYPE1',
                   'CTYPE2', 'CRPIX1', 'CRPIX2', 'CRVAL1', 'CRVAL2',
                   'CUNIT1', 'CUNIT2', 'CDELT1', 'CDELT2', 'PC1_1',
                   'PC1_2', 'PC2_1', 'PC2_2', 'WCSNAMEP', 'WCSAXESP',
                   'CTYPE1P', 'CUNIT1P', 'CRPIX1P', 'CRVAL1P', 'CDELT1P',
                   'CTYPE2P', 'CUNIT2P', 'CRPIX2P', 'CRVAL2P', 'CDELT2P',
                   'NPIXSAP', 'NPIXMISS']
    else:
        return []

    cards = []
    cards.append(('COMMENT', '************************'))
    cards.append(('COMMENT', '*     MISSION INFO     *'))
    cards.append(('COMMENT', '************************'))
    for entry in entries:
        try:
            cards.append(tuple(tpf_header[entry]))
        except KeyError:
            pass
    return cards
280175
def _read_header(self, header_str):
        """"""

        # regular expressions
        re_float = '[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?'
        re_uint = '\d+'
        re_binning = '{d} in (?P<nbins>' + re_uint + ') bin[ s] '
        re_binning += 'of (?P<binwidth>' + re_float + ') {unit}'

        # map of dimensions and units
        dim_units = {
            'X': 'cm',
            'Y': 'cm',
            'Z': 'cm',
            'R': 'cm',
            'Phi': 'deg',
            'Theta': 'deg',
        }

        # retrieve binning info
        self.dimensions = []
        for line in header_str.splitlines():

            for dim, unit in dim_units.items():
                re_tmp = re_binning.format(d=dim, unit=unit)
                regex = re.compile(re_tmp)
                match = regex.search(line)

                if match:
                    N = int(match.group('nbins'))
                    width = float(match.group('binwidth'))
                    dimension = BinnedDimension(dim, unit, N, width)
                    self.dimensions.append(dimension)

        # retrieve scored quantity info
        re_score_unit = '# (?P<quant>.+) \( (?P<unit>.+) \) : (?P<stats>.+)'
        re_score_unitless = '# (?P<quant>.+) : (?P<stats>.+)'
        regex_unit = re.compile(re_score_unit)
        regex_unitless = re.compile(re_score_unitless)

        for line in header_str.splitlines():

            match = regex_unit.search(line)
            if match:
                self.quantity = match.group('quant')
                self.unit = match.group('unit')
                self.statistics = match.group('stats').split()
                break

            match = regex_unitless.search(line)
            if match:
                self.quantity = match.group('quant')
                self.unit = None
                self.statistics = match.group('stats').split()
                break
682050
def read_hlas(fasta_fai):
    
    out = []
    with open(fasta_fai) as in_handle:
        for line in in_handle:
            if line.startswith("HLA"):
                out.append(line.split()[0])
    return out
238408
def read_nih_image_header(fd, byte_order, dtype, count):
    """"""
    fd.seek(12, 1)
    return {'version': struct.unpack(byte_order+'H', fd.read(2))[0]}
968254
def hdf5_read_out(self):
        
        with h5py.File(self.WORKING_DIRECTORY + '/' + self.output_file_name, 'w') as f:

            header = f.create_group('header')
            header.attrs['Title'] = 'Generated SNR Out'
            header.attrs['Author'] = 'Generator by: Michael Katz'
            header.attrs['Date/Time'] = str(datetime.datetime.now())

            for which in ['x', 'y']:
                header.attrs[which + 'val_name'] = getattr(self, which + 'val_name')
                header.attrs['num_' + which + '_pts'] = getattr(self, 'num_' + which)

            ecc = 'eccentricity' in self.__dict__
            if ecc:
                name_list = ['observation_time', 'start_frequency', 'start_separation'
                             'eccentricity']
            else:
                name_list = ['spin_1', 'spin_2', 'spin', 'end_time']

            name_list += ['total_mass', 'mass_ratio', 'start_time', 'luminosity_distance',
                          'comoving_distance', 'redshift']

            for name in name_list:
                if name != self.xval_name and name != self.yval_name:
                    try:
                        getattr(self, name)
                        header.attrs[name] = getattr(self, name)
                    except AttributeError:
                        pass

            if self.added_note != '':
                header.attrs['Added note'] = self.added_note

            data = f.create_group('data')

            # read out x,y values in compressed data set
            dset = data.create_dataset(self.x_col_name, data=self.xvals,
                                       dtype='float64', chunks=True,
                                       compression='gzip', compression_opts=9)

            dset = data.create_dataset(self.y_col_name, data=self.yvals,
                                       dtype='float64', chunks=True,
                                       compression='gzip', compression_opts=9)

            # read out all datasets
            for key in self.output_dict.keys():
                dset = data.create_dataset(key, data=self.output_dict[key],
                                           dtype='float64', chunks=True,
                                           compression='gzip', compression_opts=9)
43556
def get_headers(hide_env=True):
    """"""

    headers = dict(request.headers.items())

    if hide_env and ('show_env' not in request.args):
        for key in ENV_HEADERS:
            try:
                del headers[key]
            except KeyError:
                pass

    return CaseInsensitiveDict(headers.items())
1373923
def parse_results_header(cls, header):
        
        header = IORMetricsExtractor.RE_MULTIPLE_SPACES.sub(' ', header)
        header = header.split(' ')
        return header
359558
def _read_header(filename):
    
    header = _read_header_text(filename)
    first_row = header[0]
    EXTRA_ROWS = 3  # drop DefaultValue1 LowRange1 HighRange1

    hdr = {}
    for group in finditer('(\w*)= ([\w.]*)', first_row):
        hdr[group.group(1)] = group.group(2)

    if first_row.startswith('BCI2000V'):
        VERSION = hdr['BCI2000V']

    else:
        VERSION = '1'
        hdr['DataFormat'] = 'int16'

    for row in header[1:]:
        if row.startswith('['):  # remove '[ ... Definition ]'
            section = row[2:-14].replace(' ', '')

            if section == 'StateVector':
                hdr[section] = []
            else:
                hdr[section] = {} # defaultdict(dict)
            continue

        if row == '':
            continue

        elif section == 'StateVector':
            statevector = {key: value for key, value in list(zip(STATEVECTOR, row.split(' ')))}
            hdr[section].append(statevector)

        else:
            group = match('(?P<subsection>[\w:%]*) (?P<format>\w*) (?P<key>\w*)= (?P<value>.*) // ', row)
            onerow = group.groupdict()

            values = onerow['value'].split(' ')
            if len(values) > EXTRA_ROWS:
                value = ' '.join(onerow['value'].split(' ')[:-EXTRA_ROWS])
            else:
                value = ' '.join(values)

            hdr[section][onerow['key']] = value  # similar to matlab's output

    return hdr
975505
def read_hdf5_dict(h5f, names=None, path=None, on_missing='error', **kwargs):
    
    if path:
        h5f = h5f[path]

    # allow alternative keyword argument name (FIXME)
    if names is None:
        names = kwargs.pop('flags', None)

    # try and get list of names automatically
    if names is None:
        try:
            names = find_flag_groups(h5f, strict=True)
        except KeyError:
            names = None
        if not names:
            raise ValueError("Failed to automatically parse available flag "
                             "names from HDF5, please give a list of names "
                             "to read via the ``names=`` keyword")

    # read data
    out = DataQualityDict()
    for name in names:
        try:
            out[name] = read_hdf5_flag(h5f, name, **kwargs)
        except KeyError as exc:
            if on_missing == 'ignore':
                pass
            elif on_missing == 'warn':
                warnings.warn(str(exc))
            else:
                raise ValueError('no H5Group found for flag '
                                 '{0!r}'.format(name))

    return out
264367
def readbdfv1(filename, bdfext='.bdf', bhfext='.bhf'):
    
    return header.readbhfv1(filename, True, bdfext, bhfext)
431053
def _headers(self, headers_dict):
        
        return Headers(dict((k,[v]) for (k,v) in headers_dict.items()))
595676
def parse_headers(self, req: Request, name: str, field: Field) -> typing.Any:
        """"""
        return core.get_value(req.headers, name, field)
443345
def _parse(self):
        """"""
        with open(self.filename, 'r') as fobj:
            lines = fobj.read().split('\n')

        # Create a header object with content at start of file
        self.header = MOPHeader(self.subfmt).parser(lines)

        # Create a data attribute to hold an astropy.table.Table object
        self.data = MOPDataParser(self.header).parse(lines)
1135553
def _read_dict(self, f):
        
        d = {}
        for k, item in f.items():
            if type(item) == h5py._hl.dataset.Dataset:
                v = item.value
                if type(v) == np.string_:
                    v = str(v)
                if type(v) == str and v == "NONE":
                    d[k] = None
                elif type(v) == str and v == "EMPTYARR":
                    d[k] = np.array([])
                elif isinstance(v, bytes):
                    d[k] = v.decode('utf-8')
                else:
                    d[k] = v

            elif k[:5] == "DICT_":
                d[k[5:]] = self._read_dict(item)
            elif k[:5] == "LIST_":
                tmpD = self._read_dict(item)
                d[k[5:]] = [tmpD[str(i)] for i in range(len(tmpD))]
        return d
61687
def extract_headers(headers):
    """"""
    sorted_headers = {}
    matches = re.findall(r'(.*):\s(.*)', headers)
    for match in matches:
        header = match[0]
        value = match[1]
        try:
            if value[-1] == ',':
                value = value[:-1]
            sorted_headers[header] = value
        except IndexError:
            pass
    return sorted_headers