Exemple #1
0
def plotTurbulenceTime(fileh5, dir='Y', pos=(-2,-1), doFit='False', posT=(1,-1)):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .
    """
    D = gkcData.getDomain(fileh5)
    data = fileh5.root.Analysis.PowerSpectrum.Y[1:,:]
    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]
    timeEvolution = []
    for step in range(len(data[0,:])):
       timeEvolution.append(data[:,step]/sum(data[:,step]))

    contourf(np.log10(D['ky']), T,timeEvolution, 250, locator=ticker.LogLocator(), cmap=cm.jet)
    colorbar()
Exemple #2
0
def getFrequencyGrowthrates(fileh5, start=1, stop=-1, q=0):
          
   T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]

   power = fileh5.root.Analysis.PowerSpectrum.Y[q, :,:]
   phase = fileh5.root.Analysis.PhaseShift.Y   [q, :,:]
        
   frequency   = getFrequency (T,phase, start,stop)
   growthrates = getGrowthrate(T,power, start, stop)

   return np.array(frequency) + 1.j * np.array(growthrates)
Exemple #3
0
def getFrequencyGrowthrates(fileh5, start=1, stop=-1, q=0):

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]

    power = fileh5.root.Analysis.PowerSpectrum.Y[q, :, :]
    phase = fileh5.root.Analysis.PhaseShift.Y[q, :, :]

    frequency = getFrequency(T, phase, start, stop)
    growthrates = getGrowthrate(T, power, start, stop)

    return np.array(frequency) + 1.j * np.array(growthrates)
Exemple #4
0
def plotTurbulenceTime(fileh5,
                       dir='Y',
                       pos=(-2, -1),
                       doFit='False',
                       posT=(1, -1)):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .
    """
    D = gkcData.getDomain(fileh5)
    data = fileh5.root.Analysis.PowerSpectrum.Y[1:, :]
    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]
    timeEvolution = []
    for step in range(len(data[0, :])):
        timeEvolution.append(data[:, step] / sum(data[:, step]))

    contourf(np.log10(D['ky']),
             T,
             timeEvolution,
             250,
             locator=ticker.LogLocator(),
             cmap=cm.jet)
    colorbar()
Exemple #5
0
def plotFrequencyGrowthrates(fileh5, which='b', markline="-", **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)
    
    doCFL    = kwargs.pop('doCFL', True)
    dir      = kwargs.pop('dir', 'Y')
    modes    = kwargs.pop('modes' , range(D['Nky']))
    field    = kwargs.pop('field', 'phi')  
    n_offset = kwargs.pop('offset', 2)  
    label    = kwargs.pop('label', 'ky')  
    leg_loc  = kwargs.pop('loc', 'best')  
    start    = kwargs.pop('start', 1)  
    stop     = kwargs.pop('stop', -1)  
    

    if doCFL == True : pylab.clf()
    
    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]
        
    print "Fitting from T : ", T[start], " - ", T[stop]
    
    if   field == 'phi' : n_field = 0
    elif field == 'A'   : n_field = 1
    elif field == 'B'   : n_field = 2
    else : raise TypeError("Wrong argument for field : " + str(field))

    if(dir == 'X'):
      pl = semilogy(T, fileh5.root.Analysis.PowerSpectrum.X[n_field,:numModes,2:].T)
      legend_list = []
      for i in range(len(fileh5.root.Analysis.PowerSpectrum.X[n_field, :numModes,0])):
        legend_list.append("kx = %i" % i)
      leg = pylab.legend(legend_list, loc='lower right', ncol=2)
      leg.draw_frame(0)
    
    elif(dir == 'Y'):

      scale = fileh5.root.Grid._v_attrs.Ly/(2. * np.pi)
      
      legend_list = []
      if   which=='i' or which=='b':
        power = fileh5.root.Analysis.PowerSpectrum.Y[n_field, :,:]
        growthrates = getGrowthrate(T,power, start,stop, dir='Y')
        pl = pylab.semilogx(D['ky'], growthrates, "s" + markline, label='$\\gamma$')
      if which=='r' or which=='b':
        shift = fileh5.root.Analysis.PhaseShift.Y   [n_field, :,:]
        frequency   = getFrequency(T,shift, start,stop, dir='Y')
        pl = pylab.semilogx(D['ky'], frequency, "v" + markline, label='$\\omega_r$')
      #if which !='r' or which != 'i' or which !='b':
      #      raise TypeError("Wrong argument for which (r/i/b) : " + str(dir))
    
      #pylab.twinx()
      pylab.xlim((0.8*min(D['ky']), 1.2*max(D['ky'])))

    
      
    else : raise TypeError("Wrong argument for dir : " + str(dir))
     
    pylab.xlabel("$k_y$")
   
    leg = pylab.legend(loc=leg_loc, ncol=1, mode="expand").draw_frame(0)

    gkcStyle.plotZeroLine(0.8*min(D['ky']), 1.2*max(D['ky']))

    pylab.ylabel("Growthrate $\\gamma(k_y)$ / Frequency $\\omega_r(k_y)$")
