示例#1
0
def test_generate_signal():

    # Inputs for generate_signal
    dimensions = np.array([10, 10, 10])  # What is the size of the brain
    feature_size = [3]
    feature_type = ['cube']
    feature_coordinates = np.array([[5, 5, 5]])
    signal_magnitude = [30]

    # Generate a volume representing the location and quality of the signal
    volume = sim.generate_signal(
        dimensions=dimensions,
        feature_coordinates=feature_coordinates,
        feature_type=feature_type,
        feature_size=feature_size,
        signal_magnitude=signal_magnitude,
    )

    assert np.all(volume.shape == dimensions), "Check signal shape"
    assert np.max(volume) == signal_magnitude, "Check signal magnitude"
    assert np.sum(volume > 0) == math.pow(feature_size[0],
                                          3), ("Check feature size")
    assert volume[5, 5, 5] == signal_magnitude, "Check signal location"
    assert volume[5, 5, 1] == 0, "Check noise location"

    feature_coordinates = np.array([[5, 5, 5], [3, 3, 3], [7, 7, 7]])

    # Check feature size is correct
    volume = sim.generate_signal(dimensions=dimensions,
                                 feature_coordinates=feature_coordinates,
                                 feature_type=['loop', 'cavity', 'sphere'],
                                 feature_size=[3],
                                 signal_magnitude=signal_magnitude)
    assert volume[5, 5, 5] == 0, "Loop is empty"
    assert volume[3, 3, 3] == 0, "Cavity is empty"
    assert volume[7, 7, 7] != 0, "Sphere is not empty"

    # Check feature size manipulation
    volume = sim.generate_signal(dimensions=dimensions,
                                 feature_coordinates=feature_coordinates,
                                 feature_type=['loop', 'cavity', 'sphere'],
                                 feature_size=[1],
                                 signal_magnitude=signal_magnitude)
    assert volume[5, 6, 6] == 0, "Loop is too big"
    assert volume[3, 5, 5] == 0, "Cavity is too big"
    assert volume[7, 9, 9] == 0, "Sphere is too big"

    # Check that out of bounds feature coordinates are corrected
    feature_coordinates = np.array([0, 2, dimensions[2]])
    x, y, z = sim._insert_idxs(feature_coordinates, feature_size[0],
                               dimensions)
    assert x[1] - x[0] == 2, "x min not corrected"
    assert y[1] - y[0] == 3, "y was corrected when it shouldn't be"
    assert z[1] - z[0] == 1, "z max not corrected"

    # Check that signal patterns are created
    feature_coordinates = np.array([[5, 5, 5]])
    volume = sim.generate_signal(
        dimensions=dimensions,
        feature_coordinates=feature_coordinates,
        feature_type=feature_type,
        feature_size=feature_size,
        signal_magnitude=signal_magnitude,
        signal_constant=0,
    )
    assert volume[4:7, 4:7, 4:7].std() > 0, "Signal is constant"
示例#2
0
def test_generate_signal():

    # Inputs for generate_signal
    dimensions = np.array([10, 10, 10])  # What is the size of the brain
    feature_size = [3]
    feature_type = ['cube']
    feature_coordinates = np.array([[5, 5, 5]])
    signal_magnitude = [30]

    # Generate a volume representing the location and quality of the signal
    volume = sim.generate_signal(dimensions=dimensions,
                                 feature_coordinates=feature_coordinates,
                                 feature_type=feature_type,
                                 feature_size=feature_size,
                                 signal_magnitude=signal_magnitude,
                                 )

    assert np.all(volume.shape == dimensions), "Check signal shape"
    assert np.max(volume) == signal_magnitude, "Check signal magnitude"
    assert np.sum(volume > 0) == math.pow(feature_size[0], 3), (
        "Check feature size")
    assert volume[5, 5, 5] == signal_magnitude, "Check signal location"
    assert volume[5, 5, 1] == 0, "Check noise location"

    feature_coordinates = np.array(
        [[5, 5, 5], [3, 3, 3], [7, 7, 7]])

    # Check feature size is correct
    volume = sim.generate_signal(dimensions=dimensions,
                                 feature_coordinates=feature_coordinates,
                                 feature_type=['loop', 'cavity', 'sphere'],
                                 feature_size=[3],
                                 signal_magnitude=signal_magnitude)
    assert volume[5, 5, 5] == 0, "Loop is empty"
    assert volume[3, 3, 3] == 0, "Cavity is empty"
    assert volume[7, 7, 7] != 0, "Sphere is not empty"

    # Check feature size manipulation
    volume = sim.generate_signal(dimensions=dimensions,
                                 feature_coordinates=feature_coordinates,
                                 feature_type=['loop', 'cavity', 'sphere'],
                                 feature_size=[1],
                                 signal_magnitude=signal_magnitude)
    assert volume[5, 6, 6] == 0, "Loop is too big"
    assert volume[3, 5, 5] == 0, "Cavity is too big"
    assert volume[7, 9, 9] == 0, "Sphere is too big"

    # Check that out of bounds feature coordinates are corrected
    feature_coordinates = np.array([0, 2, dimensions[2]])
    x, y, z = sim._insert_idxs(feature_coordinates, feature_size[0],
                               dimensions)
    assert x[1] - x[0] == 2, "x min not corrected"
    assert y[1] - y[0] == 3, "y was corrected when it shouldn't be"
    assert z[1] - z[0] == 1, "z max not corrected"

    # Check that signal patterns are created
    feature_coordinates = np.array([[5, 5, 5]])
    volume = sim.generate_signal(dimensions=dimensions,
                                 feature_coordinates=feature_coordinates,
                                 feature_type=feature_type,
                                 feature_size=feature_size,
                                 signal_magnitude=signal_magnitude,
                                 signal_constant=0,
                                 )
    assert volume[4:7, 4:7, 4:7].std() > 0, "Signal is constant"