Exemplo n.º 1
0
def test_load_ffi_files():

    files = find_ffi_files(INPUT_DIR, camera=1)

    img = load_ffi_fits(files[0])
    assert (img.shape == (2048, 2048))

    img, hdr = load_ffi_fits(files[0], return_header=True)
    assert (img.shape == (2048, 2048))
Exemplo n.º 2
0
def test_load_ffi_files(SHARED_INPUT_DIR):

    files = u.find_ffi_files(SHARED_INPUT_DIR, camera=1)

    img = u.load_ffi_fits(files[0])
    assert (img.shape == (2048, 2048))

    img, hdr = u.load_ffi_fits(files[0], return_header=True)
    assert (img.shape == (2048, 2048))
Exemplo n.º 3
0
def test_background(SHARED_INPUT_DIR):
    """Test of background estimator"""

    # Load the first image in the input directory:
    fname = find_ffi_files(SHARED_INPUT_DIR)[0]
    img, hdr = load_ffi_fits(fname, return_header=True)

    # Estimate the background:
    bck, mask = fit_background(fname)

    # Print some information:
    print(fname)
    print(bck.shape)
    print(mask.shape)

    # Check the sizes of the returned images:
    assert (bck.shape == img.shape)
    assert (mask.shape == img.shape)
Exemplo n.º 4
0
def fit_background(image, catalog=None, flux_cutoff=8e4):
    """
	Estimate background in Full Frame Image.

	Parameters:
		image (ndarray or string): Either the image as 2D ndarray or a path to FITS or NPY file where to load image from.
		catalog (`astropy.table.Table` object): Catalog of stars in the image. Is not yet being used for anything.
		flux_cutoff (float): Flux value at which any pixel above will be masked out of the background estimation.

	Returns:
		ndarray: Estimated background with the same size as the input image.
		ndarray: Boolean array specifying which pixels was used to estimate the background (``True`` if pixel was used).

	.. codeauthor:: Rasmus Handberg <*****@*****.**>
	"""

    # Load file:
    if isinstance(image, np.ndarray):
        img = image
    elif isinstance(image, six.string_types):
        if image.endswith('.npy'):
            img = np.load(image)
        else:
            img = load_ffi_fits(image)
    else:
        raise ValueError(
            "Input image must be either 2D ndarray or path to file.")

    # Create mask
    # TODO: Use the known locations of bright stars
    mask = ~np.isfinite(img)
    mask |= (img > flux_cutoff)

    # Estimate the background:
    sigma_clip = SigmaClip(sigma=3.0, iters=5)
    bkg_estimator = SExtractorBackground()
    bkg = Background2D(img, (64, 64),
                       filter_size=(3, 3),
                       sigma_clip=sigma_clip,
                       bkg_estimator=bkg_estimator,
                       mask=mask,
                       exclude_percentile=50)

    return bkg.background, mask
Exemplo n.º 5
0
def test_background():
	"""Test of background estimator"""

	# Load the first image in the input directory:
	INPUT_DIR = os.path.join(os.path.dirname(__file__), 'input', 'images')
	fname = find_ffi_files(INPUT_DIR)[0]
	img, hdr = load_ffi_fits(fname, return_header=True)

	# Estimate the background:
	bck, mask = fit_background(fname, )

	# Print some information:
	print(fname)
	print(bck.shape)
	print(mask.shape)

	# Check the sizes of the returned images:
	assert(bck.shape == img.shape)
	assert(mask.shape == img.shape)
