예제 #1
0
if os.path.exists('orb') == True:
    os.remove('orb')
    print("./orb directory has been removed.")

parser = AG.ArgumentParser()
parser.add_argument("control_file",
                    nargs='?',
                    help="Control file ",
                    default='control.data')
args = parser.parse_args()

# open control file
p_file = args.control_file

pf = PF.pfile(p_file)

machine = pf.get_value('machine')

input_root = pf.get_value('input_root')

input_dir_ext = pf.get_value('input_dir_ext')

input_dir = input_root + machine + input_dir_ext + '/'

input_file = pf.get_value('input_file')

input_name = input_dir + input_file

input_ext = pf.get_value('nml_ext')
예제 #2
0
    A = z_prime/(np.sqrt(x_prime**2 + z_prime**2))
    return np.arccos(A)/dtr

#########################Proper Files###############

# reverse direction
reverse = False

parser = AG.ArgumentParser()
parser.add_argument("control_file", nargs = '?', help="Control file ", default = 'control.data')
args = parser.parse_args()

# open control file
c_file = args.control_file

cd = PF.pfile(c_file)

machine = cd.get_value('machine')

input_root = cd.get_value('input_root')
input_dir_ext = cd.get_value('input_dir_ext')

nml_dir = input_root + machine + input_dir_ext + '//'

#nml_filename = 'MAST_p6'
nml_filename = cd.get_value('input_file')

make_new_nml = cd.get_value('make_new_nml', var_type = cd.Bool)


#static_dir = 'MAST_input'
예제 #3
0
h_file = data_dir + 'header_comments.data'
s_file = data_dir + 'small_R.data'

files = [\
    'large_R_0.data',\
    'large_R_01.data',\
    'large_R_11.data',\
    'large_R_02.data',\
    'large_R_2.data',\
    'large_R_3.data',\
    'large_R_4.data',\
    'large_R_5.data',\
    'large_R_6.data']

cd = pfile(h_file)

rl = []
zl = []
phil = []
comments = []

# large R data
for fn in files:
    f = data_dir + fn
    d = B.get_file(f)
    rl.append(B.get_data(d, 'r'))
    zl.append(B.get_data(d, 'z'))
    phil.append(d.par.get_value('phi'))
    comments.append(d.par.get_value('comment'))
rl = np.array(rl)
예제 #4
0
def main(control_file, output_folder, vlen):
    global plot_command

    # open control file and read parameters
    c_file = control_file 
    cd = PF.pfile(c_file)

    dynamic_dir = cd.get_value('dynamic_dir')
    dyn_file = cd.get_value('dynamic_file')
    
    plot_command = cd.get_value('plot_command') + ' ' + c_file

