Ejemplo n.º 1
0
def plotMagPhase(h5fname):

    mdata = fdata(h5fname)

    lenz2 = (mdata.vars.nz2 - 1) * mdata.vars.dz2
    z2axis = (np.arange(0, mdata.vars.nz2)) * mdata.vars.dz2
    saxis = z2axis * mdata.vars.lc

    xaxis = (np.arange(0, mdata.vars.nx)) * mdata.vars.dxbar
    yaxis = (np.arange(0, mdata.vars.ny)) * mdata.vars.dybar

    sampleFreq = 1.0 / mdata.vars.dz2

    lenz2 = (mdata.vars.nz2 - 1) * mdata.vars.dz2
    z2axis = (np.arange(0, mdata.vars.nz2)) * mdata.vars.dz2

    xf, yf = readField(h5fname, f1D=1)

    intens = np.square(xf) + np.square(yf)

    mgx, phx = getMagPhase(xf, mdata.vars.nz2, mdata.vars.rho, lenz2)
    mgy, phy = getMagPhase(yf, mdata.vars.nz2, mdata.vars.rho, lenz2)

    ax1 = plt.subplot(311)
    plt.plot(z2axis, xf, label='x-field')
    plt.plot(z2axis, yf, label='y-field')
    plt.xlabel('z2')
    plt.ylabel('Fields')
    plt.legend()

    # example for adding subplot
    plt.subplot(312, sharex=ax1)
    plt.plot(z2axis, mgx, label='x-field')
    plt.plot(z2axis, mgy, label='y-field')
    plt.xlabel('z2')
    plt.ylabel('Mag')

    axes = plt.subplot(313, sharex=ax1)
    plt.plot(z2axis, phx, label='x-field')
    plt.plot(z2axis, phy, label='y-field')
    plt.xlabel('z2')
    plt.ylabel('Phase')
    axes.set_ylim([0, 2. * pi])

    nameparts = h5fname.split('_')
    basename = nameparts[0]

    z = mdata.vars.z

    plt.savefig(basename + "_magPhase_z_" + str(z) + ".png")
Ejemplo n.º 2
0
def getFilteredFields(h5fname, cfr=None, dfr=None, qAv = 0, qScale = None):

    mdata = fdata(h5fname)

    if (qScale==None):
        qScale = mdata.vars.qscale

    lenz2 = (mdata.vars.nz2-1) * mdata.vars.dz2
    z2axis = (np.arange(0, mdata.vars.nz2)) * mdata.vars.dz2
    
    xaxis = (np.arange(0, mdata.vars.nx)) * mdata.vars.dxbar
    yaxis = (np.arange(0, mdata.vars.ny)) * mdata.vars.dybar

    xf, yf = readField(h5fname)

    if ((cfr != None) and (dfr != None)):

        xf = filterField(xf, cfr, dfr, mdata.vars)
        yf = filterField(yf, cfr, dfr, mdata.vars)


    return xf, yf
