def test_get_velocity_diff_for_two_tracks(self):
        """Ensures correct output from _get_velocity_diff_for_two_tracks.

        This is an integration test, not a unit test, because it depends on
        _theil_sen_fit.
        """

        theil_sen_model_for_x_early, theil_sen_model_for_y_early = (
            best_tracks._theil_sen_fit(
                unix_times_sec=TIMES_EARLY_TRACK_UNIX_SEC,
                x_coords_metres=X_COORDS_EARLY_TRACK_METRES,
                y_coords_metres=Y_COORDS_EARLY_TRACK_METRES))

        theil_sen_model_for_x_late, theil_sen_model_for_y_late = (
            best_tracks._theil_sen_fit(
                unix_times_sec=TIMES_LATE_TRACK_UNIX_SEC,
                x_coords_metres=X_COORDS_LATE_TRACK_METRES,
                y_coords_metres=Y_COORDS_LATE_TRACK_METRES))

        this_velocity_diff_m_s01 = (
            best_tracks._get_velocity_diff_for_two_tracks(
                [theil_sen_model_for_x_early, theil_sen_model_for_x_late],
                [theil_sen_model_for_y_early, theil_sen_model_for_y_late]))
        self.assertTrue(
            numpy.isclose(this_velocity_diff_m_s01,
                          VELOCITY_DIFFERENCE_M_S01,
                          atol=TOLERANCE))
    def test_get_mean_prediction_error_for_two_tracks(self):
        """Ensures correctness of _get_mean_prediction_error_for_two_tracks.

        This is an integration test, not a unit test, because it depends on
        _theil_sen_fit.
        """

        theil_sen_model_for_x_early, theil_sen_model_for_y_early = (
            best_tracks._theil_sen_fit(
                unix_times_sec=TIMES_EARLY_TRACK_UNIX_SEC,
                x_coords_metres=X_COORDS_EARLY_TRACK_METRES,
                y_coords_metres=Y_COORDS_EARLY_TRACK_METRES))

        this_mean_error_metres = (
            best_tracks._get_mean_prediction_error_for_two_tracks(
                x_coords_late_metres=X_COORDS_LATE_TRACK_METRES,
                y_coords_late_metres=Y_COORDS_LATE_TRACK_METRES,
                late_times_unix_sec=TIMES_LATE_TRACK_UNIX_SEC,
                theil_sen_model_for_x_early=theil_sen_model_for_x_early,
                theil_sen_model_for_y_early=theil_sen_model_for_y_early))

        self.assertTrue(
            numpy.isclose(this_mean_error_metres,
                          MEAN_ERROR_LATE_PREDICTED_BY_EARLY_METRES,
                          atol=TOLERANCE))
    def test_theil_sen_fit(self):
        """Ensures correct output from _theil_sen_fit."""

        this_ts_model_for_x, this_ts_model_for_y = best_tracks._theil_sen_fit(
            unix_times_sec=TIMES_THEIL_SEN_INPUT_UNIX_SEC,
            x_coords_metres=X_FOR_THEIL_SEN_INPUT_METRES,
            y_coords_metres=Y_FOR_THEIL_SEN_INPUT_METRES)

        this_x_coefficient_m_s01 = this_ts_model_for_x.coef_[0]
        this_y_coefficient_m_s01 = this_ts_model_for_y.coef_[0]

        self.assertTrue(
            numpy.absolute(this_x_coefficient_m_s01 -
                           X_COEFF_THEIL_SEN_M_S01) <= TOLERANCE)
        self.assertTrue(
            numpy.absolute(this_y_coefficient_m_s01 -
                           Y_COEFF_THEIL_SEN_M_S01) <= TOLERANCE)
    def test_break_ties_one_storm_track(self):
        """Ensures correct output from _break_ties_one_storm_track."""

        this_theil_sen_model_for_x, this_theil_sen_model_for_y = (
            best_tracks._theil_sen_fit(unix_times_sec=TIMES_IN_TIE_UNIX_SEC,
                                       x_coords_metres=X_COORDS_IN_TIE_METRES,
                                       y_coords_metres=Y_COORDS_IN_TIE_METRES))

        these_indices_to_remove = best_tracks._break_ties_one_storm_track(
            object_x_coords_metres=X_COORDS_IN_TIE_METRES,
            object_y_coords_metres=Y_COORDS_IN_TIE_METRES,
            object_times_unix_sec=TIMES_IN_TIE_UNIX_SEC,
            theil_sen_model_for_x=this_theil_sen_model_for_x,
            theil_sen_model_for_y=this_theil_sen_model_for_y)

        self.assertTrue(
            numpy.array_equal(these_indices_to_remove,
                              INDICES_TO_REMOVE_FROM_TIE))
    def test_theil_sen_predict(self):
        """Ensures correct output from _theil_sen_predict.

        This is an integration test, not a unit test, because it also requires
        _theil_sen_fit.
        """

        this_ts_model_for_x, this_ts_model_for_y = best_tracks._theil_sen_fit(
            unix_times_sec=TIMES_THEIL_SEN_INPUT_UNIX_SEC,
            x_coords_metres=X_FOR_THEIL_SEN_INPUT_METRES,
            y_coords_metres=Y_FOR_THEIL_SEN_INPUT_METRES)

        this_x_predicted_metres, this_y_predicted_metres = (
            best_tracks._theil_sen_predict(
                theil_sen_model_for_x=this_ts_model_for_x,
                theil_sen_model_for_y=this_ts_model_for_y,
                query_time_unix_sec=QUERY_TIME_THEIL_SEN_UNIX_SEC))

        self.assertTrue(
            numpy.absolute(this_x_predicted_metres -
                           X_PREDICTED_THEIL_SEN_METRES) <= TOLERANCE)
        self.assertTrue(
            numpy.absolute(this_y_predicted_metres -
                           Y_PREDICTED_THEIL_SEN_METRES) <= TOLERANCE)