##########################Obtaining Parameters and Data########################

    # Grabbing dynamic data file
    dd = B.get_file(dynamic_dir + dyn_file)
    dpar = dd.par



    
    # get the assigned detectors ids
    detector_id = B.get_data(dd, 'detector_id')
    
    # total number of detectors in dynamic file
    N_det = len(detector_id)

    # Port angle of each detector when the Reciprocating probe arm is at a rotation angle of 0, convert to rads
    ppb = B.get_data(dd, 'phi_port_base')*dtr
    
    # Theta angle of each detector when the Reciprocating
    # probe arm is at a rotation angle of 0
    # Port angle was input in degrees
    tpb = B.get_data(dd, 'theta_port_base')*dtr

    # Horizontal offset, from the center of the diagnostic, of each detector
    # Horizontal offset was input in mm
    dyo = B.get_data(dd, 'detector_horizontal_offset')*mm2m

    # Radial offset of each detector (measured from the base)
    # Radial offset was input in mm
    dro = B.get_data(dd, 'detector_radial_axis_offset')*mm2m

    # Height offset of each detector (measured from the center)
    # Height offset was input in mm
    dzo = B.get_data(dd, 'detector_height_offest')*mm2m

    # detector type (Probe or Fixed)
    det_type = B.get_data(dd, 'det_type')
    
    # Alpha is the rotational angle of the RP arm
    # converted to radians
    alpha = dpar.get_value('RP_rotation')*dtr

    
    
    ##############################Making Calculations##########################
    # indexes of fixed detectors
    fixed_dets = np.where(det_type == 'Fixed')
    
    # calculation of positions change for each Probe detector due to rotation
    dyor = np.sqrt(dyo**2 + dzo**2)*np.cos(alpha + pol_angle(dyo, dzo))
    dzor = np.sqrt(dyo**2 + dzo**2)*np.sin(alpha + pol_angle(dyo, dzo))
    
    # RDist is the distance from the center of the tokamak to each detector (m)
    RDist = np.sqrt((dpar.get_value('RDist') + dro + dpar.get_value('RDist_offset'))**2 + dyor**2)
    RDist[fixed_dets] = dro[fixed_dets]
    
    # ZDist here is the height of each detector relative to the centr of the
    # tokamak, in dynamic file ZDist is RP position hight
    ZDist = dpar.get_value('ZDist') + dzor
    ZDist[fixed_dets] = dzor[fixed_dets]
    
    #RP phd angle
    RP_phd = dpar.get_value('PHDangle')
    
    # PHD angle shift for each detector relative to RP_phd
    dphd= np.arcsin(dyor/RDist)/dtr
    
    # phdangle is the toroidal angle of each detector in radians
    phdangle = RP_phd + dphd
    phdangle[fixed_dets] = dyo[fixed_dets]

    # The following are the calculations for the change in phi and theta angles
    phi_port, theta_port = rotate_det(ppb, tpb, alpha, dphd*dtr)
    phi_port /= dtr
    theta_port /= dtr
    
    phi_port[fixed_dets] = ppb[fixed_dets]/dtr
    theta_port[fixed_dets] = tpb[fixed_dets]/dtr
    
    
    for k in range(N_det):
        geom = open(output_folder + 'track' + str(k)+ '.dat', 'w')
        xx=RDist[k]*np.cos(phdangle[k])
        yy=RDist[k]*np.sin(phdangle[k])
        zz=ZDist[k]
        
        geom.write('{}  {}  {}\n'.format(xx,yy,zz))

        print(xx, yy, zz)
        
        vx =  -vlen*np.cos(phi_port[k]*dtr)*np.sin(theta_port[k]*dtr)
        vy =  -vlen*np.sin(phi_port[k]*dtr)
        vz =   vlen*np.cos(phi_port[k]*dtr)*np.cos(theta_port[k]*dtr)

        print("V", vx, vy, vz)
        
        v1 = vx*np.cos(phdangle[k]*dtr) - vy*np.sin(phdangle[k]*dtr)
        v2 = vx*np.sin(phdangle[k]*dtr) + vy*np.cos(phdangle[k]*dtr)
        v3 = vz
        
        print("Vr", v1,v2,v3)
        xx = xx + v1
        yy = yy + v2
        zz = zz + v3
        
        print(xx, yy, zz)
        geom.write('{}  {}  {}\n'.format(xx,yy,zz))
        geom.close()
