def testWeights(self):
        " a bit more than just numpy.interp wrapper, re-used weights..."
        dima = self.dima
        newindex = self.newindex

        dima2d = dima.newaxis('bla', pos=1)

        dima_s = dima.sort_axis()
        expected = np.interp(newindex, dima_s.x0, dima_s.values)  # np.interp, pure numpy
        actual = dima2d.interp_axis(newindex).squeeze().values  # self-computed weights using np.interp

        _assert_allclose(actual, expected)
    def testVsNumpy(self):
        dima = self.dima
        newindex = self.newindex

        dima_sorted = dima.sort_axis()

        expected = np.interp(newindex, dima_sorted.x0, dima_sorted.values)  # np.interp, pure numpy

        actual = dima_sorted.interp_axis(newindex, issorted=True)
        _assert_allclose(actual.values, expected) 
        _assert_allclose(actual.axes[0], newindex) 

        actual = dima.interp_axis(newindex) # additional-presorting
        _assert_allclose(actual.values, expected) 
        _assert_allclose(actual.axes[0], newindex) 
Beispiel #3
0
    def test_compute_delta_L_in_moving_frame_east():
        wgs84 = FrameE(name='WGS84')
        point_a = wgs84.GeoPoint(latitude=1, longitude=2, z=0, degrees=True)
        point_b = wgs84.GeoPoint(latitude=1,
                                 longitude=2.005,
                                 z=0,
                                 degrees=True)
        sensor_position = wgs84.GeoPoint(latitude=1.000090437,
                                         longitude=2.0025,
                                         z=0,
                                         degrees=True)
        path = GeoPath(point_a, point_b)
        ti = np.linspace(0, 1.0, 8)
        ship_positions0 = path.interpolate(ti[:-1])
        ship_positions1 = path.interpolate(ti[1:])
        headings = ship_positions0.delta_to(ship_positions1).azimuth_deg
        assert_allclose(headings, 90, rtol=1e-4)  # , decimal=4)

        ship_positions = path.interpolate(ti)

        delta = delta_L(ship_positions,
                        sensor_position,
                        wander_azimuth=np.pi / 2)

        x, y, z = delta.pvector
        azimuth = np.round(delta.azimuth_deg)
        # positive angle about down-axis

        true_x = [
            278.2566243359911, 198.7547317612817, 119.25283909376164,
            39.750946370747656, -39.75094637085409, -119.25283909387079,
            -198.75473176137066, -278.2566243360949
        ]
        assert_allclose(x, true_x)  # decimal=3)
        assert_allclose(y, -10, rtol=1e-3)  # decimal=3)
        assert_allclose(azimuth,
                        [-2., -3., -5., -14., -166., -175., -177., -178.])
        _assert_allclose(z, 0, atol=1e-2)  # decimal=2)
Beispiel #4
0
    def test_compute_delta_N_in_moving_frame_east():
        wgs84 = FrameE(name='WGS84')
        point_a = wgs84.GeoPoint(latitude=1, longitude=2, z=0, degrees=True)
        point_b = wgs84.GeoPoint(latitude=1,
                                 longitude=2.005,
                                 z=0,
                                 degrees=True)
        sensor_position = wgs84.GeoPoint(latitude=1.0,
                                         longitude=2.0025,
                                         z=0,
                                         degrees=True)
        path = GeoPath(point_a, point_b)
        ti = np.linspace(0, 1.0, 8)
        ship_positions0 = path.interpolate(ti[:-1])
        ship_positions1 = path.interpolate(ti[1:])
        headings = ship_positions0.delta_to(ship_positions1).azimuth_deg
        assert_allclose(headings, 90, rtol=1e-4)  # , decimal=4)

        ship_positions = path.interpolate(ti)

        delta = ship_positions.delta_to(sensor_position)

        x, y, z = delta.pvector
        azimuth = np.round(delta.azimuth_deg)
        # positive angle about down-axis

        true_y = [
            278.2566243359911, 198.7547317612817, 119.25283909376164,
            39.750946370747656, -39.75094637085409, -119.25283909387079,
            -198.75473176137066, -278.2566243360949
        ]
        _assert_allclose(x, 0, atol=1e-3)  # decimal=3)
        assert_allclose(y, true_y)
        _assert_allclose(z, 0, atol=1e-2)  # , decimal=2)
        n2 = len(azimuth) // 2
        assert_allclose(azimuth[:n2], 90)
        assert_allclose(azimuth[n2:], -90)
Beispiel #5
0
    def test_compute_delta_L_in_moving_frame_north():
        wgs84 = FrameE(name='WGS84')
        point_a = wgs84.GeoPoint(latitude=1, longitude=2, z=0, degrees=True)
        point_b = wgs84.GeoPoint(latitude=1.005,
                                 longitude=2.0,
                                 z=0,
                                 degrees=True)
        sensor_position = wgs84.GeoPoint(latitude=1.0025,
                                         longitude=2.0,
                                         z=0,
                                         degrees=True)
        path = GeoPath(point_a, point_b)
        ti = np.linspace(0, 1.0, 8)
        ship_positions0 = path.interpolate(ti[:-1])
        ship_positions1 = path.interpolate(ti[1:])
        headings = ship_positions0.delta_to(ship_positions1).azimuth_deg
        _assert_allclose(headings, 0, atol=1e-8)  # , decimal=8)

        ship_positions = path.interpolate(ti)

        delta0 = delta_L(ship_positions, sensor_position, wander_azimuth=0)
        delta = ship_positions.delta_to(sensor_position)
        assert_allclose(delta0.pvector, delta.pvector)

        x, y, z = delta.pvector
        azimuth = np.round(np.abs(delta.azimuth_deg))
        # positive angle about down-axis

        true_x = [
            276.436537069603, 197.45466985931083, 118.47280221160541,
            39.49093416312986, -39.490934249581684, -118.47280298990226,
            -197.454672021303, -276.4365413071498
        ]
        assert_allclose(x, true_x)
        _assert_allclose(y, 0, atol=1e-8)  # , decimal=8)
        _assert_allclose(z, 0, atol=1e-2)  # , decimal=2)
        n2 = len(azimuth) // 2
        assert_allclose(azimuth[:n2], 0)
        assert_allclose(azimuth[n2:], 180)
