diff --git a/calfile/profiler/immersion_factors_Lu.dat b/calfile/profiler/immersion_factors_Lu.dat new file mode 100644 index 0000000..9eaced0 --- /dev/null +++ b/calfile/profiler/immersion_factors_Lu.dat @@ -0,0 +1,63 @@ +;immersion factors for TriOS radiance +;wavelength(nm) factors +350 1.7743 +360 1.7710 +370 1.7681 +380 1.7653 +390 1.7628 +400 1.7604 +410 1.7583 +420 1.7563 +430 1.7544 +440 1.7526 +450 1.7510 +460 1.7494 +470 1.7480 +480 1.7466 +490 1.7454 +500 1.7441 +510 1.7430 +520 1.7419 +530 1.7409 +540 1.7399 +550 1.7390 +560 1.7381 +570 1.7372 +580 1.7364 +590 1.7356 +600 1.7349 +610 1.7342 +620 1.7335 +630 1.7328 +640 1.7322 +650 1.7316 +660 1.7310 +670 1.7305 +680 1.7299 +690 1.7294 +700 1.7289 +710 1.7284 +720 1.7280 +730 1.7275 +740 1.7271 +750 1.7267 +760 1.7263 +770 1.7259 +780 1.7255 +790 1.7251 +800 1.7248 +810 1.7244 +820 1.7241 +830 1.7238 +840 1.7235 +850 1.7232 +860 1.7229 +870 1.7226 +880 1.7223 +890 1.7220 +900 1.7217 +910 1.7215 +920 1.7212 +930 1.7210 +940 1.7207 +950 1.7205 \ No newline at end of file diff --git a/profiler.py b/profiler.py index e7a615d..5ba97a1 100644 --- a/profiler.py +++ b/profiler.py @@ -9,7 +9,7 @@ from scipy.optimize import leastsq from datetime import datetime, timedelta from myRamses import RamsesFactoryHandle,AirWater from tools.mylogger import log -from myconfig import TOKEN,NEWLINE,DATA_DIR,SAVE_EXT_NAME +from myconfig import TOKEN,NEWLINE,DATA_DIR,SAVE_EXT_NAME,CAL_DIR from myconfig import RamsesPROFILE from pubsub import pub @@ -287,10 +287,11 @@ class Profiler(object): configSensor:List[str] =None # 序列号 configFunc:List[str] =None # 功能 Ed Esky Lu calibrationCfg:dict =None - data : ProfilerData =None + data : ProfilerData =None depth : List[float] =None wavelength:List[np.ndarray] =None spectrum:List[np.ndarray] =None + immersion_factors:np.ndarray = None beginWavelength: float = None endWavelength: float = None rowFactor:float = None @@ -333,6 +334,12 @@ class Profiler(object): self.newWavelength = np.arange(self.beginWavelength,self.endWavelength,self.wvInterval) pass + def set_immersion_factors(self, ifs:np.ndarray): + wv = ifs[:, 0] + val = ifs[:, 1] + self.immersion_factors = np.interp(self.newWavelength,wv,val) + pass + def set_ramses_sensor_numbers(self, num:int = 3): self.data.data_frame = DataFrame() self.data.data_frame.set_ramses_num( num ) @@ -494,7 +501,10 @@ class Profiler(object): '''' Get Lu0 Ku ''' log.info( " >> ", __name__, "get_Lu0_Ku" ) x = np.array(self.depth) - y = np.log(self.Lu) # ln_Lu + + ## 浸没因子处理 ## + tmp = self.deal_Lu_by_immersion_factors() + y = np.log(tmp) # ln_Lu self.Ku,ln_Lu0 = self.leastsq_linear_fitting( x, y) self.Lu0 = np.exp(ln_Lu0) @@ -512,6 +522,12 @@ class Profiler(object): # log.warning(t) # log.warning(self.Ed0) + def deal_Lu_by_immersion_factors ( self, ): + '''' ?????? 浸没因子处理 Lu ??? ''' + ifs = self.immersion_factors + lu = self.Lu + return lu + def leastsq_linear_fitting( self, arr_depth:np.ndarray, arr_data:np.ndarray ): '''最小二乘拟合 # arr_depth np一维数组 @@ -610,7 +626,7 @@ class ProfilerHandle(object): self.profiler.set_tilt_range(tilt_angle) def read_info_path(self,infopath: Path ): - assert infopath.exists(), f">>>> not find {fpath} " + assert infopath.exists(), f">>>> not find {infopath} " ret_bytes = b'' with open(infopath, 'rb') as file: ret_bytes = file.read() @@ -618,7 +634,7 @@ class ProfilerHandle(object): self.profiler.data.set_info_frame( ret_bytes ) def read_sensor_path(self, sensorpath:Path): - assert sensorpath.exists(), f">>>> not find {fpath} " + assert sensorpath.exists(), f">>>> not find {sensorpath} " with open(sensorpath, 'rb') as file: ret_bytes = file.read() assert len(ret_bytes) > 1754, f">>>> no data " @@ -639,7 +655,7 @@ class ProfilerHandle(object): if bf.name != "info.bin": bytes_list.append( self.read_bin(bf) ) - self.profiler.data.set_data_frame( bytes_list, pth, self.aw.callback ) # 目录也要传过去 + self.profiler.data.set_data_frame( bytes_list, pth, self.profiler.callback ) # 目录也要传过去 pass def read_folders_from_SD(self, pth:Path): @@ -670,6 +686,7 @@ class ProfilerHandle(object): self.read_info_path(infopath) self.profiler.reset_profiler() self.profiler.data.set_wavelength( ) # 设置波长 + self.read_immersion_factors( ) # 读取浸没因子 # log.warning( f" {self.profiler.data.wavelength}" ) self.profiler.get_depth_offset() self.read_sensor_path(sensorpath) @@ -683,7 +700,15 @@ class ProfilerHandle(object): msg = {"flag":"notice", "data": "完成数据处理 " } pub.sendMessage('update' , msg=msg) pass - + + def read_immersion_factors(self,)->np.ndarray: + assert fpath.exists(), f">>>> not find {fpath} " + fname = "immersion_factors_Lu.dat" + fpath = CAL_DIR.joinpath( "profiler" ,fname) + ret = np.loadtxt(fpath,skiprows=2) + return ret + pass + def read_bin(self,fpath: Path): assert fpath.exists(), f">>>> not find {fpath} " ret = b'' @@ -750,35 +775,48 @@ def profiler_demo(): ph.profiler.get_Lw_Rs(ph.retrieve["n_t_square"]) ph.profiler.save(savedir) - +# def read_immersion_factors( )->np.ndarray: +# fname = "immersion_factors_Lu.dat" +# fpath = CAL_DIR.joinpath( "profiler" ,fname) +# assert fpath.exists(), f">>>> not find {fpath} " +# ret = np.loadtxt(fpath,skiprows=2) +# return ret +# pass + if __name__ == '__main__': - device_id = 2 - ph = ProfilerHandle( device_id, ProfilerCfg.cfg, ProfilerCfg.calcfg, ProfilerCfg.rtv) - fpath = Path.cwd() - # t= ("data", "2","2002","8", "17","51", "info.bin") - # t= ("data" ) - infopath = fpath.joinpath('data','2','37','info.bin') - sensorpath = fpath.joinpath('data','2','37','sensor.bin') - savedir = fpath.joinpath('data','2','37' ) + # ret = read_immersion_factors() + # print(ret) + # print(ret[:,0]) + # print(ret[:,1]) + + # device_id = 2 + # ph = ProfilerHandle( device_id, ProfilerCfg.cfg, ProfilerCfg.calcfg, ProfilerCfg.rtv) + # fpath = Path.cwd() + # # t= ("data", "2","2002","8", "17","51", "info.bin") + # # t= ("data" ) + # infopath = fpath.joinpath('data','2','37','info.bin') + # sensorpath = fpath.joinpath('data','2','37','sensor.bin') + # savedir = fpath.joinpath('data','2','37' ) - ph.set_ramses_number(3) - ph.set_tilt_range(21.0) + # ph.set_ramses_number(3) + # ph.set_tilt_range(21.0) - ph.read_info_path(infopath) - ph.profiler.reset_profiler() - ph.profiler.data.set_wavelength( ) # 设置波长 - ph.profiler.get_depth_offset() - ph.read_sensor_path(sensorpath) + # ph.read_info_path(infopath) + # ph.profiler.reset_profiler() + # ph.profiler.data.set_wavelength( ) # 设置波长 + # ph.profiler.get_depth_offset() + # ph.read_sensor_path(sensorpath) - # log.info( f" Ed: {ph.profiler.Ed} ") - # log.info( f" Lu: {ph.profiler.Lu} ") - ph.profiler.get_Ed0_kd() - ph.profiler.get_Lu0_Ku() - # log.info( f" Ed0: {ph.profiler.Ed0} ") - # log.info( f" Lu0: {ph.profiler.Lu0} ") - ph.profiler.get_Lw_Rs(ph.retrieve["n_t_square"]) - # log.info( f" Lw: {ph.profiler.Lw} ") - # log.info( f" Rs: {ph.profiler.Rs} ") - ph.profiler.save(savedir) + # # log.info( f" Ed: {ph.profiler.Ed} ") + # # log.info( f" Lu: {ph.profiler.Lu} ") + # ph.profiler.get_Ed0_kd() + # ph.profiler.get_Lu0_Ku() + # # log.info( f" Ed0: {ph.profiler.Ed0} ") + # # log.info( f" Lu0: {ph.profiler.Lu0} ") + # ph.profiler.get_Lw_Rs(ph.retrieve["n_t_square"]) + # # log.info( f" Lw: {ph.profiler.Lw} ") + # # log.info( f" Rs: {ph.profiler.Rs} ") + # ph.profiler.save(savedir) + pass