2 import matplotlib.pyplot
as plt
8 parser = argparse.ArgumentParser(description=
'csv_merger')
9 parser.add_argument(
"-iname",
"--input-name", dest=
"input_name", required=
"True", type=str, help=
"input csv file prefix" )
10 parser.add_argument(
"-path",
"--input-path", dest=
"path", default=
".", type=str, help=
"input csv file directory" )
11 parser.add_argument(
"-of",
"--output-file", dest=
"output_name", default=
" ", type=str, help=
"output file name" )
12 args = parser.parse_args()
18 input_name=args.input_name
22 if item.startswith(input_name): lis_file.append(item)
25 particle_collection={}
27 for filename
in lis_file:
28 f=open(path+
"/"+filename)
29 print(
"Read in datafile: "+path+
"/"+filename)
32 tem=list(map(float,line.split(
', ')))
33 if (
not (tem[0],tem[1])
in particle_collection)
and (
not all(data==0
for data
in tem[6:])):
34 particle_collection[(tem[0],tem[1])]=[[]]
35 particle_collection[(tem[0],tem[1])][0]=tem[2:]
36 elif (
not tem[2]
in np.array(particle_collection[(tem[0],tem[1])])[:,0] )
and (
not all(data==0
for data
in tem[6:])):
37 particle_collection[(tem[0],tem[1])].append(tem[2:])
41 for items
in particle_collection.values():
42 items.sort(reverse=
True)
45 print(
"number of valid tracers: "+
str(len(particle_collection.keys())) )
47 if args.output_name==
" ":
48 output_name=path+
"/merged_"+input_name+
".csv"
50 output_name=path+
"/"+args.output_name+
".csv"
52 f=open(output_name,
"w")
53 f.write(
"t, number(0), number(1), x(0), x(1), x(2), data \n")
55 for number, data
in particle_collection.items():
57 f.write(
str(snapshot[0])+
", "+
str(
int(number[0]))+
", "+
str(
int(number[1])) )
58 for variable
in snapshot[1:]:
59 f.write(
", "+
str(variable))