def test_starfind_strong_weak(self): size = (100, 200) posx = (50, 150) posy = (40, 60) sky = 800 rdnoise = 20 flux = (64000, 6000) theta = 0 fwhm = 3 sigma = fwhm * gaussian_fwhm_to_sigma threshold = 10 im = gen_image(size, posx, posy, flux, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) sources = starfind(im, threshold, sky, rdnoise, fwhm) assert_equal(len(sources), 2) assert_almost_equal(sources['x'], posx, decimal=1) assert_almost_equal(sources['y'], posy, decimal=1) assert_almost_equal(sources.meta['astropop fwhm'], sigma * 2.355, decimal=1)
def test_simbad_catalog_filter_id(self): # performe filter in a different class query = self.cat.query_region('Sirius', '5m') id = self.cat.filter_id(query) id_resolved = self.cat._id_resolve(query['MAIN_ID']) assert_equal(id, id_resolved)
def test_extract_header_nowcs(self): header = fits.Header.fromstring(_base_header, sep='\n') h, wcs = extract_header_wcs(header) assert_is_none(wcs) assert_is_instance(h, fits.Header) assert_equal(h, header) assert_false(h is header)
def test_guess_coords_skycord_float(): ra = 10.0 dec = 0.0 sk = guess_coordinates(ra, dec, skycoord=True) assert_is_instance(sk, SkyCoord) assert_equal(sk.ra.degree, ra) assert_equal(sk.dec.degree, dec)
def test_fg_getitem_slice(self, tmpdir): tmpdir, flist = tmpdir fg = FitsFileGroup(location=tmpdir / 'fits', compression=False) row = fg[2:5] assert_is_instance(row, FitsFileGroup) assert_equal(len(row), 3) assert_equal(row.files, flist['fits'][2:5])
def test_fg_getitem_empty(self, tmpdir): tmpdir, flist = tmpdir fg = FitsFileGroup(location=tmpdir / 'fits', compression=False) row = fg[[]] assert_is_instance(row, FitsFileGroup) assert_equal(len(row), 0) assert_equal(row.files, [])
def test_1D_simple(self): arr = np.arange(10) low, high = (2, 6) expect = np.array([1, 1, 0, 0, 0, 0, 0, 1, 1, 1], dtype=bool) mask = _minmax_clip(arr, low, high) assert_equal(mask, expect)
def test_apply_minmax_clip(self): _min, _max = (0, 20) outliers = ((1, 2), (6, 2), (2, 9), (5, 2)) outvalues = [1e6, -2e3, 5e3, -7e2] expect = np.zeros((10, 10)) with NumpyRNGContext(123): data = np.ma.MaskedArray(np.random.normal(loc=10, scale=1, size=[10, 10]), mask=np.zeros((10, 10))) for p, v in zip(outliers, outvalues): data[p] = v expect[p] = 1 data[0:2, 0:3].mask = 1 expect[0:2, 0:3] = 1 # force assign the buffer comb = ImCombiner() comb._buffer = data # with these limits, only the outliers must be masked comb.set_minmax_clip(_min, _max) comb._apply_rejection() # original mask must be kept assert_equal(comb._buffer.mask, expect)
def test_sepfind_multiple_stars(self): size = (1024, 1024) number = 15 low = 2000 high = 30000 sky = 800 rdnoise = 20 sigma = 3 theta = 0 x, y, f = gen_position_flux(size, number, low, high, rng_seed=456) im = gen_image(size, x, y, f, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) sources = sepfind(im, 5, sky, rdnoise) x, y, f = self.resort_sources(x, y, f) assert_equal(len(sources), number) assert_almost_equal(sources['x'], x, decimal=0) assert_almost_equal(sources['y'], y, decimal=0)
def test_starfind_recenter_sources(self): size = (256, 256) number = 10 sky = 70 rdnoise = 20 low = 120000 high = 320000 sigma = 5 theta = 0 x, y, f = gen_position_flux(size, number, low, high, rng_seed=456) im = gen_image(size, x, y, f, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) nx, ny = recenter_sources( im, x + np.random.normal(loc=0, scale=1, size=len(x)), y + np.random.normal(loc=0, scale=1, size=len(x)), box_size=15, model='gaussian') assert_equal(len(nx), number) assert_equal(len(ny), number) # TODO: this seems unprecise. Investigate it. assert_almost_equal(nx, x, decimal=-1) assert_almost_equal(ny, y, decimal=-1)
def test_starfind_one_star(self): size = (128, 128) x, y = (64, 64) f = 80000 sky = 70 rdnoise = 20 sigma = 5 theta = 0 fwhm = 5 # dummy low value threshold = 10 im = gen_image(size, [x], [y], [f], sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) sources = starfind(im, threshold, sky, rdnoise, fwhm) assert_equal(len(sources), 1) assert_almost_equal(sources['x'], x, decimal=0) assert_almost_equal(sources['y'], y, decimal=0) assert_almost_equal(sources.meta['astropop fwhm'], sigma * 2.355, decimal=1)
def test_daofind_multiple_stars(self): size = (512, 512) number = 15 low = 2000 high = 30000 sky = 800 rdnoise = 20 fwhm = 5 sigma = fwhm * gaussian_fwhm_to_sigma theta = 0 threshold = 10 x, y, f = gen_position_flux(size, number, low, high, rng_seed=456) im = gen_image(size, x, y, f, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) sources = daofind(im, threshold, sky, rdnoise, fwhm) x, y, f = self.resort_sources(x, y, f) assert_equal(len(sources), number) assert_almost_equal(sources['x'], x, decimal=0) assert_almost_equal(sources['y'], y, decimal=0)
def test_daofind_four_stars_fixed_position(self): size = (128, 128) posx = (45, 90, 45, 90) posy = (45, 50, 90, 100) sky = 800 rdnoise = 20 flux = (15000, 3000, 5000, 35000) fwhm = 3 sigma = fwhm * gaussian_fwhm_to_sigma theta = 0 threshold = 10 im = gen_image(size, posx, posy, flux, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) sources = daofind(im, threshold, sky, rdnoise, fwhm) assert_equal(len(sources), 4) assert_almost_equal(sources['x'], posx, decimal=0) assert_almost_equal(sources['y'], posy, decimal=0)
def test_daofind_strong_and_weak(self): size = (128, 128) posx = (45, 90) posy = (45, 90) sky = 800 rdnoise = 20 flux = (32000, 16000) fwhm = 3 sigma = fwhm * gaussian_fwhm_to_sigma theta = 0 im = gen_image(size, posx, posy, flux, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) threshold = 10 sources = daofind(im, threshold, sky, rdnoise, fwhm) assert_equal(len(sources), 2) assert_almost_equal(sources['x'], posx, decimal=0) assert_almost_equal(sources['y'], posy, decimal=0)
def test_invalid(self): # must mask invalid numbers arr = np.array([0, 1, 2, np.inf, np.nan, 5, 1]) low, high = (1, 3) expect = np.array([1, 0, 0, 1, 1, 1, 0]) mask = _minmax_clip(arr, low, high) assert_equal(mask, expect)
def test_starfind_blind_fwhm(self): size = (512, 512) number = 12 low, high = (15000, 60000) sky = 800 rdnoise = 20 sigma = 2 theta = 0 threshold = 8 x, y, f = gen_position_flux(size, number, low, high, rng_seed=456) x, y, f = self.resort_sources(x, y, f) im = gen_image(size, x, y, f, sky, rdnoise, model='gaussian', sigma=sigma, theta=theta) sources = starfind(im, threshold, sky, rdnoise) assert_equal(len(sources), number) assert_almost_equal(sources['x'], x, decimal=1) assert_almost_equal(sources['y'], y, decimal=1) assert_almost_equal(sources.meta['astropop fwhm'], sigma * 2.355, decimal=2)
def test_simbad_catalog_get_simbad_copy(self): # always return a copy of the querier s = Simbad() # assign our simbad self.cat.simbad = s assert_is_not(self.cat.simbad, s) assert_equal(self.cat.simbad.ROW_LIMIT, 0)
def test_framememta_repr(self): a = FrameMeta({'A': 1, 'B': (2, 'with comment'), 'c': 3}) expect = "FrameMeta:\n" expect += "a = 1 # \n" expect += "b = 2 # with comment\n" expect += "c = 3 # \n" assert_equal(repr(a), expect)
def test_simple_import(self): ccd = self.ccd f = _extract_ccddata(ccd) assert_equal(f['data'], 100 * np.ones(self.shape)) assert_equal(f['mask'], self.mask) assert_equal(f['unit'], self.unit) assert_equal(f['meta'], self.meta) assert_equal(f['uncertainty'], 10 * np.ones(self.shape))
def test_logger_no_loglist(): mylog = logger.getChild('testing') msg = 'Some error happend here.' lh = ListHandler() assert_is_instance(lh.log_list, list) mylog.addHandler(lh) mylog.error(msg) assert_equal(lh.log_list[0], msg)
def test_process_list_with_args(self): def dummy_func(i, a, b): return (i+a)*b i_array = np.arange(20) a_val = 2 b_val = 3 res = process_list(dummy_func, i_array, a_val, b=b_val) assert_equal((i_array+a_val)*b_val, res)
def test_math_int(tmpdir, memmap, value, other): f = os.path.join(tmpdir, 'int.npy') arr = np.arange(10, dtype='int8') * value a = MemMapArray(arr, filename=f, memmap=memmap) with pytest.raises(TypeError): int(a) a = MemMapArray([value], filename=f, memmap=memmap) assert_equal(int(value), int(a))
def test_mergeheaders_default(self): # default is 'no_merge' images = self.create_images() comb = ImCombiner() res = comb.combine(images, method='sum') assert_equal(res.meta, { 'astropop imcombine nimages': 30, 'astropop imcombine method': 'sum' })
def test_process_list(self): def dummy_func(i): i = 1 return i a = np.zeros(20) b = np.ones(20) c = process_list(dummy_func, a) assert_equal(b, c) assert_false(np.array_equal(a, c))
def test_solve_astrometry_hdu(tmpdir): data, index = get_image_index() hdu = fits.open(data)[0] header, wcs = _generate_wcs_and_update_header(hdu.header) hdu.header = header nwcs = solve_astrometry_hdu(hdu, return_wcs=True) assert_true(isinstance(nwcs, WCS)) assert_equal(nwcs.naxis, 2) compare_wcs(wcs, nwcs)
def test_qfloat_unit_property(unit, expect): # Getter test c = DummyClass(unit) assert_equal(c.unit, expect) # Setter test c = DummyClass(None) c.unit = unit assert_equal(c.unit, expect)
def test_list_custom_extension(self, tmpdir): tmpdir, flist = tmpdir found_files = list_fits_files(tmpdir / 'custom', fits_extensions='.myfits') assert_equal(sorted(found_files), sorted(flist['myfits'])) found_files = list_fits_files( tmpdir / 'custom', fits_extensions=['.myfits', '.otherfits']) assert_equal(sorted(found_files), sorted(flist['custom']))
def test_run_command(self, com): stdout = [] stderr = [] _, out, err = run_command(com, stdout=stdout, stderr=stderr, stdout_loglevel='WARN') assert_is(out, stdout) assert_is(err, stderr) assert_equal(stdout, [str(i) for i in range(1, 11)]) assert_equal(stderr, [])
def test_run_command_stderr(self, com): stdout = [] stderr = [] _, out, err = run_command(com, stdout=stdout, stderr=stderr, stdout_loglevel='WARN') assert_is(out, stdout) assert_is(err, stderr) assert_equal(stdout, []) assert_equal(stderr, ['this is an error'])
def test_apply_sigmaclip_only_higher(self): data = np.ma.MaskedArray([1, -1, 1, -1, -65000], mask=np.zeros(5)) comb = ImCombiner() # -65000 must not be masked comb._buffer = data.copy() comb.set_sigma_clip((None, 1)) expect = [0, 0, 0, 0, 0] comb._apply_rejection() assert_equal(comb._buffer.mask, expect)