Exemple #6
0
def plotTimeEvolutionModePhase(fileh5, **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)
    
    doCFL    = kwargs.pop('doCFL', True)
    leg_loc  = kwargs.pop('loc', 'best')  
    dir      = kwargs.pop('dir', 'Y')
    modes    = kwargs.pop('modes' , range(D['Nky']))
    field    = kwargs.pop('field', 'phi')  
    n_offset = kwargs.pop('offset', 2)  
    label    = kwargs.pop('label', 'ky')  
    leg_loc  = kwargs.pop('loc', 'best')  
    ncol     = kwargs.pop('ncol', 2)  
    
    if doCFL == True : pylab.clf()
    
    T = gkcData.getTime(fileh5.root.Analysis.PhaseShift.Time)[2:,1]
    
    if   field == 'phi' : n_field = 0
    elif field == 'A'   : n_field = 1
    elif field == 'B'   : n_field = 2
    else : raise TypeError("Wrong argument for field : " + str(field))

    if(dir == 'X'):
      pl = plot(T, fileh5.root.Analysis.PhaseShift.X[n_field,:numModes,2:].T)
      legend_list = []
      for i in range(len(fileh5.root.Analysis.PhaseShift.X[n_field, :numModes,0])):
        legend_list.append("kx = %i" % i)
      leg = pylab.legend(legend_list, loc='lower right', ncol=2)
      leg.draw_frame(0)
    
    elif(dir == 'Y'):

      scale = fileh5.root.Grid._v_attrs.Ly/(2. * np.pi)
      
      legend_list = []
      
      for m in modes:

            data  = fileh5.root.Analysis.PhaseShift.Y[n_field, m,n_offset:]
            
            # set jump value to nan so it is not plotted, (can we speed up using ma ?)
            data_m = []
            for n in range(len(data[:-1])):
                if abs(data[n] - data[n+1]) < 1.: data_m.append(data[n])
                else                            : data_m.append(float('nan'))
            data_m.append(data[-1])
            data_m = np.array(data_m)

            pl = pylab.plot(T, data_m)
            if  (label == 'm' ) : legend_list.append("m = %i" % m)
            elif(label == 'ky') : legend_list.append("ky = %.1f" % (m / scale)) 
            else                : print "Name Error"
    
      leg = pylab.legend(legend_list, loc=leg_loc, ncol=ncol, mode="expand").draw_frame(0)
 
    else : raise TypeError("Wrong argument for dir : " + str(dir))
    


    pylab.xlabel("Time")
    pylab.xlim((0.,max(T)))
    
    ax = pylab.gca()
    ax.set_yticks([-np.pi, -np.pi/2.,0.,np.pi/2., np.pi])
    ax.set_yticklabels(['$-\\pi$','$-\\pi/2$','$0$', '$\\pi/2.$', '$\\pi$'])
    pylab.ylim((-3.5,3.5))



    if    field == "phi" : pylab.ylabel("Mode Phase $|\\phi|^2$")
    elif  field == "A"   : pylab.ylabel("Mode Phase $|A_\\parallel|^2$")
    elif  field == "B"   : pylab.ylabel("Mode Phase $|B_\\parallel|^2$")
    else : raise TypeError("Wrong argument for field : " + str(field))
    
    return pl, leg
Exemple #7
0
def plotTimeEvolutionModePower(fileh5, **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)
    
    doCFL    = kwargs.pop('doCFL', True)
    doLog    = kwargs.pop('doLog', True)
    dir      = kwargs.pop('dir', 'Y')
    modes    = kwargs.pop('modes' , range(D['Nky']))
    field    = kwargs.pop('field', 'phi')  
    n_offset = kwargs.pop('offset', 3)  
    label    = kwargs.pop('label', 'k')  
    leg_loc  = kwargs.pop('loc', 'best')  
    ncol     = kwargs.pop('ncol', 3)  
    showLegend = kwargs.pop('showLegend', True)  
    
    if doCFL == True : pylab.clf()
    
    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]
    
    if   field == 'phi' : n_field = 0
    elif field == 'A'   : n_field = 1
    elif field == 'B'   : n_field = 2
    else : raise TypeError("Wrong argument for field : " + str(field))

    legend_list = []
    if(dir == 'X'):
      
      for n in modes:
            pl = pylab.semilogy(T[n_offset:], fileh5.root.Analysis.PowerSpectrum.X[n_field, n,n_offset:].T)
            if  (label == 'm' ) : legend_list.append("n = %i" % n)
            elif(label == 'k')  : legend_list.append("kx = %.1f" % (D['kx'][n])) 
            else                : print "Name Error"
    
    elif(dir == 'Y'):

      legend_list = []
      
      for m in modes:
        if(doLog) : pylab.semilogy(T[n_offset:], fileh5.root.Analysis.PowerSpectrum.Y[n_field, m,n_offset:].T, label='$k_y^{(%i)} = %.2f$' % (m, D['ky'][m]))
        else      : pylab.plot(T[n_offset:], fileh5.root.Analysis.PowerSpectrum.Y[n_field, m,n_offset:].T, label='$k_y^{(%i)} = %.2f$' % (m, D['ky'][m]))
 
    else : raise TypeError("Wrong argument for dir : " + str(dir))
     
    #if showLegend == True:
    leg = pylab.legend(loc=leg_loc, ncol=ncol, mode="expand").draw_frame(0)
     
    pylab.xlabel("Time")
    pylab.xlim((0.,max(T)))


    if    field == "phi" : pylab.ylabel("Mode Power $|\\phi|^2$")
    elif  field == "A"   : pylab.ylabel("Mode Power $|A_\\parallel|^2$")
    elif  field == "B"   : pylab.ylabel("Mode Power $|B_\\parallel|^2$")
    else : raise TypeError("Wrong argument for field : " + str(field))
