コード例 #1
0
from cosy_output import CosyOutput
from simulation_output import SimulationOutput

parser = argparse.ArgumentParser(description='Write the two columns for the velocity data: z,gamma_z')
parser.add_argument('directory', type=str, help='The path where the step files and screen.txt are stored.')
parser.add_argument('-m','--number_of_electron_per_macroparticle', dest="number_of_electrons_per_macroparticle", type=int, help='The number of electrons per macroparticle for the simulation.  This defaults to 100 unless specified.', default=100)
args = parser.parse_args()

print "z,gamma_z,gamma_z_divided_by_std_z";
mass_of_electron = constants.physical_constants["electron mass energy equivalent in MeV"][0]
mass_of_macroparticle = args.number_of_electrons_per_macroparticle*mass_of_electron
cosy_output = CosyOutput()
cosy_output.injectFile(os.path.join(args.directory,"screen.txt"))
cosy_output.addVelocityField(mass_of_macroparticle)
for row in cosy_output.rows:
  step_number = row.getCellWithFieldname("step number").getValue()
  if step_number % 10 == 0:
    output = []
    output.append(str(row.getCellWithFieldname("z").getValue()))
    simulation_output = SimulationOutput()
    for filename in os.listdir(args.directory):
      if filename.startswith(str(step_number)+"-x-"):
        pathname = os.path.join(args.directory,filename)
        if os.path.isfile(pathname):
          simulation_output.injectFile(pathname)
    gamma_z = simulation_output.calcGamma("z")
    output.append(str(gamma_z))
    std_z = row.getCellWithFieldname("std_z").getValue()*10**-6
    output.append(str(gamma_z/std_z))
    print ",".join(output)
コード例 #2
0
    for line in f:
        line = line.rstrip()
        output = []
        folder_metadata = parse_folder_for_metadata(line)
        cosy_output = CosyOutput()
        cosy_output.injectFile(os.path.join(line, "2-Cosy/screen.txt"))
        row_numbers = cosy_output.getRowNumbersWithKeyValuePair("time", 120e-12, comparison="gt")
        if row_numbers == []:
            continue
        step = int(cosy_output.returnTableValue("step number", row_numbers[0]))
        number_of_macroparticles = int(cosy_output.returnTableValue("number macroparticles", row_numbers[0]))
        number_of_electrons = number_of_macroparticles * args.number_of_electrons_per_macroparticle
        files = []
        for filename in os.listdir(os.path.join(line, "2-Cosy")):
            if filename.startswith(str(step) + "-x"):
                files.append(os.path.join(line, "2-Cosy/" + filename))
        simulation_output = SimulationOutput()
        for path in files:
            simulation_output.injectFile(path)
        simulation_output.convertCoordinatesToBetterUnits(mass_of_macroparticle)
        simulation_output = simulation_output.boostCoordinates("z")
        ex = simulation_output.calcEmittance("x") / args.number_of_electrons_per_macroparticle
        ez = simulation_output.calcEmittance("z") / args.number_of_electrons_per_macroparticle
        if ex == 0 or ez == 0:
            continue
        output.append(str(number_of_electrons))
        output.append(str(ex))
        output.append(str(ez))
        output.append(folder_metadata["applied_field"])
        print ",".join(output)
コード例 #3
0
parser = argparse.ArgumentParser(description='Write the two columns for the velocity data: z,gamma_z')
parser.add_argument('directory', type=str, help='The path where the step files and screen.txt are stored.')
parser.add_argument('-m','--number_of_electron_per_macroparticle', dest="number_of_electrons_per_macroparticle", type=int, help='The number of electrons per macroparticle for the simulation.  This defaults to 100 unless specified.', default=100)
args = parser.parse_args()

print "z,eta_z,eta_z_2,ez,gamma_z,mean_z,mean_pz,mean_pzxz,mean_z_squared,mean_pz_squared,var_z,var_pz"#,e_spread,var_pz,gamma_z_squared,var_z";
mass_of_electron = constants.physical_constants["electron mass energy equivalent in MeV"][0]
mass_of_macroparticle = args.number_of_electrons_per_macroparticle*mass_of_electron
cosy_output = CosyOutput()
cosy_output.injectFile(os.path.join(args.directory,"screen.txt"))
for row in cosy_output.rows:
  step_number = row.getCellWithFieldname("step number").getValue()
  if step_number % 10 == 0:
    output = []
    output.append(str(row.getCellWithFieldname("z").getValue()))
    simulation_output = SimulationOutput()
    for filename in os.listdir(args.directory):
      if filename.startswith(str(step_number)+"-x-"):
        pathname = os.path.join(args.directory,filename)
        if os.path.isfile(pathname):
          simulation_output.injectFile(pathname)
    simulation_output.convertCoordinatesToBetterUnits(mass_of_macroparticle)
    simulation_output = simulation_output.boostCoordinates("z")
    eta_z = simulation_output.calcEta("z")
    ez = simulation_output.calcEmittance("z")
    position = simulation_output.returnAllColumnValues("z")
    momentum = simulation_output.returnAllColumnValues("p_z")
    mean_position = numpy.mean(position)
    mean_momentum = numpy.mean(momentum)
    mean_positionxmomentum = numpy.mean([x*p for x,p in zip(position,momentum)])
    mean_position_squared = numpy.mean([x*x for x in position])