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)
Пример #2
0
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)
    
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))
  parameter_set.time_to_continue_from = cosy_output.returnTableValue("time",row_number=relevant_row_numbers[0])