示例#1
0
#from calc_gammaE import *
#from read_cxrs_file import *
#from read_Er import *
from read_iterdb_file import *
#from w_iterdb import *
#from matplotlib.backends.backend_pdf import PdfPages

e = 1.6*10**(-19)
a = 2.6863997038399379E-01

efit_file_name = 'g1120907032.01012'
p_file_name = 'p1120907032.01012'
cxrs_file_name = 'cxrs1120907032.01010_v20140623'
iterdb_filename = 'cmod1120907032.01012.iterdb'

rhot_idb, te_idb, ti_idb, ne_idb, ni_idb, nb_idb, vrot_idb = read_iterdb_file(iterdb_filename)
    
plt.plot(rhot_idb,te_idb,'x',label='te iterdb')
plt.plot(rhot_idb,ti_idb,'x',label='ti iterdb')
plt.xlabel('rhot_n')
plt.legend()
plt.show()

plt.plot(rhot_idb,ne_idb,'x',label='ne iterdb')
plt.plot(rhot_idb,ni_idb,'x',label='ni iterdb')
plt.plot(rhot_idb,nb_idb,'x',label='nb iterdb')
plt.xlabel('rhot_n')
plt.legend()
plt.show()

plt.plot(rhot_idb,vrot_idb,'.',label='iterdb')
示例#2
0
geomfile = 'g098889.04530'  #name of the magnetic geometry file

f_max = 250  #upper bound of the frequency experimentally observed
f_min = 0  #lower bound of the frequency experimentally observed
plot = 1  #set to 1 if you want to plot the result
report = 1  #set to 1 if you want to export a csv report
omega_percent = 10.  #choose the omega within the top that percent defined in(0,100)
n0_min = 1  #minmum mode number (include) that finder will cover
n0_max = 100  #maximum mode number (include) that finder will cover
q_scale = 1.  #set the q to q*q_scale
mref = 2.  # mass of ion in proton mass
#**************End of Setting up*********************************************
#**************End of Block for user******************************************

#*************Loading the data******************************************
rhot0, te0, ti0, ne0, ni0, nz0, vrot0 = read_iterdb_file(iterdb_file_name)
EFITdict = read_EFIT(geomfile)
xgrid = EFITdict['psipn']
q = EFITdict['qpsi'] * q_scale

uni_rhot = np.linspace(min(rhot0), max(rhot0), len(rhot0) * 10.)

te_u = interp(rhot0, te0, uni_rhot)
ne_u = interp(rhot0, ne0, uni_rhot)
vrot_u = interp(rhot0, vrot0, uni_rhot)
q = interp(xgrid, q, uni_rhot)
tprime_e = -fd_d1_o4(te_u, uni_rhot) / te_u
nprime_e = -fd_d1_o4(ne_u, uni_rhot) / ne_u

midped, topped = find_pedestal(file_name=geomfile, path_name='', plot=False)
x0_center = midped
示例#3
0
Please include names of iterdb file, geometry file, parameters file, and EFIT file."
    \n""")

iterdb_file = args[0]
geom_file = args[1]
parameters_file = args[2]
efit_file = args[3]
xbound = options.xbound
impurity = options.impurity
qtreatment = options.qtreatment

geompars, geom = read_geometry_global(geom_file)
print "np.shape(geom['gzz'])", np.shape(geom['gzz'])

if impurity:
    rhot_te, te, ti, ne, ni, nb, vrot = read_iterdb_file(iterdb_file)
else:
    rhot_te, te, ti, ne, ni, vrot = read_iterdb_file(iterdb_file)

print "len(rhot_te)", len(rhot_te)
#for i in range(len(rhot_te)):
#    print "i, rhot",i,rhot_te[i]

par = Parameters()
par.Read_Pars(parameters_file)
pars = par.pardict

rhotor_min = pars['x0'] - pars['lx_a'] / 2.0
rhotor_max = pars['x0'] + pars['lx_a'] / 2.0
rhot0 = np.linspace(rhotor_min, rhotor_max, pars['nx0'])
if xbound == -1:
示例#4
0
Please include names of iterdb file, geometry file, parameters file, and EFIT file."
    \n""")

