From bbc8a101ece70a67f6815e865bc5fce7e61e1527 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Fri, 19 Feb 2016 14:27:31 +0000 Subject: [PATCH] Updated to merge and plot (in separate figure windows) multiple receiver points. --- tools/outputfiles_merge.py | 26 +++++++++++++------ tools/plot_Bscan.py | 53 ++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/tools/outputfiles_merge.py b/tools/outputfiles_merge.py index f941e14b..552d160b 100644 --- a/tools/outputfiles_merge.py +++ b/tools/outputfiles_merge.py @@ -30,8 +30,7 @@ args = parser.parse_args() basefilename = args.basefilename modelruns = args.modelruns -outputfile = basefilename + '_merge.out' -path = '/rxs/rx1' +outputfile = basefilename + '_merged.out' # Combined output file fout = h5py.File(outputfile, 'w') @@ -39,16 +38,27 @@ fout = h5py.File(outputfile, 'w') # Add positional data for rxs for model in range(modelruns): fin = h5py.File(basefilename + str(model + 1) + '.out', 'r') - availableoutputs = list(fin[path].keys()) + nrx = fin.attrs['nrx'] + + # Write properties for merged file on first iteration if model == 0: fout.attrs['Iterations'] = fin.attrs['Iterations'] fout.attrs['dt'] = fin.attrs['dt'] - fields = fout.create_group(path) - for output in availableoutputs: - fields[output] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/' + output].dtype) + fout.attrs['nrx'] = fin.attrs['nrx'] + for rx in range(1, nrx + 1): + path = '/rxs/rx' + str(rx) + grp = fout.create_group(path) + availableoutputs = list(fin[path].keys()) + for output in availableoutputs: + grp.create_dataset(output, (fout.attrs['Iterations'], modelruns), dtype=fin[path + '/' + output].dtype) - for output in availableoutputs: - fields[path + '/' + output][:,model] = fin[path + '/' + output][:] + # For all receivers + for rx in range(1, nrx + 1): + path = '/rxs/rx' + str(rx) + '/' + availableoutputs = list(fin[path].keys()) + # For all receiver outputs + for output in availableoutputs: + fout[path + '/' + output][:,model] = fin[path + '/' + output][:] fin.close() diff --git a/tools/plot_Bscan.py b/tools/plot_Bscan.py index b95d6cdf..34d6cd45 100644 --- a/tools/plot_Bscan.py +++ b/tools/plot_Bscan.py @@ -33,36 +33,39 @@ args = parser.parse_args() # Open output file and read some attributes f = h5py.File(args.outputfile, 'r') -path = '/rxs/rx1' -availableoutputs = list(f[path].keys()) +nrx = f.attrs['nrx'] -# Check if requested output is in file -if args.output not in availableoutputs: - raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(args.output, ', '.join(availableoutputs))) +for rx in range(1, nrx + 1): + path = '/rxs/rx' + str(rx) + '/' + availableoutputs = list(f[path].keys()) -outputdata = f[path + '/' + args.output] + # Check if requested output is in file + if args.output not in availableoutputs: + raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(args.output, ', '.join(availableoutputs))) -# Check that there is more than one A-scan present -if outputdata.shape[1] == 1: - raise CmdInputError('{} contains only a single A-scan.'.format(args.outputfile)) + outputdata = f[path + '/' + args.output] -# Plot B-scan image -fig = plt.figure(num=args.outputfile, figsize=(20, 10), facecolor='w', edgecolor='w') -plt.imshow(outputdata, extent=[0, outputdata.shape[1], outputdata.shape[0]*f.attrs['dt'], 0], interpolation='nearest', aspect='auto', cmap='seismic', vmin=-np.amax(np.abs(outputdata)), vmax=np.amax(np.abs(outputdata))) -plt.xlabel('Trace number') -plt.ylabel('Time [s]') -plt.grid() -cb = plt.colorbar() -if 'E' in args.output: - cb.set_label('Field strength [V/m]') -elif 'H' in args.output: - cb.set_label('Field strength [A/m]') -elif 'I' in args.output: - cb.set_label('Current [A]') + # Check that there is more than one A-scan present + if outputdata.shape[1] == 1: + raise CmdInputError('{} contains only a single A-scan.'.format(args.outputfile)) -# Save a PDF/PNG of the figure -#fig.savefig(os.path.splitext(os.path.abspath(file))[0] + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) -#fig.savefig(os.path.splitext(os.path.abspath(file))[0] + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1) + # Plot B-scan image + fig = plt.figure(num='rx' + str(rx), figsize=(20, 10), facecolor='w', edgecolor='w') + plt.imshow(outputdata, extent=[0, outputdata.shape[1], outputdata.shape[0]*f.attrs['dt'], 0], interpolation='nearest', aspect='auto', cmap='seismic', vmin=-np.amax(np.abs(outputdata)), vmax=np.amax(np.abs(outputdata))) + plt.xlabel('Trace number') + plt.ylabel('Time [s]') + plt.grid() + cb = plt.colorbar() + if 'E' in args.output: + cb.set_label('Field strength [V/m]') + elif 'H' in args.output: + cb.set_label('Field strength [A/m]') + elif 'I' in args.output: + cb.set_label('Current [A]') + + # Save a PDF/PNG of the figure + #fig.savefig(os.path.splitext(os.path.abspath(file))[0] + '.pdf', dpi=None, format='pdf', bbox_inches='tight', pad_inches=0.1) + #fig.savefig(os.path.splitext(os.path.abspath(file))[0] + '.png', dpi=150, format='png', bbox_inches='tight', pad_inches=0.1) plt.show() f.close()