Exemple #8
0
def plotModeStructure(fileh5, mode, part = "b", phaseCorrect=True, **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)
    
    
    doCFL    = kwargs.pop('doCFL', True)
    field    = kwargs.pop('field', 'phi')  
    Z        = kwargs.pop('Z', 0)  
    frame    = kwargs.pop('frame', -1)  
    label    = kwargs.pop('label', "")  
    norm     = kwargs.pop('norm', 'max')  
    m        = kwargs.pop('m', 0)  
    phase    = kwargs.pop('phase', 0.)  
    color    = kwargs.pop('color', '')  


    phase = np.exp(1.j * phase)
    
    if   field == 'phi' : 
      data_X = fileh5.root.Visualization.Phi[Z,mode,:,frame]
      y_label = '$\\phi(x)$'
    elif field == 'A'   : 
      data_X = fileh5.root.Visualization.Ap[Z,mode,:,frame]
      n_field = 2
      y_label = '$A_\parallel(x)$'
    elif field == 'B'   : 
      n_field = 2
      data_X = fileh5.root.Visualization.Bp[Z,mode,:,frame]
      y_label = '$B_\\parallel(x)$'
    else : raise TypeError("Wrong argument for field : " + str(field))
      
    print "Mode Structure at T = ", gkcData.getTime(fileh5.root.Visualization.Time)[frame,:]

    # Normalization
    def Normalize_data(data):
      print norm
      if    norm == 'sum2' : return np.sum(abs(data))
      elif  norm == 'max'  : return abs(data).max()
      else         : raise TypeError("No such normalization")

    if(phaseCorrect == True): 
            # Calculate phase 
            phase_shift = np.arctan2(np.sum(np.imag(np.sum(data_X))), np.real(np.sum(data_X)))
            print "phaseCorrect = True : Correcting for phase ", phase_shift
            data_X = data_X * np.exp(- 1.j * phase_shift)
  

    # Normalization is to real part
    if part == "a" : 
                     if color=='' : color='g'
                     data_X = abs(data_X)     / Normalize_data(data_X)
                     pylab.plot(D['X'], data_X, color=color, label=label)
    if part in [ 'r' , 'b' ]:
                     if color=='' : color='r'
                     data_X = np.real(data_X * phase) / Normalize_data(np.real(data_X))
                     pylab.plot(D['X'], data_X, 'o-', color=color, label=label, markersize=8., markeredgecolor='None')
    if part in [ 'i', 'b' ] : 
                     if color=='' : color=gkcStyle.color_indigo
                     data_X = np.imag(data_X * phase) / Normalize_data(np.real(data_X)) 
                     pylab.plot(D['X'], data_X, 's-', color=color, label=label, markersize=8., markeredgecolor='None')
    #else : raise TypeError("Wrong argument for part : " + str(part))


    if    field == "phi" : pylab.ylabel("Mode Power $|\\phi|^2$")
    elif  field == "A"   : pylab.ylabel("Mode Power $|A_\\parallel|^2$")
    elif  field == "B"   : pylab.ylabel("Mode Power $|B_\\parallel|^2$")
    else : raise TypeError("Wrong argument for field : " + str(field))

    pylab.xlim((min(D['X']), max(D['X'])))
    pylab.xlabel("X")

    
    pylab.ylabel(y_label)
