Esempio n. 1
0
def test_to_fits_tab_time_cube(gwcs_cube_with_separable_time):
    # gWCS:
    w = gwcs_cube_with_separable_time

    # FITS WCS -SIP (for celestial) and -TAB (for spectral):
    hdr, bt = w.to_fits(projection=models.Sky2Pix_TAN(name='TAN'))

    # create FITS WCS object:
    hdus = [fits.PrimaryHDU(np.zeros(w.array_shape), hdr)]
    hdus.extend(bt)
    hdulist = fits.HDUList(hdus)
    fits_wcs = astwcs.WCS(hdulist[0].header, hdulist)

    assert np.allclose(hdulist[1].data['coordinates'].ravel(), np.arange(128))

    # test points:
    (xmin, xmax), (ymin, ymax), (zmin, zmax) = w.bounding_box
    np.random.seed(1)
    x = xmin + (xmax - xmin) * np.random.random(5)
    y = ymin + (ymax - ymin) * np.random.random(5)
    z = zmin + (zmax - zmin) * np.random.random(5)

    world_crds = w(x, y, z)

    # test forward transformation:
    assert np.allclose(world_crds, fits_wcs.wcs_pix2world(x, y, z, 0))

    # test round-tripping:
    assert np.allclose((x, y, z), fits_wcs.wcs_world2pix(*world_crds, 0), rtol=1e-5, atol=1e-5)
Esempio n. 2
0
def test_transforms_compound(tmpdir):
    tree = {
        'compound':
        astmodels.Shift(1) & astmodels.Shift(2) | astmodels.Sky2Pix_TAN()
        | astmodels.Rotation2D()
        | astmodels.AffineTransformation2D([[2, 0], [0, 2]], [42, 32]) +
        astmodels.Rotation2D(32)
    }

    helpers.assert_roundtrip_tree(tree, tmpdir)
Esempio n. 3
0
def project_to_tangent_plane(ra, dec, ra_ref, dec_ref, scale=1.):
    """Convert ra/dec coordinates into pixel coordinates using a tangent plane projection.

    Theprojection's reference point has to be specified.
    Scale is a convenience parameter that defaults to 1.0, in which case the returned pixel
    coordinates are also in degree. Scale can be set to a pixel scale to return detector coordinates
    in pixels

    Parameters
    ----------
    ra : float
        Right Ascension in decimal degrees

    dec: float
        declination in decimal degrees

    ra_ref : float
        Right Ascension of reference point in decimal degrees

    dec_ref: float
        declination of reference point in decimal degrees

    scale : float
        Multiplicative factor that is applied to the returned values. Default is 1.0

    Returns
    -------
    x,y : float
        pixel coordinates in decimal degrees if scale = 1.0

    """
    # for zenithal projections, i.e. gnomonic, i.e. TAN:
    if isinstance(ra_ref, u.Quantity):
        lonpole = 180. * u.deg
    else:
        lonpole = 180.

    # tangent plane projection from phi/theta to x,y
    tan = astmodels.Sky2Pix_TAN()

    # compute native coordinate rotation to obtain phi and theta
    rot_for_tan = astrotations.RotateCelestial2Native(ra_ref, dec_ref, lonpole)

    phi_theta = rot_for_tan(ra, dec)

    # pixel coordinates,  x and y are in degree-equivalent
    x, y = tan(phi_theta[0], phi_theta[1])

    x = x * scale
    y = y * scale

    return x, y