예제 #5
0
def main(c_file):
    control_file = c_file

    # contpour plotting controle
    cont_scale = 1.0
    ncont = 25

    #colormap = pl.get_cmap('CMRmap')
    #colormap = pl.get_cmap('gnuplot')
    #colormap = pl.get_cmap('gnuplot2')
    colormap = pl.get_cmap('gist_heat')
    #colormap = pl.get_cmap('jet')
    #colormap = pl.get_cmap('hot')

    # open control file
    p_file = control_file
    pf = PF.pfile(p_file)

    output_dir = pf.get_value('output_dir')
    # ???
    plot_em = pf.get_value('plot_em', var_type=pf.Bool)
    # ??
    em_filled = pf.get_value('em_filled', var_type=pf.Bool)
    # ??
    plot_psirel = pf.get_value('plot_psirel', var_type=pf.Bool)
    # ??
    psirel_filled = pf.get_value('psirel_filled', var_type=pf.Bool)
    ##
    all_yellow = pf.get_value('all_yellow', var_type=pf.Bool)

    # color array
    if all_yellow:
        colors = ['y', 'y', 'y', 'y', 'y', 'y', 'y', 'y', 'y',
                  'y']  # make everything yellow
    else:
        colors = [
            'red', 'green', 'blue', 'yellow', 'magenta', 'cyan', 'orange',
            'lavenderblush', 'maroon', 'plum'
        ]

    # dynamic input file for detector/channels assignment
    di_dir = pf.get_value('dynamic_dir')
    di_file = pf.get_value('dynamic_file')

    dynamic_file = di_dir + di_file
    df = B.get_file(dynamic_file)
    dfd = df.par

    # get channel/detector assignement
    try:
        dn = np.array(dfd.get_value('detector_to_use').split(','), dtype=int)
    except:
        dn = np.array([int(dfd.get_value('detector_to_use'))])

    channel_number = B.get_data(df, 'ch')
    detector_id = B.get_data(df, 'detector_id')
    ch_touse = channel_number[np.in1d(detector_id, dn)]

    # flux grid
    try:
        flux_data_file = pf.get_value('flux_data_file')
    except:
        flux_data_file = 'flux.data'
    print('using : ', flux_data_file, ' for flux and Em data')

    # flux limiter
    try:
        flux_limiter_file = pf.get_value('flux_limiter_file')
    except:
        flux_limiter_file = 'flux_limit.data'
    print('using : ', flux_limiter_file, ' for flux limit data')

    # plot n-flux at mid-plane
    try:
        flux_data_file_mp = pf.get_value('flux_data_file_mp')
    except:
        flux_data_file_mp = None

    orbit_output = open(output_dir + 'orbit_output').readlines()

    # find the EQ file used:
    eq_file = 'generic'
    for d in orbit_output:
        if (d.find('--> EQ File unit, name') >= 0.):
            eq_file = d.split()[-1:][0]

    # flux
    print('reading flux data')
    fl = gf.flux(output_dir + flux_data_file)

    print('reading flux limit data')
    fll_d = DF.dfile(output_dir + flux_limiter_file)
    r_fll = np.array(fll_d.get_data('xlim'))
    z_fll = np.array(fll_d.get_data('ylim'))

    # limiter
    print('reading limiter data')
    li = gl.limiter(output_dir + 'limiter_drawing.data')
    #orbits

    print('reading orbits data')

    # each view can now have several trajectories
    PD_views = []
    PD_views_f = []
    PD_accept = []
    PD_channel_number = []
    PD_step = []
    for i, i_d in enumerate(dn):
        cc = ch_touse[i]

        name_patt = output_dir + '/track_{}*.data'.format(i_d)

        PD_view_files = G.glob(name_patt)

        # use the first file in the list to get some parameters used for calculating rates
        PDd = DF.pdfile(PD_view_files[0])
        PD_accept.append(PDd.par.get_value('accept'))
        PD_channel_number.append(
            PDd.par.get_value('channel_number', var_type=int))
        PD_step.append(PDd.par.get_value('stepsize'))
        # load the trajectories for each view
        PD_v = [vd.view(f) for f in PD_view_files]
        PD_views_f.append(PD_view_files)
        PD_views.append(PD_v)
        print('channel : ', cc, ', detecor : ', i_d, ' loaded')
    PD_accept = np.array(PD_accept)

    #----------------------------------------------------------------------
    # start drawing
    #----------------------------------------------------------------------

    draw_top_view = pf.get_value('draw_top_view', var_type=pf.Bool)
    draw_top_view = True
    if draw_top_view:
        f1 = pl.figure(figsize=(11, 6))