Exemple #9
0
def plotInstantGrowthrates(fileh5, **kwargs):
    """
        Plots instant growthrates of mode power

        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    import scipy.ndimage 
    import scipy.interpolate
    
    D = gkcData.getDomain(fileh5)
    
    doCFL    = kwargs.pop('doCFL', True)
    dir      = kwargs.pop('dir', 'Y')
    modes    = kwargs.pop('modes' , range(D['Nky']))
    field    = kwargs.pop('field', 'phi')  
    n_offset = kwargs.pop('offset', 2)  
    label    = kwargs.pop('label', 'ky')  
    leg_loc  = kwargs.pop('loc', 'best')  
    off      = kwargs.pop('off', 2)  
    
    sigma      = kwargs.pop('sigma', 10)  
    #filterType = kwargs.pop('filterType', 'hanning')  
    
    if doCFL == True : pylab.clf()

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]

    # TimeStep is irregular thus needs to cast into regular 
    def cast2Equidistant(T, Var):
        f = scipy.interpolate.interp1d(T, Var)
        Tnew = np.linspace(min(T), max(T), 1000)
        return Tnew, f(Tnew)

    if   field == 'phi' : n_field = 0
    elif field == 'A'   : n_field = 1
    elif field == 'B'   : n_field = 2
    else : raise TypeError("Wrong argument for field : " + str(field))
    
    

    if(dir == 'X'):

      plot(T, grad)
      legend_list = []
      for i in range(len(fileh5.root.Analysis.PowerSpectrum.X[n_field,:numModes,0])):
        legend_list.append("kx = %i" % i)
      
      leg = legend(legend_list, loc='best', ncol=3)
      leg.draw_frame(0)
    
    if(dir == 'Y'):
      for m in modes:
        Var =   fileh5.root.Analysis.PowerSpectrum.Y[n_field,m,off:]
        Tn, V = cast2Equidistant(T[off:], np.log(Var))
        # Use NdImage for line-smoothening (convolution with gaussian kernel)
        V   = scipy.ndimage.gaussian_filter(V, sigma=sigma, mode='nearest')
        gamma = np.gradient(V, Tn[1]-Tn[0])
        pylab.plot(Tn, gamma, "-", label='$k_y^{(%i)} = %.2f$' % (m, D['ky'][m]))#, color=gkcStyle.markers_C[m])
      
    leg = pylab.legend(loc='best', ncol=3).draw_frame(0)
    
    
    pylab.xlabel("Time")
    pylab.xlim((0.,max(T)))

    pylab.ylabel("Instant Mode Growth $\gamma$")
Exemple #10
0
def plotFrequencyGrowthrates(fileh5, which='b', markline="-", **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)

    doCLF = kwargs.pop('doCLF', True)
    dir = kwargs.pop('dir', 'Y')
    modes = kwargs.pop('modes', range(D['Nky']))
    field = kwargs.pop('field', 'phi')
    n_offset = kwargs.pop('offset', 2)
    label = kwargs.pop('label', 'ky')
    leg_loc = kwargs.pop('loc', 'best')
    start = kwargs.pop('start', 1)
    stop = kwargs.pop('stop', -1)
    m = kwargs.pop('m', 0)
    useLog = kwargs.pop('useLog', True)

    if useLog == True: pf = pylab.semilogx
    else: pf = pylab.plot

    if doCLF == True: pylab.clf()

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]

    if field == 'phi': n_field = 0
    elif field == 'A': n_field = 1
    elif field == 'B': n_field = 2
    else: raise TypeError("Wrong argument for field : " + str(field))

    if (dir == 'X'):
        pl = pf(T, fileh5.root.Analysis.PowerSpectrum.X[n_field, :numModes,
                                                        2:].T)
        legend_list = []
        for i in range(
                len(fileh5.root.Analysis.PowerSpectrum.X[n_field, :numModes,
                                                         0])):
            legend_list.append("kx = %i" % i)
        leg = pylab.legend(legend_list, loc='lower right', ncol=2)
        leg.draw_frame(0)

    elif (dir == 'Y'):

        scale = fileh5.root.Grid._v_attrs.Ly / (2. * np.pi)

        legend_list = []
        if which == 'i' or which == 'b':
            power = fileh5.root.Analysis.PowerSpectrum.Y[n_field, :, :]
            growthrates = getGrowthrate(T, power, start, stop)
            pl = pf(D['ky'], growthrates, "s" + markline, label='$\\gamma$')
        if which == 'r' or which == 'b':
            shift = fileh5.root.Analysis.PhaseShift.Y[n_field, :, :]
            frequency = getFrequency(T, shift, start, stop)
            pl = pf(D['ky'], frequency, "v" + markline, label='$\\omega_r$')
        #if which !='r' or which != 'i' or which !='b':
        #      raise TypeError("Wrong argument for which (r/i/b) : " + str(dir))

        #pylab.twinx()
        pylab.xlim((0.8 * min(D['ky']), 1.2 * max(D['ky'])))

    else:
        raise TypeError("Wrong argument for dir : " + str(dir))

    pylab.xlabel("$k_y$")

    leg = pylab.legend(loc=leg_loc, ncol=1, mode="expand").draw_frame(0)

    gkcStyle.plotZeroLine(0.8 * min(D['ky']), 1.2 * max(D['ky']))

    pylab.ylabel("Growthrate $\\gamma(k_y)$ / Frequency $\\omega_r(k_y)$")
Exemple #11
0
def plotAveragedFluxes(fileh5, var='H', **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    import gkcData
    import gkcStyle

    import pylab
    import numpy as np

    D = gkcData.getDomain(fileh5)

    doCFL = kwargs.pop('doCFL', True)
    start = kwargs.pop('start', 1)
    stop = kwargs.pop('stop', -1)
    scale = kwargs.pop('scale', 'ky')
    field = kwargs.pop('field', 'phi')

    if doCFL == True: pylab.clf()

    if field == 'phi': n_field = 0
    elif field == 'A': n_field = 1
    elif field == 'B': n_field = 2
    else: raise TypeError("Wrong argument for field : " + str(field))

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]

    # Averaged over Z and start stop
    if var == 'P':
        data = np.mean(fileh5.root.Analysis.Flux.Density[n_field, :, :,
                                                         start:stop],
                       axis=2)
        ylabel = "Particle Flux $k_y \\Gamma/\\Gamma_{gB}\,(ky)$"
    elif var == 'H':
        data = np.mean(fileh5.root.Analysis.Flux.Heat[n_field, :, :,
                                                      start:stop],
                       axis=2)
        #ylabel = "Heat Flux $Q/Q_\\textrm{gB}(k_y)$"
        ylabel = "Heat Flux $k_y Q/Q_{gB}\,(k_y)$"
    else:
        raise TypeError("No such variable")

    if scale == 'ky': gor_ky = D['ky'][1:]
    else: gor_ky = 1.

    for s in range(D['Ns']):
        species_name = fileh5.root.Species.cols.Name[s + 1]
        pylab.semilogx(D['ky'][1:],
                       gor_ky * data[1:, s],
                       gkcStyle.markers_D[s] + '-',
                       label=species_name,
                       color=gkcStyle.markers_C[s],
                       markersize=7.)

    pylab.xlabel("$k_y \\rho_i$")
    pylab.ylabel(ylabel)

    pylab.legend(ncol=2).draw_frame(0)
    pylab.xlim((0.8 * D['ky'][1], 1.2 * D['ky'][-1]))
Exemple #12
0
def plotFrequencySpectra(fileh5, which='b', markline="-", **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    import gkcData
    import gkcStyle

    import pylab
    import numpy as np

    D = gkcData.getDomain(fileh5)

    doCFL = kwargs.pop('doCFL', True)
    dir = kwargs.pop('dir', 'Y')
    modes = kwargs.pop('modes', range(D['Nky']))
    field = kwargs.pop('field', 'phi')
    n_offset = kwargs.pop('offset', 2)
    label = kwargs.pop('label', 'ky')
    leg_loc = kwargs.pop('loc', 'best')
    start = kwargs.pop('start', 1)
    stop = kwargs.pop('stop', -1)

    if doCFL == True: pylab.clf()

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]

    if field == 'phi': n_field = 0
    elif field == 'A': n_field = 1
    elif field == 'B': n_field = 2
    else: raise TypeError("Wrong argument for field : " + str(field))

    if (dir == 'X'):
        raise TypeError("Not implemented for X-direction")
    elif (dir == 'Y'):

        shift = fileh5.root.Analysis.PhaseShift.Y[n_field, :, start:stop]
        print "Using data from T=", T[start], " to T = ", T[stop]
        freq = []
        for nky in np.arange(1, len(D['ky'])):
            time_series = np.sin(shift[nky, :])
            FS = np.fft.rfft(time_series)

            # Not only if we have constant time step !
            freq.append(abs(FS))
            fftfreq = np.fft.fftfreq(len(abs(np.fft.fftshift(FS))),
                                     d=(T[-10] - T[-11]))

        freq = np.array(freq)
        print np.shape(fftfreq), " 2 : ", np.shape(D['ky'][1:]), np.shape(freq)
        pylab.contourf(D['ky'][1:],
                       np.fft.fftshift(fftfreq),
                       freq.T,
                       100,
                       cmap=pylab.cm.jet)
        pylab.xlim((D['ky'][1], D['ky'][-1]))
        pylab.ylim((min(fftfreq), max(fftfreq)))
        pylab.colorbar()
    else:
        raise TypeError("Wrong argument for dir : " + str(dir))
    pylab.gca().set_xscale("log")

    pylab.xlabel("$k_y$")

    gkcStyle.plotZeroLine(D['ky'][1], D['ky'][-1], color='r')

    pylab.ylabel("Frequency $\\omega_r(k_y)$")
Exemple #13
0
def plotTimeEvolutionModePhase(fileh5, **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)

    doCFL = kwargs.pop('doCFL', True)
    leg_loc = kwargs.pop('loc', 'best')
    dir = kwargs.pop('dir', 'Y')
    modes = kwargs.pop('modes', range(D['Nky']))
    field = kwargs.pop('field', 'phi')
    n_offset = kwargs.pop('offset', 2)
    label = kwargs.pop('label', 'ky')
    leg_loc = kwargs.pop('loc', 'best')
    ncol = kwargs.pop('ncol', 2)

    if doCFL == True: pylab.clf()

    T = gkcData.getTime(fileh5.root.Analysis.PhaseShift.Time)[2:, 1]

    if field == 'phi': n_field = 0
    elif field == 'A': n_field = 1
    elif field == 'B': n_field = 2
    else: raise TypeError("Wrong argument for field : " + str(field))

    if (dir == 'X'):
        pl = plot(T, fileh5.root.Analysis.PhaseShift.X[n_field, :numModes,
                                                       2:].T)
        legend_list = []
        for i in range(
                len(fileh5.root.Analysis.PhaseShift.X[n_field, :numModes, 0])):
            legend_list.append("kx = %i" % i)
        leg = pylab.legend(legend_list, loc='lower right', ncol=2)
        leg.draw_frame(0)

    elif (dir == 'Y'):

        scale = fileh5.root.Grid._v_attrs.Ly / (2. * np.pi)

        legend_list = []

        for m in modes:

            data = fileh5.root.Analysis.PhaseShift.Y[n_field, m, n_offset:]

            # set jump value to nan so it is not plotted, (can we speed up using ma ?)
            data_m = []
            for n in range(len(data[:-1])):
                if abs(data[n] - data[n + 1]) < 1.: data_m.append(data[n])
                else: data_m.append(float('nan'))
            data_m.append(data[-1])
            data_m = np.array(data_m)

            pl = pylab.plot(T, data_m)
            if (label == 'm'): legend_list.append("m = %i" % m)
            elif (label == 'ky'): legend_list.append("ky = %.1f" % (m / scale))
            else: print "Name Error"

        leg = pylab.legend(legend_list, loc=leg_loc, ncol=ncol,
                           mode="expand").draw_frame(0)

    else:
        raise TypeError("Wrong argument for dir : " + str(dir))

    pylab.xlabel("Time")
    pylab.xlim((0., max(T)))

    ax = pylab.gca()
    ax.set_yticks([-np.pi, -np.pi / 2., 0., np.pi / 2., np.pi])
    ax.set_yticklabels(['$-\\pi$', '$-\\pi/2$', '$0$', '$\\pi/2.$', '$\\pi$'])
    pylab.ylim((-3.5, 3.5))

    if field == "phi": pylab.ylabel("Mode Phase $|\\phi|^2$")
    elif field == "A": pylab.ylabel("Mode Phase $|A_\\parallel|^2$")
    elif field == "B": pylab.ylabel("Mode Phase $|B_\\parallel|^2$")
    else: raise TypeError("Wrong argument for field : " + str(field))

    return pl, leg
Exemple #14
0
def plotTimeEvolutionModePower(fileh5, **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)

    doCFL = kwargs.pop('doCFL', True)
    doLog = kwargs.pop('doLog', True)
    dir = kwargs.pop('dir', 'Y')
    modes = kwargs.pop('modes', range(D['Nky']))
    field = kwargs.pop('field', 'phi')
    n_offset = kwargs.pop('offset', 3)
    label = kwargs.pop('label', 'k')
    leg_loc = kwargs.pop('loc', 'best')
    ncol = kwargs.pop('ncol', 3)
    showLegend = kwargs.pop('showLegend', True)

    if doCFL == True: pylab.clf()

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]

    if field == 'phi': n_field = 0
    elif field == 'A': n_field = 1
    elif field == 'B': n_field = 2
    else: raise TypeError("Wrong argument for field : " + str(field))

    legend_list = []
    if (dir == 'X'):

        for n in modes:
            pl = pylab.semilogy(
                T[n_offset:],
                fileh5.root.Analysis.PowerSpectrum.X[n_field, n, n_offset:].T)
            if (label == 'm'): legend_list.append("n = %i" % n)
            elif (label == 'k'): legend_list.append("kx = %.1f" % (D['kx'][n]))
            else: print "Name Error"

    elif (dir == 'Y'):

        legend_list = []

        for m in modes:
            if (doLog):
                pylab.semilogy(
                    T[n_offset:],
                    fileh5.root.Analysis.PowerSpectrum.Y[n_field, m,
                                                         n_offset:].T,
                    label='$k_y^{(%i)} = %.2f$' % (m, D['ky'][m]))
            else:
                pylab.plot(T[n_offset:],
                           fileh5.root.Analysis.PowerSpectrum.Y[n_field, m,
                                                                n_offset:].T,
                           label='$k_y^{(%i)} = %.2f$' % (m, D['ky'][m]))

    else:
        raise TypeError("Wrong argument for dir : " + str(dir))

    #if showLegend == True:
    leg = pylab.legend(loc=leg_loc, ncol=ncol, mode="expand").draw_frame(0)

    pylab.xlabel("Time")
    pylab.xlim((0., max(T)))

    if field == "phi": pylab.ylabel("Mode Power $|\\phi|^2$")
    elif field == "A": pylab.ylabel("Mode Power $|A_\\parallel|^2$")
    elif field == "B": pylab.ylabel("Mode Power $|B_\\parallel|^2$")
    else: raise TypeError("Wrong argument for field : " + str(field))
Exemple #15
0
def plotModeStructure(fileh5, mode, part="b", phaseCorrect=True, **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    D = gkcData.getDomain(fileh5)

    doCFL = kwargs.pop('doCFL', True)
    field = kwargs.pop('field', 'phi')
    Z = kwargs.pop('Z', 0)
    frame = kwargs.pop('frame', -1)
    label = kwargs.pop('label', "")
    norm = kwargs.pop('norm', 'max')
    m = kwargs.pop('m', 0)
    phase = kwargs.pop('phase', 0.)
    color = kwargs.pop('color', '')

    phase = np.exp(1.j * phase)

    if field == 'phi':
        data_X = fileh5.root.Visualization.Phi[Z, mode, :, frame]
        y_label = '$\\phi(x)$'
    elif field == 'A':
        data_X = fileh5.root.Visualization.Ap[Z, mode, :, frame]
        n_field = 2
        y_label = '$A_\parallel(x)$'
    elif field == 'B':
        n_field = 2
        data_X = fileh5.root.Visualization.Bp[Z, mode, :, frame]
        y_label = '$B_\\parallel(x)$'
    else:
        raise TypeError("Wrong argument for field : " + str(field))

    print "Mode Structure at T = ", gkcData.getTime(
        fileh5.root.Visualization.Time)[frame, :]

    # Normalization
    def Normalize_data(data):
        print norm
        if norm == 'sum2': return np.sum(abs(data))
        elif norm == 'max': return abs(data).max()
        else: raise TypeError("No such normalization")

    if (phaseCorrect == True):
        # Calculate phase
        phase_shift = np.arctan2(np.sum(np.imag(np.sum(data_X))),
                                 np.real(np.sum(data_X)))
        print "phaseCorrect = True : Correcting for phase ", phase_shift
        data_X = data_X * np.exp(-1.j * phase_shift)

    # Normalization is to real part
    if part == "a":
        if color == '': color = 'g'
        data_X = abs(data_X) / Normalize_data(data_X)
        pylab.plot(D['X'], data_X, color=color, label=label)
    if part in ['r', 'b']:
        if color == '': color = 'r'
        data_X = np.real(data_X * phase) / Normalize_data(np.real(data_X))
        pylab.plot(D['X'],
                   data_X,
                   'o-',
                   color=color,
                   label=label,
                   markersize=8.,
                   markeredgecolor='None')
    if part in ['i', 'b']:
        if color == '': color = gkcStyle.color_indigo
        data_X = np.imag(data_X * phase) / Normalize_data(np.real(data_X))
        pylab.plot(D['X'],
                   data_X,
                   's-',
                   color=color,
                   label=label,
                   markersize=8.,
                   markeredgecolor='None')
    #else : raise TypeError("Wrong argument for part : " + str(part))

    if field == "phi": pylab.ylabel("Mode Power $|\\phi|^2$")
    elif field == "A": pylab.ylabel("Mode Power $|A_\\parallel|^2$")
    elif field == "B": pylab.ylabel("Mode Power $|B_\\parallel|^2$")
    else: raise TypeError("Wrong argument for field : " + str(field))

    pylab.xlim((min(D['X']), max(D['X'])))
    pylab.xlabel("X")

    pylab.ylabel(y_label)
Exemple #16
0
def plotFrequencySpectra(fileh5, which='b', markline="-", **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    import gkcData
    import gkcStyle

    import pylab
    import numpy as np
    
    D = gkcData.getDomain(fileh5)

    doCFL    = kwargs.pop('doCFL', True)
    dir      = kwargs.pop('dir', 'Y')
    modes    = kwargs.pop('modes' , range(D['Nky']))
    field    = kwargs.pop('field', 'phi')  
    n_offset = kwargs.pop('offset', 2)  
    label    = kwargs.pop('label', 'ky')  
    leg_loc  = kwargs.pop('loc', 'best')  
    start    = kwargs.pop('start', 1)  
    stop     = kwargs.pop('stop', -1)  
    

    if doCFL == True : pylab.clf()
    
    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]
    
    if   field == 'phi' : n_field = 0
    elif field == 'A'   : n_field = 1
    elif field == 'B'   : n_field = 2
    else : raise TypeError("Wrong argument for field : " + str(field))

    if(dir == 'X'):
        raise TypeError("Not implemented for X-direction")
    elif(dir == 'Y'):
        
      shift = fileh5.root.Analysis.PhaseShift.Y   [n_field, :,start:stop]
      print "Using data from T=", T[start], " to T = ", T[stop]
      freq = [] 
      for nky in np.arange(1,len(D['ky'])):
        time_series = np.sin(shift[nky,:])
        FS = np.fft.rfft(time_series)
      
        # Not only if we have constant time step !
        freq.append(abs(FS))
        fftfreq = np.fft.fftfreq(len(abs(np.fft.fftshift(FS))), d = (T[-10]-T[-11])) 
    
      freq = np.array(freq)
      print np.shape(fftfreq), " 2 : ", np.shape(D['ky'][1:]), np.shape(freq)
      pylab.contourf(D['ky'][1:], np.fft.fftshift(fftfreq), freq.T, 100, cmap=pylab.cm.jet) 
      pylab.xlim((D['ky'][1], D['ky'][-1]))
      pylab.ylim((min(fftfreq), max(fftfreq)))
      pylab.colorbar()
    else : raise TypeError("Wrong argument for dir : " + str(dir))
    pylab.gca().set_xscale("log") 
     
    pylab.xlabel("$k_y$")
   
    gkcStyle.plotZeroLine(D['ky'][1], D['ky'][-1], color='r')

    pylab.ylabel("Frequency $\\omega_r(k_y)$")
Exemple #17
0
def plotAveragedFluxes(fileh5, var='H', **kwargs):
    """
        Plots time evolution of mode power.


        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    import gkcData
    import gkcStyle

    import pylab
    import numpy as np
    
    D = gkcData.getDomain(fileh5)

    doCFL    = kwargs.pop('doCFL', True)
    start    = kwargs.pop('start', 1)  
    stop     = kwargs.pop('stop', -1)  
    scale    = kwargs.pop('scale', 'ky')  
    field    = kwargs.pop('field', 'phi')  
    

    if doCFL == True : pylab.clf()
    
    if   field == 'phi' : n_field = 0
    elif field == 'A'   : n_field = 1
    elif field == 'B'   : n_field = 2
    else : raise TypeError("Wrong argument for field : " + str(field))
    
    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:,1]

    # Averaged over Z and start stop
    if   var == 'P' : 
      data = np.mean(fileh5.root.Analysis.Flux.Density[n_field,:,:,start:stop], axis=2)
      ylabel = "Particle Flux $k_y \\Gamma/\\Gamma_{gB}\,(ky)$"
    elif var == 'H' : 
      data = np.mean(fileh5.root.Analysis.Flux.Heat   [n_field,:,:,start:stop], axis=2)
      #ylabel = "Heat Flux $Q/Q_\\textrm{gB}(k_y)$"
      ylabel = "Heat Flux $k_y Q/Q_{gB}\,(k_y)$"
    else : raise TypeError("No such variable")
     
    if scale == 'ky' : gor_ky = D['ky'][1:]
    else             : gor_ky = 1.

    for s in range(D['Ns']):
      species_name = fileh5.root.Species.cols.Name[s+1]
      pylab.semilogx(D['ky'][1:], gor_ky * data[1:,s], gkcStyle.markers_D[s]+'-', label=species_name, color=gkcStyle.markers_C[s], markersize=7.)
    
    pylab.xlabel("$k_y \\rho_i$")
    pylab.ylabel(ylabel)
  
    pylab.legend(ncol=2).draw_frame(0)
    pylab.xlim((0.8*D['ky'][1], 1.2*D['ky'][-1]))
