コード例 #1
0
ファイル: spectraTools.py プロジェクト: monakurp/P4UL
def spectraAnalysis(fig, v , time, vName, Nbins, mode, normalize=False ):
      
  nterms  = np.shape(v) # Number of variables in the file, number of entries in the data. 
  print(' Number of terms in the {} data series, N = {}'.format(vName, nterms))

  # Determine the sampling frequency.
  samplingFreq   = samplingFrequency( time, None )
  print(' sampling frequency = {}'.format(samplingFreq))

  deltaT = (time[-1]-time[0])
  vw     = applyTapering( v , deltaT , samplingFreq )

  # Evaluate, Power (P), power spectral energy (E), and power spectral density (S).
  P, E, S, freqs = evalSpectra( vw, samplingFreq, normalize )

  
  if(mode == 'S'): 
    Sbin, fbin = frequencyBins( S , freqs, Nbins )
    Vbin = Sbin
  if(mode == 'E'): 
    Ebin, fbin = frequencyBins( E , freqs, Nbins )
    Vbin = Ebin
  if(mode == 'P'): 
    Pbin, fbin = frequencyBins( P , freqs, Nbins )
    Vbin = Pbin

  Refbin = 1.E-1 * fbin[Nbins/2:]**(-5./3.)

  if( mode == 'S' ):
    if( normalize ):
      labelStr = "{}, normalized power spectral density".format(vName)
      plotStr  = [ "Normalized power spectral density","Frequency [Hz]","f*S/$\sigma^2$ "] 
    else:
      labelStr = "{}, power spectral density: $\Phi(f)$".format(vName)
      plotStr  = ["Power spectral density" ,"Frequency [Hz]","$\Phi(f)$"] 
  elif( mode == 'E' ):
    labelStr = "{}, energy spectrum: E(f)".format(vName)
    plotStr  = ["Energy spectrum","Frequency [Hz]","E(f)"]
  else:
    labelStr = "{}, power spectrum: P(f)".format(vName)
    plotStr  = ["Power spectrum","Frequency [Hz]","P(f)"]

    
  if( fig is None ):
    fig = plt.figure(num=1, figsize=(12.,10.))
    fig = addToPlot(fig,fbin[Nbins/2:],np.nanmean(Vbin)*Refbin,"Model -5/3 curve",plotStr,logOn=True)
  fig = addToPlot(fig, fbin, Vbin, labelStr, plotStr, logOn=True)
  
  
  return fig

# =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*


# =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*



# =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
コード例 #2
0
                        Re_t[i], Re_d[i]))
elif (isinstance(u, np.float)):
    print(dStr.format(u, l, nu, t, epsilon, v, eta, Re_t, Re_d))

# The log-law profile for the velocity
z = np.linspace(0., l, int(l / dz))
kappa = 0.41

# Um := mean(U)/u*
Um = us / kappa * np.log(np.maximum((z - d) / z0, 1.))

if (printOn):
    ufig = plt.figure(1)
    ufig = addToPlot(ufig,
                     Um,
                     z,
                     '<U>', ["Log-law Velocity profile", "<U>", "z"],
                     logOn=False)
    plt.show()

dUm = Um[1:] - Um[:-1]
dz = z[1:] - z[:-1]
zm = z[:-1]
dUmdz = dUm / dz

print('u(z):\n' + ' '.join('{:.2f},'.format(uv) for uv in Um[::c]))
print('z :\n' + ' '.join('{},'.format(zi) for zi in z[::c].astype(int)))
print('v(z):\n' + ' '.join('{},'.format(v) for v in np.zeros(len(z[::c]))))

print('dudz(z):\n' + ' '.join('{:.3f},'.format(s * duz) for duz in dUmdz[::c]))
print('z :\n' + ' '.join('{},'.format(zim) for zim in zm[::c].astype(int)))
コード例 #3
0
  
    # ======= Write 100% F_km ================
    f_vtk = vtkWritePointDataStructured2D( f_vtk, F_km, Xt, 'fp_km' )
  
    # ======= Write 00% F_km ================
    Ftmp[:,:] = 0.; Ftmp += F_km*id90_km
    f_vtk = vtkWritePointDataStructured2D( f_vtk, Ftmp , Xt, 'fp90_km' )

    # Close the file at the end.
    f_vtk.close(); Ftmp = None

if( printOn ):
  CfD = dict()
  CfD['title']='F(x,y)'; CfD['label']=fileout; CfD['N']=16
  Cfp = addContourf( Xt, Yt, Ft  , CfD )
  
  CfD['title']='F_km(x,y), Ana'; CfD['label']=fileout+'_km'
  Cfa = addContourf( Xt, Yt, F_km, CfD )
  
  Fym = writeCrossWindSum( Ft, Xt, None, None )
  pfig = plt.figure(num=3, figsize=(12.,9.))
  varLabel = '$fp_y(x) = \sum_y fp(x,y)$'
  axLabels = ['Cross Wind Integrated Footprint', 'x', 'sum_y fp(x,y) ']
  pfig = addToPlot(pfig, Xt[0,:], Fym, varLabel, axLabels, False )


