def test_can_initialize_default_extensions(): ad = astrofaker.create('GMOS-S') ad.init_default_extensions() assert len(ad) == 12 assert ad.detector_x_bin() in [1, 2, 4]
def test_mosaic_detectors_gmos_binning(astrofaker): """ Tests that the spacing between amplifier centres for NxN binned data is precisely N times smaller than for unbinned data when run through mosaicDetectors() """ from geminidr.gmos.primitives_gmos_image import GMOSImage for hemi in 'NS': for ccd in ('EEV', 'e2v', 'Ham'): for binning in (1, 2, 4): try: ad = astrofaker.create('GMOS-{}'.format(hemi), ['IMAGE', ccd]) except ValueError: # No e2v for GMOS-S continue ad.init_default_extensions(binning=binning, overscan=False) for ext in ad: shape = ext.data.shape ext.add_star(amplitude=10000, x=0.5 * (shape[1] - 1), y=0.5 * (shape[0] - 1), fwhm=0.5 * binning) p = GMOSImage([ad]) ad = p.mosaicDetectors([ad])[0] ad = p.detectSources([ad])[0] x = np.array(sorted(ad[0].OBJCAT['X_IMAGE'])) if binning == 1: unbinned_positions = x else: diffs = np.diff(unbinned_positions) - binning * np.diff(x) assert np.max(abs(diffs)) < 0.01
def test_can_create_dataset(): ad = astrofaker.create('GMOS-S') assert isinstance(ad, astrodata.AstroData) assert isinstance(ad, astrofaker.AstroFaker) assert isinstance(ad, gmos.AstroFakerGmos) assert len(ad) == 0
def geminiimage(): af = astrofaker.create('NIRI', 'IMAGE') af.init_default_extensions() # SExtractor struggles if the background is noiseless af.add_read_noise() for x, y in STAR_POSITIONS: af[0].add_star(amplitude=500, x=x, y=y) return af # geminiimage([af])
def test_adu_to_electrons(astrofaker): ad = astrofaker.create("NIRI", "IMAGE") # astrodata.open(os.path.join(TESTDATAPATH, 'NIRI', 'N20070819S0104_dqAdded.fits')) p = NIRIImage([ad]) ad = p.ADUToElectrons()[0] assert ad_compare( ad, os.path.join(TESTDATAPATH, 'NIRI', 'N20070819S0104_ADUToElectrons.fits'))
def test_override_descriptor(): ad = astrofaker.create('GMOS-S') assert ad.wcs_ra() is None ad.wcs_ra = 5 assert ad.wcs_ra() == 5 ad.wcs_ra = lambda: 5 assert ad.wcs_ra() == 5
def test_apply_dq_plane(astrofaker): ad = astrofaker.create("NIRI", "IMAGE") # astrodata.open(os.path.join(TESTDATAPATH, 'NIRI', 'N20070819S0104_nonlinearityCorrected.fits')) p = NIRIImage([ad]) ad = p.applyDQPlane()[0] assert ad_compare( ad, os.path.join(TESTDATAPATH, 'NIRI', 'N20070819S0104_dqPlaneApplied.fits'))
def test_can_add_image_extension(): hdu = fits.ImageHDU() hdu.data = np.random.random((100, 100)) ad = astrofaker.create('GMOS-S') # ToDo: The line below raises a TypeError if `pixel_scale` is not provided. # We need either to provide a better error message to the programmer or # set `pixel_scale` with a default value and raise a warning. ad.add_extension(hdu, pixel_scale=1.0) assert len(ad) == 1
def niri_images(): """Create two NIRI images, one all 1s, the other all 2s""" try: import astrofaker except ImportError: pytest.skip("astrofaker not installed") adinputs = [] for i in (1, 2): ad = astrofaker.create('NIRI', 'IMAGE') ad.init_default_extensions() ad[0].data += i adinputs.append(ad) return NIRIImage(adinputs)
def niri_image(): try: import astrofaker except ImportError: pytest.skip("astrofaker is not installed") ad = astrofaker.create('NIRI', 'IMAGE') ad.init_default_extensions() # SExtractor struggles if the background is noiseless ad.add_read_noise() for x, y in STAR_POSITIONS: ad[0].add_star(amplitude=500, x=x, y=y) return NIRIImage([ad])
def test_can_update_descriptor_dispersion_axis_of_astrodata(): hdu = fits.ImageHDU() hdu.data = np.random.random((100, 100)) ad = astrofaker.create('GMOS-S') ad.add_extension(hdu, pixel_scale=1.0) # ToDo: how are descriptor assignments handled? # I suspect they should be something like Python Properties. This would # allow some variable validation with a comprehensive error message. ad.dispersion_axis = [1] assert ad.dispersion_axis() == [1] for ext in ad: assert ext.dispersion_axis() == 1
def test_add_object_mask_to_dq(): try: import astrofaker except ImportError: pytest.skip("astrofaker not installed") ad_orig = astrofaker.create('F2', 'IMAGE') # astrodata.open(os.path.join(TESTDATAPATH, 'GMOS', 'N20150624S0106_refcatAdded.fits')) p = GMOSImage([deepcopy(ad_orig)]) ad = p.addObjectMaskToDQ()[0] for ext, ext_orig in zip(ad, ad_orig): assert all( ext.mask[ext.OBJMASK == 0] == ext_orig.mask[ext.OBJMASK == 0]) assert all( ext.mask[ext.OBJMASK == 1] == ext_orig.mask[ext.OBJMASK == 1] | 1)
def test_can_update_descriptor_dispersion_axis_of_astrodata_extensions(): hdu = fits.ImageHDU() hdu.data = np.random.random((100, 100)) ad = astrofaker.create('GMOS-S') ad.add_extension(hdu, pixel_scale=1.0) ad.add_extension(hdu, pixel_scale=1.0) # ToDo: how are descriptor assignments handled? # Same as before. for ext in ad: ext.dispersion_axis = 1 # ToDo: setting descriptors should be persistent and/or raise an error for ext in ad: assert ext.dispersion_axis() == 1