def test_fill_frac_acts_correctly(self, imageplane): fill_1 = 1. fill_2 = 0.5 autoexp_1 = AutoExposure(fill_frac=fill_1, full_well=1e5, mindit=0.011) rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": 1, "!OBS.dit": None, "!OBS.ndit": None }) autoexp_1.apply_to(imageplane) out_dit_1 = from_currsys("!OBS.dit") out_ndit_1 = from_currsys("!OBS.ndit") autoexp_2 = AutoExposure(fill_frac=fill_2, full_well=1e5, mindit=0.011) rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": 1, "!OBS.dit": None, "!OBS.ndit": None }) autoexp_2.apply_to(imageplane) out_dit_2 = from_currsys("!OBS.dit") out_ndit_2 = from_currsys("!OBS.ndit") assert out_dit_1 == fill_1 / fill_2 * out_dit_2 assert out_ndit_1 == fill_2 / fill_1 * out_ndit_2
def test_exptime_specified_by_dit_ndit(self, autoexposure, imageplane): """ Test that exptime can be given by `!OBS.dit` and `!OBS.ndit` instead of `!OBS.exptime`. """ # 1. use exptime rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": 10, "!OBS.dit": None, "!OBS.ndit": None }) autoexposure.apply_to(imageplane) dit_1 = from_currsys("!OBS.dit") ndit_1 = from_currsys("!OBS.ndit") # 2. use dit and ndit rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": None, "!OBS.dit": 5, "!OBS.ndit": 2 }) autoexposure.apply_to(imageplane) dit_2 = from_currsys("!OBS.dit") ndit_2 = from_currsys("!OBS.ndit") assert dit_1 == dit_2 assert ndit_1 == ndit_2
def test_sub_pixels_integration(): yaml = { "alias": "DET", "effects": [ { "class": "DetectorWindow", "kwargs": { "pixel_size": 0.015, "x": 0, "y": 0, "width": 0.165 } }, ] } properties = { "!SIM.sub_pixel.flag": True, "!SIM.sub_pixel.fraction": 0.001, "!INST.pixel_scale": 0.0015, "!INST.plate_scale": 0.1 } cmd = UserCommands(yamls=[yaml], properties=properties) opt = OpticalTrain(cmd) opt.cmds["!TEL.area"] = 1 * u.m**2 src = so._vega_source(mag=15, x=0.001, y=0.) opt.observe(src) plt.imshow(opt.image_planes[0].data, origin="lower") plt.show()
def test_returns_imageplane(self, autoexposure, imageplane): rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": 1., "!OBS.dit": None, "!OBS.ndit": None }) outimpl = autoexposure.apply_to(imageplane) assert isinstance(outimpl, ImagePlane)
def test_detects_saturation(self, imageplane): mindit = 0.011 rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": 100., "!OBS.dit": None, "!OBS.ndit": None }) autoexposure = AutoExposure(fill_frac=0.75, full_well=10., mindit=mindit) autoexposure.apply_to(imageplane) out_dit = from_currsys("!OBS.dit") assert out_dit == mindit
def test_exptime_at_least_mindit(self, imageplane): exptime = 1 mindit = 1.3 # requested exptime smaller than mindit autoexposure = AutoExposure(fill_frac=0.75, full_well=1e5, mindit=mindit) rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": exptime, "!OBS.dit": None, "!OBS.ndit": None }) autoexposure.apply_to(imageplane) dit = from_currsys("!OBS.dit") ndit = from_currsys("!OBS.ndit") assert dit == mindit assert ndit == 1
def test_produces_correct_values(self, autoexposure, imageplane): in_dit = 50 in_ndit = 3 exptime = in_dit * in_ndit # TODO: Change AutoExposure to read exptime like dit and ndit rc.__currsys__ = UserCommands(properties={ "!OBS.exptime": exptime, "!OBS.dit": None, "!OBS.ndit": None }) # imageplane has 1e5 e/s, full_well is 1e5 e. To fill to 75% need: ref_dit = 0.75 autoexposure.apply_to(imageplane) out_dit = from_currsys("!OBS.dit") out_ndit = from_currsys("!OBS.ndit") assert out_dit == pytest.approx(ref_dit) assert out_dit * out_ndit == pytest.approx(exptime)
def test_full_run_through(self): src1 = so._vega_source(mag=20) src2 = so._vega_source(mag=22) src3 = so._vega_source(mag=25) src2.fields[0]["x"][0] += 1 src3.fields[0]["x"][0] -= 1 src = src1 + src2 + src3 cmd = UserCommands(yamls=["MICADO_SPEC.yaml"]) opt = OpticalTrain(cmd) assert isinstance(opt, OpticalTrain) opt.observe(src) # opt.readout(filename="temp_speclecado.fits") # opt.image_planes[0].hdu.writeto("temp_implane.fits", overwrite=True) if PLOTS: plt.imshow(opt.image_planes[0].data, origin="lower", norm=LogNorm()) plt.show()