##// END OF EJS Templates
Update PedestalInformation for continuous reading
jespinoza -
r1440:747a8eb02426
parent child
Show More
@@ -1,31 +1,33
1 import numpy,os,h5py
1
2 import os
3 import time
2 4 import math
3 from scipy import optimize, interpolate, signal, stats, ndimage
4 import scipy
5
5 6 import re
6 7 import datetime
7 8 import copy
8 9 import sys
9 10 import importlib
10 11 import itertools
12
11 13 from multiprocessing import Pool, TimeoutError
12 14 from multiprocessing.pool import ThreadPool
13 import time
14
15 import numpy
16 import glob
17 import scipy
18 import h5py
15 19 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
16 20 from .jroproc_base import ProcessingUnit, Operation, MPDecorator
17 21 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
18 22 from scipy import asarray as ar,exp
19 23 from scipy.optimize import curve_fit
20 24 from schainpy.utils import log
25 import schainpy.admin
21 26 import warnings
22 from numpy import NaN
27 from scipy import optimize, interpolate, signal, stats, ndimage
23 28 from scipy.optimize.optimize import OptimizeWarning
24 29 warnings.filterwarnings('ignore')
25 30
26 from time import sleep
27
28 import matplotlib.pyplot as plt
29 31
30 32 SPEED_OF_LIGHT = 299792458
31 33
@@ -4043,214 +4045,87 class WeatherRadar(Operation):
4043 4045 return dataOut
4044 4046
4045 4047 class PedestalInformation(Operation):
4046 path_ped = None
4047 path_adq = None
4048 samp_rate_ped= None
4049 t_Interval_p = None
4050 n_Muestras_p = None
4051 isConfig = False
4052 blocksPerfile= None
4053 f_a_p = None
4054 online = None
4055 angulo_adq = None
4056 nro_file = None
4057 nro_key_p = None
4058 tmp = None
4059
4060 4048
4061 4049 def __init__(self):
4062 4050 Operation.__init__(self)
4051 self.filename = False
4063 4052
4053 def find_file(self, timestamp):
4064 4054
4065 def getAnguloProfile(self,utc_adq,utc_ped_list):
4066 utc_adq = utc_adq
4067 ##list_pedestal = list_pedestal
4068 utc_ped_list = utc_ped_list
4069 #for i in range(len(list_pedestal)):
4070 # #print(i)# OJO IDENTIFICADOR DE SINCRONISMO
4071 # utc_ped_list.append(self.gettimeutcfromDirFilename(path=self.path_ped,file=list_pedestal[i]))
4072 nro_file,utc_ped,utc_ped_1 =self.getNROFile(utc_adq,utc_ped_list)
4073 #print("NROFILE************************************", nro_file,utc_ped)
4074 #print(nro_file)
4075 if nro_file < 0:
4076 return numpy.NaN,numpy.NaN
4077 else:
4078 nro_key_p = int((utc_adq-utc_ped)/self.t_Interval_p)-1 # ojito al -1 estimado alex
4079 #print("nro_key_p",nro_key_p)
4080 ff_pedestal = self.list_pedestal[nro_file]
4081 #angulo = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="azimuth")
4082 angulo = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="azi_pos")
4083 angulo_ele = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="ele_pos")
4084 #-----Adicion de filtro........................
4085 vel_ele = self.getDatavaluefromDirFilename(path=self.path_ped,file=ff_pedestal,value="ele_speed")## ele_speed
4086 '''
4087 vel_mean = numpy.mean(vel_ele)
4088 print("#############################################################")
4089 print("VEL MEAN----------------:",vel_mean)
4090 f vel_mean<7.7 or vel_mean>8.3:
4091 return numpy.NaN,numpy.NaN
4092 #------------------------------------------------------------------------------------------------------
4093 '''
4094 #print(int(self.samp_rate_ped))
4095 #print(nro_key_p)
4096 if int(self.samp_rate_ped)-1>=nro_key_p>0:
4097 #print("angulo_array :",angulo[nro_key_p])
4098 return angulo[nro_key_p],angulo_ele[nro_key_p]
4099 else:
4100 #print("-----------------------------------------------------------------")
4101 return numpy.NaN,numpy.NaN
4102
4103
4104 def getfirstFilefromPath(self,path,meta,ext):
4105 validFilelist = []
4106 #("SEARH",path)
4107 try:
4108 fileList = os.listdir(path)
4109 except:
4110 print("check path - fileList")
4111 if len(fileList)<1:
4112 return None
4113 # meta 1234 567 8-18 BCDE
4114 # H,D,PE YYYY DDD EPOC .ext
4115
4116 for thisFile in fileList:
4117 #print("HI",thisFile)
4118 if meta =="PE":
4119 try:
4120 number= int(thisFile[len(meta)+7:len(meta)+17])
4121 except:
4122 print("There is a file or folder with different format")
4123 if meta =="pos@":
4124 try:
4125 number= int(thisFile[len(meta):len(meta)+10])
4126 except:
4127 print("There is a file or folder with different format")
4128 if meta == "D":
4129 try:
4130 number= int(thisFile[8:11])
4131 except:
4132 print("There is a file or folder with different format")
4133
4134 if not isNumber(str=number):
4135 continue
4136 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
4137 continue
4138 validFilelist.sort()
4139 validFilelist.append(thisFile)
4140
4141 if len(validFilelist)>0:
4142 validFilelist = sorted(validFilelist,key=str.lower)
4143 #print(validFilelist)
4144 return validFilelist
4145 return None
4146
4147 def gettimeutcfromDirFilename(self,path,file):
4148 dir_file= path+"/"+file
4149 fp = h5py.File(dir_file,'r')
4150 #epoc = fp['Metadata'].get('utctimeInit')[()]
4151 epoc = fp['Data'].get('utc')[()]
4152 epoc = epoc[0]
4153 #print("hola",epoc)
4154 fp.close()
4155 return epoc
4156
4157 def gettimeutcadqfromDirFilename(self,path,file):
4158 pass
4055 dt = datetime.datetime.utcfromtimestamp(timestamp)
4056 path = os.path.join(self.path, dt.strftime('%Y-%m-%dT%H-00-00'))
4159 4057
4160 def getDatavaluefromDirFilename(self,path,file,value):
4161 dir_file= path+"/"+file
4162 fp = h5py.File(dir_file,'r')
4163 array = fp['Data'].get(value)[()]
4164 fp.close()
4165 return array
4058 if not os.path.exists(path):
4059 return False, False
4060 fileList = glob.glob(os.path.join(path, '*.h5'))
4061 fileList.sort()
4062 for fullname in fileList:
4063 filename = fullname.split('/')[-1]
4064 number = int(filename[4:14])
4065 if number <= timestamp:
4066 return number, fullname
4067 return False, False
4166 4068
4069 def find_next_file(self):
4167 4070
4168 def getNROFile(self,utc_adq,utc_ped_list):
4169 c=0
4170 #print(utc_adq)
4171 #print(len(utc_ped_list))
4172 ###print(utc_ped_list)
4173 if utc_adq<utc_ped_list[0]:
4174 pass
4175 else:
4176 for i in range(len(utc_ped_list)):
4177 if utc_adq>utc_ped_list[i]:
4178 #print("mayor")
4179 #print("utc_ped_list",utc_ped_list[i])
4180 c +=1
4071 while True:
4072 file_size = len(self.fp['Data']['utc'])
4073 if self.utctime < self.utcfile+file_size*self.interval:
4074 break
4075 self.utcfile += file_size*self.interval
4076 dt = datetime.datetime.utcfromtimestamp(self.utctime)
4077 path = os.path.join(self.path, dt.strftime('%Y-%m-%dT%H-00-00'))
4078 self.filename = os.path.join(path, 'pos@{}.000.h5'.format(self.utcfile))
4079 if not os.path.exists(self.filename):
4080 log.warning('Waiting for position files...', self.name)
4181 4081
4182 return c-1,utc_ped_list[c-1],utc_ped_list[c]
4082 if not os.path.exists(self.filename):
4183 4083
4184 def verificarNROFILE(self,dataOut,utc_ped,f_a_p,n_Muestras_p):
4185 pass
4084 raise IOError('No new position files found in {}'.format(path))
4085 self.fp.close()
4086 self.fp = h5py.File(self.filename, 'r')
4087 log.log('Opening file: {}'.format(self.filename), self.name)
4186 4088
4187 def setup_offline(self,dataOut,list_pedestal):
4188 pass
4089 def get_values(self):
4189 4090
4190 def setup_online(self,dataOut):
4191 pass
4091 index = int((self.utctime-self.utcfile)/self.interval)
4092 return self.fp['Data']['azi_pos'][index], self.fp['Data']['ele_pos'][index]
4192 4093
4193 #def setup(self,dataOut,path_ped,path_adq,t_Interval_p,n_Muestras_p,blocksPerfile,f_a_p,online):
4194 def setup(self,dataOut,path_ped,samp_rate_ped,t_Interval_p,wr_exp):
4195 #print("**************SETUP******************")
4196 self.__dataReady = False
4197 self.path_ped = path_ped
4198 self.samp_rate_ped= samp_rate_ped
4199 self.t_Interval_p = t_Interval_p
4200 self.list_pedestal = self.getfirstFilefromPath(path=self.path_ped,meta="pos@",ext=".h5")
4201
4202 self.utc_ped_list= []
4203 for i in range(len(self.list_pedestal)):
4204 #print(i,self.gettimeutcfromDirFilename(path=self.path_ped,file=self.list_pedestal[i]))# OJO IDENTIFICADOR DE SINCRONISMO
4205 self.utc_ped_list.append(self.gettimeutcfromDirFilename(path=self.path_ped,file=self.list_pedestal[i]))
4206 #print(self.utc_ped_list)
4207 #exit(1)
4208 #print("que paso")
4209 dataOut.wr_exp = wr_exp
4210 #print("SETUP READY")
4094 def setup(self, dataOut, path, conf, samples, interval, wr_exp):
4211 4095
4096 self.path = path
4097 self.conf = conf
4098 self.samples = samples
4099 self.interval = interval
4100 self.utcfile, self.filename = self.find_file(dataOut.utctime)
4212 4101
4213 def setNextFileP(self,dataOut):
4214 pass
4102 if not self.filename:
4103 log.error('No position files found in {}'.format(path), self.name)
4104 raise IOError('No position files found in {}'.format(path))
4105 else:
4106 log.log('Opening file: {}'.format(self.filename), self.name)
4107 self.fp = h5py.File(self.filename, 'r')
4215 4108
4216 def checkPedFile(self,path,nro_file):
4217 pass
4109 def run(self, dataOut, path, conf=None, samples=1500, interval=0.04, wr_exp=None):
4218 4110
4219 def setNextFileoffline(self,dataOut):
4220 pass
4111 if not self.isConfig:
4112 self.setup(dataOut, path, conf, samples, interval, wr_exp)
4113 self.isConfig = True
4221 4114
4222 def setNextFileonline(self):
4223 pass
4115 self.utctime = dataOut.utctime
4224 4116
4225 def run(self, dataOut,path_ped,samp_rate_ped,t_Interval_p,wr_exp):
4226 #print("INTEGRATION -----")
4227 #print("PEDESTAL")
4117 self.find_next_file()
4228 4118
4229 if not self.isConfig:
4230 self.setup(dataOut, path_ped,samp_rate_ped,t_Interval_p,wr_exp)
4231 self.__dataReady = True
4232 self.isConfig = True
4233 #print("config TRUE")
4234 utc_adq = dataOut.utctime
4235 #print("utc_adq---------------",utc_adq)
4236
4237 list_pedestal = self.list_pedestal
4238 #print("list_pedestal",list_pedestal[:20])
4239 angulo,angulo_ele = self.getAnguloProfile(utc_adq=utc_adq,utc_ped_list=self.utc_ped_list)
4240 #print("angulo**********",angulo)
4119 az, el = self.get_values()
4241 4120 dataOut.flagNoData = False
4242 4121
4243 if numpy.isnan(angulo) or numpy.isnan(angulo_ele) :
4244 #print("PEDESTAL 3")
4245 #exit(1)
4122 if numpy.isnan(az) or numpy.isnan(el) :
4246 4123 dataOut.flagNoData = True
4247 4124 return dataOut
4248 dataOut.azimuth = angulo
4249 dataOut.elevation = angulo_ele
4250 #print("PEDESTAL END")
4251 #print(dataOut.azimuth)
4252 #print(dataOut.elevation)
4253 #exit(1)
4125
4126 dataOut.azimuth = az
4127 dataOut.elevation = el
4128 # print('AZ: ', az, ' EL: ', el)
4254 4129 return dataOut
4255 4130
4256 4131 class Block360(Operation):
General Comments 0
You need to be logged in to leave comments. Login now