Esempio n. 1
0
    def test_galacticToEcliptic(self):
        """
        Verify correctness of transformations from the Galactic to Ecliptic coordinate systems.
        """
        ct=CoordinateTransformation(Transformations.GAL2ECL)
        x, y, z = ct.transformCartesianCoordinates(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 = cartesianToSpherical(self.expectedMatGalacticToEcliptic[0,:],
                self.expectedMatGalacticToEcliptic[1,:], self.expectedMatGalacticToEcliptic[2,:])
        lambdaEcl, betaEcl = ct.transformSkyCoordinates(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.transformSkyCoordinates(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)
Esempio n. 2
0
def ProperMotionError__ICRS_to_GAL(phi, theta, sigMuPhiStar, sigMuTheta,
                                   rhoMuPhiMuTheta):
    """
        ----------
        phi             - The longitude-like angle of the position of the source (radians).
        theta           - The latitude-like angle of the position of the source (radians).
        sigMuPhiStar    - Standard error in the proper motion in the longitude-like direction (including cos(latitude) factor).
        sigMuTheta      - Standard error in the proper motion in the latitude-like direction.
        
        Keywords (optional)
        -------------------
        rhoMuPhiMuTheta - Correlation coefficient of the proper motion errors. Set to zero if this keyword is not provided.
        
        Retuns
        ------
        sigMuPhiRotStar    - The transformed standard error in the proper motion in the longitude direction
        (including cos(latitude) factor).
        sigMuThetaRot      - The transformed standard error in the proper motion in the longitude direction.
        rhoMuPhiMuThetaRot - The transformed correlation coefficient.
        """
    # transformation ICRS to GAL
    ctICRS2GAL = CoordinateTransformation(Transformations.ICRS2GAL)
    #
    sigMuPhiRotStar, sigMuThetaRot, rhoMuPhiMuThetaRot = ctICRS2GAL.transformProperMotionErrors(
        phi, theta, sigMuPhiStar, sigMuTheta, rhoMuPhiMuTheta)

    return sigMuPhiRotStar, sigMuThetaRot, rhoMuPhiMuThetaRot
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
    def test_transformProperMotions(self):
        """
        Verify the correct implementation of the direct transformation of proper motions.
        """
        ct = CoordinateTransformation(Transformations.ICRS2GAL)
        nTests = 100
        phi = 2.0*pi*rand(nTests)
        theta = -pi/2.0+pi*rand(nTests)
        parallax = rand(nTests)*99.0+1.0
        muphistar = -30.0+60.0*rand(nTests)
        mutheta = -30.0+60.0*rand(nTests)
        vrad = -200.0+400.0*rand(nTests)

        x,y,z,vx,vy,vz = astrometryToPhaseSpace(phi,theta,parallax,muphistar,mutheta,vrad)
        xrot, yrot, zrot = ct.transformCartesianCoordinates(x,y,z)
        vxrot, vyrot, vzrot = ct.transformCartesianCoordinates(vx,vy,vz)
        phiRot, thetaRot, parRot, muphistarRotExpected, muthetaRotExpected, vradRot = \
                phaseSpaceToAstrometry(xrot, yrot, zrot, vxrot, vyrot, vzrot)

        muphistarRot, muthetaRot = ct.transformProperMotions(phi, theta, muphistar, mutheta)

        assert_array_almost_equal(muphistarRotExpected, muphistarRot, decimal=2)
        assert_array_almost_equal(muthetaRotExpected, muthetaRot, decimal=2)

        #
        # Test scalar version of method.
        #
        for i in range(nTests):
            muphistarRot, muthetaRot = ct.transformProperMotions(phi[i], theta[i], muphistar[i], mutheta[i])
            assert_almost_equal(muphistarRotExpected[i], muphistarRot, decimal=2)
            assert_almost_equal(muthetaRotExpected[i], muthetaRot, decimal=2)
Esempio n. 8
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)
Esempio n. 9
0
    def test_icrsToGalactic(self):
        """
        Verify correctness of transformations from the ICRS to Galactic coordinate systems.
        """
        ct=CoordinateTransformation(Transformations.ICRS2GAL)
        x, y, z = ct.transformCartesianCoordinates(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 = cartesianToSpherical(self.expectedMatIcrsToGal[0,:],
                self.expectedMatIcrsToGal[1,:], self.expectedMatIcrsToGal[2,:])
        galon, galat = ct.transformSkyCoordinates(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)
Esempio n. 10
0
def GAL_to_ICRS(phi, theta, muphistar, mutheta):
    """
        phi       - The longitude-like angle of the position of the source (radians).
        theta     - The latitude-like angle of the position of the source (radians).
        muphistar - Value of the proper motion in the longitude-like angle, multiplied by cos(latitude).
        mutheta   - Value of the proper motion in the latitude-like angle.
        """
    # transformation ICRS to GAL
    ctGAL2ICRS = CoordinateTransformation(Transformations.GAL2ICRS)
    #
    ra, dec = ctGAL2ICRS.transformSkyCoordinates(phi, theta)
    murastar, mudec = ctGAL2ICRS.transformProperMotions(
        phi, theta, muphistar, mutheta)

    return ra, dec, murastar, mudec
Esempio n. 11
0
def ICRS_to_GAL(phi, theta, muphistar, mutheta):
    """
        phi       - The longitude-like angle of the position of the source (radians).
        theta     - The latitude-like angle of the position of the source (radians).
        muphistar - Value of the proper motion in the longitude-like angle, multiplied by cos(latitude).
        mutheta   - Value of the proper motion in the latitude-like angle.
        """
    # transformation ICRS to GAL
    ctICRS2GAL = CoordinateTransformation(Transformations.ICRS2GAL)
    #
    ell, bee = ctICRS2GAL.transformSkyCoordinates(phi, theta)
    muellstar, mubee = ctICRS2GAL.transformProperMotions(
        phi, theta, muphistar, mutheta)

    return ell, bee, muellstar, mubee
Esempio n. 12
0
  def test_eclipticToGalactic(self):
    """
    Verify correctness of transformations from the Ecliptic to Galactic coordinate systems.
    """
    ct=CoordinateTransformation(Transformations.ECL2GAL)
    x, y, z = ct.transformCartesianCoordinates(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, expectedGalon, expectedGalat = cartesianToSpherical(self.expectedMatGalacticToEcliptic[:,0],
        self.expectedMatGalacticToEcliptic[:,1], self.expectedMatGalacticToEcliptic[:,2])
    galon, galat = ct.transformSkyCoordinates(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)
Esempio n. 13
0
    def test_galacticToIcrs(self):
        """
        Verify correctness of transformations from the Galactic to ICRS coordinate systems.
        """
        ct = CoordinateTransformation(Transformations.GAL2ICRS)
        x, y, z = ct.transformCartesianCoordinates(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 = cartesianToSpherical(self.expectedMatIcrsToGal[:,0],
                self.expectedMatIcrsToGal[:,1], self.expectedMatIcrsToGal[:,2])
        alpha, delta = ct.transformSkyCoordinates(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.transformSkyCoordinates(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)
Esempio n. 14
0
    def test_eclipticToIcrs(self):
        """
        Verify correctness of transformations from the Ecliptic to ICRS coordinate systems.
        """
        ct=CoordinateTransformation(Transformations.ECL2ICRS)
        x, y, z = ct.transformCartesianCoordinates(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 = cartesianToSpherical(self.expectedMatEclipticToIcrs[0,:],
                self.expectedMatEclipticToIcrs[1,:], self.expectedMatEclipticToIcrs[2,:])
        alpha, delta = ct.transformSkyCoordinates(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.transformSkyCoordinates(lambdaEcl, betaEcl)
        result = 0.9175*sin(betaEcl)+0.3978*sin(lambdaEcl)*cos(betaEcl)
        assert_array_almost_equal(result, sin(delta), decimal=2)
Esempio n. 15
0
    def test_icrsToEcliptic(self):
        """
        Verify correctness of transformations from the ICRS to Ecliptic coordinate systems.
        """
        ct=CoordinateTransformation(Transformations.ICRS2ECL)
        x, y, z = ct.transformCartesianCoordinates(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 = cartesianToSpherical(self.expectedMatEclipticToIcrs[:,0],
                self.expectedMatEclipticToIcrs[:,1], self.expectedMatEclipticToIcrs[:,2])
        lambdaEcl, betaEcl = ct.transformSkyCoordinates(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.transformSkyCoordinates(alpha, delta)
        result = 0.9175*sin(delta)-0.3978*sin(alpha)*cos(delta)
        assert_array_almost_equal(result, sin(betaEcl), decimal=2)
Esempio n. 16
0
    def test_transformProperMotions(self):
        """
        Verify the correct implementation of the direct transformation of proper motions.
        """
        ct = CoordinateTransformation(Transformations.ICRS2GAL)
        nTests = 100
        phi = 2.0 * pi * rand(nTests)
        theta = -pi / 2.0 + pi * rand(nTests)
        parallax = rand(nTests) * 99.0 + 1.0
        muphistar = -30.0 + 60.0 * rand(nTests)
        mutheta = -30.0 + 60.0 * rand(nTests)
        vrad = -200.0 + 400.0 * rand(nTests)

        x, y, z, vx, vy, vz = astrometry_to_phase_space(phi, theta, parallax, muphistar, mutheta, vrad)
        xrot, yrot, zrot = ct.transform_cartesian_coordinates(x, y, z)
        vxrot, vyrot, vzrot = ct.transform_cartesian_coordinates(vx, vy, vz)
        phiRot, thetaRot, parRot, muphistarRotExpected, muthetaRotExpected, vradRot = \
            phase_space_to_astrometry(xrot, yrot, zrot, vxrot, vyrot, vzrot)

        muphistarRot, muthetaRot = ct.transform_proper_motions(phi, theta, muphistar, mutheta)

        assert_array_almost_equal(muphistarRotExpected, muphistarRot, decimal=2)
        assert_array_almost_equal(muthetaRotExpected, muthetaRot, decimal=2)

        #
        # Test scalar version of method.
        #
        for i in range(nTests):
            muphistarRot, muthetaRot = ct.transform_proper_motions(phi[i], theta[i], muphistar[i], mutheta[i])
            assert_almost_equal(muphistarRotExpected[i], muphistarRot, decimal=2)
            assert_almost_equal(muthetaRotExpected[i], muthetaRot, decimal=2)
Esempio n. 17
0
    def test_transformProperMotionErrors(self):
        """
        Verify that the transformed covariance matrix for the proper motions remains a covariance matrix.
        """
        ct = CoordinateTransformation(Transformations.ICRS2GAL)
        nTests = 100
        phi = 2.0*pi*rand(nTests)
        theta = -pi/2.0+pi*rand(nTests)
        sigPhiStar, sigTheta, rhoPhiTheta = self._generateRandomCovarianceMatrices(nTests)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transformProperMotionErrors(phi, theta, sigPhiStar,
                sigTheta, rhoMuPhiMuTheta=rhoPhiTheta)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1<=rhoPhiTheta[i] and rhoPhiTheta[i]<=1)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transformProperMotionErrors(phi, theta, sigPhiStar, sigTheta)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1<=rhoPhiTheta[i] and rhoPhiTheta[i]<=1)
Esempio n. 18
0
    def test_transformProperMotionErrors(self):
        """
        Verify that the transformed covariance matrix for the proper motions remains a covariance matrix.
        """
        ct = CoordinateTransformation(Transformations.ICRS2GAL)
        nTests = 100
        phi = 2.0 * pi * rand(nTests)
        theta = -pi / 2.0 + pi * rand(nTests)
        sigPhiStar, sigTheta, rhoPhiTheta = self._generateRandomCovarianceMatrices(nTests)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transform_proper_motion_errors(phi, theta, sigPhiStar,
                                                                                       sigTheta,
                                                                                       rho_muphi_mutheta=rhoPhiTheta)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1 <= rhoPhiTheta[i] <= 1)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transform_proper_motion_errors(phi, theta, sigPhiStar, sigTheta)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1 <= rhoPhiTheta[i] <= 1)
Esempio n. 19
0
    def test_transformSkyCoordinateErrors(self):
        """
        Verify that the transformed covariance matrix for the positions remains a covariance matrix.
        """
        ct = CoordinateTransformation(Transformations.ICRS2GAL)
        nTests = 100
        phi = 2.0 * pi * rand(nTests)
        theta = -pi / 2.0 + pi * rand(nTests)
        sigPhiStar, sigTheta, rhoPhiTheta = self._generateRandomCovarianceMatrices(
            nTests)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transform_sky_coordinate_errors(
            phi, theta, sigPhiStar, sigTheta, rho_phi_theta=rhoPhiTheta)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1 <= rhoPhiThetaRot[i] and rhoPhiThetaRot[i] <= 1)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transform_sky_coordinate_errors(
            phi, theta, sigPhiStar, sigTheta)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1 <= rhoPhiThetaRot[i] and rhoPhiThetaRot[i] <= 1)

        sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transform_sky_coordinate_errors(
            phi, theta, sigPhiStar, sigTheta, rho_phi_theta=0.7)
        for i in range(nTests):
            self.assertGreater(sigPhiStarRot[i], 0.0)
            self.assertGreater(sigThetaRot[i], 0.0)
            self.assertTrue(-1 <= rhoPhiThetaRot[i] and rhoPhiThetaRot[i] <= 1)

        for i in range(nTests):
            sigPhiStarRot, sigThetaRot, rhoPhiThetaRot = ct.transform_sky_coordinate_errors(
                phi[i],
                theta[i],
                sigPhiStar[i],
                sigTheta[i],
                rho_phi_theta=0.7)
            self.assertGreater(sigPhiStarRot, 0.0)
            self.assertGreater(sigThetaRot, 0.0)
            self.assertTrue(-1 <= rhoPhiThetaRot and rhoPhiThetaRot <= 1)
Esempio n. 20
0
def plot_coordinate_transformation_on_sky(
        transformation,
        outfile=None,
        no_title=False,
        no_labels=False,
        return_plot_object=False,
        lc=plt.cm.get_cmap('tab10').colors[0],
        tc=plt.cm.get_cmap('tab10').colors[1],
        lonpos=True):
    """
    Produce a sky-plot in a given coordinate system with the meridians and paralles for another
    coordinate system overlayed. The coordinate systems are specified through the
    pygaia.coordinates.Transformations enum. For example for Transformations.GAL2ECL the sky plot will be
    in Ecliptic coordinates with the Galactic coordinate grid overlayed.

    Keywords
    --------

    transformation - The coordinate transformation for which to make the plot (e.g.,
                     Transformations.GAL2ECL).
    outfile        - Save plot to this output file (default is to plot on screen). Make sure an extension
                     (.pdf, .png, etc) is included.
    noTitle        - If true do not include the plot title.
    noLabels       - If true do not include plot labels.
    returnPlotObject - If true return the matplotlib object used for plotting. Further plot elements can
                       then be added.
    lc             - Colour for gridlines.
    tc             - Colour for text labels.
    lonpos         - If true use longitude labels between 0 and 360 degrees.
    """
    ct = CoordinateTransformation(transformation)

    parallels = np.arange(-80.0, 90.0, 10.0)
    meridians = np.arange(0.0, 375.0, 15.0)
    meridian_max = np.deg2rad(85.0)

    default_proj = ccrs.PlateCarree()
    addtolabel = 0
    if lonpos:
        addtolabel = 360

    fig = plt.figure(figsize=(12, 6))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mollweide())
    ax.invert_xaxis()

    for thetaDeg in parallels:
        phi = np.linspace(-np.pi, np.pi, 1001)
        theta = np.zeros_like(phi) + np.deg2rad(thetaDeg)
        phirot, thetarot = ct.transform_sky_coordinates(phi, theta)
        phirot[(phirot > np.pi)] = phirot[(phirot > np.pi)] - 2 * np.pi
        x, y = np.rad2deg(phirot), np.rad2deg(thetarot)

        indices = (phirot >= 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = order_points_for_sky_plot(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=default_proj)

        indices = (phirot < 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = order_points_for_sky_plot(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=default_proj)

    for phiDeg in meridians:
        theta = np.linspace(-meridian_max, meridian_max, 1001)
        phi = np.zeros_like(theta) + np.deg2rad(phiDeg)
        phirot, thetarot = ct.transform_sky_coordinates(phi, theta)
        phirot[(phirot > np.pi)] = phirot[(phirot > np.pi)] - 2 * np.pi
        x, y = np.rad2deg(phirot), np.rad2deg(thetarot)

        indices = (phirot >= 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = order_points_for_sky_plot(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=default_proj)

        indices = (phirot < 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = order_points_for_sky_plot(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=default_proj)

    if not no_title:
        plt.title("Sky projection in " + ct.transformationStrings[1] +
                  " coordinates with the corresponding " +
                  ct.transformationStrings[0] + " grid overlayed")

    if not no_labels:
        for theta in np.arange(-60, 90, 30):
            phirot, thetarot = ct.transform_sky_coordinates(
                0.0, np.deg2rad(theta))
            x, y = (np.rad2deg(phirot), np.rad2deg(thetarot))
            ax.text(x,
                    y,
                    "${0}$".format(theta),
                    fontsize=16,
                    va='bottom',
                    ha='center',
                    color=tc,
                    transform=default_proj)
        for phi in np.arange(-150, 0, 30):
            phirot, thetarot = ct.transform_sky_coordinates(
                np.deg2rad(phi), 0.0)
            x, y = (np.rad2deg(phirot), np.rad2deg(thetarot))
            ax.text(x,
                    y,
                    "${0}$".format(phi + addtolabel),
                    fontsize=16,
                    va='bottom',
                    ha='center',
                    color=tc,
                    transform=default_proj)
        for phi in np.arange(30, 210, 30):
            phirot, thetarot = ct.transform_sky_coordinates(
                np.deg2rad(phi), 0.0)
            x, y = (np.rad2deg(phirot), np.rad2deg(thetarot))
            ax.text(x,
                    y,
                    "${0}$".format(phi),
                    fontsize=16,
                    va='bottom',
                    ha='center',
                    color=tc,
                    transform=default_proj)

    if outfile is not None:
        plt.savefig(outfile)
    elif return_plot_object:
        return plt.gca()
    else:
        plt.show()
Esempio n. 21
0
def init(args):
    """
    Initialize the arrays of (l,b) values for the star trails, the background image, and other configuration variables.

    Parameters
    ----------

    args: array-like
        Command line arguments

    Returns
    -------

    Dictionary with the requested configuration. The l and b coordinates per source and per epoch for the animation
    frames and the end frame, the array for scaling the brightness of the stars and star trails, the background image,
    maximum number of epochs to plot, the image DPI, the folder in which to store the images, and the sky projection
    information.

    Example:
    config = init(args)
    """
    infile = args['inputFile']
    delta_epoch = args['exposure'] * 1.0e+5
    delta_epoch_endframe = args['exposure_endframe'] * 1.0e+5
    n_epochs = args['num_epochs']
    n_epochs_endframe = args['num_epochs_endframe']
    t0 = 2016.0
    epp = EpochPropagation()
    epochs = np.linspace(t0, t0 + delta_epoch, n_epochs)
    epochs_endframe = np.linspace(t0, t0 + delta_epoch_endframe,
                                  n_epochs_endframe)
    max_trail_epochs = args['max_trail_epochs']
    if args['highres']:
        fdpi = 240
        dr2sky = plt.imread('./sky-images/GaiaSky-colour-4k.png')
        imfolder = "images-4k"
    else:
        fdpi = 120
        dr2sky = plt.imread('./sky-images/GaiaSky-colour-2k.png')
        imfolder = "images-2k"

    data = Table.read('./data/' + infile, format='fits')

    nsample = args['nstars_max']
    print(
        f"A random selection of {nsample} out of {data['ra'].size} stars will be plotted"
    )

    rng = np.random.default_rng(args['rngseed'])
    raninds = rng.choice(np.arange(data['ra'].size), nsample)

    ra0 = np.deg2rad(data['ra'][raninds])
    dec0 = np.deg2rad(data['dec'][raninds])
    plx0 = data['parallax'][raninds]
    pmra0 = data['pmra'][raninds]
    pmdec0 = data['pmdec'][raninds]
    vrad0 = data['dr2_radial_velocity'][raninds]
    mag = data['phot_g_mean_mag'][raninds]

    ct = CoordinateTransformation(Transformations.ICRS2GAL)

    l1 = np.zeros((nsample, n_epochs))
    b1 = np.zeros((nsample, n_epochs))
    l1ef = np.zeros((nsample, n_epochs_endframe))
    b1ef = np.zeros((nsample, n_epochs_endframe))

    for i, t1 in zip(range(n_epochs), epochs):
        ra1, dec1 = epp.propagate_pos(ra0, dec0, plx0, pmra0, pmdec0, vrad0,
                                      t0, t1)
        l1[:, i], b1[:, i] = ct.transform_sky_coordinates(ra1, dec1)
    l1 = np.rad2deg(l1)
    b1 = np.rad2deg(b1)

    for i, t1 in zip(range(n_epochs_endframe), epochs_endframe):
        ra1, dec1 = epp.propagate_pos(ra0, dec0, plx0, pmra0, pmdec0, vrad0,
                                      t0, t1)
        l1ef[:, i], b1ef[:, i] = ct.transform_sky_coordinates(ra1, dec1)
    l1ef = np.rad2deg(l1ef)
    b1ef = np.rad2deg(b1ef)

    magrange = mag.max() - mag.min()
    magscaling_stars = 0.2 + 0.8 * (mag.max() - mag) / magrange
    min_alpha = 0.1
    magscaling_trails = min_alpha + (args['max_alpha'] -
                                     min_alpha) * (mag.max() - mag) / magrange

    return {
        'l1': l1,
        'b1': b1,
        'l1ef': l1ef,
        'b1ef': b1ef,
        'magscaling_stars': magscaling_stars,
        'magscaling_trails': magscaling_trails,
        'backgr': dr2sky,
        'max_trail_epochs': max_trail_epochs,
        'dpi': fdpi,
        'imfolder': imfolder,
        'default_projection': ccrs.PlateCarree(),
        'sky_projection': ccrs.Mollweide()
    }
Esempio n. 22
0
def plotCoordinateTransformationOnSky(transformation,
                                      outfile=None,
                                      myProjection='hammer',
                                      noTitle=False,
                                      noLabels=False,
                                      returnPlotObject=False):
    """
    Produce a sky-plot in a given coordinate system with the meridians and paralles for another
    coordinate system overlayed. The coordinate systems are specified through the
    pygaia.coordinates.Transformations enum. For example for Transformations.GAL2ECL the sky plot will be
    in Ecliptic coordinates with the Galactic coordinate grid overlayed.

    Keywords
    --------

    transformation - The coordinate transformation for which to make the plot (e.g.,
                     Transformations.GAL2ECL)
    outfile        - Save plot to this output file (default is to plot on screen). Make sure an extension
                     (.pdf, .png, etc) is included.
    myProjection   - Use this map projection (default is 'hammer', see basemap documentation)
    noTitle        - If true do not include the plot title.
    noLabels       - If true do not include plot labels.
    returnPlotObject - If true return the matplotlib object used for plotting. Further plot elements can
                       then be added.
    """
    ct = CoordinateTransformation(transformation)

    parallels = arange(-80.0, 90.0, 10.0)
    meridians = arange(0.0, 375.0, 15.0)
    meridianMax = degreesToRadians(85.0)
    parallelsMax = degreesToRadians(179.0)

    fig = plt.figure(figsize=(12, 6))
    basemapInstance = Basemap(projection=myProjection, lon_0=0, celestial=True)
    basemapInstance.drawmapboundary()

    for thetaDeg in parallels:
        phi = linspace(-pi, pi, 1001)
        theta = zeros_like(phi) + degreesToRadians(thetaDeg)
        phirot, thetarot = ct.transformSkyCoordinates(phi, theta)
        x, y = basemapInstance(radiansToDegrees(phirot),
                               radiansToDegrees(thetarot))

        indices = (phirot >= 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        plt.plot(xplot, yplot, 'b-')

        indices = (phirot < 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        plt.plot(xplot, yplot, 'b-')

    for phiDeg in meridians:
        theta = linspace(-meridianMax, meridianMax, 1001)
        phi = zeros_like(theta) + degreesToRadians(phiDeg)
        phirot, thetarot = ct.transformSkyCoordinates(phi, theta)
        x, y = basemapInstance(radiansToDegrees(phirot),
                               radiansToDegrees(thetarot))

        indices = (phirot >= 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        plt.plot(xplot, yplot, 'b-')

        indices = (phirot < 0.0)
        xplot = x[indices]
        yplot = y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        plt.plot(xplot, yplot, 'b-')

    if (not noTitle):
        plt.title("Sky projection in " + ct.transformationStrings[1] +
                  " coordinates with the corresponding " +
                  ct.transformationStrings[0] + " grid overlayed")

    if (not noLabels):
        for theta in arange(-60, 90, 30):
            phirot, thetarot = ct.transformSkyCoordinates(
                0.0, degreesToRadians(theta))
            x, y = basemapInstance(radiansToDegrees(phirot),
                                   radiansToDegrees(thetarot))
            plt.text(x,
                     y,
                     "${0}$".format(theta),
                     fontsize=16,
                     va='bottom',
                     ha='center',
                     color='r')
        for phi in arange(-180, 0, 30):
            phirot, thetarot = ct.transformSkyCoordinates(
                degreesToRadians(phi), 0.0)
            x, y = basemapInstance(radiansToDegrees(phirot),
                                   radiansToDegrees(thetarot))
            plt.text(x,
                     y,
                     "${0}$".format(phi),
                     fontsize=16,
                     va='bottom',
                     ha='center',
                     color='r')
        for phi in arange(30, 180, 30):
            phirot, thetarot = ct.transformSkyCoordinates(
                degreesToRadians(phi), 0.0)
            x, y = basemapInstance(radiansToDegrees(phirot),
                                   radiansToDegrees(thetarot))
            plt.text(x,
                     y,
                     "${0}$".format(phi),
                     fontsize=16,
                     va='bottom',
                     ha='center',
                     color='r')

    if (outfile != None):
        plt.savefig(outfile)
    elif (returnPlotObject):
        return plt.gca(), basemapInstance
    else:
        plt.show()
Esempio n. 23
0
def plotCoordinateTransformationOnSky(transformation, outfile=None, noTitle=False, noLabels=False,
        returnPlotObject=False, lc=plt.cm.tab10.colors[0], tc=plt.cm.tab10.colors[1], lonpos=True):
    """
    Produce a sky-plot in a given coordinate system with the meridians and paralles for another
    coordinate system overlayed. The coordinate systems are specified through the
    pygaia.coordinates.Transformations enum. For example for Transformations.GAL2ECL the sky plot will be
    in Ecliptic coordinates with the Galactic coordinate grid overlayed.

    Keywords
    --------

    transformation - The coordinate transformation for which to make the plot (e.g.,
                     Transformations.GAL2ECL).
    outfile        - Save plot to this output file (default is to plot on screen). Make sure an extension
                     (.pdf, .png, etc) is included.
    noTitle        - If true do not include the plot title.
    noLabels       - If true do not include plot labels.
    returnPlotObject - If true return the matplotlib object used for plotting. Further plot elements can
                       then be added.
    lc             - Colour for gridlines.
    tc             - Colour for text labels.
    lonpos         - If true use longitude labels between 0 and 360 degrees.
    """
    ct = CoordinateTransformation(transformation)

    parallels=arange(-80.0,90.0,10.0)
    meridians=arange(0.0,375.0,15.0)
    meridianMax=degreesToRadians(85.0)
    parallelsMax=degreesToRadians(179.0)

    defaultProj = ccrs.PlateCarree()
    addtolabel = 0
    if lonpos:
        addtolabel = 360

    fig=plt.figure(figsize=(12,6))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.Mollweide())
    ax.invert_xaxis()

    for thetaDeg in parallels:
        phi=linspace(-pi,pi,1001)
        theta=zeros_like(phi)+degreesToRadians(thetaDeg)
        phirot, thetarot = ct.transformSkyCoordinates(phi, theta)
        phirot[(phirot>pi)] = phirot[(phirot>pi)]-2*pi
        x ,y = radiansToDegrees(phirot), radiansToDegrees(thetarot)
      
        indices=(phirot>=0.0)
        xplot=x[indices]
        yplot=y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=defaultProj)
     
        indices=(phirot<0.0)
        xplot=x[indices]
        yplot=y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=defaultProj)

    for phiDeg in meridians:
        theta=linspace(-meridianMax,meridianMax,1001)
        phi=zeros_like(theta)+degreesToRadians(phiDeg)
        phirot, thetarot = ct.transformSkyCoordinates(phi, theta)
        phirot[(phirot>pi)] = phirot[(phirot>pi)]-2*pi
        x ,y = radiansToDegrees(phirot), radiansToDegrees(thetarot)
  
        indices=(phirot>=0.0)
        xplot=x[indices]
        yplot=y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=defaultProj)
       
        indices=(phirot<0.0)
        xplot=x[indices]
        yplot=y[indices]
        if any(indices):
            xplot, yplot = _orderGridlinePoints(xplot, yplot)
        ax.plot(xplot, yplot, '-', color=lc, transform=defaultProj)

    if (not noTitle):
        plt.title("Sky projection in " + ct.transformationStrings[1] + " coordinates with the corresponding " + ct.transformationStrings[0] + " grid overlayed")

    if (not noLabels):
        for theta in arange(-60,90,30):
            phirot, thetarot=ct.transformSkyCoordinates(0.0,degreesToRadians(theta))
            x, y = (radiansToDegrees(phirot), radiansToDegrees(thetarot))
            ax.text(x, y, "${0}$".format(theta), fontsize=16, va='bottom', ha='center', color=tc,
                    transform=defaultProj)
        for phi in arange(-150,0,30):
            phirot, thetarot=ct.transformSkyCoordinates(degreesToRadians(phi), 0.0)
            x, y = (radiansToDegrees(phirot), radiansToDegrees(thetarot))
            ax.text(x, y, "${0}$".format(phi+addtolabel), fontsize=16, va='bottom', ha='center', color=tc,
                    transform=defaultProj) 
        for phi in arange(30,210,30):
            phirot, thetarot=ct.transformSkyCoordinates(degreesToRadians(phi), 0.0)
            x, y = (radiansToDegrees(phirot), radiansToDegrees(thetarot))
            ax.text(x, y, "${0}$".format(phi), fontsize=16, va='bottom', ha='center', color=tc,
                    transform=defaultProj)

    if (outfile != None):
        plt.savefig(outfile)
    elif (returnPlotObject):
        return plt.gca()
    else:
        plt.show()