Skip to content

Geometry Object Import

GPRMax UI 1.0.3 supports gprMax geometry-object files through GeometryObjectsRead. This is useful when geometry is prepared outside the model script, for example from segmented images or other preprocessing tools.

Convert an Image to Geometry

png2geometry() converts visible pixels in an image to an HDF5 geometry-object file. The generated .h5 file can be paired with a material mapping text file and referenced from a model.

1
2
3
4
5
6
7
8
9
from pathlib import Path

from gprmaxui.utils import png2geometry

png2geometry(
    Path("root_images/root1.png"),
    dxdydz=(0.005, 0.005, 0.005),
    scale=0.05,
)

Reference Geometry in a Model

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pathlib import Path

from gprmaxui import GprMaxModel
from gprmaxui.commands import (
    DomainBox,
    DomainResolution,
    DomainSize,
    GeometryObjectsRead,
    HertzianDipole,
    Material,
    Rx,
    RxSteps,
    SrcSteps,
    TimeWindow,
    Tx,
    TxRxPair,
    Waveform,
)

model = GprMaxModel(
    title="B-scan from imported geometry",
    output_folder=Path("output"),
    domain_size=DomainSize(x=1.0, y=0.3, z=0.005),
    domain_resolution=DomainResolution(dx=0.005, dy=0.005, dz=0.005),
    time_window=TimeWindow(twt=512),
)

model.register_materials(
    Material(id="sand", permittivity=3.0, conductivity=0.01, permeability=1),
    Material(id="object", permittivity=1.0, conductivity=0.01, permeability=1),
)

model.add_geometry(
    DomainBox(
        x_min=0.0,
        y_min=0.0,
        z_min=0.0,
        x_max=model.domain_size.x,
        y_max=0.2,
        z_max=model.domain_size.z,
        material="sand",
    )
)

model.add_geometry(
    GeometryObjectsRead(
        filename="root_images/root1.h5",
        materials_filename="root_images/root1.txt",
        x=0.1,
        y=0.02,
        z=0.0,
    )
)

tx = Tx(
    waveform=Waveform(wave_family="ricker", amplitude=1.0, frequency=1.8e9),
    source=HertzianDipole(polarization="z", x=0.02, y=0.21, z=0.0),
)

model.set_source(
    TxRxPair(
        tx=tx,
        rx=Rx(x=0.04, y=0.21, z=0.0),
        src_steps=SrcSteps(dx=0.005, dy=0.0, dz=0.0),
        rx_steps=RxSteps(dx=0.005, dy=0.0, dz=0.0),
    )
)

Serialize the Imported-Geometry Model

Geometry-object commands are included in the model JSON schema.

1
2
model.to_json("imported_geometry_model.json")
restored_model = GprMaxModel.from_json("imported_geometry_model.json")

The restored model keeps the same geometry-object references, material definitions, source, receiver, and output path.