Ejemplo n.º 3
0
def plotSpecPow(h5fname, ftplottype=None):

    mdata = fdata(h5fname)

    #   To select temporal slice of field....

    #z2s = 50
    #z2e = 80

    #z2si = int(np.floor(z2s / dz2))
    #z2ei = int(np.floor(z2e / dz2))

    #z2axis = (np.arange(z2si,z2ei) - z2si) * dz2

    #    ...otherwise take full field

    lenz2 = (mdata.vars.nz2 - 1) * mdata.vars.dz2
    z2axis = (np.arange(0, mdata.vars.nz2)) * mdata.vars.dz2

    xaxis = (np.arange(0, mdata.vars.nx)) * mdata.vars.dxbar
    yaxis = (np.arange(0, mdata.vars.ny)) * mdata.vars.dybar

    xf, yf = readField(h5fname, f1D=1)

    #xf = np.concatenate((xf, xf))
    #xf = np.concatenate((xf, xf))
    #xf = np.concatenate((xf, xf))
    #xf = np.concatenate((xf, xf))
    #xf[mdata.vars.nz2:] = 0.
    #yf = np.concatenate((yf, yf)) # [yf, yf, yf, yf]
    #yf = np.concatenate((yf, yf))
    #yf = np.concatenate((yf, yf))
    #yf = np.concatenate((yf, yf))
    #yf[mdata.vars.nz2:] = 0.

    intens = np.square(xf) + np.square(yf)

    #npads = np.int(np.round(mdata.vars.nz2 / 2))
    npads = mdata.vars.nz2

    xff = np.fft.fft(xf, n=npads)
    yff = np.fft.fft(yf, n=npads)

    NumUniquePts = np.int_(np.ceil((npads + 1) / 2))
    fs = (mdata.vars.nz2) / lenz2  #sampling frequency

    ftfieldtemp = np.zeros(NumUniquePts + 1)
    ftfieldtemp = xff[0:NumUniquePts]

    ftxpower = np.square(np.absolute(ftfieldtemp))

    if np.remainder(npads, 2) == 1:
        ftxpower[1:] = ftxpower[1:] * 2
    else:
        ftxpower[1:-1] = ftxpower[1:-1] * 2

    ftfieldtemp = yff[0:NumUniquePts]

    ftypower = np.square(np.absolute(ftfieldtemp))

    if np.remainder(npads, 2) == 1:
        ftypower[1:] = ftypower[1:] * 2
    else:
        ftypower[1:-1] = ftypower[1:-1] * 2

    #print str(mdata.vars.lr)
    #ftxaxis = (np.arange(0,NumUniquePts)*(fs/(npads)))*(4.*np.pi*mdata.vars.rho)
    #ftxaxis[1:] = 1 / ftxaxis[1:]
    #ftxaxis[0] = ftxaxis[-1] + 1

    if (ftplottype == 1):
        ftxaxis = mdata.vars.lr / ((np.arange(0, NumUniquePts) * (fs /
                                                                  (npads))) *
                                   (4. * np.pi * mdata.vars.rho))
        sp_x_axis = r'$\lambda (m)$'

    else:
        ftxaxis = (np.arange(0, NumUniquePts) *
                   (fs / (npads))) * (4. * np.pi * mdata.vars.rho)
        sp_x_axis = r'$\omega / \omega_r$'

    sp_title = 'Intensity Spectrum'

    #    z2axis = [z2axis,z2axis,z2axis,z2axis]

    ax1 = plt.subplot(211)
    plt.plot(z2axis, xf, label='x field')
    plt.plot(z2axis, yf, label='y field')
    plt.xlabel(r'$\bar{z}_2$', fontsize=16)
    plt.ylabel('Fields', fontsize=16)
    plt.legend()

    # example for adding subplot
    axes = plt.subplot(212)
    plt.xlabel(sp_x_axis, fontsize=16)
    plt.ylabel('Intensity', fontsize=16)
    #print np.len(ftxaxis), np.len(ftxpower)

    if ftplottype == 1:
        plt.loglog(ftxaxis, ftxpower, label='x intensity')
        plt.plot(ftxaxis, ftypower, label='y intensity')
        plt.plot(ftxaxis, ftxpower + ftypower, label='combined')
#        axes.set_xlim([5.8e-10, 7.2e-10])

    else:
        plt.semilogy(ftxaxis, ftxpower, label='x intensity')
        plt.plot(ftxaxis, ftypower, label='y intensity')
        plt.plot(ftxaxis, ftxpower + ftypower, label='combined')
        axes.set_xlim([0.8, 1.2])

    plt.legend()

    nameparts = h5fname.split('_')
    basename = nameparts[0]
    z = mdata.vars.z

    plt.tight_layout()

    plt.savefig(basename + "-spec-intensity-z-" + str(z) + ".png")
