Exemplo n.º 1
0
    def test_something_comes_out_img_n(self):
        """Basic test for N imaging"""
        src = star_field(100, 0, 10, width=10, use_grid=True)

        cmds = scopesim.UserCommands(use_instrument="METIS",
                                     set_modes=["img_n"])

        metis = scopesim.OpticalTrain(cmds)
        metis['chop_nod'].include = False
        #metis['detector_linearity'].include = False

        metis.observe(src)
        hdus = metis.readout()

        im = metis.image_planes[0].data
        mx, med, std = np.max(im), np.median(im), np.std(im)

        if PLOTS:
            for i, img in enumerate([metis.image_planes[0].data,
                                     hdus[0][1].data]):
                plt.subplot(1, 2, i+1)
                med = np.median(img)
                plt.imshow(img, vmin=0.7*med, vmax=1.3*med, norm=LogNorm())
                plt.title("LM Imaging Test")
                plt.colorbar()
            plt.show()

        assert mx > med + 3 * std
Exemplo n.º 2
0
    def test_get_lim_mags_for_micado(self):
        dit, ndit = 3.6, 5000
        filter_name = "Ks"
        bg_mag = 13.6

        from scopesim.source.source_templates import star_field
        src = star_field(8 * 8, 26, 33, 3, use_grid=True)
        cmd = scopesim.UserCommands(use_instrument="MICADO",
                                    properties={
                                        "!OBS.filter_name": filter_name,
                                        "!OBS.dit": dit,
                                        "!OBS.ndit": ndit
                                    })
        opt = scopesim.OpticalTrain(cmd)
        opt["armazones_atmo_dispersion"].include = False
        opt["micado_adc_3D_shift"].include = False
        opt["detector_linearity"].include = False
        opt["detector_window"].include = True
        opt["full_detector_array"].include = False

        new_kwargs = {
            "rescale_emission": {
                "filter_name": filter_name,
                "filename_format": "filters/TC_filter_{}.dat",
                "value": bg_mag,
                "unit": "mag"
            }
        }
        opt["armazones_atmo_default_ter_curve"] = new_kwargs

        opt.observe(src)
        hdus = opt.readout()
        # hdus = opt.readout(filename=f"test_{dit}s.fits")

        print(opt.effects)

        image = hdus[0][1].data
        pixel_scale = opt.cmds["!INST.pixel_scale"]
        xs = src.fields[0]["x"] / pixel_scale + image.shape[1] / 2
        ys = src.fields[0]["y"] / pixel_scale + image.shape[1] / 2

        if PLOTS:
            plt.imshow(image, norm=LogNorm())
            # plt.plot(xs, ys, "r.")
            plt.show()

            snr = get_snr(xs=xs,
                          ys=ys,
                          image=hdus[0][1].data,
                          inner=5,
                          outer=10)
            plt.plot(src.fields[0]["weight"], snr)
            plt.show()
Exemplo n.º 3
0
    def test_get_lim_mags_for_micado(self):
        dit, ndit = 60, 60 * 5
        filter_name = "J"
        bg_mag = 16.5

        from scopesim.source.source_templates import star_field
        src = star_field(10**2, 20, 30, 1.8, use_grid=True)
        cmd = scopesim.UserCommands(use_instrument="MICADO",
                                    properties={
                                        "!OBS.filter_name": filter_name,
                                        "!OBS.dit": dit,
                                        "!OBS.ndit": ndit,
                                        "!ATMO.background.magnitude": bg_mag,
                                        "!ATMO.background.filter_name":
                                        filter_name
                                    })
        opt = scopesim.OpticalTrain(cmd)
        for el in opt["micado_detector_array"]["detector_linearity"]:
            el.include = False
        for el in opt["micado_detector_array"]["full_detector_array"]:
            el.include = False
        # "armazones_atmo_dispersion" # not enabled anyway
        # "micado_adc_3D_shift"
        opt["detector_window"].include = True
        opt.update()

        # new_kwargs = {"rescale_emission": {"filter_name": filter_name,
        #                                    "filename_format": "filters/TC_filter_{}.dat",
        #                                    "value": bg_mag,
        #                                    "unit": "mag"}}
        # opt["armazones_atmo_default_ter_curve"] = new_kwargs
        # TODO: is the below the same as the above?
        opt["armazones"].properties["background"]["filter_name"] = "J"

        opt.observe(src)
        hdus = opt.readout()
        # hdus[0][1].data = hdus[0][1].data[256:-256, 256:-256]
        # hdus[0].writeto(f"TEST_{filter_name}.fits", overwrite=True)

        image = hdus[0][1].data  #[350:700, 300:700]
        pixel_scale = opt.cmds["!INST.pixel_scale"]
        xs = src.fields[0]["x"] / pixel_scale + image.shape[1] / 2
        ys = src.fields[0]["y"] / pixel_scale + image.shape[1] / 2

        if PLOTS:
            plt.imshow(
                image,  #norm=LogNorm(),
                vmin=0.9999 * np.median(image),
                vmax=1.01 * np.median(image))
            plt.show()
    def test_basic_run_makes_image(self):
        src = star(flux=0)
        src = star_field(100, 0, 20, 10, use_grid=True)
        cmd = sim.UserCommands(use_instrument="METIS", set_modes=["img_lm"])
        metis = sim.OpticalTrain(cmd)
        metis['detector_linearity'].include = False
        # metis['metis_psf_img'].include = False

        metis.observe(src)
        img = metis.image_planes[0].data
        hdus = metis.readout()
        img = hdus[0][1].data

        assert np.median(img) > 0

        if not PLOTS:
            plt.imshow(img, norm=LogNorm())
            plt.show()
Exemplo n.º 5
0
    def test_something_comes_out(self):
        src = star_field(100, 0, 10, width=360, use_grid=True)

        cmds = scopesim.UserCommands(use_instrument="ViennaLT")
        cmds["!OBS.dit"] = 300
        cmds["!OBS.ndit"] = 1
        cmds["!OBS.filter_name"] = "sloan_z"

        lfoa = scopesim.OpticalTrain(cmds)
        lfoa.observe(src)
        hdus = lfoa.readout()

        if PLOTS:
            plt.subplot(121)
            wave = np.arange(3000, 11000)
            plt.plot(wave, lfoa.optics_manager.surfaces_table.throughput(wave))

            plt.subplot(122)
            im = hdus[0][1].data
            plt.imshow(im, norm=LogNorm())
            plt.colorbar()

            plt.show()
Exemplo n.º 6
0
 def test_star_fiels_data(self):
     src = src_ts.star_field(100, 15, 25, 60)
     assert isinstance(src.fields[0], Table)
     assert all(src.fields[0]["weight"] == 10**(-0.4 *
                                                src.fields[0]["mag"]))
Exemplo n.º 7
0
 def test_star_field_throws_error_with_no_kwargs(self):
     with pytest.raises(TypeError):
         src_ts.star_field()
Exemplo n.º 8
0
 def test_star_field_return_source_object(self):
     src = src_ts.star_field(100, 15, 25, 60)
     assert isinstance(src, Source)
Exemplo n.º 9
0
 def test_makes_grid_for_jansky_flux(self):
     src = src_ts.star_field(4, 3631 * u.Jy, 36.31 * u.Jy, 1)
     assert src.fields[0]["weight"][0] == approx(1, rel=0.01)
     assert src.fields[0]["weight"][-1] == approx(0.01, rel=0.01)