# Python Finding specific points in data array

1. Jul 20, 2016

### lee403

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.

Code (Python):
BA1='ANP-Heat-BA1.csv'

#Time Trial 1
time1=time1['Time(s)']

#Temperature
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.

2. Jul 25, 2016

### Greg Bernhardt

Thanks for the post! This is an automated courtesy bump. Sorry you aren't generating responses at the moment. Do you have any further information, come to any new conclusions or is it possible to reword the post?

3. Jul 29, 2016

### chiro

Hey lee403.

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

What model are you using?

4. Jul 29, 2016

### FactChecker

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.