Exemplo n.º 6
0
def test_imagemotion():
    """Test of ImageMovementKernel"""

    # Load the first image in the input directory:
    INPUT_DIR = os.path.join(os.path.dirname(__file__), 'input', 'images')
    files = find_ffi_files(INPUT_DIR, camera=1, ccd=1)
    fname = files[0]

    # Load the image:
    img = load_ffi_fits(fname)

    # Create new image, moved down by one pixel:
    #img2 = np.roll(img, 1, axis=0)

    # Some positions across the image:
    xx, yy = np.meshgrid(
        np.linspace(0, img.shape[0], 5, dtype='float64'),
        np.linspace(0, img.shape[1], 5, dtype='float64'),
    )
    xy = np.column_stack((xx.flatten(), yy.flatten()))
    print("Positions to be tested:")
    print(xy)

    desired1 = np.zeros_like(xy)
    desired2 = np.zeros_like(xy)
    desired2[:, 1] = 1

    for warpmode in ('unchanged', 'translation', 'euclidian'):
        print("Testing warpmode=" + warpmode)

        # Create ImageMovementKernel instance:
        imk = ImageMovementKernel(image_ref=img, warpmode=warpmode)

        # Calculate kernel for the same image:
        kernel = imk.calc_kernel(img)
        print("Kernel:")
        print(kernel)
        assert (len(kernel) == imk.n_params)

        # Calculate the new positions based on the kernel:
        delta_pos = imk(xy, kernel)
        print("Extracted movements:")
        print(delta_pos)

        assert (delta_pos.shape == xy.shape)

        # The movements should all be very close to zero,
        # since we used the same image as the reference:
        np.testing.assert_allclose(delta_pos, desired1, atol=1e-5, rtol=1e-5)
        """
		kernel = imk.calc_kernel(img2)
		print("Kernel 2:")
		print(kernel)

		# Calculate the new positions based on the kernel:
		delta_pos = imk(xy, kernel)
		print("Extracted movements:")
		print(delta_pos)

		assert(delta_pos.shape == xy.shape)

		# The movements should all be very close to zero,
		# since we used the same image as the reference:
		# FIXME: Would LOVE this to be more accurate!
		np.testing.assert_allclose(delta_pos, desired2, atol=1e-3, rtol=1e-2)
		"""

    print("Done")
Exemplo n.º 7
0
def test_imagemotion(SHARED_INPUT_DIR, warpmode):
    """Test of ImageMovementKernel"""

    print("Testing warpmode=" + warpmode)

    # Load the first image in the input directory:
    files = find_ffi_files(os.path.join(SHARED_INPUT_DIR, 'images'),
                           camera=1,
                           ccd=1)
    fname = files[0]

    # Load the image:
    img = load_ffi_fits(fname)

    # Create new image, moved down by one pixel:
    #img2 = np.roll(img, 1, axis=0)

    # Some positions across the image:
    xx, yy = np.meshgrid(
        np.linspace(0, img.shape[0], 5, dtype='float64'),
        np.linspace(0, img.shape[1], 5, dtype='float64'),
    )
    xy = np.column_stack((xx.flatten(), yy.flatten()))
    print("Positions to be tested:")
    print(xy)

    desired1 = np.zeros_like(xy)
    desired2 = np.zeros_like(xy)
    desired2[:, 1] = 1

    # Create ImageMovementKernel instance:
    imk = ImageMovementKernel(image_ref=img, warpmode=warpmode)

    # If calling interpolate before defining kernels, we should get an error:
    with pytest.raises(ValueError):
        imk.interpolate(1234, 1234)

    # Calculate kernel for the same image:
    kernel = imk.calc_kernel(img)
    print("Kernel:")
    print(kernel)
    assert (len(kernel) == imk.n_params)

    # Calculate the new positions based on the kernel:
    delta_pos = imk(xy, kernel)
    print("Extracted movements:")
    print(delta_pos)

    assert (delta_pos.shape == xy.shape)

    # The movements should all be very close to zero,
    # since we used the same image as the reference:
    np.testing.assert_allclose(delta_pos, desired1, atol=1e-5, rtol=1e-5)

    #
    with pytest.raises(ValueError) as excinfo:
        imk.load_series([1234, 1235], kernel)

    print(excinfo.value)
    assert str(excinfo.value).startswith('Wrong shape of kernels.')
    """
	kernel = imk.calc_kernel(img2)
	print("Kernel 2:")
	print(kernel)

	# Calculate the new positions based on the kernel:
	delta_pos = imk(xy, kernel)
	print("Extracted movements:")
	print(delta_pos)

	assert(delta_pos.shape == xy.shape)

	# The movements should all be very close to zero,
	# since we used the same image as the reference:
	# FIXME: Would LOVE this to be more accurate!
	np.testing.assert_allclose(delta_pos, desired2, atol=1e-3, rtol=1e-2)
	"""

    print("Done")