def assert_allclose_structured(x, y): """Assert that two structured arrays are close. Compares floats relatively and everything else exactly. """ assert x.dtype == y.dtype for name in x.dtype.names: if np.issubdtype(x.dtype[name], float): assert_allclose(x[name], y[name]) else: assert_equal(x[name], y[name]) # If we have a FITS reader, read in the necessary test images if not NO_FITS: image_data = getdata(IMAGE_FNAME) image_refback = getdata(BACKIMAGE_FNAME) # ----------------------------------------------------------------------------- # Test versus Source Extractor results @pytest.mark.skipif(NO_FITS, reason="no FITS reader") def test_vs_sextractor(): """Test behavior of sep versus sextractor. Note: we turn deblending off for this test. This is because the deblending algorithm uses a random number generator. Since the sequence of random numbers is not the same between sextractor and sep or between different platforms, object member pixels (and even the number of objects) can differ when deblending is on.
# Try to import any FITS reader try: from fitsio import read as getdata HAVE_FITS = True NEED_BYTESWAP = False except: try: from astropy.io.fits import getdata HAVE_FITS = True except: HAVE_FITS = False CONDENSED = True if HAVE_FITS: rawdata = getdata(join("data", "image.fits")) # original is 256 x 256 data = np.tile(rawdata, (4, 4)) print("test image shape:", data.shape) print("test image dtype:", data.dtype) t0 = time.time() bkg = sep.Background(data) # estimate background t1 = time.time() print("measure background: {0:6.2f} ms".format((t1-t0) * 1.e3)) t0 = time.time() bkg.subfrom(data) # subtract it t1 = time.time() print("subtract background: {0:6.2f} ms".format((t1-t0) * 1.e3))
# Try to import any FITS reader try: from fitsio import read as getdata HAVE_FITS = True NEED_BYTESWAP = False except ImportError: try: from astropy.io.fits import getdata HAVE_FITS = True except ImportError: HAVE_FITS = False CONDENSED = True if HAVE_FITS: rawdata = getdata(join("data", "image.fits")) # original is 256 x 256 data = np.tile(rawdata, (4, 4)) print("test image shape:", data.shape) print("test image dtype:", data.dtype) t0 = time.time() bkg = sep.Background(data) # estimate background t1 = time.time() print("measure background: {0:6.2f} ms".format((t1 - t0) * 1.e3)) t0 = time.time() bkg.subfrom(data) # subtract it t1 = time.time() print("subtract background: {0:6.2f} ms".format((t1 - t0) * 1.e3))