#        f1=pickle.load(file('neutron.pickle_both_view'))
    else:
        f1 = pl.gcf()  #figure(figsize= (5,8))
    #f1.text(0.1, 0.925, eq_file)

    # draw 3 regions
    if draw_top_view:
        li.draw_all()
    else:
        li.draw_side_all()

    # draw the rel. flux
    # get a nice set of contour lines
    # select the first plot
    Em_cont = None

    # axes = li.ax1.get_axes()
    # f1.sca( axes )
    axes = li.ax1
    f1.sca(axes)

    # draw the flux limit
    pl.plot(r_fll, z_fll, color='m', linewidth=2.)

    if plot_em:
        Em_range = fl.Em.max() - fl.Em.min()
        Em_min = fl.Em.min() + Em_range / 100.
        v = np.linspace(Em_min, fl.Em.max() * cont_scale, ncont)
        if em_filled:
            Em_cont = fl.draw_Em_filled(v, cmap=colormap)
        else:
            Em_cont = fl.draw_Em(v)

    if plot_psirel:
        v = np.linspace(-0.1, fl.Zrel.max(), 23)
        if psirel_filled:
            fl.draw_psirel_filled(v, cmap=colormap)
        else:
            fl.draw_psirel(v)

    # make a nice x-axis
    axes.xaxis.set_major_locator(MaxNLocator(4))

    #----------------------------------------------------------------------
    # draw orbits
    #----------------------------------------------------------------------
    #    # animation part
    #    for i, PDv in enumerate(PD_views):
    #        icol = dn[i]-1
    #        animate(li, PDv, color = colors[icol])
    #
    # axes = li.ax1.get_axes()
    axes = li.ax1
    f1.sca(axes)
    for i, PDv in enumerate(PD_views):
        icol = dn[i] - 1
        plot_view_side(PDv, color=colors[icol], label='Ch {0:d}'.format(dn[i]))

    #pl.legend(fontsize = 12,loc = 'upper left')
    pl.title
    # draw  orbits into the top view
    #draw_top_view=True
    if draw_top_view:
        # axes = li.ax2.get_axes()
        axes = li.ax2
        f1.sca(axes)
        # draw a few orbits
        for i, PDv in enumerate(PD_views):
            icol = dn[i] - 1
            plot_view_top(PDv,
                          color=colors[icol],
                          label='Ch {0:d}'.format(dn[i]))
        # get the mid-plane emmissivity
        if plot_em:
            if (flux_data_file_mp != None):
                # load data file
                d = np.load(output_dir + '/' + flux_data_file_mp)
                X = d['X']
                Y = d['Y']
                Em_mid = d['EM_mp']
                Em_range = Em_mid.max() - Em_mid.min()
                Em_min = Em_mid.min() + Em_range / 100.
                v = np.linspace(Em_min, Em_mid.max() * cont_scale, ncont)
                if em_filled:
                    Em_cont = pl.contourf(X, Y, Em_mid, v, cmap=colormap)
                else:
                    Em_cont = pl.contour(X, Y, Em_mid, v, cmap=colormap)

        #pl.legend(fontsize = 12, loc = 'upper left')


# The following code plots histogram of orbits midplane intersection radii
#    h_range =(0.0, 0.3)#(0.6, 1.6)
#    r0 = []
#    f2 = pl.figure()
#    for  i,PDv in enumerate( PD_views ):
#        icol = dn[i]-1
#        rr = []
#        for v in PDv:
#            rr.append(get_effective_dist(v))#get_zero_crossing(v))
#
#        rr = np.array(rr)
#        r = rr.mean()
#        h = B.histo(rr, range =h_range, bins = 200)
#        h.plot(color = colors[icol])
#        print colors[icol]
#        sig_r = np.sqrt(rr.var())
#        r0.append([h, r, sig_r, rr])
#    # all done
#    pl.xlabel('R (m)')
#    pl.ylabel('counts')
#    pl.title('mid-plane Radius')
#
#    #pl.savefig(orbit_dir+'image.png')
    pl.show()
