Ejemplo n.º 1
0
    def process_from_samples(self):
        # populate data from files
        for index, file in enumerate(self.hdf5files):
            print 'Processing data from file', self.hdf5files[index]
            f = h5py.File(file, "r")

            # load input scalars
            for scalar in self.inputscalars:
                self.__dict__['in_'+scalar] = np.squeeze(f[scalar][()])

            # load input data
            for data in list(self.inputdata):
                self.__dict__['in_'+data]   = np.squeeze(f[data][()])
            f.close()

            # populate scalars
            for scalar in self.scalars:
                #self.__dict__[scalar][index] = howtocompute[scalar]()
                self.__dict__[scalar][index] = self.get_t()

            # populate arrays
            for var, data, varindex in list(self.planes):
                self.__dict__[var][index,:] = self.get_scalar(data, varindex)

        # Compute mean with arsel
        # Compute arsel for all variables
        if self.nfiles == 1:
            for var in [planes[0] for planes in self.planes]:
                #print "... Computing for", var
                for index in xrange(self.Ny):
                    self.__dict__['mean_'   +var][index] = self.__dict__[var][0,index]
                    self.__dict__['sigma_'  +var][index] = 0
                    self.__dict__['eff_N_'  +var][index] = 0
                    self.__dict__['eff_var_'+var][index] = 0
                    self.__dict__['T0_'     +var][index] = 0
        else:
            for var in [planes[0] for planes in self.planes]:
                #print "... Computing for", var
                for index in xrange(self.Ny):
                    t = ar.arsel(self.__dict__[var][:,index])
                    self.__dict__['mean_'   +var][index] = t.mu[0]
                    self.__dict__['sigma_'  +var][index] = t.mu_sigma[0]
                    self.__dict__['eff_N_'  +var][index] = t.eff_N[0]
                    self.__dict__['eff_var_'+var][index] = t.eff_var[0]
                    self.__dict__['T0_'     +var][index] = t.T0[0]
Ejemplo n.º 2
0
def writeResult(option, result, info='-', timeSeriesFile=None):

    globalResult = [res/(nSteps-avgStart) for res in result]
    resultFile = primal.resultFile
    if parallel.rank == 0:
        noise = 0
        if option == 'perturb':
            previousResult = float(open(resultFile).readline().split(' ')[3])
            globalResult[0] -= previousResult
        noise = [0. for res in result]
        if timeSeriesFile:
            import ar
            timeSeries = np.loadtxt(timeSeriesFile,ndmin=1)[avgStart::sampleInterval]
            if len(timeSeries.shape) == 1:
                timeSeries = timeSeries.reshape(-1,1)
            for index in range(0, len(result)):
                noise[index] = (ar.arsel(timeSeries[:, index]).mu_sigma**2)[0]
        with open(resultFile, 'a') as handle:
            for index in range(0, len(result)):
                handle.write('{} {} {} {} {}\n'.format(option, index, info, globalResult[index], noise[index]))
Ejemplo n.º 3
0
p = 3
n = len(s) + 1
Np = (2 * n - 1) * p + n
if not submean:
    Np += n
s = np.array(s)
# HACK
#s = s[:,:100]
N = len(s[0])

t = np.zeros(Np)
import ar
import matplotlib.pyplot as plt
for i in range(0, n - 1):
    A = ar.arsel(s[i], 0, 1, "CIC", p, p)
    c = -np.array(A.AR[0][1:])
    t[i:n * p:n] = c
    t[n - 1:n * p:n] = c
    #t[n*i+n-1] = 1.
    t[(2 * n - 1) * p + i] = A.sigma2eps[0]
    if not submean:
        t[(2 * n - 1) * p + n + i] = ms[i]

    #yp = []
    #for j in range(p, N):
    #    yp.append(np.dot(s[i][j-p:j+1][::-1],A.AR[0]))
    #plt.plot(yp)
    ##plt.hist(yp, bins=100)
    #plt.show()
