Last active
February 7, 2020 16:15
-
-
Save becahp/fb5117d1bc42d409a299e111faa3972c to your computer and use it in GitHub Desktop.
Reading a HDR file from ENVI/Abilio and storing into a python dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#filename = 'abilio.hdr' | |
file = open(base_path/filename_hdr) | |
lista = file.readlines() #todo o arquivo esta em lista | |
dicionario = {} | |
for i in range(len(lista)): | |
parts = lista[i].split('=') #return list: ('times ',' 1\n') | |
termo = '' | |
comp = '' | |
#pular linhas que nao tem termos | |
if (len(parts) == 2): | |
termo = (parts[0].strip()).replace(' ', '_') | |
comp = parts[1].strip() | |
if ((termo == 'class_names') or (termo == 'description') ): | |
#lista de strings | |
comp = ((lista[i+1]).strip()).split(',') | |
if ((termo == 'modelos') or (termo == 'class_lookup') or (termo == 'roisThreshold')): | |
#transforma em uma lista de inteiros | |
comp = list(map(int, ((lista[i+1]).strip()).split(','))) | |
if (termo == 'band_names'): | |
#a partir do numero de bandas gera uma lista dos nomes das bandas | |
n_bands = int(dicionario['bands']) | |
comp = [x.strip() for x in lista[(i+1):(i+1+n_bands)]] | |
dicionario[termo] = comp | |
print(dicionario) | |
# Pegar os rois a partir do arquivo hdr | |
if ('roisThreshold' in dicionario.keys()): | |
roiTipo = dicionario['roisThreshold'][0] | |
roiColunas = dicionario['roisThreshold'][1] | |
roiLinhas = dicionario['roisThreshold'][2] | |
roiTempos = dicionario['roisThreshold'][3] | |
else: | |
print("Esse hdr nao possui roisThreshold") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment