def __hdr2dict(self):
        """
        read a HDR file into a dictionary
        http://gis.stackexchange.com/questions/48618/how-to-read-write-envi-metadata-using-gdal
        Returns
        -------
        dict
            the hdr file metadata attributes
        """
        with open(self.filename, 'r') as infile:
            lines = infile.readlines()
        i = 0
        out = dict()
        while i < len(lines):
            line = lines[i].strip('\r\n')
            if '=' in line:
                if '{' in line and '}' not in line:
                    while '}' not in line:
                        i += 1
                        line += lines[i].strip('\n').lstrip()
                line = list(filter(None, re.split(r'\s+=\s+', line)))
                line[1] = re.split(',[ ]*', line[1].strip('{}'))
                key = line[0].replace(' ', '_')
                val = line[1] if len(line[1]) > 1 else line[1][0]
                out[key] = parse_literal(val)
            i += 1
        if 'band_names' in out.keys() and not isinstance(out['band_names'], list):
            out['band_names'] = [out['band_names']]
        return out
def __hdr2dict ( self ) : with open ( self . filename , 'r' ) as infile : lines = infile . readlines ( ) i = 0 out = dict ( ) while i < len ( lines ) : line = lines [ i ] . strip ( '\r\n' ) if '=' in line : if '{' in line and '}' not in line : while '}' not in line : i += 1 line += lines [ i ] . strip ( '\n' ) . lstrip ( ) line = list ( filter ( None , re . split ( r'\s+=\s+' , line ) ) ) line [ 1 ] = re . split ( ',[ ]*' , line [ 1 ] . strip ( '{}' ) ) key = line [ 0 ] . replace ( ' ' , '_' ) val = line [ 1 ] if len ( line [ 1 ] ) > 1 else line [ 1 ] [ 0 ] out [ key ] = parse_literal ( val ) i += 1 if 'band_names' in out . keys ( ) and not isinstance ( out [ 'band_names' ] , list ) : out [ 'band_names' ] = [ out [ 'band_names' ] ] return out
read a HDR file into a dictionary
        http://gis.stackexchange.com/questions/48618/how-to-read-write-envi-metadata-using-gdal
        Returns
        -------
        dict
            the hdr file metadata attributes