Exemplo n.º 1
0
    def test_cartesianToSpherical(self):
        """
    Check correct working of the Cartesian to Spherical coordinates transformation.
    """
        r, phi, theta = cartesian_to_spherical(array([1, 0, 0]),
                                               array([0, 1, 0]),
                                               array([0, 0, 1]))
        assert_array_almost_equal(r, array([1.0, 1.0, 1.0]))
        assert_array_almost_equal(phi, array([0.0, pi / 2.0, 0.0]))
        assert_array_almost_equal(theta, array([0.0, 0.0, pi / 2.0]))

        r, phi, theta = cartesian_to_spherical(1.0, 1.0, 0.0)
        assert_almost_equal(r, sqrt(2.0))
        assert_almost_equal(phi, pi / 4.0)
        assert_almost_equal(theta, 0.0)

        r, phi, theta = cartesian_to_spherical(1.0, 1.0, 1.0)
        assert_almost_equal(r, sqrt(3.0))
        assert_almost_equal(phi, pi / 4.0)
        assert_almost_equal(theta, arcsin(1.0 / sqrt(3.0)))

        r, phi, theta = cartesian_to_spherical(1.0, 1.0, -1.0)
        assert_almost_equal(r, sqrt(3.0))
        assert_almost_equal(phi, pi / 4.0)
        assert_almost_equal(theta, -arcsin(1.0 / sqrt(3.0)))

        r, phi, theta = cartesian_to_spherical(-1.0, -1.0, -1.0)
        assert_almost_equal(r, sqrt(3.0))
        assert_almost_equal(phi, pi / 4.0 + pi)
        assert_almost_equal(theta, -arcsin(1.0 / sqrt(3.0)))

        assert_raises(Exception, cartesian_to_spherical, 0.0, 0.0, 0.0)
        assert_raises(Exception, cartesian_to_spherical, array([1, 0, 0, 0]),
                      array([0, 1, 0, 0]), array([0, 0, 0, 1]))
Exemplo n.º 2
0
    def test_icrsToEcliptic(self):
        """
        Verify correctness of transformations from the ICRS to Ecliptic coordinate systems.
        """
        ct = CoordinateTransformation(Transformations.ICRS2ECL)
        x, y, z = ct.transform_cartesian_coordinates(self.basisVectorXValues,
                                                     self.basisVectorYValues,
                                                     self.basisVectorZValues)
        assert_array_almost_equal(x,
                                  self.expectedMatEclipticToIcrs[:, 0],
                                  decimal=2)
        assert_array_almost_equal(y,
                                  self.expectedMatEclipticToIcrs[:, 1],
                                  decimal=2)
        assert_array_almost_equal(z,
                                  self.expectedMatEclipticToIcrs[:, 2],
                                  decimal=2)

        r, expectedLambda, expectedBeta = cartesian_to_spherical(
            self.expectedMatEclipticToIcrs[:, 0],
            self.expectedMatEclipticToIcrs[:, 1],
            self.expectedMatEclipticToIcrs[:, 2])
        lambdaEcl, betaEcl = ct.transform_sky_coordinates(
            array([0.0, pi / 2.0, 0.0]), array([0.0, 0.0, pi / 2.0]))
        assert_array_almost_equal(expectedLambda, lambdaEcl, decimal=1)
        assert_array_almost_equal(expectedBeta, betaEcl, decimal=1)

        alpha = 2.0 * pi * rand(100)
        delta = -pi / 2.0 + pi * rand(100)
        lambdaEcl, betaEcl = ct.transform_sky_coordinates(alpha, delta)
        result = 0.9175 * sin(delta) - 0.3978 * sin(alpha) * cos(delta)
        assert_array_almost_equal(result, sin(betaEcl), decimal=2)
Exemplo n.º 3
0
    def test_icrsToGalactic(self):
        """
        Verify correctness of transformations from the ICRS to Galactic coordinate systems.
        """
        ct = CoordinateTransformation(Transformations.ICRS2GAL)
        x, y, z = ct.transform_cartesian_coordinates(self.basisVectorXValues,
                                                     self.basisVectorYValues,
                                                     self.basisVectorZValues)
        assert_array_almost_equal(x,
                                  self.expectedMatIcrsToGal[0, :],
                                  decimal=2)
        assert_array_almost_equal(y,
                                  self.expectedMatIcrsToGal[1, :],
                                  decimal=2)
        assert_array_almost_equal(z,
                                  self.expectedMatIcrsToGal[2, :],
                                  decimal=2)

        r, expectedGalon, expectedGalat = cartesian_to_spherical(
            self.expectedMatIcrsToGal[0, :], self.expectedMatIcrsToGal[1, :],
            self.expectedMatIcrsToGal[2, :])
        galon, galat = ct.transform_sky_coordinates(
            array([0.0, pi / 2.0, 0.0]), array([0.0, 0.0, pi / 2.0]))
        assert_array_almost_equal(expectedGalon, galon, decimal=1)
        assert_array_almost_equal(expectedGalat, galat, decimal=1)
