@@ -247,7 +247,8 @@ class serialport:
247247 'YOCTOthread' ,'YOCTOvoltageOutputs' ,'YOCTOcurrentOutputs' ,'YOCTOrelays' ,'YOCTOservos' ,'YOCTOpwmOutputs' ,'HH506RAid' ,'MS6514PrevTemp1' ,'MS6514PrevTemp2' ,'DT301PrevTemp' ,'EXTECH755PrevTemp' ,\
248248 'controlETpid' ,'readBTpid' ,'useModbusPort' ,'showFujiLCDs' ,'arduinoETChannel' ,'arduinoBTChannel' ,'arduinoATChannel' ,\
249249 'ArduinoIsInitialized' ,'ArduinoFILT' ,'HH806Winitflag' ,'R1' ,'devicefunctionlist' ,'externalprogram' ,\
250- 'externaloutprogram' ,'externaloutprogramFlag' ,'PhidgetHUMtemp' ,'PhidgetHUMhum' ,'PhidgetPREpre' ,'TMP1000temp' , 'colorTrackSerial' , 'colorTrackBT' , 'CM_ET_readings_count' , 'CM_BT_readings_count' , 'CM_ET_sum_of_squared_differences' , 'CM_BT_sum_of_squared_differences' ]
250+ 'externaloutprogram' ,'externaloutprogramFlag' ,'PhidgetHUMtemp' ,'PhidgetHUMhum' ,'PhidgetPREpre' ,'TMP1000temp' , 'colorTrackSerial' , 'colorTrackBT' ,
251+ 'CM_reference_timeb' , 'CM_ET_readings_count' , 'CM_BT_readings_count' , 'CM_ET_sum_of_squared_differences' , 'CM_BT_sum_of_squared_differences' ]
251252
252253 def __init__ (self , aw :'ApplicationWindow' ) -> None :
253254
@@ -333,6 +334,7 @@ def __init__(self, aw:'ApplicationWindow') -> None:
333334 self .colorTrackSerial :ColorTrack | None = None
334335 self .colorTrackBT :ColorTrackBLE | None = None
335336
337+ self .CM_reference_timeb :float | None = None # set on adding first reading to detect updated horizontal background profile alignment which resets calculation
336338 self .CM_ET_readings_count :int = 0
337339 self .CM_BT_readings_count :int = 0
338340 self .CM_ET_sum_of_squared_differences :float = 0
@@ -1018,39 +1020,45 @@ def slider_23(self) -> tuple[float,float,float]:
10181020 def CM_ETBT (self ) -> tuple [float ,float ,float ]:
10191021 tx = self .aw .qmc .timeclock .elapsedMilli ()
10201022 try :
1021- t1 = - 1
1022- t2 = - 1
1023- # update counts and sum_of_squared_differences
1024- BTlimit = self .aw .qmc .phases [1 ]
1025- BT = (self .aw .qmc .temp2 [- 1 ] if len (self .aw .qmc .temp2 )> 0 else - 1 )
1026- if (BTlimit < BT and self .aw .qmc .timeindex [0 ] > - 1 and
1027- (tx - self .aw .qmc .timex [self .aw .qmc .timeindex [0 ]] > 90 ) and
1028- self .aw .qmc .timeindex [6 ] == 0 ):
1029- # BT above DRY END as specified in Phased dialog, at least 1:30m after CHARGE and before DROP is registered
1030- ET = (self .aw .qmc .temp1 [- 1 ] if len (self .aw .qmc .temp1 )> 0 else - 1 )
1031- nowB = self .aw .qmc .backgroundtime2index (tx ) # points to the last entry if tx > all elements in btimex
1032- ETB = (self .aw .qmc .temp1B [nowB ] if len (self .aw .qmc .temp1B )> nowB > - 1 else - 1 )
1033- BTB = (self .aw .qmc .temp2B [nowB ] if len (self .aw .qmc .temp2B )> nowB > - 1 else - 1 )
1034- if ET > - 1 and ETB > - 1 :
1035- self .CM_ET_readings_count += 1
1036- ET_squared_diff = (ET - ETB )** 2
1037- self .CM_ET_sum_of_squared_differences += ET_squared_diff
1038- if BT > - 1 and BTB > - 1 :
1039- self .CM_BT_readings_count += 1
1040- BT_squared_diff = (BT - BTB )** 2
1041- self .CM_BT_sum_of_squared_differences += BT_squared_diff
1042- elif self .aw .qmc .timeindex [0 ] == 0 :
1043- # if CHARGE is not set reset readings, keep readings otherwise (eg. after DROP)
1044- self .CM_ET_readings_count = 0
1045- self .CM_ET_sum_of_squared_differences = 0
1046- self .CM_BT_readings_count = 0
1047- self .CM_BT_sum_of_squared_differences = 0
1048- # calc results
1049- if self .CM_ET_readings_count > 0 :
1050- t1 = numpy .sqrt (self .CM_ET_sum_of_squared_differences / self .CM_ET_readings_count )
1051- if self .CM_BT_readings_count > 0 :
1052- t2 = numpy .sqrt (self .CM_BT_sum_of_squared_differences / self .CM_BT_readings_count )
1053- return tx ,t2 ,t1
1023+ if self .aw .qmc .backgroundprofile is not None and len (self .aw .qmc .timeB )> 0 : # a non-empty background profile is loaded
1024+ # set CM reference timeb to first reading of the background profile, if any
1025+ first_timeb :float = self .aw .qmc .timeB [0 ]
1026+ t1 = - 1
1027+ t2 = - 1
1028+ # update counts and sum_of_squared_differences
1029+ BTlimit = self .aw .qmc .phases [1 ]
1030+ BT = (self .aw .qmc .temp2 [- 1 ] if len (self .aw .qmc .temp2 )> 0 else - 1 )
1031+ if (BTlimit < BT and self .aw .qmc .timeindex [0 ] > - 1 and
1032+ (self .CM_reference_timeb is None or self .CM_reference_timeb == first_timeb ) and
1033+ (tx - self .aw .qmc .timex [self .aw .qmc .timeindex [0 ]] > 90 ) and
1034+ self .aw .qmc .timeindex [6 ] == 0 ):
1035+ # BT above DRY END as specified in Phased dialog, at least 1:30m after CHARGE and before DROP is registered
1036+ ET = (self .aw .qmc .temp1 [- 1 ] if len (self .aw .qmc .temp1 )> 0 else - 1 )
1037+ nowB = self .aw .qmc .backgroundtime2index (tx ) # points to the last entry if tx > all elements in btimex (-1 if btime is empty!)
1038+ ETB = (self .aw .qmc .temp1B [nowB ] if len (self .aw .qmc .temp1B )> nowB > - 1 else - 1 )
1039+ BTB = (self .aw .qmc .temp2B [nowB ] if len (self .aw .qmc .temp2B )> nowB > - 1 else - 1 )
1040+ if ET > - 1 and ETB > - 1 :
1041+ self .CM_ET_readings_count += 1
1042+ ET_squared_diff = (ET - ETB )** 2
1043+ self .CM_ET_sum_of_squared_differences += ET_squared_diff
1044+ if BT > - 1 and BTB > - 1 :
1045+ self .CM_BT_readings_count += 1
1046+ BT_squared_diff = (BT - BTB )** 2
1047+ self .CM_BT_sum_of_squared_differences += BT_squared_diff
1048+ self .CM_reference_timeb = first_timeb
1049+ elif self .aw .qmc .timeindex [0 ] == 0 or (self .CM_reference_timeb is not None and self .CM_reference_timeb != first_timeb ):
1050+ # if CHARGE is not set reset readings, keep readings otherwise (eg. after DROP)
1051+ self .CM_reference_timeb = None
1052+ self .CM_ET_readings_count = 0
1053+ self .CM_ET_sum_of_squared_differences = 0
1054+ self .CM_BT_readings_count = 0
1055+ self .CM_BT_sum_of_squared_differences = 0
1056+ # calc results
1057+ if self .CM_ET_readings_count > 0 :
1058+ t1 = numpy .sqrt (self .CM_ET_sum_of_squared_differences / self .CM_ET_readings_count )
1059+ if self .CM_BT_readings_count > 0 :
1060+ t2 = numpy .sqrt (self .CM_BT_sum_of_squared_differences / self .CM_BT_readings_count )
1061+ return tx ,t2 ,t1
10541062 except Exception as e : # pylint: disable=broad-except
10551063 _log .exception (e )
10561064 return tx , - 1 , - 1
0 commit comments