def test_instrument_throughput_without_atmospheric_bg(self): cmd = sim.UserCommands(use_instrument="METIS", set_modes=["img_lm"]) metis = sim.OpticalTrain(cmd) metis["skycalc_atmosphere"].include = True src = empty_sky() metis.observe(src) img = metis.image_planes[0].data plt.imshow(img) plt.show()
def test_background_level_is_around_roys_level(self, filter_name, expected_phs): src = empty_sky() cmd = sim.UserCommands(use_instrument="METIS", set_modes=["img_lm"]) cmd["!OBS.filter_name"] = filter_name metis = sim.OpticalTrain(cmd) metis['detector_linearity'].include = False metis.observe(src) img = metis.image_planes[0].data assert np.median(img) == approx(expected_phs, rel=0.1)
def test_flux_scales_with_pixel_scale(self, filter_name, bg_level): yaml_text = YAML_TEXT % (WAVE_MIN, WAVE_MAX, PIXEL_SCALE, PIXEL_SCALE, filter_name) yamls = [yml for yml in yaml.full_load_all(yaml_text)] cmd = sim.UserCommands(yamls=yamls) opt = sim.OpticalTrain(cmd) opt.cmds["!TEL.area"] = 1 * u.m**2 src = empty_sky() opt.observe(src) img = opt.image_planes[0].data # Ks band photon flux is 1026 ph/s/m2/arcsec2 assert np.median(img) == pytest.approx(bg_level, rel=0.01)
def test_print_background_contributions(self): cmd = sim.UserCommands(use_instrument="METIS", set_modes=["img_lm"]) metis = sim.OpticalTrain(cmd) metis["psf"].include = False metis.observe(empty_sky()) if PLOTS: plt.figure(figsize=(10, 5)) fov = metis.fov_manager.fovs[0] for field in fov.fields[1:]: spec = fov.spectra[field.header["SPEC_REF"]] wave = spec.waveset plt.plot(wave, spec(wave), label=field.header["BG_SURF"]) plt.legend() plt.show()
def test_flux_scales_with_pixel_scale(self, pixel_scale): yaml_text = YAML_TEXT % (wave_min, wave_max, pixel_scale, pixel_scale, filter_name) yamls = [yml for yml in yaml.full_load_all(yaml_text)] cmd = sim.UserCommands(yamls=yamls) opt = sim.OpticalTrain(cmd) opt.cmds["!TEL.area"] = 1 * u.m**2 src = empty_sky() opt.observe(src) img = opt.image_planes[0].data # Ks band photon flux is 1014 ph/s/m2/arcsec2 assert np.median(img) == pytest.approx(1014 * pixel_scale**2, rel=0.01) if PLOTS: plt.imshow(img) plt.show()
def test_integrated_spec_bg_equals_img_bg(self): src = empty_sky() toggle_effects = [ # "skycalc_atmosphere", # "telescope_reflection", # "common_fore_optics", # "metis_img_lm_mirror_list", # "quantum_efficiency", # "psf", ] cmds_img = sim.UserCommands(use_instrument="METIS", set_modes=["img_lm"]) cmds_img["!SIM.spectral.wave_min"] = 3.5 cmds_img["!SIM.spectral.wave_max"] = 4.0 metis_img = sim.OpticalTrain(cmds_img) for eff in toggle_effects: metis_img[eff].include = False metis_img.observe(src) img = metis_img.image_planes[0].data cmds_lss = sim.UserCommands(use_instrument="METIS", set_modes=["lss_l"]) cmds_lss["!SIM.spectral.wave_min"] = 3.5 cmds_lss["!SIM.spectral.wave_max"] = 4.0 metis_lss = sim.OpticalTrain(cmds_lss) for eff in toggle_effects: metis_lss[eff].include = False metis_lss.observe(src) lss = metis_lss.image_planes[0].data img_med = np.median(img) lss_med = np.median(np.sum(lss, axis=0)) # 7x because we need to sum up the overlapping slice images # and the slit is 7 pixels wide assert 7 * img_med == approx(lss_med, rel=0.05)
def skycalc_plus_eso_filter_gives_similar_photons_flux_to_ohio(): """ ohio: http://www.astronomy.ohio-state.edu/~martini/usefuldata.html skycalc: https://www.eso.org/observing/etc/doc/skycalc/helpskycalc.html#mags - Use the skycalc background spectrum - Multiply it by a filter curve - Sum up the photons - Divide by FWHM - Rescale to zero mag using skycalc backgorund magnitude """ paranal_bg_mags = { "U": 20.76, "B": 21.14, "V": 20.67, "R": 20.32, "I": 19.48, "Z": 18.67, "Y": 17.58, "J": 16.87, "H": 14.43, "K": 15.23, "L": 6.00, "M": 1.14, "N": -2.29, "Q": -7.27 } ohio_zero_ph = { "U": 756, "B": 1393, "V": 996, "R": 702, "I": 452, "J": 193, "H": 93, "K": 43.6 } # ph s-1 cm-2 angstrom-1 ohio_fwhm = { "U": 0.06, "B": 0.09, "V": 0.085, "R": 0.15, "I": 0.15, "J": 0.26, "H": 0.29, "K": 0.41 } # micron for filt_name in ohio_zero_ph: # load the sky background curve and the filter print(filt_name) skycalc_file = "eso_skycalc_r_6000_wave_0.3_15nm_airmass_1_pwv_2.5.dat" filter_file = f"eso_etc_filter_{filt_name}.dat" atmo_ter = AtmosphericTERCurve(filename=skycalc_file) filt_ter = FilterCurve(filename=filter_file) print(filt_ter.fwhm, filt_ter.centre) # get skycalc bg flux src = empty_sky() src = atmo_ter.apply_to(src) src = filt_ter.apply_to(src) wave = np.arange(0.2, 2.5, 0.0001) * u.um flux = src.spectra[1](wave) # report normalised flux ratio in ph s-1 cm-2 angstrom-1 arcsec-2 ph = np.trapz(flux, wave) / filt_ter.fwhm.to(u.AA) ph = ph.to("ph s-1 cm-2 angstrom-1") ph_zero_mag = ph / 10**(-0.4 * paranal_bg_mags[filt_name]) ohio_ph = ohio_zero_ph[filt_name] print("Sky BG:", ph) print(f"Zero mag normalised flux [{ph_zero_mag.unit}]:", "Ohio:", ohio_zero_ph[filt_name], "ESO:", ph_zero_mag.value) print("Ratio:", ph_zero_mag.value / ohio_ph) # report absolute flux ratio in ph s-1 cm-2 arcsec-2 (per filter bandpass) ph = np.trapz(flux, wave) ph = ph.to("ph s-1 cm-2") ph_zero_mag = ph / 10**(-0.4 * paranal_bg_mags[filt_name]) ohio_ph = ohio_zero_ph[filt_name] * ohio_fwhm[filt_name] * 1e4 print("Sky BG:", ph) print(f"Zero mag absolute flux [{ph_zero_mag.unit}]:", "Ohio:", ohio_ph, "ESO:", ph_zero_mag.value) print("Ratio:", ph_zero_mag.value / ohio_ph)