python - Remove peak lines -


i have data file in save datetime, ph, , temperature. once in while, temperature misses 1 digit shown below:

12-08-2017_14:52:21 temp: 28.9 ph: 7.670 12-08-2017_14:52:42 temp: 28.9 ph: 7.672 12-08-2017_14:53:03 temp: 28.9 ph: 7.672 12-08-2017_14:53:24 temp: 8.91 ph: 7.667 12-08-2017_14:53:45 temp: 28.9 ph: 7.667 12-08-2017_14:54:06 temp: 28.9 ph: 7.669 12-08-2017_14:54:27 temp: 28.9 ph: 7.671 

i'd remove whole line error. i've found solutions this, don't understand how implement in python. there specific way should it, either in python or bash?

it depends lot on behavior desire , complexity of solution required. data posted, can try computing difference last measurement , rejecting measurements have difference on threshold degrees previous one. quick , dirty example of this:

threshold = 10 lasttemp = none  while true:     line = raw_input().split()     temp = float(line[2])      if not lasttemp:        lasttemp = temp      if abs(temp - lasttemp) > threshold:        continue      # process line here     print line 

this skips lines measurements 10 degrees difference previous one. suitable if measurements taken @ small enough intervals , no large temperature changes expected.

a small improvement on consider last few measurements, compute prediction next measurement (if 2 considered, derivative - more points bit more complicated approaches required), reject if value far away prediction. alternatively, more complex statistical approaches can used.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -