Finding specific points in data array

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 1K views
lee403
Messages
16
Reaction score
1
I have this really noisy data and I'm wanting to plot Temperature v. Time. I used this function to calculate a moving average. Here's some sample code.

Python:
BA1='ANP-Heat-BA1.csv'

#Time Trial 1
time1=pd.read_csv(BA1,skiprows=0)
time1=time1['Time(s)']

#Temperature 
tmp1=pd.read_csv(BA1,skiprows=0)
tmp1=tmp1['Temp']

def movingaverage (values, window):
    weights = np.repeat(1.0, window)/window
    sma = np.convolve(values, weights, 'valid')
    return sma
   
tmp1MA=movingaverage(tmp1, 10)

p.plot(time1[len(time1)-len(tmp1MA):],tmp1MA)

The moving average function seems to work fine at removing some of the random noise, but now I want to find the point in the array tmp1MA that corresponds to a given time1 value. For example, I would like be able to find the averaged temperature at time 500.
 
Hey lee403.

You'd have to define a model and then look at the expectation of that random variable.

What model are you using?
 
You have the moving average values, MAi for a specific set of time points ti. Any particular value of time, t, might be exactly one of the ti values, or in between two ti values or above all of the tis or below all of the tis.

There are a few things you need to decide. Do you want to extrapolate above or use the value of the highest ti? Same question for t below the lowest ti. Do you want to linearly interpolate for between tis or fit a polynomial and use that? You can also do a spline fit to the values and evaluate the spline at t.