Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python Finding specific points in data array

  1. Jul 20, 2016 #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.

    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.
     
  2. jcsd
  3. Jul 25, 2016 #2
    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?
     
  4. Jul 29, 2016 #3

    chiro

    User Avatar
    Science Advisor

    Hey lee403.

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

    What model are you using?
     
  5. Jul 29, 2016 #4

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Finding specific points in data array
Loading...