Ft = Zt = Xt = Yt = None
F_km = None

plt.show()
コード例 #4
0
ファイル: dataAnalysisNetCdf.py プロジェクト: monakurp/P4UL
  # Process data vr --> vp 
  if( mode == 'mean'):
    vp  = np.mean( vr, axis=axs ); zp = z
    if( vr2 is not None ): vp2 = np.mean( vr2, axis=axs )
    plotStr  = ["mean({}) vs z ".format(varname), varname ,"z"]

  elif( mode == 'std'):
    vp  = np.std( vr, axis=axs ); zp = z
    if( vr2 is not None ): vp2 = np.std( vr2, axis=axs ) 
    
    if(meanErrorOn):
      N = len( vr[:,0,0,0] )
      vmerr = vp/np.sqrt(N)
      if( len(vmerr.shape)  == 3 ): vmerr  = vmerr[:,0,0]
      plotStr  = ["std. error of mean({}) vs z ".format(varname), varname ,"z"]
      fig = addToPlot(fig, vmerr, zp,'{}({}), {}'\
        .format('std error of mean',varname,fileList[fn].split('_')[-1]), plotStr, False )
    
      '''
      N2 = len( vr2[:,0,0,0] )
      vmerr2 = vp2/np.sqrt(N2)
      if( len(vmerr2.shape) == 3 ): vmerr2 = vmerr2[:,0,0]
      fig = addToPlot(fig, vmerr2, zp,'{}({}), {}'\
      .format('std error of mean',varname,fileList[fn]), plotStr, False )
      '''
    plotStr  = ["std({}) vs z ".format(varname), varname ,"z"]
    
  elif( mode == 'var' ):
    vp  = np.var( vr, axis=axs ); zp = z
    if( vr2 is not None ): vp2 = np.var( vr2, axis=axs )
    plotStr  = ["var({}) vs z ".format(varname), varname ,"z"]
  
コード例 #5
0
ファイル: plotNetCdf1D.py プロジェクト: monakurp/P4UL
    for iy in iyList:
        # Read data
        y, xdict = readVariableFromDataset(varList[iy], ds, 1)

        if ('time' not in list(xdict.keys())):
            print(' time not in dict = {} '.format(xdict.keys()))
            print(' adding time=[None] ...')
            xdict['time'] = np.array([None])
            y = y.reshape((1, len(y)))  # to ensure len(np.shape(y)) == 2

        # If time is the only parameter, use it on x-axis
        if (len(np.shape(y)) == 1):
            xStr = 'time'
            labelStr = ' {}({}) '.format(varList[iy], 'time')
            plotTxt = [labelStr, xStr, varList[iy]]
            fig = addToPlot(fig, xdict[xStr], y, labelStr, plotTxt, logOn)
            if (writeAscii):
                print(' (1) Writing data to ascii file: {}.dat'.format(
                    varList[iy]))
                np.savetxt(varList[iy] + '_ts.dat',
                           np.c_[xdict[xStr],
                                 y])  # x,y,z equal sized 1D arrays

        elif (len(np.shape(y)) == 2):
            time = xdict['time']
            xList = list(xdict.keys())
            xList.remove('time')  # remove time ...
            xStr = xList[0]  # and take what is left ... z-something, typically
            tskip = min(tskip, len(time) - 1)

            # Plot profiles for chosen time instances
コード例 #6
0
        fig.append(pl.figure(num=j, figsize=(10., 8.)))

    for fn in fileNos:
        lblList.append(fileList[fn])

        for j in xrange(len(pId)):
            d = pl.loadtxt(fileList[fn])
            """
            Cols:   0       1      2      3       4       5     6
            Vars: Center  Umean   Umax   Umin    Width    Id   time
            """

            if (pId[j] == 0):
                x = d[:, 6]
                y = d[:, 0]
            if (pId[j] == 1):
                x = d[:, 6]
                y = d[:, 1]
            if (pId[j] == 2):
                x = d[:, 6]
                y = d[:, 4]
            fig[j] = addToPlot(fig[j], x, y, fileList[fn],
                               [selections[j], xlb[j], ylb[j]], 0)

    for j in xrange(len(pId)):
        ax, = fig[j].get_axes()
        lns = ax.get_lines()
        ax.legend(lns, lblList, loc=1)

    pl.show()
