Пример #1
0
def test_fits_wcs(ra, dec, pa):
    input_image = AstroImage(ra=ra, dec=dec, pa=pa, psf=False)
    input_image.toFits('test_wcs.fits')

    pc_11 = np.cos(np.radians(pa))
    pc_12 = -np.sin(np.radians(pa))
    pc_21 = np.sin(np.radians(pa))
    pc_22 = np.cos(np.radians(pa))
    pc_matrix = [[pc_11, pc_12], [pc_21, pc_22]]

    with fits.open("test_wcs.fits") as input_file:
        img_wcs = WCS(input_file[0].header)
        assert np.isclose(img_wcs.wcs.crval[0], ra)
        assert np.isclose(img_wcs.wcs.crval[1], dec)
        assert np.isclose(img_wcs.wcs.pc[0][0], pc_matrix[0][0])
        assert np.isclose(img_wcs.wcs.pc[0][1], pc_matrix[0][1])
        assert np.isclose(img_wcs.wcs.pc[1][0], pc_matrix[1][0])
        assert np.isclose(img_wcs.wcs.pc[1][1], pc_matrix[1][1])
        assert np.isclose(input_file[0].header["CRVAL1"], ra)
        assert np.isclose(input_file[0].header["CRVAL2"], dec)
        assert np.isclose(input_file[0].header["PC1_1"], pc_matrix[0][0])
        assert np.isclose(input_file[0].header["PC1_2"], pc_matrix[0][1])
        assert np.isclose(input_file[0].header["PC2_1"], pc_matrix[1][0])
        assert np.isclose(input_file[0].header["PC2_2"], pc_matrix[1][1])

    os.remove("test_wcs.fits")
Пример #2
0
def test_DEC(coords, coord_types, ra, dec, new_dec, out_dec):
    my_wcs = makeWCS(coords=coords, coord_types=coord_types)
    image = AstroImage(wcs=my_wcs, psf=False)
    assert image.ra == ra
    assert image.dec == dec
    image.dec = new_dec
    assert image.dec == out_dec
Пример #3
0
def test_addHistory(history):
    image = AstroImage(psf=False)
    for item in history:
        image.addHistory(item)
    for item in history:
        assert item in image.history
    for item in image.history:
        assert item in history
Пример #4
0
def test_PA(pa_in, pa, scale, new_pa, pa_out):
    image = AstroImage(pa=pa_in, scale=scale, psf=False)
    assert abs(image.pa - pa) < 1.e-4
    assert abs(image.xscale - scale[0] * 3600) < 1.e-4
    assert abs(image.yscale - scale[1] * 3600) < 1.e-4
    image.pa = new_pa
    assert abs(image.pa - pa_out) < 1.e-4
    assert abs(image.xscale - scale[0] * 3600) < 1.e-4
    assert abs(image.yscale - scale[1] * 3600) < 1.e-4
Пример #5
0
def test_bin(input, bin, result):
    # If psf=True, then the image will create a default PSF, and pad its
    #   borders (and thus increase its size) sufficiently to include off-image
    #   regions of half the PSF width on each side. That will, in turn, result
    #   in the image sizes not matching the pre-made output arrays. Because this
    #   test is not related to PSFs in any way, no PSF is created.
    im1 = AstroImage(data=input, psf=False)
    im1.bin(bin[0], bin[1])
    verifyData(im1.hdu.data, result)
Пример #6
0
def test_astro_image_rotation_full(data_base):
    fits_path = os.path.join(data_base, "test", "wcs_test.fits")

    # Test 90 degree rotation
    ai = AstroImage.initFromFits(fits_path, psf=False)
    default_wcs = ai._getWcs()  # WCS(ai.hdu)
    default_data = ai.hdu.data[:]

    ai.rotate(90)
    rotated_wcs = ai._getWcs()  # WCS(ai.hdu)
    rotated_data = ai.hdu.data[:]

    arr_size_x = ai.hdu.shape[0]
    arr_size_y = ai.hdu.shape[1]

    for x in range(arr_size_x):
        print("Starting Iteration {} of {}".format(x, arr_size_x))
        for y in range(arr_size_y):
            wcs_location = default_wcs.all_pix2world([[y, x]], 0)
            default_value = default_data[y][x]

            y, x = np.round(rotated_wcs.all_world2pix(wcs_location,
                                                      0)).astype(int)[0]
            assert (0 <= x < arr_size_x)
            assert (0 <= y < arr_size_y)
            rotated_value = rotated_data[y][x]

            if not np.isclose(default_value, rotated_value):
                print("Failed Values: ", default_value, rotated_value)
            assert np.isclose(default_value, rotated_value)
Пример #7
0
def test_astro_image_rotation_sample(data_base):
    fits_path = os.path.join(data_base, "test", "wcs_test.fits")

    # Test 90 degree rotation
    ai = AstroImage.initFromFits(fits_path, psf=False)
    default_wcs = ai._getWcs()  # WCS(ai.hdu)
    default_data = ai.hdu.data[:]

    ai.rotate(90)
    rotated_wcs = ai._getWcs()  # WCS(ai.hdu)
    rotated_data = ai.hdu.data[:]

    arr_size_x = ai.hdu.shape[0]
    arr_size_y = ai.hdu.shape[1]

    random.seed()

    coords = []

    for x in range(1000):
        coords.append(
            (random.randrange(arr_size_x), random.randrange(arr_size_y)))

    for x, y in coords:
        wcs_location = default_wcs.all_pix2world([[y, x]], 0)
        default_value = default_data[y][x]

        y, x = np.round(rotated_wcs.all_world2pix(wcs_location,
                                                  0)).astype(int)[0]
        assert (0 <= x < arr_size_x)
        assert (0 <= y < arr_size_y)
        rotated_value = rotated_data[y][x]

        if not np.isclose(default_value, rotated_value):
            print("Failed Values: ", default_value, rotated_value)
        assert np.isclose(default_value, rotated_value)
Пример #8
0
def test_updateHeader(header_in, header_out):
    image = AstroImage(psf=False)
    for k, v in header_in:
        image.updateHeader(k, v)
    for k, v in header_out:
        assert image.header[k] == v
Пример #9
0
def test_convolve(input, kernel, result):
    input_image = AstroImage(data=input, psf=False)
    kernel_image = AstroImage(data=kernel, psf=False)
    input_image.convolve(kernel_image)
    verifyData(input_image.hdu.data, result)
Пример #10
0
def new_empty_astro_image(data_base):
    fits_path = os.path.join(data_base, "astro_image", "zero_image.fits")
    print(fits_path)
    return AstroImage.initFromFits(fits_path, psf=False)