Ejemplo n.º 1
0
def test_XAxis_append_summary(position_xvalues, exp_summary):
    xaxis = XAxis.XAxis(ident=b'A', long_name=b'B', units=b'C')
    x_values = []
    for frame_number, (vr_postion, lrsh_position,
                       x_value) in enumerate(position_xvalues):
        xaxis.append(File.LogicalRecordPositionBase(vr_postion, lrsh_position),
                     frame_number + 1, x_value)
        x_values.append(x_value)
    result = xaxis.summary
    # print(result)
    assert result.count == len(x_values)
    assert result.min == min(x_values)
    assert result.max == max(x_values)
    array = np.array(x_values)
    spacing_summary = XAxis.compute_spacing(array)
    assert result.spacing == spacing_summary
Ejemplo n.º 2
0
def test_XAxis_getitem(position_xvalues, expected):
    x_axis = XAxis.XAxis(ident=b'A', long_name=b'B', units=b'C')
    x_values = []
    for frame_number, (vr_postion, lrsh_position,
                       x_value) in enumerate(position_xvalues):
        x_axis.append(
            File.LogicalRecordPositionBase(vr_postion, lrsh_position),
            frame_number + 1, x_value)
        x_values.append(x_value)
    assert len(x_axis) == len(expected)
    # print()
    for i in range(len(x_axis)):
        # print(x_axis[i])
        assert x_axis[i] == expected[i]
Ejemplo n.º 3
0
 def add_iflr(self, file_logical_data: File.FileLogicalData, iflr: IFLR.IndirectlyFormattedLogicalRecord) -> None:
     """Adds a IFLR entry to the index. The IFLR just contains the object name and frame number.
     This extracts the X axis from the first value in the IFLR free data and appends this to the
     iflr_position_map.
     """
     self._check_fld_iflr(file_logical_data, iflr)
     frame_array: LogPass.FrameArray = self.log_pass[iflr.object_name]
     frame_array.read_x_axis(file_logical_data.logical_data, frame_number=0)
     if iflr.object_name not in self.iflr_position_map:
         self.iflr_position_map[iflr.object_name] = XAxis.XAxis(
             frame_array.x_axis.ident,
             frame_array.x_axis.long_name,
             frame_array.x_axis.units,
         )
     self.iflr_position_map[iflr.object_name].append(
         file_logical_data.position,
         iflr.frame_number,
         frame_array.x_axis.array.mean(),
     )
Ejemplo n.º 4
0
def test_compute_spacing_eq(x_array, expected):
    result = XAxis.compute_spacing(x_array)
    assert result == expected
    assert result != 1
Ejemplo n.º 5
0
def test_compute_spacing_counts_counts_negative(diff_array, exp_median, exp_counts):
    _median, counts = XAxis.compute_spacing_counts(-diff_array)
    assert exp_counts == counts
Ejemplo n.º 6
0
def test_compute_spacing_counts_median(diff_array, exp_median, exp_counts):
    median, _counts = XAxis.compute_spacing_counts(diff_array)
    assert exp_median == median
Ejemplo n.º 7
0
def test_XAxis_ctor():
    xaxis = XAxis.XAxis(ident=b'A', long_name=b'B', units=b'C')
    assert xaxis.ident == b'A'
    assert xaxis.long_name == b'B'
    assert xaxis.units == b'C'
Ejemplo n.º 8
0
def test_x_axis_spacing_summary_eq(array_a, array_b, expected):
    x_axis_a = XAxis.compute_spacing(array_a)
    x_axis_b = XAxis.compute_spacing(array_b)
    assert (x_axis_a == x_axis_b) == expected
    assert (x_axis_b == x_axis_a) == expected
    assert not x_axis_a == 1
Ejemplo n.º 9
0
def test_xaxis_spacing_counts_total(norm, dupe, skip, back, expected):
    counts = XAxis.XAxisSpacingCounts(norm, dupe, skip, back)
    assert counts.total == expected
Ejemplo n.º 10
0
def test_compute_spacing_histogram_str(x_array, expected):
    x_axis = XAxis.compute_spacing(x_array)
    result = x_axis.histogram_str()
    # print(result)
    assert result == expected
Ejemplo n.º 11
0
from TotalDepth.RP66V1.core import XAxis, File


@pytest.mark.parametrize(
    'norm, dupe, skip, back, expected',
    (
        (1, 2, 3, 4, 10),
    )
)
def test_xaxis_spacing_counts_total(norm, dupe, skip, back, expected):
    counts = XAxis.XAxisSpacingCounts(norm, dupe, skip, back)
    assert counts.total == expected


SPACING_COUNTS = (
    (np.array([1.0, 1.0, 1.0]), 1.0, XAxis.XAxisSpacingCounts(3, 0, 0, 0),),
    # Norm
    (np.array([1.0, 1.0, 1.1]), 1.0, XAxis.XAxisSpacingCounts(3, 0, 0, 0),),
    # Dupe
    (np.array([1.0, 1.0, 0.0]), 1.0, XAxis.XAxisSpacingCounts(2, 1, 0, 0),),
    # Skip
    (np.array([1.0, 1.0, 2.0]), 1.0, XAxis.XAxisSpacingCounts(2, 0, 1, 0),),
    # Back
    (np.array([1.0, 1.0, -1.0]), 1.0, XAxis.XAxisSpacingCounts(2, 0, 0, 1),),
)


@pytest.mark.parametrize('diff_array, exp_median, exp_counts', SPACING_COUNTS)
def test_compute_spacing_counts_median(diff_array, exp_median, exp_counts):
    median, _counts = XAxis.compute_spacing_counts(diff_array)
    assert exp_median == median