コード例 #7
0
    if (len(veldict.keys()) == 2):
        umag = np.mean(umag, axis=(0))
        pt = np.mean(pt, axis=(0))

    for dstr in veldict.keys():
        if ('z' in dstr): z = veldict[dstr]

    veldict = None

    dudz = (umag[1:] - umag[:-1]) / (z[1:] - z[:-1])
    dptdz = (pt[1:] - pt[:-1]) / (z[1:] - z[:-1])
    zm = 0.5 * (z[1:] + z[:-1])

    Ri = (9.81 / np.mean(pt)) * (dptdz) / (dudz**2 +
                                           1e-9) * (dudz > 1e-3).astype(float)

    plotStr = ["Local Ri vs z ", "Ri", "z"]
    fig = addToPlot(fig, Ri[2:-4], zm[2:-4], '{}'.format(fileList[fn]),
                    plotStr, False)

    plotStr = ["dpt/dz vs z ", "dpt/dz", "z"]
    fig2 = addToPlot(fig2, dptdz[2:-4], zm[2:-4], '{}'.format(fileList[fn]),
                     plotStr, False)

    plotStr = ["du/dz vs z ", "du/dz", "z"]
    fig3 = addToPlot(fig3, dudz[2:-4], zm[2:-4], '{}'.format(fileList[fn]),
                     plotStr, False)

plt.legend(loc=0)
plt.show()
コード例 #8
0
ファイル: profilesFromCSV.py プロジェクト: biglimp/P4UL
avar    = args.appendv
af      = args.appendf

nY = len(args.yvars)

# Append the x- and a-variables into the variable list. 
varList.append(xvar)
varList.append(avar)

fileNos, fileList = filesFromList( "*"+strKey+"*" )

pfig = plt.figure(num=1, figsize=(12,10))

for fn in fileNos:
  dat = extractFromCSV( fileList[fn] , varList )
  a = dat[-1]; x = dat[-2]; y = dat[:-2]
  dat = None
  
  for i in xrange(nY):
    astr ='_'+str(int(a[0]/100.))
    y[i]+=(a*af)
    axLabels = ["{}(z)".format(varList[i]),"{} +x/100 [m/s]".format(varList[i]),"z [m]"]
    varLabel = varList[i]+astr
    pfig = addToPlot(pfig,y[i], x, varLabel, axLabels, False )
    
if(args.labels): pfig = userLabels( pfig )
  
plt.legend(loc=0)
plt.grid(True)
plt.show()
コード例 #9
0
    Fo = np.array( extractColumns( raw , [7,8,9] ) )
    Tp = np.array( extractColumns( raw , [10,11,12] ) )
    Tv = np.array( extractColumns( raw , [13,14,15] ) )
    To = np.array( extractColumns( raw , [16,17,18] ) )

    time.extend(t)
    for n in xrange(3):
        Ftot[n].extend( Fp[n]+Fv[n]+Fo[n] )
        Ttot[n].extend( Tp[n]+Tv[n]+To[n] )

    #print np.shape(t), np.shape(time), np.shape(Fp[0]),np.shape(Ftot[0])     

fig = pl.figure(1, figsize=(8.5,8.5))
if( not args.torgue ):
    plotTxt = ["Forces", "Iter/Time (s)", "F (N)"]
    fig = addToPlot(fig, time, Ftot[0],'Fx', plotTxt, False)
    fig = addToPlot(fig, time, Ftot[1],'Fy', plotTxt, False)
    fig = addToPlot(fig, time, Ftot[2],'Fz', plotTxt, False)
else:
    plotTxt = ["Torques", "Iter/Time (s)", "T (Nm)"]
    fig = addToPlot(fig, time, Ttot[0],'Tx', plotTxt, False)
    fig = addToPlot(fig, time, Ttot[1],'Ty', plotTxt, False)
    fig = addToPlot(fig, time, Ttot[2],'Tz', plotTxt, False)

if(args.labels):
    fig = userLabels( fig )
pl.legend(loc=0)
pl.grid(True)


pl.show()
コード例 #10
0
dtime = np.mean( time[1:] - time[:-1] )
ltime = (time[-1] - time[0])/Nt
f1    = 1./ltime
f2    = 1./(2.*dtime)
nsteps= int( (f2-f1)/f1 )
freq  = np.linspace(f1,f2,nsteps,endpoint=False)


print(' f1 = {}, f2 = {}, nsteps = {} '.format(f1,f2,nsteps))
print(' freq = {} '.format( freq ))


sig  = v[:,kIds[0], ijk1[1], ijk1[0]] - np.mean( v[:,kIds[0], ijk1[1], ijk1[0]] )
fig1 = plt.figure()
plotStr = [" Signal "," time "," v(time) "]
fig1 = addToPlot(fig1, time, \
  ndimage.gaussian_filter(sig, sigma=60.),'Filtered', plotStr )
fig1 = addToPlot(fig1, time,sig,'Signal', plotStr )



WD1 = wtDataset(sig,  time, f=freq )

if( complexOn ):  tt = "complex"
else:             tt = "real"


if('hist' in mode):
  Qstr = '''    Enter the index of desired {} values
    given the range values {}...{} with indecies {}...{}.'''
  if( 'spectro' in mode ):
    histmode = 'frequency'