你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
Updating of outputfiles_merge to allow it to be imported as a function.
这个提交包含在:
@@ -155,7 +155,7 @@ You should have produced 60 output files, one for each A-scan, with names ``cyli
|
|||||||
|
|
||||||
python -m tools.outputfiles_merge user_models/cylinder_Bscan_2D
|
python -m tools.outputfiles_merge user_models/cylinder_Bscan_2D
|
||||||
|
|
||||||
You should see a combined output file ``cylinder_Bscan_2D_merged.out``. The tool will ask you if you want to delete the original single A-scan output files or keep them.
|
You should see a combined output file ``cylinder_Bscan_2D_merged.out``. You can add the optional argument ``--remove-files`` if you want to automatically delete the original single A-scan output files.
|
||||||
|
|
||||||
You can now view an image of the B-scan using the command:
|
You can now view an image of the B-scan using the command:
|
||||||
|
|
||||||
@@ -171,9 +171,3 @@ You can now view an image of the B-scan using the command:
|
|||||||
:width: 600px
|
:width: 600px
|
||||||
|
|
||||||
B-scan of model of a metal cylinder buried in a dielectric half-space.
|
B-scan of model of a metal cylinder buried in a dielectric half-space.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -21,15 +21,16 @@ where ``inputfile`` is the name of input file including the path.
|
|||||||
outputfiles_merge.py
|
outputfiles_merge.py
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
gprMax produces a separate output file for each trace (A-scan) in a B-scan. This module combines the separate output files into a single file, and offers to remove the separate output files afterwards. Usage (from the top-level gprMax directory) is:
|
gprMax produces a separate output file for each trace (A-scan) in a B-scan. This module combines the separate output files into a single file, and can remove the separate output files afterwards. Usage (from the top-level gprMax directory) is:
|
||||||
|
|
||||||
.. code-block:: none
|
.. code-block:: none
|
||||||
|
|
||||||
python -m tools.outputfiles_merge basefilename
|
python -m tools.outputfiles_merge basefilename --remove-files
|
||||||
|
|
||||||
where:
|
where:
|
||||||
|
|
||||||
* ``basefilename`` is the base name file of the output file series, e.g. for ``myoutput1.out``, ``myoutput2.out`` the base file name would be ``myoutput``
|
* ``basefilename`` is the base name file of the output file series, e.g. for ``myoutput1.out``, ``myoutput2.out`` the base file name would be ``myoutput``
|
||||||
|
* ``remove-files`` is an optional argument (flag) that when given will remove the separate output files after the merge.
|
||||||
|
|
||||||
|
|
||||||
convert_png2h5.py
|
convert_png2h5.py
|
||||||
|
@@ -25,19 +25,55 @@ import numpy as np
|
|||||||
|
|
||||||
from gprMax._version import __version__
|
from gprMax._version import __version__
|
||||||
|
|
||||||
"""Merges traces (A-scans) from multiple output files into one new file, then removes the series of output files."""
|
|
||||||
|
|
||||||
# Parse command line arguments
|
def get_output_data(filename, rxnumber, rxcomponent):
|
||||||
parser = argparse.ArgumentParser(description='Merges traces (A-scans) from multiple output files into one new file, then removes the series of output files.', usage='cd gprMax; python -m tools.outputfiles_merge basefilename')
|
"""Gets B-scan output data from a model.
|
||||||
parser.add_argument('basefilename', help='base name of output file series including path')
|
|
||||||
args = parser.parse_args()
|
Args:
|
||||||
|
filename (string): Filename (including path) of output file.
|
||||||
|
rxnumber (int): Receiver output number.
|
||||||
|
rxcomponent (str): Receiver output field/current component.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
outputdata (array): Array of A-scans, i.e. B-scan data.
|
||||||
|
dt (float): Temporal resolution of the model.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Open output file and read some attributes
|
||||||
|
f = h5py.File(filename, 'r')
|
||||||
|
nrx = f.attrs['nrx']
|
||||||
|
dt = f.attrs['dt']
|
||||||
|
|
||||||
|
# Check there are any receivers
|
||||||
|
if nrx == 0:
|
||||||
|
raise CmdInputError('No receivers found in {}'.format(filename))
|
||||||
|
|
||||||
|
path = '/rxs/rx' + str(rxnumber) + '/'
|
||||||
|
availableoutputs = list(f[path].keys())
|
||||||
|
|
||||||
|
# Check if requested output is in file
|
||||||
|
if rxcomponent not in availableoutputs:
|
||||||
|
raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(rxcomponent, ', '.join(availableoutputs)))
|
||||||
|
|
||||||
|
outputdata = f[path + '/' + rxcomponent]
|
||||||
|
outputdata = np.array(outputdata)
|
||||||
|
|
||||||
|
return outputdata, dt
|
||||||
|
|
||||||
|
|
||||||
|
def merge_files(basefilename, removefiles=False):
|
||||||
|
"""Merges traces (A-scans) from multiple output files into one new file,
|
||||||
|
then optionally removes the series of output files.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
basefilename (string): Base name of output file series including path.
|
||||||
|
outputs (boolean): Flag to remove individual output files after merge.
|
||||||
|
"""
|
||||||
|
|
||||||
basefilename = args.basefilename
|
|
||||||
outputfile = basefilename + '_merged.out'
|
outputfile = basefilename + '_merged.out'
|
||||||
files = glob.glob(basefilename + '*.out')
|
files = glob.glob(basefilename + '*.out')
|
||||||
outputfiles = [filename for filename in files if '_merged' not in filename]
|
outputfiles = [filename for filename in files if '_merged' not in filename]
|
||||||
modelruns = len(outputfiles)
|
modelruns = len(outputfiles)
|
||||||
print('Found {} files to merge'.format(modelruns))
|
|
||||||
|
|
||||||
# Combined output file
|
# Combined output file
|
||||||
fout = h5py.File(outputfile, 'w')
|
fout = h5py.File(outputfile, 'w')
|
||||||
@@ -73,8 +109,17 @@ for model in range(modelruns):
|
|||||||
|
|
||||||
fout.close()
|
fout.close()
|
||||||
|
|
||||||
check = input('Do you want to remove the multiple individual output files? [y] or n:')
|
if removefiles:
|
||||||
if not check or check == 'y':
|
|
||||||
for model in range(modelruns):
|
for model in range(modelruns):
|
||||||
file = basefilename + str(model + 1) + '.out'
|
file = basefilename + str(model + 1) + '.out'
|
||||||
os.remove(file)
|
os.remove(file)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
parser = argparse.ArgumentParser(description='Merges traces (A-scans) from multiple output files into one new file, then optionally removes the series of output files.', usage='cd gprMax; python -m tools.outputfiles_merge basefilename')
|
||||||
|
parser.add_argument('basefilename', help='base name of output file series including path')
|
||||||
|
parser.add_argument('--remove-files', action='store_true', default=False, help='flag to remove individual output files after merge')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
merge_files(args.basefilename, removefiles=args.remove_files)
|
||||||
|
@@ -25,45 +25,7 @@ import numpy as np
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from gprMax.exceptions import CmdInputError
|
from gprMax.exceptions import CmdInputError
|
||||||
|
from .outputdata import get_output_data
|
||||||
|
|
||||||
def get_output_data(filename, rxnumber, rxcomponent):
|
|
||||||
"""Gets B-scan output data from a model.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
filename (string): Filename (including path) of output file.
|
|
||||||
rxnumber (int): Receiver output number.
|
|
||||||
rxcomponent (str): Receiver output field/current component.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
outputdata (array): Array of A-scans, i.e. B-scan data.
|
|
||||||
dt (float): Temporal resolution of the model.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Open output file and read some attributes
|
|
||||||
f = h5py.File(filename, 'r')
|
|
||||||
nrx = f.attrs['nrx']
|
|
||||||
dt = f.attrs['dt']
|
|
||||||
|
|
||||||
# Check there are any receivers
|
|
||||||
if nrx == 0:
|
|
||||||
raise CmdInputError('No receivers found in {}'.format(filename))
|
|
||||||
|
|
||||||
path = '/rxs/rx' + str(rxnumber) + '/'
|
|
||||||
availableoutputs = list(f[path].keys())
|
|
||||||
|
|
||||||
# Check if requested output is in file
|
|
||||||
if rxcomponent not in availableoutputs:
|
|
||||||
raise CmdInputError('{} output requested to plot, but the available output for receiver 1 is {}'.format(rxcomponent, ', '.join(availableoutputs)))
|
|
||||||
|
|
||||||
outputdata = f[path + '/' + rxcomponent]
|
|
||||||
outputdata = np.array(outputdata)
|
|
||||||
|
|
||||||
# Check that there is more than one A-scan present
|
|
||||||
if outputdata.shape[1] == 1:
|
|
||||||
raise CmdInputError('{} contains only a single A-scan.'.format(filename))
|
|
||||||
|
|
||||||
return outputdata, dt
|
|
||||||
|
|
||||||
|
|
||||||
def mpl_plot(filename, outputdata, dt, rxnumber, rxcomponent):
|
def mpl_plot(filename, outputdata, dt, rxnumber, rxcomponent):
|
||||||
|
在新工单中引用
屏蔽一个用户