mercredi 22 février 2017

Resample a time series reducing the uncertainties for multiple selection with numpy random?

I would like to know how to resample a time series reducing the uncertainties of only the points that have multiple repetitions when using numpy random uniform generator of numbers. Let said I have the following time series T1 in the file "serie.dat" with column1 days column2 Fluxes and column3 errors. First I am using asciitable to read the file:

T1 = asciitable.read('serie.dat')

Now getting each column separately:

days   = T1.col1
fluxes = T1.col2
errors = T1.col3

Computing the random numbers:

ran = np.random.random(len(days)) * len(days)

Using itemfreq from scipy.stats to get the frequency table

freq = itemfreq(ran)

Select the values that are repeated:

repsel = freq[freq[:,1] > 1][:,0]

From here I would like to index the column 3 (the errors) with the numbers obtained before and divide by the root-square of the repetitions and finally resample the original days, fluxes and errors with the new index.

If is not yet clear, Here is what I am doing with matlab: First reading the file:

LC1=dlmread('serie.dat')

Computing the random numbers:

ran=rand(length(LC1),1)*length(LC1)

Get the frequency table

freq=tabulate(ran)

The difference with matlab is that tabulate gives 3 columns, the unique values, the number of repetitions and the percentage of each value (the third column is not important)

Now select only the multiple repetitions (>0) from column 2

freq(freq(:,2)==0,:)=[]

Now reducing the uncertainties (my original errors column) for multiple selected points:

 LC1(freq(:,1),3)=LC1(freq(:,1),3)./sqrt(freq(:,2))

And finally resampling the original time series:

LC1=LC1(freq(:,1),:)

I hope the problem is clear. Thanks a lot for your help!




Aucun commentaire:

Enregistrer un commentaire