Exemplo n.º 4
0
    def test_galacticToIcrs(self):
        """
        Verify correctness of transformations from the Galactic to ICRS coordinate systems.
        """
        ct = CoordinateTransformation(Transformations.GAL2ICRS)
        x, y, z = ct.transform_cartesian_coordinates(self.basisVectorXValues,
                                                     self.basisVectorYValues,
                                                     self.basisVectorZValues)
        assert_array_almost_equal(x,
                                  self.expectedMatIcrsToGal[:, 0],
                                  decimal=2)
        assert_array_almost_equal(y,
                                  self.expectedMatIcrsToGal[:, 1],
                                  decimal=2)
        assert_array_almost_equal(z,
                                  self.expectedMatIcrsToGal[:, 2],
                                  decimal=2)

        r, expectedAlpha, expectedDelta = cartesian_to_spherical(
            self.expectedMatIcrsToGal[:, 0], self.expectedMatIcrsToGal[:, 1],
            self.expectedMatIcrsToGal[:, 2])
        alpha, delta = ct.transform_sky_coordinates(
            array([0.0, pi / 2.0, 0.0]), array([0.0, 0.0, pi / 2.0]))
        assert_array_almost_equal(expectedAlpha, alpha, decimal=1)
        assert_array_almost_equal(expectedDelta, delta, decimal=1)

        alpha, delta = ct.transform_sky_coordinates(0.0, pi / 2.0)
        assert_allclose(alpha / pi * 180, 192.9, atol=1.0)
        assert_allclose(delta / pi * 180, 27.1, atol=1.0)
Exemplo n.º 5
0
    def test_eclipticToIcrs(self):
        """
        Verify correctness of transformations from the Ecliptic to ICRS coordinate systems.
        """
        ct = CoordinateTransformation(Transformations.ECL2ICRS)
        x, y, z = ct.transform_cartesian_coordinates(self.basisVectorXValues,
                                                     self.basisVectorYValues,
                                                     self.basisVectorZValues)
        assert_array_almost_equal(x,
                                  self.expectedMatEclipticToIcrs[0, :],
                                  decimal=2)
        assert_array_almost_equal(y,
                                  self.expectedMatEclipticToIcrs[1, :],
                                  decimal=2)
        assert_array_almost_equal(z,
                                  self.expectedMatEclipticToIcrs[2, :],
                                  decimal=2)

        r, expectedAlpha, expectedDelta = cartesian_to_spherical(
            self.expectedMatEclipticToIcrs[0, :],
            self.expectedMatEclipticToIcrs[1, :],
            self.expectedMatEclipticToIcrs[2, :])
        alpha, delta = ct.transform_sky_coordinates(
            array([0.0, pi / 2.0, 0.0]), array([0.0, 0.0, pi / 2.0]))
        assert_array_almost_equal(expectedAlpha, alpha, decimal=1)
        assert_array_almost_equal(expectedDelta, delta, decimal=1)

        lambdaEcl = 2.0 * pi * rand(100)
        betaEcl = -pi / 2.0 + pi * rand(100)
        alpha, delta = ct.transform_sky_coordinates(lambdaEcl, betaEcl)
        result = 0.9175 * sin(betaEcl) + 0.3978 * sin(lambdaEcl) * cos(betaEcl)
        assert_array_almost_equal(result, sin(delta), decimal=2)
Exemplo n.º 6
0
    def test_galacticToEcliptic(self):
        """
        Verify correctness of transformations from the Galactic to Ecliptic coordinate systems.
        """
        ct = CoordinateTransformation(Transformations.GAL2ECL)
        x, y, z = ct.transform_cartesian_coordinates(self.basisVectorXValues, self.basisVectorYValues,
                                                     self.basisVectorZValues)
        assert_array_almost_equal(x, self.expectedMatGalacticToEcliptic[0, :], decimal=2)
        assert_array_almost_equal(y, self.expectedMatGalacticToEcliptic[1, :], decimal=2)
        assert_array_almost_equal(z, self.expectedMatGalacticToEcliptic[2, :], decimal=2)

        r, expectedLambda, expectedBeta = cartesian_to_spherical(self.expectedMatGalacticToEcliptic[0, :],
                                                                 self.expectedMatGalacticToEcliptic[1, :],
                                                                 self.expectedMatGalacticToEcliptic[2, :])
        lambdaEcl, betaEcl = ct.transform_sky_coordinates(array([0.0, pi / 2.0, 0.0]), array([0.0, 0.0, pi / 2.0]))
        #
        # Note the abs() in the line below is required to avoid an error when -pi and pi are compared.
        # The better solution of course is to write an assert function that can handle modulo 2*pi cases.
        #
        assert_array_almost_equal(abs(expectedLambda), abs(lambdaEcl), decimal=1)
        assert_array_almost_equal(expectedBeta, betaEcl, decimal=1)

        galon = 2.0 * pi * rand(100)
        galat = -pi / 2.0 + pi * rand(100)
        lambdaEcl, betaEcl = ct.transform_sky_coordinates(galon, galat)
        phi = 6.38 / 180.0 * pi
        result = 0.4971 * sin(galat) + 0.8677 * sin(galon - phi) * cos(galat)
        assert_array_almost_equal(result, sin(betaEcl), decimal=2)