예제 #6
0
def main(control_file):

    # open control file and read parameters
    c_file = control_file
    cd = PF.pfile(c_file)

    nml_dir = cd.get_value('input_dir')
    nml_filename = cd.get_value('input_file')

    make_new_nml = cd.get_value('make_new_nml', var_type=cd.Bool)

    static_dir = cd.get_value('static_dir')
    stat_file = cd.get_value('static_file')

    dynamic_dir = cd.get_value('dynamic_dir')
    dyn_file = cd.get_value('dynamic_file')

    orbit_command = cd.get_value('orbit_command') + ' ' + c_file
    #    plot_command = cd.get_value('plot_command') + ' ' + c_file

    ##########################Obtaining Parameters and Data########################

    # Grabbing dynamic data file
    dd = B.get_file(dynamic_dir + dyn_file)
    dpar = dd.par

    # which detectors are used in the calculations
    try:
        det_use = np.array(dpar.get_value('detector_to_use').split(','),
                           dtype=int)
    except:
        det_use = np.array([int(dpar.get_value('detector_to_use'))])

    # total number of detectors to be used in calculations
    detectors = len(det_use)

    # get the assigned detectors ids
    detector_id = B.get_data(dd, 'detector_id')

    # total number of detectors in dynamic file
    N_det = len(detector_id)

    # get the assigned channel numbers
    channel_number = B.get_data(dd, 'ch')

    # Port angle of each detector when the Reciprocating probe arm is at a rotation angle of 0, convert to rads
    ppb = B.get_data(dd, 'phi_port_base') * dtr

    # Theta angle of each detector when the Reciprocating
    # probe arm is at a rotation angle of 0
    # Port angle was input in degrees
    tpb = B.get_data(dd, 'theta_port_base') * dtr

    # Horizontal offset, from the center of the diagnostic, of each detector
    # Horizontal offset was input in mm
    dyo = B.get_data(dd, 'detector_horizontal_offset') * mm2m

    # Radial offset of each detector (measured from the base)
    # Radial offset was input in mm
    dro = B.get_data(dd, 'detector_radial_axis_offset') * mm2m

    # Height offset of each detector (measured from the center)
    # Height offset was input in mm
    dzo = B.get_data(dd, 'detector_height_offest') * mm2m

    # detector type (Probe or Fixed)
    det_type = B.get_data(dd, 'det_type')

    # Alpha is the rotational angle of the RP arm
    # converted to radians
    alpha = dpar.get_value('RP_rotation') * dtr

    ##################################Making Calculations##########################
    # indexes of fixed detectors
    fixed_dets = np.where(det_type == 'Fixed')

    # calculation of positions change for each Probe detector due to rotation
    dyor = np.sqrt(dyo**2 + dzo**2) * np.cos(alpha + pol_angle(dyo, dzo))
    dzor = np.sqrt(dyo**2 + dzo**2) * np.sin(alpha + pol_angle(dyo, dzo))

    # RDist is the distance from the center of the tokamak to each detector (m)
    RDist = np.sqrt((dpar.get_value('RDist') + dro +
                     dpar.get_value('RDist_offset'))**2 + dyor**2)
    RDist[fixed_dets] = dro[fixed_dets]

    # ZDist here is the height of each detector relative to the centr of the
    # tokamak, in dynamic file ZDist is RP position hight
    ZDist = dpar.get_value('ZDist') + dzor
    ZDist[fixed_dets] = dzor[fixed_dets]

    #RP phd angle
    RP_phd = dpar.get_value('PHDangle')

    # PHD angle shift for each detector relative to RP_phd
    dphd = np.arcsin(dyor / RDist) / dtr

    # phdangle is the toroidal angle of each detector in radians
    phdangle = RP_phd + dphd
    phdangle[fixed_dets] = dyo[fixed_dets] / mm2m

    # The following are the calculations for the change in phi and theta angles
    phi_port, theta_port = rotate_det(ppb, tpb, alpha, dphd * dtr)
    phi_port /= dtr
    theta_port /= dtr

    phi_port[fixed_dets] = ppb[fixed_dets] / dtr
    theta_port[fixed_dets] = tpb[fixed_dets] / dtr

    #######################Detector orientation vectors for SolidWorks##############
    #    output_folder = '../MAST-U_output/g29975_TRANSP/DetectorsVectors/'
    #    vlen = 0.1 #vector lenght in meters
    #    for k in range(N_det):
    #        geom = open(output_folder + 'track' + str(k)+ '.dat', 'w+')
    #
    #        xx=RDist[k]*np.cos(phdangle[k]*dtr)
    #        yy=RDist[k]*np.sin(phdangle[k]*dtr)
    #        zz=ZDist[k]
    #
    #        geom.write('{}  {}  {}\n'.format(xx,yy,zz))
    #
    #        print xx, yy, zz
    #
    #        vx =  -vlen*np.cos(phi_port[k]*dtr)*np.sin(theta_port[k]*dtr)
    #        vy =  -vlen*np.sin(phi_port[k]*dtr)
    #        vz =   vlen*np.cos(phi_port[k]*dtr)*np.cos(theta_port[k]*dtr)
    #
    #        #print "V", vx, vy, vz
    #
    #        v1 = vx*np.cos(phdangle[k]*dtr) - vy*np.sin(phdangle[k]*dtr)
    #        v2 = vx*np.sin(phdangle[k]*dtr) + vy*np.cos(phdangle[k]*dtr)
    #        v3 = vz
    #
    #        #print "Vr", v1,v2,v3
    #        xx = xx + v1
    #        yy = yy + v2
    #        zz = zz + v3
    #
    #        print xx, yy, zz
    #        geom.write('{}  {}  {}\n'.format(xx,yy,zz))
    #        geom.close()

    #########################Creating New Dictionary###############################

    # Physical Parameter Dictionary
    PA = {
        'PHDangle': phdangle,
        'RDist': RDist,
        'phi_port': phi_port,
        'theta_port': theta_port,
        'channel_number': channel_number,
        'detector_id': detector_id,
        'ZDist': ZDist,
        'detector_number': det_use,
        'detectors': detectors
    }

    PAK = list(PA.keys())
    PAG = PA.get

    #   ######################Make a new NML file#########################
    if make_new_nml is True:

        staticf = open(static_dir + stat_file, 'r').readlines()
        # opens and reads static file

        staticf = [s.replace('\r\n', '\n') for s in staticf]
        #this is for linux compatibility

        bothf = open(nml_dir + nml_filename, 'w+')
        # creates nml writable file

        # Writing New nml file
        bothf.writelines(staticf[:staticf.index(' &orbit_par\n') + 1])
        # writes the static file into the new nml file

        # Selecting the inputs under orbitpar

        orbit_par = [
            'detectors', 'detector_number', 'detector_id', 'channel_number',
            'theta_port', 'phi_port'
        ]
        # Writing Parameters into orbit_par in nml file
        for i in orbit_par:
            for k in range(N_det):
                try:
                    bothf.write('    ' + i + '({0:1})'.format(k + 1) +
                                '= {0:1}\n'.format(PAG(i)[k]))
                except:
                    if i == 'detector_number': break
                    bothf.write('    ' + i + '= {0:1}\n'.format(PAG(i)))
                    break
            bothf.write('\n')

        bothf.writelines(staticf[staticf.index(' &orbit_par\n') +
                                 1:staticf.index(' &detection\n') + 1])

        # Choosing keys for detection nml section
        detection = []
        for i in PAK:
            if i not in orbit_par:
                detection.append(i)

        # Writing Parameters into detection in nml file

        for i in detection:
            for k in range(N_det):
                try:
                    bothf.write('    ' + i + '({0:1})'.format(k + 1) +
                                '= {0:1}\n'.format(PAG(i)[k]))
                except:
                    bothf.write('    ' + i + '= {0:1}\n'.format(PAG(i)))
                    break
            bothf.write('\n')
        bothf.writelines(staticf[staticf.index(' &detection\n') + 1:])
        bothf.close()

    os.system(orbit_command)