Example #1
0
    def test_interface_reflection(self):
        n = 10
        points = g.Points(np.random.uniform(size=(n, 3)))
        orientations = g.Points(np.eye(3), "coordinate system")

        interface = c.Interface(
            points,
            orientations,
            transmission_reflection="reflection",
            kind="fluid_solid",
            are_normals_on_inc_rays_side=True,
            are_normals_on_out_rays_side=None,
            reflection_against=water,
        )

        with pytest.raises(ValueError):
            c.Interface(
                points,
                orientations,
                transmission_reflection="reflection",
                kind="fluid_solid",
                are_normals_on_inc_rays_side=True,
                are_normals_on_out_rays_side=None,
                reflection_against=None,
            )

        assert interface.points is points
        assert np.allclose(interface.orientations[np.newaxis, ...],
                           interface.orientations[...])
        assert interface.transmission_reflection is c.TransmissionReflection.reflection
        assert interface.reflection_against is water
        str(interface)
        repr(interface)
Example #2
0
    def make_case(self, are_normals_zplus):
        """
        Source point: omega
        Dest points: 12 points along a circle of centre omega and radius 5 (points are
        spaced by  30°)

        Parameters
        ----------
        are_normals_zplus

        Returns
        -------

        """
        omega = np.array((3.0, 0.0, 5.0)) * 1e-2
        src_points = g.Points(omega.reshape([1, 3]), name="source")
        src_basis = g.default_orientations(src_points)
        src_basis = src_basis.rotate(g.rotation_matrix_y(np.pi / 6))
        source_interface = arim.Interface(
            src_points,
            src_basis,
            are_normals_on_out_rays_side=are_normals_zplus)

        # circle:
        dst_points = g.Points(np.zeros([len(self.circle_theta), 3]),
                              name="dest")
        dst_points.x[...] = omega[0]
        dst_points.y[...] = omega[1]
        dst_points.z[...] = omega[2]
        dst_points.x[...] += self.circle_radius * np.sin(self.circle_theta)
        dst_points.z[...] += self.circle_radius * np.cos(self.circle_theta)

        dst_basis = g.default_orientations(dst_points)

        dest_interface = arim.Interface(
            dst_points,
            dst_basis,
            are_normals_on_inc_rays_side=are_normals_zplus)

        material = arim.Material(1.0, metadata=dict(long_name="Dummy"))

        interfaces = [source_interface, dest_interface]

        # The i-th ray starts from the source and ends at the i-th destination point.
        shape = [len(source_interface.points), len(dest_interface.points)]
        ray_indices = np.zeros((0, *shape), arim.settings.INT)
        times = np.empty(shape, float)
        times.fill(np.nan)

        path = arim.Path(interfaces, [material], ["L"])
        ray = arim.ray.Rays(times, ray_indices, path.to_fermat_path())
        path.rays = ray
        ray_geometry = arim.ray.RayGeometry.from_path(path)
        return path, ray_geometry
Example #3
0
    def test_interface_probe(self):
        n = 10
        points = g.Points(np.random.uniform(size=(n, 3)))
        orientations = g.Points(np.eye(3), "coordinate system")

        interface = c.Interface(
            points,
            orientations,
            are_normals_on_inc_rays_side=None,
            are_normals_on_out_rays_side=True,
        )

        assert interface.points is points
        assert np.allclose(interface.orientations[np.newaxis, ...],
                           interface.orientations[...])
        str(interface)
        repr(interface)
