Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Averaging over 15 minutes excluding a negative


brf11 Aug 8, 2019 05:09 PM

I am currently avering a DO (CS511) sensor over a 15 minute period. The problem is the sensor occasionally records a negative value for some reason (no one seems to know why). I would like to put in the code that if a negative value exists ignore that value in the average. Here is my program right now:


'Decagon CTD 10 vented sensor

'2019-08-01 added CS511 DO sensor
'Multiplier started at 0.29839
'Wiring
==========================================================================================
'CTD
'white = 12v
'black = ground
'red = C1

'DO Sensor

'Save and restore variables in case of a power outage or other problems.
PreserveVariables

'DO
Public DOmv : Units DOmv = mv
Public DOppm : Units DOppm = ppm
Public DOMult

'Decagon CTD sensor variables
Public Results(3)
Alias Results(1) = WaterHead_mm : Units WaterHead_mm = mm
Alias Results(2) = Water_TempC : Units Water_TempC = °C
Alias Results(3) = Cond : Units Cond = uS/cm

'Conversions
Public WaterHead_m : Units WaterHead_m = meter
Public WaterGrndLvl_m : Units WaterGrndLvl_m = meter
Public WtrGrnLvlCrctd_m : Units WtrGrnLvlCrctd_m = meter
Public WaterLvlElev : Units WaterLvlElev = meter

'CTD measurement control
Public CTD_Control As Boolean

'DO measurement control
Public DO_Control As Boolean

'Datalogger battery voltage and panel temperature.
Public BattV : Units BattV = vdc
Public CR1000_TmpC : Units CR1000_TmpC = °C

'DISTANCE FROM SENSOR HEAD TO GROUND IN METERS.
Public Ground_Height : Units Ground_Height = meter
Dim Old_GrndHght : Units Old_GrndHght = meter

'Old & New DO calibration multiplier
Dim Old_DOmult

'GROUND ELEVATION IN METERS
Public Elev_mtr : Units Elev_mtr = meter
Dim Old_Elev : Units Old_Elev = meter

'SENSOR HEAD OFFSET
Public Sensor_Offset : Units Sensor_Offset = meter
Dim Old_Sensr_Offst : Units Old_Sensr_Offst = meter

'Define data table
DataTable(_DO, True, -1)
DataInterval(0,15,Min,10)
Sample(1,DOmv,FP2)
Sample(1,DOppm,FP2)
Average(1,DOppm,FP2,False)
EndTable

'Save changes to DO multiplier keeping old and new with timestamp.
DataTable(DO_mult_chng,DOMult <> Old_DOmult,100)
Sample(1,Old_DOmult,IEEE4)
FieldNames("Old Multiplier")
Sample(1,DOMult,IEEE4)
FieldNames("New Multiplier")
EndTable

DataTable(CZMW_10, True, -1)
DataInterval(0,15,Min,10)
Average (1,WtrGrnLvlCrctd_m,FP2,False)
Average (2,Results(2),FP2,False)

EndTable
'Try moving these from above table
DataTable(CZMW_10_Info, True, -1)
DataInterval(0,15,Min,10)
Average (1,WaterLvlElev,FP2,False)
Sample (1,Elev_mtr,IEEE4)
Sample (1,Ground_Height,IEEE4)
Sample (1,Sensor_Offset,IEEE4)

EndTable

'Table for monitoring battery minimums
DataTable(Health,True,-1)
DataInterval(0,1440,Min,10)
Minimum(1,BattV,FP2,False,False)
Maximum (1,BattV,FP2,False,False)
Minimum (1,CR1000_TmpC,FP2,False,False)
Maximum (1,CR1000_TmpC,FP2,False,False)
EndTable

'Only save changes to ground height, elevation of the site, or sensor offset
'when they occur. Save a timestamp along with the old and new information.
DataTable(Grnd_Ht_Chng,Ground_Height <> Old_GrndHght,100)
Sample (1,Old_GrndHght,IEEE4)
FieldNames ("Old Grnd Hght")
Sample (1,Ground_Height,IEEE4)
FieldNames ("New Grnd Hght")
EndTable

DataTable(Elev_Chng,Elev_mtr <> Old_Elev,100)
Sample (1,Old_Elev,IEEE4)
FieldNames ("Old Elevation")
Sample (1,Elev_mtr,IEEE4)
FieldNames ("New Elevation")
EndTable

DataTable(Snsr_Offset_Chng,Sensor_Offset <> Old_Sensr_Offst,100)
Sample (1,Old_Sensr_Offst,IEEE4)
FieldNames ("Old Sensr Offst")
Sample (1,Sensor_Offset,IEEE4)
FieldNames ("New Sensr Offst")
EndTable

BeginProg
Scan(1,Min,1,0)
Battery(BattV)

'Make an automated measurement every three minutes. This will give five
'samples to be averaged for the 15 minute data storage.
If TimeIntoInterval (0,3,Min) Then CTD_Control = True

If CTD_Control Then
CTD_Control = False
SDI12Recorder (Results(),1,1,"M!",1.0,0,-1)
'convert mm to meters
WaterHead_m = WaterHead_mm/1000

'Corrected sensor head distance.
WaterGrndLvl_m = Ground_Height - WaterHead_m
WtrGrnLvlCrctd_m = WaterGrndLvl_m + Sensor_Offset

'Calculate water level elevation.
WaterLvlElev = Elev_mtr - WtrGrnLvlCrctd_m
EndIf

If TimeIntoInterval(0,3,Min) Then DO_Control = True

If DO_Control Then
DO_Control = False
VoltDiff(DOmv,1,mv250,1,True,0,60,-1,0)
DOppm = DOMult * DOmv
EndIf

'Save any changes to any site specific information.
CallTable(Grnd_Ht_Chng)
CallTable(Elev_Chng)
CallTable(Snsr_Offset_Chng)
CallTable(DO_mult_chng)

'Normal data storage.
CallTable(_DO)
CallTable(CZMW_10)
CallTable(CZMW_10_Info)
CallTable(Health)

'This section of code MUST follow the associated CallTable instructions to
'work correctly.
Old_Elev = Elev_mtr
Old_GrndHght = Ground_Height
Old_Sensr_Offst = Sensor_Offset
Old_DOmult = DOMult
NextScan
EndProg


JDavis Aug 9, 2019 08:24 PM

The Average instruction has a DisableVar parameter. Instead of false, you could put in DOppm<0 


brf11 Aug 13, 2019 01:07 PM

Thanks, I will try that. It seems this sensor and and now another cs511 are not stable. Both sensors are deployed in wellls. The readings over a 15 min period are quite large and do not make sense at all. The direct samples jump between 2 and 14 and back to or even lower to the negatives. 

Something seems "off" on these DO sensors....Anyone else have this issue?

Log in or register to post/reply in the forum.