iterdb_file = args[0]
geom_file = args[1]
parameters_file = args[2]
efit_file = args[3]
xbound = options.xbound
impurity = options.impurity
qtreatment = options.qtreatment

geompars, geom = read_geometry_global(geom_file)
print "np.shape(geom['gzz'])",np.shape(geom['gzz'])

if impurity:
    rhot_te, te, ti, ne, ni, nb, vrot = read_iterdb_file(iterdb_file)
else:
    rhot_te, te, ti, ne, ni, vrot = read_iterdb_file(iterdb_file)

print "len(rhot_te)",len(rhot_te)
#for i in range(len(rhot_te)):
#    print "i, rhot",i,rhot_te[i]

par = Parameters()
par.Read_Pars(parameters_file)
pars = par.pardict

rhotor_min = pars['x0']-pars['lx_a']/2.0
rhotor_max = pars['x0']+pars['lx_a']/2.0
rhot0 = np.linspace(rhotor_min,rhotor_max,pars['nx0']) 
if xbound == -1:
示例#5
0
import numpy as np
import matplotlib.pyplot as plt
from write_iterdb import *
from read_iterdb_file import *
from interp import *

fileName = "13left015NegOmTorCMOD1120815027.iterdb"
profilesName = 'profiles_i'
rhot, te, ti, ne, ni, nz, omega_tor = read_iterdb_file(fileName)
data = np.genfromtxt(profilesName)
rhot0 = data[:, 0]
rhop0 = data[:, 1]
rhop = interp(rhot0, rhop0, rhot)
Ptot = te * ne + ti * (ni + nz)

# collisionality scan
if 1 == 0:
    factor = 1.4
    newTe = 1. / factor * te
    newTi = 1. / factor * ti
    newNe = factor * ne
    newNi = factor * ni
    newNz = factor * nz
    newPtot = newTe * newNe + newTi * (newNi + newNz)

# alpha times omte & omti
if 1 == 1:
    rhotMidPed = 0.97
    midPedIndex = np.argmin(abs(rhot - rhotMidPed))
    teMidPed = te[midPedIndex]
    tiMidPed = ti[midPedIndex]
rhostar_prof = np.sqrt(1000.0 * ee * Teprof / mref) * mref / ee / Bref / Lref
print "pars['rhostar']", pars['rhostar']
print "rhostar", rhostar_prof[int(pars['nx0'] / 2.0)]

#Calculate radial dependence of omega_star for given n0
omega_star_prof = n0 * qprof / xgrid * rhostar_prof * (omte + omne)
omega_star_prof_kHz = omega_star_prof * np.sqrt(
    1000.0 * ee * Teprof / mref) / Lref / 1000.0 / 2.0 / np.pi
omega_star_prof_locnorm = omega_star_prof_kHz * 1000.0 * Lref / crefSI * 2.0 * np.pi

betaprof = 403.0e-5 * neprof * Teprof / Bref**2
beta_avg = np.sum(betaprof[ixmin:ixmax]) / (ixmax - ixmin)

if idb_file:
    if pars['n_spec'] > 2:
        rhotidb, teidb, tiidb, neidb, niidb, nzidb, vrot0 = read_iterdb_file(
            idb_file)
    else:
        rhotidb, teidb, tiidb, neidb, niidb, vrot0 = read_iterdb_file(idb_file)
    vrot_u = interp(rhotidb, vrot0, xgrid)
    omegaDoppler = vrot_u * n0 / 2.0 / np.pi / 1000.0
    omegaDoppler_norm = omegaDoppler * 1000.0 * Lref / crefSI * 2.0 * np.pi

