Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4638a6563c |
+64
-7
@@ -7,6 +7,7 @@ import argparse
|
||||
import glob
|
||||
import re
|
||||
import os
|
||||
import plot_standards as pst
|
||||
|
||||
def get_time_and_total_charge_(files, considered_keys=['All'], exclude_underflow=False):
|
||||
times = []
|
||||
@@ -52,6 +53,46 @@ def get_time_and_total_charge_(files, considered_keys=['All'], exclude_underflow
|
||||
|
||||
return times, total_charges
|
||||
|
||||
def get_time_and_wall_losses(files, considered_keys=['All']):
|
||||
times = []
|
||||
phys_wall_loss = []
|
||||
for file in files:
|
||||
with h5py.File(file, 'r') as cfile:
|
||||
time = 0
|
||||
for key in cfile.keys():
|
||||
if(key == "PoissonSolver" or key == "RestartInfo" or key == 'NumberProcesses'):
|
||||
continue
|
||||
if (not considered_keys[0] == 'All') and (not key in considered_keys):
|
||||
continue
|
||||
cfile_specieslogger = cfile[key]['DeletionLogger']
|
||||
|
||||
for time_key in cfile_specieslogger.keys():
|
||||
time = cfile[key]['DensityField/SimulationData'][time_key]['PhysicalTime'][0]
|
||||
deltat = cfile[key]['CurrentCollector/SimulationData'][time_key]['PhysicalTime'][0]
|
||||
try:
|
||||
index = times.index(time)
|
||||
try:
|
||||
phys_wall_loss[index] += cfile_specieslogger[time_key]\
|
||||
['NumDeletions/Wall(physical)'][0]/deltat
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
times.append(time)
|
||||
try:
|
||||
phys_wall_loss.append(cfile_specieslogger[time_key]\
|
||||
['NumDeletions/Wall(physical)'][0]/deltat)
|
||||
except:
|
||||
phys_wall_loss.append(-1)
|
||||
|
||||
times = np.array(times)
|
||||
phys_wall_loss = np.array(phys_wall_loss)
|
||||
|
||||
sorting_mask = np.argsort(times)
|
||||
times = times[sorting_mask]
|
||||
phys_wall_loss = phys_wall_loss[sorting_mask]
|
||||
|
||||
return times, phys_wall_loss
|
||||
|
||||
def getFiles(dir:str, base_name:str, pattern:str) :
|
||||
if dir[-1] == '/':
|
||||
pathname = dir + base_name
|
||||
@@ -64,7 +105,10 @@ if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description="Program to create a plot of the charge against time from the output of KARL")
|
||||
parser.add_argument("dir", type = str, help="directory where the files are stored in")
|
||||
parser.add_argument("basename", type = str, help = 'identifying pattern of the files (i.e. basename[0-9]*\\.h5])')
|
||||
parser.add_argument('--losses', action='store_true', help = 'create wall loss rate plot instead')
|
||||
parser.add_argument("--pattern", type = str, nargs = '?', help = 'Regular expression pattern, that specifies the naming of the files (by default [0-9]*). Gets added to dir+basename+pattern+".h5".', default = '[0-9]*')
|
||||
parser.add_argument("--width", type = str, nargs = '?', default="thesis", help = "Either \'thesis\' or \'beamer\' as defined in plot_standards.py")
|
||||
parser.add_argument("--fraction", type = float, default=1, nargs="?", help= "the fraction of width that the plot should occupy, as defined in plot_standards.py")
|
||||
parser.add_argument("species", action='extend', nargs='+', help = 'Names of the Species in the KARL output or \'All\' if all species should be summed. If name does not exist it will be ignored.')
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -74,10 +118,17 @@ if __name__ == '__main__':
|
||||
print(files)
|
||||
|
||||
if(files == []):
|
||||
print(f"No files found in {args.dir}, which match '{args.basename}[0-9]*\\.h5'")
|
||||
print(f"No files found in {args.dir}, which match '{args.basename}{args.pattern}\\.h5'")
|
||||
exit(1)
|
||||
|
||||
times, charges = get_time_and_total_charge_(files, args.species)
|
||||
if (not args.width == 'thesis') and (not args.width == 'beamer'):
|
||||
print(f"{args.width} is not a valid parameter for width; fall back to \'thesis\'")
|
||||
args.width = 'thesis'
|
||||
|
||||
if args.losses:
|
||||
times, charges = get_time_and_wall_losses(files, args.species)
|
||||
else:
|
||||
times, charges = get_time_and_total_charge_(files, args.species)
|
||||
|
||||
legstr = ''
|
||||
for val in args.species:
|
||||
@@ -85,10 +136,13 @@ if __name__ == '__main__':
|
||||
legstr = legstr[:-3]
|
||||
|
||||
|
||||
plt.rcParams.update({'font.size': 14})
|
||||
fig = plt.figure(figsize=(10,6))
|
||||
plt.rcParams.update({'font.size': 10})
|
||||
fig = plt.figure(figsize=pst.set_size(args.width))
|
||||
plt.plot(times, charges, marker = 'x', label = legstr)
|
||||
plt.ylabel('charge (C)')
|
||||
if args.losses:
|
||||
plt.ylabel('loss rate (1/s)')
|
||||
else:
|
||||
plt.ylabel('charge (C)')
|
||||
plt.xlabel('time (s)')
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
@@ -102,11 +156,14 @@ if __name__ == '__main__':
|
||||
|
||||
os.makedirs(outname, exist_ok=True)
|
||||
|
||||
outname += args.basename + "_chargeAgainstTime_species-"
|
||||
if args.losses:
|
||||
outname += args.basename + "_wallLossRateAgainstTime_species-"
|
||||
else:
|
||||
outname += args.basename + "_chargeAgainstTime_species-"
|
||||
|
||||
for value in args.species:
|
||||
outname += value
|
||||
outname += '.pdf'
|
||||
outname += '_test.pdf'
|
||||
|
||||
# print(outname)
|
||||
plt.savefig(outname, format='pdf', bbox_inches = 'tight')
|
||||
|
||||
Reference in New Issue
Block a user