Airthings / wave-reader

MIT License
50 stars 18 forks source link

Radon Short Time Average is not a real moving average over last 24hr #17

Open mariusg0000 opened 1 year ago

mariusg0000 commented 1 year ago

Hello,

I use a pseudo-inversing algo from numpy in order to obtain original values from a moving average series. When i use this script on movig average from randomly generated number, everyting is ok, i can obtain original values with a small error but when I use the same script on STA values from last 7 days, the result not as expected, many negative values, high volatility which makes me think that STA in not a real moving (rolling) average, but something else. Can you provide the algorithm used for obtaining STA values or can you provide the raw, instant radon values over the last hour ?

Here is the python script I use:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.ndimage import shift
import random

def reconstruct_orig(sm_x:np.ndarray, win_size:int=7):

    arr_size = sm_x.shape[0]+win_size
    # get A and its inverse     
    A = (np.tril(np.ones((arr_size,arr_size)),-1) - np.tril(np.ones((arr_size,arr_size)),-(win_size+1)))/win_size
    A = A[win_size:,:]
    pA = np.linalg.pinv(A) #pseudo inverse
    return np.dot(pA, sm_x)

if __name__=="__main__":

    data = np.loadtxt("sta.csv", delimiter=",",dtype='float')
    orig = pd.DataFrame(data)

    re_x = reconstruct_orig(orig, win_size=24)

    data = np.concatenate([np.zeros((23)), data]) # right shift 24 values  

    plt.plot(data,label='original x')
    plt.plot(re_x, label='reconstructed x')
    plt.legend()
    plt.show()

REVERSE_RND reverse_sta

tonbut commented 2 months ago

@mariusg0000 Nice analysis! I had suspected the data wasn't a moving average either and it would certainly nice to get a realtime output and do my own averaging as required. It's shame as i'd like to get faster feedback than whatever it is doing now.

mariusg0000 commented 2 months ago

Meanwhile, I sold my Airthings Wave and bought a RadonEye RD200, a beautiful device, precise and easy to use. I can read it via Bluetooth with a Python script or even with an ESP32 module. I get a reading every 10 minutes and a one-hour moving average.

tonbut commented 2 months ago

Thanks Marius. The RD200 looks like just what I need too.