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