Example #1
0
def test_validate_confidence():
    annotations.validate_confidence(None)

    with pytest.raises(ValueError):
        annotations.validate_confidence(np.array([[0, 1], [0, 2]]))
    with pytest.raises(ValueError):
        annotations.validate_confidence(np.array([0, 2]))
    with pytest.raises(ValueError):
        annotations.validate_confidence(np.array([np.nan, 0.5]))
Example #2
0
    def __init__(
        self,
        intervals,
        intervals_unit,
        time_step,
        elevations,
        elevations_unit,
        azimuths,
        azimuths_unit,
        distances,
        distances_unit,
        labels,
        labels_unit,
        track_number_index,
        confidence=None,
    ):
        annotations.validate_array_like(intervals, list, list)
        annotations.validate_array_like(labels, list, str)
        annotations.validate_array_like(confidence,
                                        np.ndarray,
                                        float,
                                        none_allowed=True)
        [[
            annotations.validate_intervals(intervals[np.newaxis, :])
            for intervals in event_intervals
        ] for event_intervals in intervals]
        annotations.validate_confidence(confidence)
        annotations.validate_unit(labels_unit, LABEL_UNITS)
        annotations.validate_unit(intervals_unit, TIME_UNITS)

        self.intervals = intervals
        self.intervals_unit = intervals_unit
        self.labels = labels
        self.labels_unit = labels_unit
        self.confidence = confidence

        annotations.validate_array_like(track_number_index, list, str)
        annotations.validate_array_like(elevations, list, list)
        annotations.validate_array_like(azimuths, list, list)
        annotations.validate_array_like(distances, list, list)
        annotations.validate_lengths_equal([
            intervals,
            elevations,
            azimuths,
            distances,
            labels,
            track_number_index,
            confidence,
        ])
        # validate location information for each event are numpy arrays
        [[[
            annotations.validate_array_like(subitem, np.ndarray, int)
            for subitem in sitem
        ] for sitem in item] for item in [elevations, azimuths]]
        [[
            annotations.validate_array_like(subitem,
                                            np.ndarray,
                                            np.array([None]).dtype,
                                            none_allowed=True)
            for subitem in item
        ] for item in distances]
        # validate length of location information is consistent
        # for each event
        [[
            annotations.validate_lengths_equal([e, a, d])
            for e, a, d in zip(els, azs, dis)
        ] for els, azs, dis in zip(elevations, azimuths, distances)]
        [[
            validate_locations(
                np.concatenate(
                    [e[:, np.newaxis], a[:, np.newaxis], d[:, np.newaxis]],
                    axis=1)) for e, a, d in zip(els, azs, dis)
        ] for els, azs, dis in zip(elevations, azimuths, distances)]
        [[
            validate_time_steps(
                time_step,
                np.concatenate(
                    [e[:, np.newaxis], a[:, np.newaxis], d[:, np.newaxis]],
                    axis=1),
                i,
            ) for e, a, d, i in zip(els, azs, dis, ivl)
        ] for els, azs, dis, ivl in zip(elevations, azimuths, distances,
                                        intervals)]

        annotations.validate_unit(elevations_unit, ELEVATIONS_UNITS)
        annotations.validate_unit(azimuths_unit, AZIMUTHS_UNITS)
        annotations.validate_unit(distances_unit, DISTANCES_UNITS)

        self.time_step = time_step
        self.elevations = elevations
        self.azimuths = azimuths
        self.distances = distances
        self.track_number_index = track_number_index
        self.elevations_unit = elevations_unit
        self.azimuths_unit = azimuths_unit
        self.distances_unit = distances_unit