plt.plot(xgrid[ixmin:ixmax], omega_star_prof[ixmin:ixmax])
plt.title('omega_star profile n0=' + str(n0))
plt.show()
plt.plot(xgrid[ixmin:ixmax], omega_star_prof_kHz[ixmin:ixmax])
if idb_file:
    plt.plot(xgrid[ixmin:ixmax], omegaDoppler[ixmin:ixmax])
    plt.plot(xgrid[ixmin:ixmax],
             omegaDoppler[ixmin:ixmax] + omega_star_prof_kHz[ixmin:ixmax])
plt.title('omega_star profile kHz n0=' + str(n0))
示例#7
0

###plt.plot(psip_n_obmp[psi_Er_f:psi_Er_l+1],rhot_n_obmp[psi_Er_f:psi_Er_l+1],'x')
###plt.plot(psi0,rhot0,'r.')
###plt.show()

#gammaE_hb_cs, omega_t, rhot_unipsip = calc_gammaE_hb(R_obmp[psi_Er_f:psi_Er_l+1],psip_obmp[psi_Er_f:psi_Er_l+1],te_obmp[psi_Er_f:psi_Er_l+1],B_tor[psi_Er_f:psi_Er_l+1], B_pol[psi_Er_f:psi_Er_l+1], Er_obmp,rhot_n_obmp[psi_Er_f:psi_Er_l+1],a)

##plt.plot(rhot_unipsip, abs(gammaE_hb_cs)/2.5, '.', label ='gammaE_hb_cs/2.5')
##x1,x2,y1,y2 = plt.axis()
##plt.axis((0.95,1.0,y1,y2))
##plt.legend()
##plt.show()


rhot_iterdb, ni_iterdb, ti_iterdb = read_iterdb_file(iterdb_filename)


###plt.plot(rhotp_obmp,ni_obmp,'x',label='ni p-file')
###plt.plot(rhot_iterdb,ni_iterdb,'r.',label='ni iterdb')
###plt.xlabel('rhot_n')
###plt.legend()
###plt.show()

###plt.plot(rhotp_obmp,ti_obmp/e,'x',label='ti p-file')
###plt.plot(rhot_iterdb,ti_iterdb,'r.',label='ti iterdb')
###plt.xlabel('rhot_n')
###plt.legend()
###plt.show()

rhot_gene,gammaE_gene = calc_gammaE_gene(R_obmp[psi_Er_f:psi_Er_l+1], rhot_n_obmp[psi_Er_f:psi_Er_l+1], te_obmp[psi_Er_f:psi_Er_l+1], B_pol[psi_Er_f:psi_Er_l+1], Er_obmp, q_obmp[psi_Er_f:psi_Er_l+1], a)
parser = op.OptionParser()
options,args = parser.parse_args()
c_buffer_x = float(args[0])
buffer_size = float(args[1])
physW = float(args[2])
file1 = args[3]

l_buffer_x = float(c_buffer_x) - physW*float(buffer_size)
r_buffer_x = float(c_buffer_x) + physW*float(buffer_size)

#pdata=np.genfromtxt('p_info.dat')
#pdata=np.genfromtxt(prof_file_name)
#rhot=pdata[:,0]
#te=pdata[:,2]

rhot, te, ti1, ne1, ni1, nb1, vrot1 = read_iterdb_file(file1)
e = 1.6*10**(-19)

rhot_fine = linspace(rhot[0],rhot[-1],10*len(rhot))
te_fine = interp(rhot,te,rhot_fine)

l_ind = np.argmin(abs(rhot_fine - float(l_buffer_x)))
c_ind = np.argmin(abs(rhot_fine - float(c_buffer_x)))
r_ind = np.argmin(abs(rhot_fine - float(r_buffer_x)))

te_l = te_fine[l_ind]
te_c = te_fine[c_ind]
te_r = te_fine[r_ind]

