def merge_screen_files(original_file,continued_file,merged_file,step_to_continue_from):
  """
  Removes the appropriate lines from the original screen file
  and add the step to continue from number to the steps of the second file
  and then tacks that editted file to the end of the original file.
  """
  cosy_output = CosyOutput()
  cosy_output.injectScreenFile(original_file)
  row_numbers = cosy_output.returnRowNumbersWithKeyValuePair("step number",step_to_continue_from,comparison = 'gt')
  for row_number in row_numbers:
    del cosy_output.table[row_number]
  cosy_output.injectScreenFile(continued_file,adjust_step_number=step_to_continue_from)
  cosy_output.writeToFile(merged_file)
import sys
import os
import argparse
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.', default=None)
args = parser.parse_args()

print "z,v/c";
with open(args.list_of_directories) as f:
  for line in f:
    line = line.rstrip()
    output =[]
    folder_metadata = parse_folder_for_metadata(line)
    output.append(folder_metadata["total_electrons"])
    cosy_output = CosyOutput()
    cosy_output.injectScreenFile(os.path.join(line,"2-Cosy/screen.txt"))
    row_numbers = cosy_output.returnRowNumbersWithKeyValuePair("time",120e-12,comparison = 'gt')
    if row_numbers == []:
      continue
    output.append(str(100 * int(cosy_output.returnTableValue("number macroparticles",row_numbers[0]))))
    output.append(folder_metadata["applied_field"])
    print ",".join(output)
    
Example #3
0
    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()

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)
Example #4
0
header.append("det_ref_cov_matrix")
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
Example #5
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)
Example #6
0
import os
import argparse
from scipy import constants
from folder_convention import parse_folder_for_metadata
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))
parser.add_argument('filepath', type=str, help='The csv file with the specifications for the simulations desired to be continued.')
parser.add_argument('-w','--working-directory', dest="working_dir", type=str, help='The path where the output directories should originate from.',default="/mnt/home/zerbe/working_dir")
parser.add_argument('-r','--run_template', dest="run_template", type=str, help='The template with the qsub script.',default="/mnt/home/zerbe/src/tem_simulations/2-Cosy/run_120ps.template")
parser.add_argument('-f','--positive_hole_files_dir', dest="pos_dir", type=str, help='The directory where the files are stored describing the positive hole geometry.',default="/mnt/home/zerbe/src/tem_simulations/2-Cosy/Files")
parser.add_argument('-b','--bin_file', dest="bin_file", type=str, help='The path to the cosy binary.',default="/mnt/home/zerbe/src/tem_simulations/2-Cosy/cosy.bin")
args = parser.parse_args()

parameter_set_list = ParameterSetList()
parameter_set_list.injectParametersFromCsv(args.filepath)
for parameter_set in parameter_set_list.list:
  parameter_set.createMainOutputPath(args.working_dir)
  parameter_set.createStepnamePath("Cosy")

  #Idenfity step number to begin from.
  screen_file = os.path.join(parameter_set.returnStepnamePath("Cosy"),"screen.txt")
  cosy_output = CosyOutput()
  cosy_output.injectScreenFile(screen_file)
  last_step = cosy_output.returnTableValue("step number")
  parameter_set.step_to_continue_from = int((floor(float(last_step)/float(10))-1)*10)
  
  #Create output dir
  continue_dir = os.path.join(parameter_set.returnStepnamePath("Cosy"),"continue_from_" + str(parameter_set.step_to_continue_from))
  if not os.path.exists(continue_dir) or not os.path.isdir(continue_dir):
    os.mkdir(continue_dir)

  #Grab the correct step's files for new initial conditions file.
  parameter_set.initial_conditions_file = os.path.join(continue_dir,"InitCondition_from_" + str(parameter_set.step_to_continue_from) + ".txt")
  make_continuing_initial_condition_file(parameter_set.returnStepnamePath("Cosy"),parameter_set.step_to_continue_from, parameter_set.initial_conditions_file)

  #Edit existing PE-setup.txt file.
  relevant_row_numbers = cosy_output.returnRowNumbersWithKeyValuePair("step number",str(parameter_set.step_to_continue_from))
Example #8
0
import numpy
import argparse
from scipy import constants
from folder_convention import parse_folder_for_metadata
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,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")