def test_observe_works_for_source_distributed_over_several_fovs( self, cmds, im_src): orig_sum = np.sum(im_src.fields[0].data) cmds["SIM_PIXEL_SCALE"] = 0.02 opt = OpticalTrain(cmds) opt.observe(im_src) wave = np.arange(0.5, 2.51, 0.1) * u.um unit = u.Unit("ph s-1 m-2 um-1") print(opt.optics_manager.surfaces_table.emission(wave).to(unit)) print(opt.optics_manager.surfaces_table.table) implane = opt.image_planes[0] final_sum = np.sum(implane.image) print(orig_sum, final_sum) if PLOTS: for fov in opt.fov_manager.fovs: cnrs = fov.corners[1] plt.plot(cnrs[0], cnrs[1]) plt.imshow(implane.image.T, origin="lower", norm=LogNorm(), extent=( -implane.hdu.header["NAXIS1"] / 2, implane.hdu.header["NAXIS1"] / 2, -implane.hdu.header["NAXIS2"] / 2, implane.hdu.header["NAXIS2"] / 2, )) plt.colorbar() plt.show()
def test_observe_works_for_image(self, cmds, im_src): opt = OpticalTrain(cmds) opt.observe(im_src) if PLOTS: plt.imshow(opt.image_plane.image.T, origin="lower", norm=LogNorm()) plt.show()
def test_works_with_a_pointer_to_fits_imagehdu(self, cmds): # Basically just checking to make sure observe doesn't throw an error # when passed a Source object with a file pointer ImageHDU fits_src = src_objs._fits_image_source() array_src = src_objs._image_source() src = fits_src + array_src opt = OpticalTrain(cmds) opt.observe(src) assert np.sum(opt.image_planes[0].data) > 0
def yaml_file_can_be_loaded_into_optical_train(self): # .. todo: get this working on Travis filename = os.path.join(TEST_PATH, "MICADO_SCAO_WIDE_2.yaml") cmds = UserCommands(yamls=[filename]) assert isinstance(cmds, UserCommands) assert isinstance(cmds.yaml_dicts, list) psf_file = cmds.yaml_dicts[1]["effects"][0]["kwargs"]["filename"] if find_file(psf_file) is None: new_file = "test_FVPSF.fits" cmds.yaml_dicts[1]["effects"][0]["kwargs"]["filename"] = new_file opt = OpticalTrain(cmds=cmds) assert isinstance(opt, OpticalTrain) assert isinstance(opt.optics_manager, OpticsManager) assert isinstance( opt.optics_manager.get_all(efs.FieldVaryingPSF)[0], efs.FieldVaryingPSF) assert isinstance(opt.image_plane, ImagePlane) assert opt.image_plane.hdu.header["NAXIS1"] >= 4096 assert isinstance(opt.fov_manager, FOVManager) assert len(opt.fov_manager.fovs) == 64 if PLOTS: for fov in opt.fov_manager.fovs: sky_cnrs, det_cnrs = fov.corners plt.plot(sky_cnrs[0], sky_cnrs[1]) plt.show() r = np.arange(-25, 25) x, y = np.meshgrid(r, r) x = x.flatten() * u.arcsec y = y.flatten() * u.arcsec ref = [0] * len(x) weight = [1] * len(x) spec = sp.SourceSpectrum(sp.Empirical1D, points=[0.5, 3.0] * u.um, lookup_table=[1e3, 1e3] * u.Unit("ph s-1 m-2 um-1")) src = Source(x=x, y=y, ref=ref, weight=weight, spectra=[spec]) opt.observe(src) if PLOTS: plt.imshow(opt.image_plane.image.T, origin="lower", norm=LogNorm()) plt.colorbar() plt.show()
def test_flux_is_conserved_for_no_bg_emission(self, cmds, tbl_src): opt = OpticalTrain(cmds) opt.observe(tbl_src) im = opt.image_planes[0].image bg_flux = np.pi / 4 * np.prod(im.shape) src_flux = tbl_src.photons_in_range(1, 2, 1)[0].value if PLOTS: implane = opt.image_planes[0] plt.imshow(implane.image.T, origin="lower", norm=LogNorm()) plt.colorbar() plt.show() # given a 1 um bandpass print(src_flux, bg_flux) area = opt.optics_manager.surfaces_table.area.value assert src_flux == approx(1) # u.Unit("ph s-1") assert np.sum(im) == approx(src_flux * area, rel=2e-3)
def test_flux_is_conserved_for_yes_bg_emission(self, non_unity_cmds, tbl_src): """ # originally all has 1 count. atmo TC=0.9, mirror TC=0.5. Hence: # 0.5 counts from atmo, 1 count from mirror, 0.45 count from source """ opt = OpticalTrain(non_unity_cmds) opt.observe(tbl_src) im = opt.image_planes[0].image src_flux = tbl_src.photons_in_range(1, 2, 1)[0].value if PLOTS: implane = opt.image_planes[0] plt.imshow(implane.image.T, origin="lower", norm=LogNorm()) plt.colorbar() plt.show() # given a 1 um bandpass assert src_flux == approx(1) # u.Unit("ph s-1") assert np.max(im) - np.median(im) == approx(0.45, rel=1e-2) assert np.median(im) == approx(1.5, abs=1e-2)
def test_observe_works_for_many_sources_distributed(self, cmds, im_src): orig_sum = np.sum(im_src.fields[0].data) im_src.fields[0].data += 1 im_src1 = deepcopy(im_src) im_src2 = deepcopy(im_src) im_src2.shift(7, 7) im_src3 = deepcopy(im_src) im_src3.shift(-10, 14) im_src4 = deepcopy(im_src) im_src4.shift(-4, -6) im_src5 = deepcopy(im_src) im_src5.shift(15, -15) multi_img = im_src1 + im_src2 + im_src3 + im_src4 + im_src5 cmds["SIM_PIXEL_SCALE"] = 0.02 opt = OpticalTrain(cmds) opt.observe(multi_img) implane = opt.image_planes[0] final_sum = np.sum(implane.image) print(orig_sum, final_sum) if PLOTS: for fov in opt.fov_manager.fovs: cnrs = fov.corners[1] plt.plot(cnrs[0], cnrs[1]) plt.imshow(implane.image.T, origin="lower", norm=LogNorm(), extent=( -implane.hdu.header["NAXIS1"] / 2, implane.hdu.header["NAXIS1"] / 2, -implane.hdu.header["NAXIS2"] / 2, implane.hdu.header["NAXIS2"] / 2, )) plt.colorbar() plt.show()
def test_readout_works_when_source_observed(self, unity_cmds, unity_src): opt = OpticalTrain(unity_cmds) opt.observe(unity_src) hdus = opt.readout() hdu = hdus[0] if PLOTS: plt.subplot(221) plt.imshow(unity_src.fields[0].data) plt.colorbar() plt.subplot(222) plt.imshow(opt.image_planes[0].image) plt.colorbar() plt.subplot(223) plt.imshow(hdu[1].data) plt.colorbar() plt.show() src_average = np.average(unity_src.fields[0].data) assert np.average(hdu[1].data) == approx(np.pi / 4., rel=1e-3)