lv = 3*np.sqrt(te_l/te_c)
lw = lv**2
示例#9
0
import matplotlib.pyplot as plt
from interp import *


iterdb_file_name = 'newDIIID153764.iterdb'
aGENE_m = 0.76
Bref_Gauss = 19545.
n0_global = 14
kymin = 0.1044
x0 = 0.975

e = 1.6*10**(-19)
mref = 2.
M_kg = 3.3*10**(-27)

rhot0, te0, ti0, ne0, ni0, nz0, vrot0 = read_iterdb_file(iterdb_file_name)

uni_rhot = np.linspace(min(rhot0),max(rhot0),len(rhot0)*10.)

te_u = interp(rhot0,te0,uni_rhot)
ne_u = interp(rhot0,ne0,uni_rhot)
vrot_u = interp(rhot0,vrot0,uni_rhot)

tprime_e = -fd_d1_o4(te_u,uni_rhot)/te_u
nprime_e = -fd_d1_o4(ne_u,uni_rhot)/ne_u

x0Ind = np.argmin(abs(uni_rhot - x0))
te_mid = te_u[x0Ind]
kyGENE = kymin * np.sqrt(te_u/te_mid)
omMTM = kyGENE*(tprime_e+nprime_e)
gyroFreq = 9.79E3/np.sqrt(mref)*np.sqrt(te_u)/aGENE_m
import matplotlib.pyplot as plt
from read_iterdb_file import *
import optparse as op

parser = op.OptionParser(
    description='Converts from iterdb file to GENE profile files.')

options, args = parser.parse_args()
if len(args) != 1:
    exit("""
Please include the name of the iterdb file as argument."
    \n""")

fiterdb = args[0]

rhot, te, ti, ne, ni, nb, vrot = read_iterdb_file(fiterdb)

plt.plot(rhot, te)
plt.xlabel('rhot')
plt.ylabel('Te(ev)')
plt.show()
plt.plot(rhot, ti)
plt.xlabel('rhot')
plt.ylabel('Ti(ev)')
plt.show()
plt.plot(rhot, ne)
plt.xlabel('rhot')
plt.ylabel('ne(m^-3)')
plt.show()
plt.plot(rhot, ni)
plt.xlabel('rhot')
示例#11
0
import numpy as np
import matplotlib.pyplot as plt
from write_iterdb import *
from read_iterdb_file import *
from interp import *

fileName = "13left015NegOmTorCMOD1120815027.iterdb"
profilesName = 'profiles_i'
rhot, te, ti, ne, ni, nz, omega_tor = read_iterdb_file(fileName)
data = np.genfromtxt(profilesName)
rhot0 = data[:,0]
rhop0 = data[:,1]
rhop = interp(rhot0,rhop0,rhot)
Ptot = te * ne + ti * (ni + nz)

# collisionality scan
if 1 == 0:
   factor = 1.4
   newTe = 1./factor * te
   newTi = 1./factor * ti
   newNe = factor * ne
   newNi = factor * ni
   newNz = factor * nz
   newPtot = newTe * newNe + newTi * (newNi + newNz)
   
# alpha times omte & omti
if 1 == 1:
    rhotMidPed = 0.97
    midPedIndex = np.argmin(abs(rhot - rhotMidPed))
    teMidPed = te[midPedIndex]
    tiMidPed = ti[midPedIndex]
示例#12
0
##plt.legend()
##plt.show()

###plt.plot(psip_n_obmp[psi_Er_f:psi_Er_l+1],rhot_n_obmp[psi_Er_f:psi_Er_l+1],'x')
###plt.plot(psi0,rhot0,'r.')
###plt.show()

#gammaE_hb_cs, omega_t, rhot_unipsip = calc_gammaE_hb(R_obmp[psi_Er_f:psi_Er_l+1],psip_obmp[psi_Er_f:psi_Er_l+1],te_obmp[psi_Er_f:psi_Er_l+1],B_tor[psi_Er_f:psi_Er_l+1], B_pol[psi_Er_f:psi_Er_l+1], Er_obmp,rhot_n_obmp[psi_Er_f:psi_Er_l+1],a)