Beispiel #6
0
            plane = (((-norm_to_plane[0] * (self._X - X2.mean())) -
                       (norm_to_plane[1] * (self._Y - Y2.mean()))) / norm_to_plane[2]) + Z2.mean()

            if self.lims_to_plane:
                if self.use_above is not None:
                    plane[plane < self.use_above] = self.use_above
                if self.use_below is not None:
                    plane[plane > self.use_below] = self.use_below
            if not self.copy:
                A[:, t] = plane
            else:
                A2[:, t] = plane
        if self.copy:
            return A2
        else:
            return A

if __name__ == '__main__':  # pragma: no cover
    A = _np.array([[1, 2, 3, 4], [4, 5, 6, 7], [7, 8, 9, 10]]).astype(_np.float)
    A_transform = _np.array([[1, 2, 3, 4], [4, 0, 0, 0], [0, 0, 0, 0]]).astype(_np.float)

    constr = ConstraintCutAbove(copy=True, value=4)
    out = constr.transform(A)

    from numpy.testing import assert_allclose as _assert_allclose
    _assert_allclose(out, A_transform)

    # No Copy
    # constr = ConstraintCutAbove(copy=False, value=4)
    # out = constr.transform(A)
    # assert_allclose(A, A_transform)
def assert_allclose(x, y, *args, **kwargs):
    _assert_allclose(x, y)
    if isinstance(x, da.DimArray) and isinstance(y, da.DimArray):
        for ax1, ax2 in zip(x.axes, y.axes):
            #assert assert_equal(ax1, ax2)
            assert ax1 == ax2
Beispiel #8
0
    def test_distance_and_azimuth(self):
        wgs84 = FrameE(name='WGS84')
        point1 = wgs84.GeoPoint(latitude=-30, longitude=0, degrees=True)
        point2 = wgs84.GeoPoint(latitude=29.9, longitude=179.8, degrees=True)
        s_12, azi1, azi2 = point1.distance_and_azimuth(point2)
        n_a = point1.to_nvector()
        n_b = point2.to_nvector()
        s_ab, azia, azib = nv.geodesic_distance(n_a.normal, n_b.normal,
                                                wgs84.a, wgs84.f)
        assert_allclose(s_12, 19989832.82761)

        point1 = wgs84.GeoPoint(latitude=0, longitude=0, degrees=True)
        point2 = wgs84.GeoPoint(latitude=0.5, longitude=179.5, degrees=True)
        s_12, azi1, azi2 = point1.distance_and_azimuth(point2)
        assert_allclose(s_12, 19936288.578965)
        n_a = point1.to_nvector()
        n_b = point2.to_nvector()
        s_ab, azia, azib = nv.geodesic_distance(n_a.normal, n_b.normal,
                                                wgs84.a, wgs84.f)
        assert_allclose(s_ab, 19936288.578965)

        point1 = wgs84.GeoPoint(latitude=88, longitude=0, degrees=True)
        point2 = wgs84.GeoPoint(latitude=89, longitude=-170, degrees=True)
        s_12, azi1, azi2 = point1.distance_and_azimuth(point2)
        assert_allclose(s_12, 333947.509468)

        n_a = point1.to_nvector()
        n_b = point2.to_nvector()

        s_ab, azia, azib = nv.geodesic_distance(n_a.normal, n_b.normal,
                                                wgs84.a, wgs84.f)
        #         n_EA_E = nv.lat_lon2n_E(0,0)
        #         n_EB_E = nv.lat_lon2n_E(*nv.rad(0.5, 179.5))
        #         np.allclose(nv.geodesic_distance(n_EA_E, n_EB_E), 19909099.44101977)

        assert_allclose(nv.deg(azi1, azi2),
                        (-3.3309161604062467, -173.327884597742))

        p3, azib = point1.displace(s_12, azi1)
        assert_allclose(nv.deg(azib), -173.327884597742)
        assert_allclose(p3.latlon_deg, (89, -170, 0))

        p4, azia = point2.displace(s_12, azi2 + np.pi)
        assert_allclose(nv.deg(azia), -3.3309161604062467 + 180)

        truth = (88, 0, 0)
        assert_allclose(p4.latlon_deg, truth, atol=1e-12)  # pylint: disable=redundant-keyword-arg

        # ------ greatcircle --------
        s_12, azi1, azi2 = point1.distance_and_azimuth(point2,
                                                       method='greatcircle')
        assert_allclose(s_12, 331713.817039)
        assert_allclose(nv.deg(azi1, azi2), (-3.330916, -173.327885))

        p3, azib = point1.displace(s_12, azi1, method='greatcircle')
        assert_allclose(nv.deg(azib), -173.32784)
        assert_allclose(p3.latlon_deg, (89.000005, -169.999949, 0))

        p4, azia = point2.displace(s_12, azi2 + np.pi, method='greatcircle')
        _assert_allclose(p4.latlon_deg, truth,
                         atol=1e-4)  # Less than 0.4 meters
        assert_allclose(nv.deg(azia), -3.3309161604062467 + 180)