Exemple #18
0
def plotInstantGrowthrates(fileh5, **kwargs):
    """
        Plots instant growthrates of mode power

        Optional keyword arguments:

        Keyword           Description
        ===============   ==============================================
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *modes*           List of modes (default plot modes). 
                           e.g. modes = [1,4,5]         - to plot all modes
                                modes = range(Nky)[::2] - to plot every second mode
         *field*           'phi' electric potential
                           'A' parallel magnetic vector potential
                           'B' parallel magnetic field
         *dir*             Direction 'X' (for radial) or 'Y' for poloidal
         *doCFL*           clear previous figure
         *label*           'ky' or 'm'
         *offset*          Offset due to zeroset to 2 .

    """
    import scipy.ndimage
    import scipy.interpolate

    D = gkcData.getDomain(fileh5)

    doCFL = kwargs.pop('doCFL', True)
    dir = kwargs.pop('dir', 'Y')
    modes = kwargs.pop('modes', range(D['Nky']))
    field = kwargs.pop('field', 'phi')
    n_offset = kwargs.pop('offset', 2)
    label = kwargs.pop('label', 'ky')
    leg_loc = kwargs.pop('loc', 'best')
    off = kwargs.pop('off', 2)

    sigma = kwargs.pop('sigma', 10)
    #filterType = kwargs.pop('filterType', 'hanning')

    if doCFL == True: pylab.clf()

    T = gkcData.getTime(fileh5.root.Analysis.PowerSpectrum.Time)[:, 1]

    # TimeStep is irregular thus needs to cast into regular
    def cast2Equidistant(T, Var):
        f = scipy.interpolate.interp1d(T, Var)
        Tnew = np.linspace(min(T), max(T), 1000)
        return Tnew, f(Tnew)

    if field == 'phi': n_field = 0
    elif field == 'A': n_field = 1
    elif field == 'B': n_field = 2
    else: raise TypeError("Wrong argument for field : " + str(field))

    if (dir == 'X'):

        plot(T, grad)
        legend_list = []
        for i in range(
                len(fileh5.root.Analysis.PowerSpectrum.X[n_field, :numModes,
                                                         0])):
            legend_list.append("kx = %i" % i)

        leg = legend(legend_list, loc='best', ncol=3)
        leg.draw_frame(0)

    if (dir == 'Y'):
        for m in modes:
            Var = fileh5.root.Analysis.PowerSpectrum.Y[n_field, m, off:]
            Tn, V = cast2Equidistant(T[off:], np.log(Var))
            # Use NdImage for line-smoothening (convolution with gaussian kernel)
            V = scipy.ndimage.gaussian_filter(V, sigma=sigma, mode='nearest')
            gamma = np.gradient(V, Tn[1] - Tn[0])
            pylab.plot(Tn,
                       gamma,
                       "-",
                       label='$k_y^{(%i)} = %.2f$' %
                       (m, D['ky'][m]))  #, color=gkcStyle.markers_C[m])

    leg = pylab.legend(loc='best', ncol=3).draw_frame(0)

    pylab.xlabel("Time")
    pylab.xlim((0., max(T)))

    pylab.ylabel("Instant Mode Growth $\gamma$")