Ejemplo n.º 4
0
def spectroT(h5fname, z2s=None, z2e=None, qScale=None):

    mdata = fdata(h5fname)

    if (qScale == None):
        qScale = mdata.vars.qscale

    lenz2 = (mdata.vars.nz2 - 1) * mdata.vars.dz2

    xf, yf = readField(h5fname, f1D=1)

    #    dz2 = h5f.root.runInfo._v_attrs.sLengthOfElmZ2
    #    nz2 = h5f.root.runInfo._v_attrs.nZ2

    sampleFreq = 1.0 / mdata.vars.dz2

    #    z2s = 0.00
    #    z2e = 0.06

    if ((z2s == None) or (z2e == None)):
        z2si = 0
        z2ei = mdata.vars.nz2
    else:
        z2si = int(np.floor(z2s / mdata.vars.dz2))
        z2ei = int(np.floor(z2e / mdata.vars.dz2))

    xfs = xf[z2si:z2ei]
    yfs = yf[z2si:z2ei]

    xaxis = (np.arange(0, mdata.vars.nx)) * mdata.vars.dxbar
    yaxis = (np.arange(0, mdata.vars.ny)) * mdata.vars.dybar
    z2axis = (np.arange(z2si, z2ei) - z2si) * mdata.vars.dz2

    if (qScale == 0):
        z2axis = z2axis * mdata.vars.lc
        freqScale = mdata.vars.lr
        xfs = xfs * mdata.vars.fieldScale  # * mdata.vars.lc / mdata.vars.c0
        sampleFreq = sampleFreq / mdata.vars.lc
        xaxisl = r'$ct-z (m)$'
        faxisl = r'x-field $(Vm^{-1})$'
        saxisl = r'$\omega / \omega_0$'
    else:
        freqScale = 4. * np.pi * mdata.vars.rho
        xaxisl = r'$\bar{z}_2$'
        faxisl = 'x-field (Scaled)'
        saxisl = r'$\bar{f}$'

    ax1 = plt.subplot(211)
    plt.plot(z2axis, xfs)
    plt.xlabel(xaxisl, fontsize=16)
    plt.ylabel(faxisl, fontsize=16)
    plt.xlim(200e-6, 210e-6)

    plt.subplot(212, sharex=ax1)
    #    specf = signal.get_window(('tukey',2.0),128)
    #    freqs, time, Sxx = signal.spectrogram(xfs, sampleFreq, nperseg=128, nfft=2048, \
    #     window=specf)
    Sxx = signal.cwt(xfs, signal.ricker, np.arange(1, 31))
    #    freqs = freqs * freqScale
    #    plt.pcolormesh(time, freqs, Sxx)
    plt.pcolormesh(z2axis, np.arange(1, 31), Sxx)
    plt.xlim(0.0025, 0.0026)
    #    plt.ylim(0.8,  1.2);
    cb = plt.colorbar()

    #    specP, freqs, time, image = specgram(xfs, \
    #    	NFFT=50, Fs=sampleFreq, noverlap=0)#, cmap=plt.cm.gist_heat)

    #    freqs = freqs * 3e8

    #    plt.pcolor(time,freqs,specP)

    plt.xlabel(xaxisl, fontsize=16)
    plt.ylabel(saxisl, fontsize=16)

    plt.tight_layout()
    # then either:
    #plt.imshow(specP,cmap='PRGn')
    #    plt.show()

    # -or- just

    nameparts = h5fname.split('_')
    basename = nameparts[0]
    z = mdata.vars.z

    plt.savefig(basename + "-spectrogram-z-" + str(z) + ".png")
Ejemplo n.º 5
0
def plotSpecInt(h5fname, ftplottype=None):

    mdata = fdata(h5fname)

#   To select temporal slice of field....
    
    #z2s = 50  # start in units of z2
    #z2e = 80  # End in units of z2 
    # (everything outside this domain will be set to zero)

    #z2si = int(np.floor(z2s / dz2))
    #z2ei = int(np.floor(z2e / dz2))

    #z2axis = (np.arange(z2si,z2ei) - z2si) * dz2


#    ...otherwise take full field

    lenz2 = (mdata.vars.nz2-1) * mdata.vars.dz2
    z2axis = (np.arange(0, mdata.vars.nz2)) * mdata.vars.dz2

    xaxis = (np.arange(0, mdata.vars.nx)) * mdata.vars.dxbar
    yaxis = (np.arange(0, mdata.vars.ny)) * mdata.vars.dybar

    npads = mdata.vars.nz2

    NumUniquePts = np.int_(np.ceil((npads+1)/2))
    fs = (mdata.vars.nz2)/lenz2 #sampling frequency

#    xpows = np.zeros(NumUniquePts)
#    ypows = np.zeros(NumUniquePts)
    ftfieldtemp = np.zeros(NumUniquePts)

#    for ix in np.arange(0, mdata.vars.nx):
#        for iy in np.arange(0, mdata.vars.ny):
#            print ix, iy

    xf, yf = readField(h5fname, f1D=1)
    xff = np.fft.fft(xf)
    yff = np.fft.fft(yf)
            
    ftfieldtemp = xff[0:NumUniquePts]

    ftxpower = np.square(np.absolute(ftfieldtemp))

    if np.remainder(npads,2) == 1:
        ftxpower[1:] = ftxpower[1:]*2
    else:
        ftxpower[1:-1] = ftxpower[1:-1]*2

