@@ -0,0 +1,189 | |||
|
1 | import os,numpy,h5py | |
|
2 | from shutil import copyfile | |
|
3 | import sys,time | |
|
4 | ||
|
5 | def isNumber(str): | |
|
6 | try: | |
|
7 | float(str) | |
|
8 | return True | |
|
9 | except: | |
|
10 | return False | |
|
11 | ||
|
12 | def getfirstFilefromPath(path,meta,ext): | |
|
13 | validFilelist = [] | |
|
14 | fileList = os.listdir(path) | |
|
15 | if len(fileList)<1: | |
|
16 | return None | |
|
17 | # meta 1234 567 8-18 BCDE | |
|
18 | # H,D,PE YYYY DDD EPOC .ext | |
|
19 | ||
|
20 | for thisFile in fileList: | |
|
21 | if meta =="PE": | |
|
22 | try: | |
|
23 | number= int(thisFile[len(meta)+7:len(meta)+17]) | |
|
24 | except: | |
|
25 | print("There is a file or folder with different format") | |
|
26 | if meta == "D": | |
|
27 | try: | |
|
28 | number= int(thisFile[8:11]) | |
|
29 | except: | |
|
30 | print("There is a file or folder with different format") | |
|
31 | ||
|
32 | if not isNumber(str=number): | |
|
33 | continue | |
|
34 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | |
|
35 | continue | |
|
36 | validFilelist.sort() | |
|
37 | validFilelist.append(thisFile) | |
|
38 | if len(validFilelist)>0: | |
|
39 | validFilelist = sorted(validFilelist,key=str.lower) | |
|
40 | return validFilelist | |
|
41 | return None | |
|
42 | ||
|
43 | def gettimeutcfromDirFilename(path,file): | |
|
44 | dir_file= path+"/"+file | |
|
45 | fp = h5py.File(dir_file,'r') | |
|
46 | epoc = fp['Metadata'].get('utctimeInit')[()] | |
|
47 | fp.close() | |
|
48 | return epoc | |
|
49 | ||
|
50 | def getDatavaluefromDirFilename(path,file,value): | |
|
51 | dir_file= path+"/"+file | |
|
52 | fp = h5py.File(dir_file,'r') | |
|
53 | array = fp['Data'].get(value)[()] | |
|
54 | fp.close() | |
|
55 | return array | |
|
56 | ||
|
57 | ||
|
58 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Velocidad de PedestalΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
59 | w = input ("Ingresa velocidad de Pedestal: ") | |
|
60 | w = 4 | |
|
61 | w = float(w) | |
|
62 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Resolucion minimo en gradosΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
63 | alfa = input ("Ingresa resolucion minima en grados: ") | |
|
64 | alfa = 1 | |
|
65 | alfa = float(alfa) | |
|
66 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· IPP del Experimento Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
67 | IPP = input ("Ingresa el IPP del experimento: ") | |
|
68 | IPP = 0.0004 | |
|
69 | IPP = float(IPP) | |
|
70 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· MODE Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
71 | mode = input ("Ingresa el MODO del experimento T or F: ") | |
|
72 | mode = "T" | |
|
73 | mode = str(mode) | |
|
74 | ||
|
75 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Tiempo en generar la resolucion minΒ·Β·Β· | |
|
76 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· MCU Β·Β· var_ang = w * (var_tiempo)Β·Β·Β· | |
|
77 | var_tiempo = alfa/w | |
|
78 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· Tiempo Equivalente en perfilesΒ·Β·Β·Β·Β·Β·Β·Β· | |
|
79 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· var_tiempo = IPP * ( num_perfiles )Β· | |
|
80 | num_perfiles = int(var_tiempo/IPP) | |
|
81 | ||
|
82 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·DATA PEDESTALΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
83 | dir_pedestal = "/home/developer/Downloads/Pedestal/P2021064" | |
|
84 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· DATA ADQΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
85 | if mode=="T": | |
|
86 | dir_adq = "/home/developer/Downloads/HDF5_TESTPP2/d2021064" # Time domain | |
|
87 | else: | |
|
88 | dir_adq = "/home/developer/Downloads/hdf5_test/d2021053" # Frequency domain | |
|
89 | ||
|
90 | print( "Velocidad angular :", w) | |
|
91 | print( "Resolucion minima en grados :", alfa) | |
|
92 | print( "Numero de perfiles equivalente:", num_perfiles) | |
|
93 | print( "Mode :", mode) | |
|
94 | ||
|
95 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· First FileΒ·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
96 | list_pedestal = getfirstFilefromPath(path=dir_pedestal,meta="PE",ext=".hdf5") | |
|
97 | list_adq = getfirstFilefromPath(path=dir_adq ,meta="D",ext=".hdf5") | |
|
98 | print("list_pedestal") | |
|
99 | #print(list_pedestal) | |
|
100 | print("list_adq") | |
|
101 | #print(list_adq) | |
|
102 | #sys.exit(0) | |
|
103 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· utc time Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β· | |
|
104 | utc_pedestal= gettimeutcfromDirFilename(path=dir_pedestal,file=list_pedestal[0]) | |
|
105 | utc_adq = gettimeutcfromDirFilename(path=dir_adq ,file=list_adq[0]) | |
|
106 | ||
|
107 | print("utc_pedestal :",utc_pedestal) | |
|
108 | print("utc_adq :",utc_adq) | |
|
109 | #sys.exit(0) | |
|
110 | ||
|
111 | #Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Β·Relacion: utc_adq (+/-) var_tiempo*nro_file= utc_pedestal | |
|
112 | time_Interval_p = 0.01 | |
|
113 | n_perfiles_p = 100 #muestras por achivo del pedestal | |
|
114 | ||
|
115 | ||
|
116 | if utc_adq>utc_pedestal: | |
|
117 | nro_file = int((utc_adq - utc_pedestal)/(time_Interval_p*n_perfiles_p)) | |
|
118 | print("nro_file",nro_file) | |
|
119 | ff_pedestal = list_pedestal[nro_file] | |
|
120 | print(ff_pedestal) | |
|
121 | utc_pedestal = gettimeutcfromDirFilename(path=dir_pedestal,file=ff_pedestal) | |
|
122 | print(utc_pedestal) | |
|
123 | nro_key_p = int((utc_adq-utc_pedestal)/time_Interval_p) | |
|
124 | print(nro_key_p) | |
|
125 | #sys.exit(0) | |
|
126 | if utc_adq >utc_pedestal: | |
|
127 | ff_pedestal = ff_pedestal | |
|
128 | else: | |
|
129 | nro_file = nro_file-1 | |
|
130 | ff_pedestal = list_pedestal[nro_file] | |
|
131 | utc_pedestal = gettimeutcfromDirFilename(path=dir_pedestal,file=ff_pedestal) | |
|
132 | angulo = getDatavaluefromDirFilename(path=dir_pedestal,file=ff_pedestal,value="azimuth") | |
|
133 | nro_key_p = int((utc_adq-utc_pedestal)/time_Interval_p) | |
|
134 | print("nro_file :",nro_file) | |
|
135 | print("name_file :",ff_pedestal) | |
|
136 | print("utc_pedestal_file :",utc_pedestal) | |
|
137 | print("nro_key_p :",nro_key_p) | |
|
138 | print("utc_pedestal_init :",utc_pedestal+nro_key_p*time_Interval_p) | |
|
139 | print("angulo_array :",angulo[nro_key_p]) | |
|
140 | #4+25+25+25+21 | |
|
141 | #while True: | |
|
142 | list_pedestal = getfirstFilefromPath(path=dir_pedestal,meta="PE",ext=".hdf5") | |
|
143 | list_adq = getfirstFilefromPath(path=dir_adq ,meta="D",ext=".hdf5") | |
|
144 | ||
|
145 | nro_file = nro_file #10 | |
|
146 | nro_key_perfil = nro_key_p | |
|
147 | blocksPerFile = 100##### aqui se cambia dependiendo de los blqoues por achivo en adq | |
|
148 | wr_path = "/home/developer/Downloads/HDF5_WR/" | |
|
149 | # Lectura de archivos de adquisicion para adicion de azimuth | |
|
150 | # factor de archivos | |
|
151 | #f_a_p = tiempo_file_1_adq/tiempo_file_1_ped=25/1 = 25 | |
|
152 | tiempo_file_1_adq=25 | |
|
153 | tiempo_file_1_ped=1 | |
|
154 | f_a_p= int(tiempo_file_1_adq/tiempo_file_1_ped) | |
|
155 | for thisFile in range(len(list_adq)): | |
|
156 | print("thisFileAdq",thisFile) | |
|
157 | angulo_adq = numpy.zeros(blocksPerFile) | |
|
158 | tmp = 0 | |
|
159 | for j in range(blocksPerFile): | |
|
160 | iterador = nro_key_perfil + f_a_p*(j-tmp) | |
|
161 | #print("iterador",iterador) | |
|
162 | if iterador < n_perfiles_p: | |
|
163 | nro_file = nro_file | |
|
164 | else: | |
|
165 | nro_file = nro_file+1 | |
|
166 | dif = blocksPerFile-(nro_key_perfil+f_a_p*(j-tmp-1)) | |
|
167 | tmp = j | |
|
168 | nro_key_perfil= f_a_p-dif | |
|
169 | iterador = nro_key_perfil | |
|
170 | #print(iterador) | |
|
171 | print("nro_file",nro_file) | |
|
172 | ff_pedestal = list_pedestal[nro_file] | |
|
173 | angulo = getDatavaluefromDirFilename(path=dir_pedestal,file=ff_pedestal,value="azimuth") | |
|
174 | angulo_adq[j]= angulo[iterador] | |
|
175 | copyfile(dir_adq+"/"+list_adq[thisFile],wr_path+list_adq[thisFile]) | |
|
176 | fp = h5py.File(wr_path+list_adq[thisFile],'a') | |
|
177 | #grp = fp.create_group("Pedestal") | |
|
178 | grp = fp['Metadata'] | |
|
179 | #sgrp = grp.create_group('Pedestal') | |
|
180 | dset = grp.create_dataset("azimuth" , data=angulo_adq) | |
|
181 | fp.close() | |
|
182 | print("Angulo",angulo_adq) | |
|
183 | print("Angulo",len(angulo_adq)) | |
|
184 | nro_key_perfil=iterador + f_a_p | |
|
185 | if nro_key_perfil< n_perfiles_p: | |
|
186 | nro_file = nro_file | |
|
187 | else: | |
|
188 | nro_file = nro_file+1 | |
|
189 | nro_key_perfil= nro_key_p |
General Comments 0
You need to be logged in to leave comments.
Login now