Esempio n. 1
0
header.append("det_cov_matrix")
header.append("log_emittance")
print ",".join(header)
step = 100 #Only calculate once all particles are present.
in_loop = True
while in_loop is True:
  output = []
  sum_covariance_matrix = MyEditableCovarianceMatrix()
  mean_phase_volume=Phase6DVolume(mass=mass_of_macroparticle)
  with open(args.list_of_directories) as f:
    initialized = False
    for directory in f:
      directory = directory.rstrip()
      if not initialized:
        cosy_output = CosyOutput()
        cosy_output.injectFile(os.path.join(directory,"screen.txt"))
        row_numbers = cosy_output.getRowNumbersWithKeyValuePair("step number",step,comparison = 'eq')
        if row_numbers == []:
          in_loop = False
          break
        time = float(cosy_output.returnTableValue("time",row_numbers[0]))
        output.append(time)
        initialized = True
      phase_volume = Phase6DVolume()
      for filename in os.listdir(directory):
        if filename.startswith(str(step)+"-x-") and filename.endswith(".txt"):
          phase_volume.injectFile(os.path.join(directory,filename),mass=mass_of_macroparticle)
      sum_covariance_matrix.cov_matrix += phase_volume.getCovarianceMatrix().cov_matrix
      x_mean = Cartesian3DVector(x=scaling_factor_for_x_mean*phase_volume.getMean(["x"]),y=scaling_factor_for_x_mean*phase_volume.getMean(["y"]),z=scaling_factor_for_x_mean*phase_volume.getMean(["z"]))
      #print x_mean
      p_mean = Cartesian3DVector(x=scaling_factor_for_p_mean*phase_volume.getMean(["px"]),y=scaling_factor_for_p_mean*phase_volume.getMean(["py"]),z=phase_volume.getMean(["pz"]))
Esempio n. 2
0
    type=int,
    help="The number of electrons per macroparticle for the simulation.  This defaults to 100 unless specified.",
    default=100,
)
args = parser.parse_args()

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
print "Ne,ex,ez,Fa"
with open(args.list_of_directories) as f:
    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")
Esempio n. 3
0
import sys
import os
import argparse
from scipy import constants
import numpy
from folder_convention import parse_folder_for_metadata
from cosy_output import CosyOutput

parser = argparse.ArgumentParser(description='Write the two columns for the velocity data: z,v/c')
parser.add_argument('screen_file', type=str, help='The path 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,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
z_conv = 10**3;
std_z_conv = 10**6;
cosy_output = CosyOutput()
cosy_output.injectFile(args.screen_file)
#cosy_output.addGammaField(mass_of_macroparticle)
for row in cosy_output.rows:
  output = []
  lorentz_gamma = numpy.sqrt(1 + (row.getCellWithFieldname("p_z").getValue()/mass_of_macroparticle)**2)
  output.append(str(row.getCellWithFieldname("z").getValue()*z_conv))
  output.append(str(row.getCellWithFieldname("std_z").getValue()*std_z_conv/lorentz_gamma))
  print ",".join(output)