你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-03 19:26:50 +08:00
Change HDF5 file attribute from 'dx,dy,dz' to 'dx_dy_dz'
这个提交包含在:
@@ -623,7 +623,7 @@ Allows you to insert pre-defined geometry into a model. The geometry is specifie
|
||||
* The integer numbers in the HDF5 file correspond to the order of material commands in the materials text file, i.e. if ``#sand: 3 0 1 0`` is the first material in the materials file, it will be associated with any integers that are zero in the HDF5 file.
|
||||
* You can use an integer of -1 in the HDF5 file to indicate not to build any material at that location, i.e. whatever material is already in the model at that location.
|
||||
* The spatial resolution of the geometry objects must match the spatial resolution defined in the model.
|
||||
* The spatial resolution must be specified as a root attribute of the HDF5 file with the name ``dx, dy, dz`` equal to a tuple of floats, e.g. (0.002, 0.002, 0.002)
|
||||
* The spatial resolution must be specified as a root attribute of the HDF5 file with the name ``dx_dy_dz`` equal to a tuple of floats, e.g. (0.002, 0.002, 0.002)
|
||||
* If the geometry objects being imported were originally generated using gprMax, i.e. exported using #geometry_objects_write, then you can use dielectric smoothing as you like when generating the original geometry objects. However, if the geometry objects being imported were generated by an external method then dielectric smoothing will not take place.
|
||||
|
||||
For example, to insert a 2x2x2mm^3 AustinMan model with the lower left corner 40mm from the origin of the domain, and using disperive material properties use ``#geometry_objects_read: 0.04 0.04 0.04 ../user_libs/AustinManWoman/AustinMan_v2.3_2x2x2.h5 ../user_libs/AustinManWoman/AustinManWoman_materials_dispersive.txt``
|
||||
|
@@ -17,8 +17,8 @@ The output file has the following HDF5 attributes at the root (``/``):
|
||||
* ``gprMax`` is the version number of gprMax used to create the output
|
||||
* ``Title`` is the title of the model
|
||||
* ``Iterations`` is the number of iterations for the time window of the model
|
||||
* ``nx, ny, nz`` is a tuple containing the number of cells in each direction of the model
|
||||
* ``dx, dy, dz`` is a tuple containing the spatial discretisation, i.e. :math:`\Delta x`, :math:`\Delta y`, :math:`\Delta z`
|
||||
* ``nx_ny_nz`` is a tuple containing the number of cells in each direction of the model
|
||||
* ``dx_dy_dz`` is a tuple containing the spatial discretisation, i.e. :math:`\Delta x`, :math:`\Delta y`, :math:`\Delta z`
|
||||
* ``dt`` is the time step of the model, i.e. :math:`\Delta t`
|
||||
* ``srcsteps`` is the spatial increment used to move all sources between model runs.
|
||||
* ``rxsteps`` is the spatial increment used to move all receivers between model runs.
|
||||
@@ -161,7 +161,3 @@ The ``#geometry_view:`` command produces either ImageData (.vti) for a per-cell
|
||||
* You can turn on and off the visibility of materials using the eye icon in the Pipeline Browser. You can select multiple materials using the Shift key, and by shift-clicking the eye icon, turn the visibility of multiple materials on and off.
|
||||
|
||||
* You can set the Color and Opacity of materials from the Properties panel.
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -110,7 +110,7 @@ def process_geometrycmds(geometry, G):
|
||||
|
||||
# Open geometry object file and read/check spatial resolution attribute
|
||||
f = h5py.File(geofile, 'r')
|
||||
dx_dy_dz = f.attrs['dx, dy, dz']
|
||||
dx_dy_dz = f.attrs['dx_dy_dz']
|
||||
if round_value(dx_dy_dz[0] / G.dx) != 1 or round_value(dx_dy_dz[1] / G.dy) != 1 or round_value(dx_dy_dz[2] / G.dz) != 1:
|
||||
raise CmdInputError("'" + ' '.join(tmp) + "'" + ' requires the spatial resolution of the geometry objects file to match the spatial resolution of the model')
|
||||
|
||||
|
@@ -93,7 +93,7 @@ for i, model in enumerate(testmodels):
|
||||
rxposrelative = ((rxpos[0] - txpos[0]), (rxpos[1] - txpos[1]), (rxpos[2] - txpos[2]))
|
||||
|
||||
# Analytical solution of a dipole in free space
|
||||
dataref = hertzian_dipole_fs(filetest.attrs['Iterations'], filetest.attrs['dt'], filetest.attrs['dx, dy, dz'], rxposrelative)
|
||||
dataref = hertzian_dipole_fs(filetest.attrs['Iterations'], filetest.attrs['dt'], filetest.attrs['dx_dy_dz'], rxposrelative)
|
||||
|
||||
filetest.close()
|
||||
|
||||
|
@@ -11,17 +11,17 @@ fullfilename = strcat(pathname, filename);
|
||||
if filename ~= 0
|
||||
header.title = h5readatt(fullfilename, '/', 'Title');
|
||||
header.iterations = double(h5readatt(fullfilename,'/', 'Iterations'));
|
||||
tmp = h5readatt(fullfilename, '/', 'dx, dy, dz');
|
||||
tmp = h5readatt(fullfilename, '/', 'dx_dy_dz');
|
||||
header.dx = tmp(1);
|
||||
header.dy = tmp(2);
|
||||
header.dz = tmp(3);
|
||||
header.dt = h5readatt(fullfilename, '/', 'dt');
|
||||
header.nsrc = h5readatt(fullfilename, '/', 'nsrc');
|
||||
header.nrx = h5readatt(fullfilename, '/', 'nrx');
|
||||
|
||||
|
||||
% Time vector for plotting
|
||||
time = linspace(0, (header.iterations)*(header.dt), header.iterations)';
|
||||
|
||||
|
||||
% Initialise structure for field arrays
|
||||
fields.ex = zeros(header.iterations, header.nrx);
|
||||
fields.ey = zeros(header.iterations, header.nrx);
|
||||
@@ -29,7 +29,7 @@ if filename ~= 0
|
||||
fields.hx = zeros(header.iterations, header.nrx);
|
||||
fields.hy = zeros(header.iterations, header.nrx);
|
||||
fields.hz = zeros(header.iterations, header.nrx);
|
||||
|
||||
|
||||
% Save and plot fields from each receiver
|
||||
for n=1:header.nrx
|
||||
path = strcat('/rxs/rx', num2str(n));
|
||||
@@ -44,7 +44,7 @@ if filename ~= 0
|
||||
fields.hx(:,n) = h5read(fullfilename, strcat(path, 'Hx'));
|
||||
fields.hy(:,n) = h5read(fullfilename, strcat(path, 'Hy'));
|
||||
fields.hz(:,n) = h5read(fullfilename, strcat(path, 'Hz'));
|
||||
|
||||
|
||||
fh1=figure('Name', strcat('rx', num2str(n)));
|
||||
ax(1) = subplot(3,2,1); plot(time, fields.ex(:,n), 'r', 'LineWidth', 2), grid on, xlabel('Time [s]'), ylabel('Field strength [V/m]'), title('E_x')
|
||||
ax(2) = subplot(3,2,3); plot(time, fields.ey(:,n), 'r', 'LineWidth', 2), grid on, xlabel('Time [s]'), ylabel('Field strength [V/m]'), title('E_y')
|
||||
@@ -53,7 +53,7 @@ if filename ~= 0
|
||||
ax(5) = subplot(3,2,4); plot(time, fields.hy(:,n), 'b', 'LineWidth', 2), grid on, xlabel('Time [s]'), ylabel('Field strength [A/m]'), title('H_y')
|
||||
ax(6) = subplot(3,2,6); plot(time, fields.hz(:,n), 'b', 'LineWidth', 2), grid on, xlabel('Time [s]'), ylabel('Field strength [A/m]'), title('H_z')
|
||||
set(ax,'FontSize', 16, 'xlim', [0 time(end)]);
|
||||
|
||||
|
||||
% Options to create a nice looking figure for display and printing
|
||||
set(fh1,'Color','white','Menubar','none');
|
||||
X = 60; % Paper size
|
||||
@@ -62,11 +62,11 @@ if filename ~= 0
|
||||
yMargin = 0; % Bottom/top margins from page borders
|
||||
xSize = X - 2*xMargin; % Figure size on paper (width & height)
|
||||
ySize = Y - 2*yMargin; % Figure size on paper (width & height)
|
||||
|
||||
|
||||
% Figure size displayed on screen
|
||||
set(fh1, 'Units','centimeters', 'Position', [0 0 xSize ySize])
|
||||
movegui(fh1, 'center')
|
||||
|
||||
|
||||
% Figure size printed on paper
|
||||
set(fh1,'PaperUnits', 'centimeters')
|
||||
set(fh1,'PaperSize', [X Y])
|
||||
|
@@ -72,7 +72,7 @@ def pixel_match(pixellist, pixeltest):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
# Parse command line arguments
|
||||
parser = argparse.ArgumentParser(description='Convert a PNG image to a HDF5 file that can be used to import geometry (#geometry_objects_read) into a 2D gprMax model. Colours from the image are selected which correspond to a list of materials that should be supplied in a separate text file.', usage='python convert_png2h5.py imagefile dx dy dz')
|
||||
parser.add_argument('imagefile', help='name of image file including path')
|
||||
@@ -82,7 +82,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Open image file
|
||||
im = mpimg.imread(args.imagefile)
|
||||
|
||||
|
||||
# Store image data to use for creating geometry
|
||||
imdata = np.rot90(im, k=3) # Rotate 90CW
|
||||
imdata = np.floor(imdata * 255).astype(np.int16) # Convert pixel values from float (0-1) to integer (0-255)
|
||||
@@ -101,25 +101,25 @@ if __name__ == "__main__":
|
||||
plt.show()
|
||||
|
||||
# Format spatial resolution into tuple
|
||||
dxdydz = (args.dxdydz[0][0], args.dxdydz[0][1], args.dxdydz[0][2])
|
||||
|
||||
dx_dy_dz = (args.dxdydz[0][0], args.dxdydz[0][1], args.dxdydz[0][2])
|
||||
|
||||
# Filename for geometry (HDF5) file
|
||||
hdf5file = os.path.splitext(args.imagefile)[0] + '.h5'
|
||||
|
||||
|
||||
# Array to store geometry data (initialised as background, i.e. -1)
|
||||
data = np.ones((imdata.shape[0], imdata.shape[1], args.zcells), dtype=np.int16) * -1
|
||||
|
||||
# Write geometry (HDF5) file
|
||||
with h5py.File(hdf5file, 'w') as fout:
|
||||
|
||||
# Add attribute with name 'dx, dy, dz' for spatial resolution
|
||||
fout.attrs['dx, dy, dz'] = dxdydz
|
||||
# Add attribute with name 'dx_dy_dz' for spatial resolution
|
||||
fout.attrs['dx_dy_dz'] = dx_dy_dz
|
||||
|
||||
# Use a boolean mask to match selected pixel values with position in image
|
||||
for i, material in enumerate(materials):
|
||||
mask = np.all(imdata == material, axis=-1)
|
||||
data[mask,:] = i
|
||||
|
||||
|
||||
# Write data to file
|
||||
fout.create_dataset('data', data=data)
|
||||
|
||||
|
@@ -44,7 +44,7 @@ def calculate_antenna_params(filename, tltxnumber=1, tlrxnumber=None, rxnumber=N
|
||||
|
||||
# Open output file and read some attributes
|
||||
f = h5py.File(filename, 'r')
|
||||
dxdydz = f.attrs['dx, dy, dz']
|
||||
dxdydz = f.attrs['dx_dy_dz']
|
||||
dt = f.attrs['dt']
|
||||
iterations = f.attrs['Iterations']
|
||||
|
||||
|
@@ -10,7 +10,7 @@ args = parser.parse_args()
|
||||
|
||||
# Read full body HDF5 file
|
||||
f = h5py.File(args.filename, 'r')
|
||||
dx_dy_dz = f.attrs['dx, dy, dz']
|
||||
dx_dy_dz = f.attrs['dx_dy_dz']
|
||||
data = f['/data'][:, :, :]
|
||||
|
||||
# Define head as last 1/8 of total body height
|
||||
@@ -21,5 +21,5 @@ print('Dimensions of head model: {:g} x {:g} x {:g} cells'.format(data.shape[0],
|
||||
# Write HDF5 file
|
||||
headfile = os.path.splitext(args.filename)[0] + '_head.h5'
|
||||
f = h5py.File(headfile, 'w')
|
||||
f.attrs['dx, dy, dz'] = dx_dy_dz
|
||||
f.attrs['dx_dy_dz'] = dx_dy_dz
|
||||
f['/data'] = data[:, :, nzhead:data.shape[2]]
|
在新工单中引用
屏蔽一个用户