wr_integrador.py
162 lines
| 6.0 KiB
| text/x-python
|
PythonLexer
r1396 | import os, numpy, h5py | |||
r1321 | from shutil import copyfile | |||
def isNumber(str): | ||||
try: | ||||
float(str) | ||||
return True | ||||
except: | ||||
return False | ||||
r1396 | def getfirstFilefromPath(path, meta, ext): | |||
r1321 | validFilelist = [] | |||
r1396 | fileList = os.listdir(path) | |||
if len(fileList) < 1: | ||||
r1321 | return None | |||
# meta 1234 567 8-18 BCDE | ||||
# H,D,PE YYYY DDD EPOC .ext | ||||
for thisFile in fileList: | ||||
r1396 | if meta == "PE": | |||
r1321 | try: | |||
r1396 | number = int(thisFile[len(meta) + 7:len(meta) + 17]) | |||
r1321 | except: | |||
print("There is a file or folder with different format") | ||||
if meta == "D": | ||||
try: | ||||
r1396 | number = int(thisFile[8:11]) | |||
r1321 | except: | |||
print("There is a file or folder with different format") | ||||
if not isNumber(str=number): | ||||
continue | ||||
if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | ||||
continue | ||||
validFilelist.sort() | ||||
validFilelist.append(thisFile) | ||||
r1396 | if len(validFilelist) > 0: | |||
validFilelist = sorted(validFilelist, key=str.lower) | ||||
r1321 | return validFilelist | |||
return None | ||||
r1396 | def gettimeutcfromDirFilename(path, file): | |||
dir_file = path + "/" + file | ||||
fp = h5py.File(dir_file, 'r') | ||||
epoc = fp['Metadata'].get('utctimeInit')[()] | ||||
r1321 | fp.close() | |||
return epoc | ||||
r1396 | def getDatavaluefromDirFilename(path, file, value): | |||
dir_file = path + "/" + file | ||||
fp = h5py.File(dir_file, 'r') | ||||
array = fp['Data'].get(value)[()] | ||||
r1321 | fp.close() | |||
return array | ||||
r1396 | # ·········· Velocidad de Pedestal················· | |||
r1321 | w = input ("Ingresa velocidad de Pedestal: ") | |||
w = 4 | ||||
w = float(w) | ||||
r1396 | # ·········· Resolucion minimo en grados··········· | |||
r1321 | alfa = input ("Ingresa resolucion minima en grados: ") | |||
alfa = 1 | ||||
alfa = float(alfa) | ||||
r1396 | # ·········· IPP del Experimento ·················· | |||
IPP = input ("Ingresa el IPP del experimento: ") | ||||
IPP = 0.0004 | ||||
IPP = float(IPP) | ||||
# ·········· MODE ·················· | ||||
r1321 | mode = input ("Ingresa el MODO del experimento T or F: ") | |||
mode = "T" | ||||
mode = str(mode) | ||||
r1396 | # ·········· Tiempo en generar la resolucion min··· | |||
# ············ MCU ·· var_ang = w * (var_tiempo)··· | ||||
var_tiempo = alfa / w | ||||
# ·········· Tiempo Equivalente en perfiles········ | ||||
# ·········· var_tiempo = IPP * ( num_perfiles )· | ||||
num_perfiles = int(var_tiempo / IPP) | ||||
r1321 | ||||
r1396 | # ··········DATA PEDESTAL·························· | |||
r1321 | dir_pedestal = "/home/alex/Downloads/pedestal" | |||
r1396 | # ·········· DATA ADQ······························ | |||
if mode == "T": | ||||
dir_adq = "/home/alex/Downloads/hdf5_testPP/d2020194" # Time domain | ||||
r1321 | else: | |||
r1396 | dir_adq = "/home/alex/Downloads/hdf5_test/d2020194" # Frequency domain | |||
r1321 | ||||
r1396 | print("Velocidad angular :", w) | |||
print("Resolucion minima en grados :", alfa) | ||||
print("Numero de perfiles equivalente:", num_perfiles) | ||||
print("Mode :", mode) | ||||
r1321 | ||||
r1396 | # ············ First File············· | |||
list_pedestal = getfirstFilefromPath(path=dir_pedestal, meta="PE", ext=".hdf5") | ||||
list_adq = getfirstFilefromPath(path=dir_adq , meta="D", ext=".hdf5") | ||||
r1321 | ||||
r1396 | # ············ utc time ·············· | |||
utc_pedestal = gettimeutcfromDirFilename(path=dir_pedestal, file=list_pedestal[0]) | ||||
utc_adq = gettimeutcfromDirFilename(path=dir_adq , file=list_adq[0]) | ||||
r1321 | ||||
r1396 | print("utc_pedestal :", utc_pedestal) | |||
print("utc_adq :", utc_adq) | ||||
# ·············Relacion: utc_adq (+/-) var_tiempo*nro_file= utc_pedestal | ||||
time_Interval_p = 0.01 | ||||
n_perfiles_p = 100 | ||||
if utc_adq > utc_pedestal: | ||||
nro_file = int((int(utc_adq) - int(utc_pedestal)) / (time_Interval_p * n_perfiles_p)) | ||||
ff_pedestal = list_pedestal[nro_file] | ||||
utc_pedestal = gettimeutcfromDirFilename(path=dir_pedestal, file=ff_pedestal) | ||||
nro_key_p = int((utc_adq - utc_pedestal) / time_Interval_p) | ||||
if utc_adq > utc_pedestal: | ||||
ff_pedestal = ff_pedestal | ||||
r1321 | else: | |||
r1396 | nro_file = nro_file - 1 | |||
ff_pedestal = list_pedestal[nro_file] | ||||
angulo = getDatavaluefromDirFilename(path=dir_pedestal, file=ff_pedestal, value="azimuth") | ||||
nro_key_p = int((utc_adq - utc_pedestal) / time_Interval_p) | ||||
print("nro_file :", nro_file) | ||||
print("name_file :", ff_pedestal) | ||||
print("utc_pedestal_file :", utc_pedestal) | ||||
print("nro_key_p :", nro_key_p) | ||||
print("utc_pedestal_init :", utc_pedestal + nro_key_p * time_Interval_p) | ||||
print("angulo_array :", angulo[nro_key_p]) | ||||
# 4+25+25+25+21 | ||||
# while True: | ||||
list_pedestal = getfirstFilefromPath(path=dir_pedestal, meta="PE", ext=".hdf5") | ||||
list_adq = getfirstFilefromPath(path=dir_adq , meta="D", ext=".hdf5") | ||||
r1321 | ||||
r1396 | nro_file = nro_file # 10 | |||
r1321 | nro_key_perfil = nro_key_p | |||
r1396 | blocksPerFile = 100 | |||
wr_path = "/home/alex/Downloads/hdf5_wr/" | ||||
r1321 | # Lectura de archivos de adquisicion para adicion de azimuth | |||
for thisFile in range(len(list_adq)): | ||||
r1396 | print("thisFileAdq", thisFile) | |||
angulo_adq = numpy.zeros(blocksPerFile) | ||||
tmp = 0 | ||||
r1321 | for j in range(blocksPerFile): | |||
r1396 | iterador = nro_key_perfil + 25 * (j - tmp) | |||
r1321 | if iterador < n_perfiles_p: | |||
nro_file = nro_file | ||||
else: | ||||
r1396 | nro_file = nro_file + 1 | |||
tmp = j | ||||
r1321 | iterador = nro_key_perfil | |||
r1396 | ff_pedestal = list_pedestal[nro_file] | |||
angulo = getDatavaluefromDirFilename(path=dir_pedestal, file=ff_pedestal, value="azimuth") | ||||
angulo_adq[j] = angulo[iterador] | ||||
copyfile(dir_adq + "/" + list_adq[thisFile], wr_path + list_adq[thisFile]) | ||||
fp = h5py.File(wr_path + list_adq[thisFile], 'a') | ||||
grp = fp.create_group("Pedestal") | ||||
dset = grp.create_dataset("azimuth" , data=angulo_adq) | ||||
r1321 | fp.close() | |||
r1396 | print("Angulo", angulo_adq) | |||
print("Angulo", len(angulo_adq)) | ||||
nro_key_perfil = iterador + 25 | ||||
if nro_key_perfil < n_perfiles_p: | ||||
r1321 | nro_file = nro_file | |||
else: | ||||
r1396 | nro_file = nro_file + 1 | |||
nro_key_perfil = nro_key_p | ||||