##plt.plot(rhot_unipsip, abs(gammaE_hb_cs)/2.5, '.', label ='gammaE_hb_cs/2.5')
##x1,x2,y1,y2 = plt.axis()
##plt.axis((0.95,1.0,y1,y2))
##plt.legend()
##plt.show()

rhot_iterdb, ni_iterdb, ti_iterdb = read_iterdb_file(iterdb_filename)

###plt.plot(rhotp_obmp,ni_obmp,'x',label='ni p-file')
###plt.plot(rhot_iterdb,ni_iterdb,'r.',label='ni iterdb')
###plt.xlabel('rhot_n')
###plt.legend()
###plt.show()

###plt.plot(rhotp_obmp,ti_obmp/e,'x',label='ti p-file')
###plt.plot(rhot_iterdb,ti_iterdb,'r.',label='ti iterdb')
###plt.xlabel('rhot_n')
###plt.legend()
###plt.show()

rhot_gene, gammaE_gene = calc_gammaE_gene(R_obmp[psi_Er_f:psi_Er_l + 1],
                                          rhot_n_obmp[psi_Er_f:psi_Er_l + 1],
示例#13
0
def Parameter_reader(iterdb_file_name,geomfile,manual_ped,mid_ped0,plot,output_csv):
    n0=1.
    mref = 2.        # mass of ion in proton mass
    rhot0, te0, ti0, ne0, ni0, nz0, vrot0 = read_iterdb_file(iterdb_file_name)
    EFITdict = read_EFIT(geomfile)
    xgrid = EFITdict['psipn']
    q = EFITdict['qpsi']

    uni_rhot = np.linspace(min(rhot0),max(rhot0),len(rhot0)*10.)

    te_u = interp(rhot0,te0,uni_rhot)
    ne_u = interp(rhot0,ne0,uni_rhot)
    ni_u = interp(rhot0,ni0,uni_rhot)
    vrot_u = interp(rhot0,vrot0,uni_rhot)
    q      = interp(xgrid,q,uni_rhot)
    tprime_e = -fd_d1_o4(te_u,uni_rhot)/te_u
    nprime_e = -fd_d1_o4(ne_u,uni_rhot)/ne_u
    qprime = fd_d1_o4(q,uni_rhot)/q


    #center_index = np.argmax((tprime_e*te_u+nprime_e*ne_u)[0:int(len(tprime_e)*0.99)])
    
    midped, topped=find_pedestal(file_name=geomfile, path_name='', plot=False)
    x0_center = midped
    if manual_ped==1:
        x0_center=mid_ped0

    print('mid pedestal is at r/a = '+str(x0_center))
    
    Lref, Bref, R_major, q0, shat0=get_geom_pars(geomfile,x0_center)

    index_begin=np.argmin(abs(uni_rhot-topped+1.*(1.-x0_center)))

    te_u = te_u[index_begin:len(uni_rhot)-1]
    ne_u = ne_u[index_begin:len(uni_rhot)-1]
    ni_u = ni_u[index_begin:len(uni_rhot)-1]
    vrot_u = vrot_u[index_begin:len(uni_rhot)-1]
    q      = q[index_begin:len(uni_rhot)-1]
    tprime_e = tprime_e[index_begin:len(uni_rhot)-1]
    nprime_e = nprime_e[index_begin:len(uni_rhot)-1]
    qprime   = qprime[index_begin:len(uni_rhot)-1]
    uni_rhot = uni_rhot[index_begin:len(uni_rhot)-1]

    Lt=1./tprime_e
    Ln=1./nprime_e
    Lq=1./qprime
    
    center_index = np.argmin(abs(uni_rhot-x0_center))

    ne=ne_u/(10**19)      # in 10^19 /m^3
    ni=ni_u/(10**19)      # in 10^19 /m^3
    te=te_u/1000.          #in keV
    m_SI = mref *1.6726*10**(-27)
    me_SI = 9.11*10**(-31)
    c  = 1.
    qref = 1.6*10**(-19)
    #refes to GENE manual
    coll_c=2.3031*10**(-5)*Lref*ne/(te)**2*(24-np.log(np.sqrt(ne*10**13)/(te*1000)))
    coll_ei=4*(ni/ne)*coll_c*np.sqrt(te*1000.*qref/me_SI)/Lref
    nuei=coll_ei
    beta=403.*10**(-5)*ne*te/Bref**2.

    nref=ne_u[center_index]
    te_mid=te_u[center_index]
    Tref=te_u[center_index] * qref

    cref = np.sqrt(Tref / m_SI)
    Omegaref = qref * Bref / m_SI / c
    rhoref = cref / Omegaref 
    kymin=n0*q0*rhoref/(Lref*x0_center)
    kyGENE =kymin * (q/q0) * np.sqrt(te_u/te_mid) * (x0_center/uni_rhot) #Add the effect of the q varying
    #from mtm_doppler
    omMTM = kyGENE*(tprime_e+nprime_e)
    gyroFreq = 9.79E3/np.sqrt(mref)*np.sqrt(te_u)/Lref
    mtmFreq = omMTM*gyroFreq/(2.*np.pi*1000.)
    omegaDoppler = vrot_u*n0/(2.*np.pi*1000.)
    omega=mtmFreq + omegaDoppler

    omega_n_GENE=kyGENE*(nprime_e)       #in cs/a
    omega_n=omega_n_GENE*gyroFreq/(2.*np.pi*1000.)  #in kHz

    coll_ei=coll_ei/(1000.)  #in kHz

    shat=Ln/Lq
    eta=Ln/Lt
    ky=kyGENE
    nu=(coll_ei)/(2.*np.pi*omega_n) 


    if plot==True:
        plt.clf()
        plt.xlabel('r/a')
        plt.ylabel('eta') 
        plt.plot(uni_rhot,eta,label='eta')
        plt.show()

        plt.clf()
        #plt.title('mode number finder')
        plt.xlabel('r/a')
        plt.ylabel('omega*(Lab), kHz') 
        plt.plot(uni_rhot,omega,label='omega*(Lab)')
        plt.show()

        plt.clf()
        plt.xlabel('r/a')
        plt.ylabel('eta') 
        plt.plot(uni_rhot,eta,label='eta')
        plt.show()

        plt.clf()
        plt.xlabel('r/a')
        plt.ylabel('shat') 
        plt.plot(uni_rhot,shat,label='shat')
        plt.show()


        plt.clf()
        plt.xlabel('r/a')
        plt.ylabel('beta') 
        plt.plot(uni_rhot,beta,label='beta')
        plt.show()
        
        plt.clf()
        plt.xlabel('r/a')
        plt.ylabel('ky rhoi') 
        plt.plot(uni_rhot,ky,label='ky')
        plt.show()

    
    if output_csv==True:
        with open('profile_output.csv','w') as csvfile:
            data = csv.writer(csvfile, delimiter=',')
            data.writerow(['x/a','nu_ei(kHz)','omega*n(kHz)','omega* plasma(kHz)','Doppler shift(kHz)','nu/omega*n','eta','shat','beta','ky rhoi(for n=1)'])
            for i in range(len(uni_rhot)):
                data.writerow([uni_rhot[i],coll_ei[i],omega_n[i],mtmFreq[i],omegaDoppler[i],nu[i],eta[i],shat[i],beta[i],ky[i]])
        csvfile.close()
    
    return uni_rhot,nu,eta,shat,beta,ky,q,mtmFreq,omegaDoppler,omega_n,omega_n_GENE