Ejemplo n.º 4
0
    
  elif control=='VC':
    Pin = 0.5*sum((pdata[indx:h-2,1]-pdata[indx:h-2,2])*
                    (pdata[indx+1:h-1,0]-pdata[indx:h-2,0]))/ \
              sum(pdata[indx+1:h-1,0]-pdata[indx:h-2,0]);  print('  \twdwdy\t:\t', Pin)
    PinN = Pin; PinP = Pin
  gamma = Pin/P0;                                          print('  \tgamma\t:\t', gamma)

# Computing uncertainties
sbar_dudy=0.0; sbar_Ub=0.0; T0_dudy=0.0; T0_Ub=0.0
if elaborate:
  t = linspace(data[indx,0],data[m-2,0],m-indx-1); dt=t[1]-t[0]
  dudyI0 = zeros((1,m-indx-1)); dudyIn = zeros((1,m-indx-1));
  dudyI0f = interp1d(data[indx-1:m-1,0], data[indx-1:m-1,1]); dudyI0[0,:] = dudyI0f(t)
  dudyInf = interp1d(data[indx-1:m-1,0], data[indx-1:m-1,2]); dudyIn[0,:] = dudyInf(t)
  ar_dudyI0 = arsel(dudyI0); ar_dudyIn = arsel(dudyIn)
  zi0  = lfiltic([1], ar_dudyI0.AR[0], ar_dudyI0.autocor[0])
  zin  = lfiltic([1], ar_dudyIn.AR[0], ar_dudyIn.autocor[0])
  rho0 = ones(m-indx-1); rho0[1:] = lfilter([1], ar_dudyI0.AR[0], \
              zeros(m-indx-2), zi=zi0)[0]
  rhon = ones(m-indx-1); rhon[1:] = lfilter([1], ar_dudyIn.AR[0], \
              zeros(m-indx-2), zi=zin)[0]
  sbar_dudy = std(concatenate((data[indx:m-1,1], data[indx:m-1,2])))/ \
              sqrt(ar_dudyI0.eff_N[0]+ar_dudyIn.eff_N[0])
  T0_dudy =  0.5*dt*(ar_dudyI0.T0[0]+ar_dudyIn.T0[0])
  if CPI:
    UbI = zeros((1,m-indx-1))
    UbIf = interp1d(data[indx-1:m-1,0], data[indx-1:m-1,5]); UbI[0,:] = 0.5*UbIf(t)
    ar_UbI  = arsel(UbI); ziUb  = lfiltic([1], ar_UbI.AR[0], ar_UbI.autocor[0])
    rhoU = ones(m-indx-1); rhoU[1:] = lfilter([1], ar_UbI.AR[0],  \
                zeros(m-indx-2), zi=ziUb)[0]
Ejemplo n.º 5
0
import ar
e = [[], []]
cmap = plt.get_cmap('nipy_spectral')
colors = [cmap(i) for i in np.linspace(0, 1, len(sys.argv) - 1)]
cs = []
c = 1

start = 50000
for f in sys.argv[1:]:
    y = np.loadtxt(f)[start:]
    n = len(y)
    x = np.arange(0, n)
    m = y.mean()
    y = y - m
    e[0].append(m)
    e[1].append(ar.arsel(y).mu_sigma[0])
    print e[0][-1], e[1][-1]
    token = os.path.basename(f).split('_')[0]
    cs.append(c)
    #plt.plot(x[:n/2], auto_corr(y)[:n/2])
    #plt.xlabel('Time unit')
    #plt.ylabel('Autocorrelation')
    #plt.savefig(f.replace('timeSeries.txt', 'autocorr.png'))
    #plt.clf()
    #plt.show()
    c += 1

x = np.arange(0, len(cs) + 2, 1)
for i, c in enumerate(cs):
    c = (33 + 0.01 * (c - 3)) / 360.
    plt.errorbar(c, e[0][i], e[1][i], ecolor='b', fmt='o')