Example #4
0
def test_find_probe_loc_from_frontwall_ideal(A, B, dA, dB):
    """Test move_probe_over_flat_surface() with 2 elements"""
    A = np.asarray(A, dtype=np.float)
    B = np.asarray(B, dtype=np.float)

    # Setup: a 2-element points1
    locations = g.Points(np.array([A, B]))  # locations in PCS
    probe = Probe(locations, 1e6)  # NB: assume PCS=GCS at this point

    tx = np.array([0, 0, 1])
    rx = np.array([0, 1, 1])

    distance_to_surface = np.array([dA, np.nan, dB])

    time = Time(0.0, 1.0, 50)
    scanlines = np.zeros((len(tx), len(time)))

    frame = Frame(scanlines, time, tx, rx, probe,
                  ExaminationObject(Material(1.0)))

    frame, iso = reg.move_probe_over_flat_surface(frame,
                                                  distance_to_surface,
                                                  full_output=True)
    new_locations = frame.probe.locations

    # Are the locations in PCS unchanged?
    assert np.allclose(frame.probe.locations_pcs, locations)

    # Right distance to the plane Oxy (NB: z<0):
    assert np.isclose(new_locations.z[0], -dA)
    assert np.isclose(new_locations.z[1], -dB)

    # Elements are in plane y=0
    assert np.isclose(new_locations.y[0], 0.0)
    assert np.isclose(new_locations.y[1], 0.0)

    # Is element A(0., 0., 0.) now in (0., 0., z)?
    assert np.allclose(new_locations[0], (0.0, 0.0, iso.z_o))

    # the elements are still in the right distance
    dAB = g.norm2(*(locations[0] - locations[1]))
    dApBp = g.norm2(*(new_locations[0] - new_locations[1]))
    assert np.isclose(dAB, dApBp)

    # Is the returned theta right?
    # Remark: (dB-dB)/(xB-xA) has the sign of theta, then
    # (zA-zB)/(xB-xA) has the sign of -theta because zA=-dA and zB=-dB
    theta = -np.arctan((new_locations.z[1] - new_locations.z[0]) /
                       (new_locations.x[1] - new_locations.x[0]))
    assert np.isclose(theta, iso.theta)
Example #5
0
def make_delay_and_sum_case_random(dtype_float,
                                   dtype_data,
                                   amplitudes="random"):
    locations = g.Points(
        np.array([(0, 0, 0), (1.0, 0, 0), (2.0, 0.0, 0.0)], dtype=np.float))
    numelements = len(locations)
    frequency = 1e6
    probe = Probe(locations, frequency)

    # examination object:
    vel = 10.0
    material = Material(vel)
    examination_object = ExaminationObject(material)

    # timetraces
    # time = Time(start=0.35, step=0.001, num=100)
    time = Time(start=0.0, step=0.001, num=100)

    tx = np.array([0, 0, 1, 1, 2, 2], dtype=np.int)
    rx = np.array([0, 1, 0, 1, 0, 1], dtype=np.int)
    numtimetraces = len(tx)

    numpoints = 10

    start_lookup = time.start / 2
    stop_lookup = (time.end - time.step) / 2

    np.random.seed(31031596)
    timetraces = _random_uniform(dtype_data,
                                 100.0,
                                 101.0,
                                 size=(numtimetraces, len(time)))
    amplitudes_tx = _random_uniform(dtype_data,
                                    1.0,
                                    1.1,
                                    size=(numpoints, numelements))
    amplitudes_rx = _random_uniform(dtype_data,
                                    -1.0,
                                    -1.1,
                                    size=(numpoints, numelements))
    timetrace_weights = _random_uniform(dtype_data, size=(numtimetraces))
    lookup_times_tx = _random_uniform(dtype_float, start_lookup, stop_lookup,
                                      (numpoints, numelements))
    lookup_times_rx = _random_uniform(dtype_float, start_lookup, stop_lookup,
                                      (numpoints, numelements))
    if amplitudes == "random":
        amplitudes = arim.im.tfm.TxRxAmplitudes(amplitudes_tx, amplitudes_rx)
    elif amplitudes == "uniform":
        amplitudes = arim.im.tfm.TxRxAmplitudes(
            np.ones((numpoints, numelements), dtype_data),
            np.ones((numpoints, numelements), dtype_data),
        )
    elif amplitudes == "none":
        amplitudes = None
    else:
        raise ValueError

    # Mess a bit lookup times to get out of bounds values:
    # lookup_times_tx[0, 0] = time.start / 2.
    # lookup_times_rx[1, 1] = time.end * 2.

    focal_law = arim.im.tfm.FocalLaw(lookup_times_tx, lookup_times_rx,
                                     amplitudes, timetrace_weights)

    frame = Frame(timetraces, time, tx, rx, probe, examination_object)

    return frame, focal_law