#    xpows = xpows + ftxpower

    ftfieldtemp = yff[0:NumUniquePts]

    ftypower = np.square(np.absolute(ftfieldtemp))

    if np.remainder(npads, 2) == 1:
        ftypower[1:] = ftypower[1:]*2
    else:
        ftypower[1:-1] = ftypower[1:-1]*2

#    ypows = ypows + ftypower
#   For padding with zeros!!!

    #xf = np.concatenate((xf, xf))
    #xf = np.concatenate((xf, xf))
    #xf = np.concatenate((xf, xf))
    #xf = np.concatenate((xf, xf))
    #xf[mdata.vars.nz2:] = 0.
    #yf = np.concatenate((yf, yf)) # [yf, yf, yf, yf]
    #yf = np.concatenate((yf, yf))
    #yf = np.concatenate((yf, yf))
    #yf = np.concatenate((yf, yf))
    #yf[mdata.vars.nz2:] = 0.

    #intens = np.square(xf) + np.square(yf)

    #npads = np.int(np.round(mdata.vars.nz2 / 2))
    


    


    
       
       
    #print str(mdata.vars.lr)
    #ftxaxis = (np.arange(0,NumUniquePts)*(fs/(npads)))*(4.*np.pi*mdata.vars.rho)
    #ftxaxis[1:] = 1 / ftxaxis[1:]
    #ftxaxis[0] = ftxaxis[-1] + 1

    if (ftplottype == 1):
        ftxaxis = mdata.vars.lr / ((np.arange(0,NumUniquePts)*(fs/(npads)))*(4.*np.pi*mdata.vars.rho))
        sp_x_axis=r'$\lambda (nm)$' 

    else:
        ftxaxis = (np.arange(0,NumUniquePts)*(fs/(npads)))*(4.*np.pi*mdata.vars.rho)
        sp_x_axis=r'$\omega / \omega_r$'

    sp_title='Intensity Spectrum'

#    z2axis = [z2axis,z2axis,z2axis,z2axis]

#    ax1 = plt.subplot(211)
#    plt.plot(z2axis, xf, label='x field')
#    plt.plot(z2axis, yf, label='y field')
#    plt.xlabel(r'$\bar{z}_2$', fontsize=16)
#    plt.ylabel('Fields', fontsize=16)
#    plt.legend()

# Adding subplot
    axes = plt.subplot(111)
    plt.xlabel(sp_x_axis, fontsize=16)
    plt.ylabel('Intensity (a.u.)', fontsize=16)

#####  SAVE DATA


#    outfilename = 'specpow.h5'
#
#    h5=tables.open_file(outfilename,'w')
#
#    h5.create_array('/','wavelens', ftxaxis)
#    h5.root.wavelens._v_attrs.vsKind='structured'
#    h5.root.wavelens._v_attrs.vsType='mesh'
#    h5.root.wavelens._v_attrs.vsStartCell=0
#    #h5.root.zSeries._v_attrs.vsNumCells=numTimes-1 # -1 as zonal
#    h5.root.wavelens._v_attrs.vsLowerBounds=ftxaxis[0]
#    h5.root.wavelens._v_attrs.vsUpperBounds=ftxaxis[-1]
#    h5.root.wavelens._v_attrs.vsAxisLabels="lambda (m)"
#    
    fttpower = ftxpower + ftypower
#
#
#
#    h5.create_array('/','specpow',fttpower)
#    h5.root.specpow._v_attrs.vsMesh='wavelens'
#    h5.root.specpow._v_attrs.vsType='variable'
#    h5.root.specpow._v_attrs.vsAxisLabels='Power (a.u.)'
#
#
#    h5.close()


    if ftplottype==1:
        #plt.loglog(ftxaxis, ftxpower, label='x intensity')
        #plt.plot(ftxaxis, ftxpower, label='x power')
        #plt.plot(ftxaxis, ftypower, label='y power')
        plt.plot(ftxaxis*1e9, fttpower / np.max(fttpower), label='Intensity')
        axes.set_xlim([90, 110])

    else:
#        plt.semilogy(ftxaxis, ftxpower, label='x intensity')
#        plt.plot(ftxaxis, ftypower, label='y intensity')
        plt.plot(ftxaxis, fttpower / np.max(fttpower), label='Intensity')
        axes.set_xlim([0.8, 1.2])

#    plt.legend()

    nameparts = h5fname.split('_')
    basename = nameparts[0]
    z = mdata.vars.z
    
    plt.tight_layout()
    
    plt.savefig(basename + "-spec-intensity-z-" + str(z) + ".png")