def _basic_fov():
    src = _image_source()
    fov = FieldOfView(_basic_fov_header(),
                      waverange=[1, 2] * u.um,
                      area=1 * u.m**2)
    fov.extract_from(src)

    return fov
Пример #2
0
    def test_contains_cube_when_passed_a_cube_source(self, basic_fov_header,
                                                     cube_source):
        src = cube_source
        the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
        the_fov.extract_from(src)

        assert len(the_fov.fields) == 1
        assert len(the_fov.spectra) == 0
        assert len(the_fov.fields[0].data.shape) == 3
Пример #3
0
    def test_ignores_fields_outside_fov_boundary(self, basic_fov_header):

        src = _combined_source(dx=[200, 200, 200])
        src.fields[0]["x"] += 200

        the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
        the_fov.extract_from(src)

        assert len(the_fov.fields) == 0
Пример #4
0
    def test_nothing_happens_if_apply_to_fov(self, fov_hdr):
        fov = FieldOfView(header=fov_hdr,
                          waverange=[0.5, 2.5],
                          area=1 * u.m**2)
        fov.view()
        fov.hdu.data = np.zeros((11, 11))
        fov.hdu.data[5, 5] = 1
        vibration = Vibration(**{"fwhm": 0.01, "pixel_scale": 0.004})
        vibration.apply_to(fov)

        assert fov.hdu.data[5, 5] == 1
Пример #5
0
 def test_contains_all_fields_inside_fov(self, basic_fov_header,
                                         cube_source, image_source,
                                         table_source):
     src = image_source + cube_source + table_source
     the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
     the_fov.extract_from(src)
     assert len(the_fov.fields) == 3
     assert isinstance(the_fov.fields[0], fits.ImageHDU)
     assert isinstance(the_fov.fields[1], fits.ImageHDU)
     assert the_fov.fields[1].header["NAXIS"] == 3
     assert isinstance(the_fov.fields[2], Table)
Пример #6
0
    def test_views_with_only_table(self, basic_fov_header):
        src = _table_source()
        fluxes = src.photons_in_range(1 * u.um, 2 * u.um)
        phs = fluxes[src.fields[0]["ref"]] * src.fields[0]["weight"]

        the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
        the_fov.extract_from(src)
        view = the_fov.view()

        assert np.sum(view) == np.sum(phs).value - 4

        if PLOTS:
            plt.imshow(view.T, origin="lower", norm=LogNorm())
            plt.colorbar()
            plt.show()
Пример #7
0
def _centre_fov(n=55, waverange=(1.0, 2.0)):
    xsky = np.array([-n, n]) * u.arcsec.to(u.deg)
    ysky = np.array([-n, n]) * u.arcsec.to(u.deg)
    sky_hdr = imp_utils.header_from_list_of_xy(xsky, ysky, 1/3600.)
    imp_hdr = imp_utils.header_from_list_of_xy([-n, n], [-n, n], 1, "D")
    imp_hdr.update(sky_hdr)
    fov = FieldOfView(imp_hdr, waverange=waverange*u.um, area=1*u.m**2)

    return fov
Пример #8
0
def _centre_micado_fov(n=128, waverange=(1.9, 2.4)):
    """ n [arcsec] """
    xsky = np.array([-n, n]) * u.arcsec.to(u.deg)
    ysky = np.array([-n, n]) * u.arcsec.to(u.deg)
    pixscale = 0.004/3600.
    sky_hdr = imp_utils.header_from_list_of_xy(xsky, ysky, pixscale)
    imp_hdr = imp_utils.header_from_list_of_xy([-n, n], [-n, n], pixscale, "D")
    imp_hdr.update(sky_hdr)
    fov = FieldOfView(imp_hdr, waverange=waverange*u.um, area=1*u.m**2)

    return fov
Пример #9
0
    def test_views_with_tables_and_images(self, basic_fov_header):
        src = _combined_source(im_angle=0,
                               weight=[1, 1, 1],
                               dx=[-2, 0, 0],
                               dy=[2, 2, 0])
        ii = src.fields[3].header["SPEC_REF"]
        flux = src.photons_in_range(1 * u.um, 2 * u.um, indexes=[ii]).value
        orig_sum = np.sum(src.fields[3].data) * flux

        the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
        the_fov.extract_from(src)
        view = the_fov.view()

        assert np.isclose(np.sum(the_fov.fields[1].data), orig_sum)
        assert np.isclose(np.sum(view), orig_sum + 36)
        assert np.sum(the_fov.fields[0]["flux"]) == approx(36)

        if PLOTS:
            plt.imshow(view.T, origin="lower", norm=LogNorm())
            plt.colorbar()
            plt.show()
Пример #10
0
    def test_views_with_rotated_image(self, basic_fov_header):
        area = 1 * u.m**2

        # works for angle=0, not working for angle!=0
        src = _image_source(angle=30)
        flux = src.photons_in_range(1 * u.um, 2 * u.um, area=area).value
        in_sum = np.sum(src.fields[0].data) * flux

        the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=area)
        the_fov.extract_from(src)
        view = the_fov.view()
        out_sum = np.sum(view)

        assert out_sum == approx(in_sum, rel=1e-3)

        if PLOTS:
            plt.subplot(121)
            plt.imshow(src.fields[0].data, origin="lower", norm=LogNorm())
            plt.colorbar()

            plt.subplot(122)
            plt.imshow(view, origin="lower", norm=LogNorm())
            plt.colorbar()
            plt.show()
    def test_can_extract_the_source_in_a_fov(self, fov_hdr, comb_src,
                                             implane_hdr):

        from scipy.ndimage.interpolation import zoom
        comb_src.fields[3].data = zoom(comb_src.fields[3].data, (1.5, 1),
                                       order=1)
        print(comb_src.fields[3].data.shape)
        print(dict(comb_src.fields[3].header))

        # angle = 30
        # deg2rad = 3.1415926 / 180
        # comb_src.fields[3].header["PC1_1"] = np.cos(angle * deg2rad)
        # comb_src.fields[3].header["PC1_2"] = np.sin(angle * deg2rad)
        # comb_src.fields[3].header["PC2_1"] = -np.sin(angle * deg2rad)
        # comb_src.fields[3].header["PC2_2"] = np.cos(angle * deg2rad)

        as2deg = u.arcsec.to(u.deg)

        fov = FieldOfView(fov_hdr, waverange=[0.5, 2.5] * u.um)
        fov.hdu.header["CRVAL1"] += 1.5 * as2deg
        fov.hdu.header["CRVAL2"] -= 1.5 * as2deg
        fov.hdu.header["CRVAL1D"] += 30
        fov.hdu.header["CRVAL2D"] -= 30

        imp = ImagePlane(implane_hdr)
        fov.extract_from(comb_src)
        fov.view()
        imp.add(fov.hdu, wcs_suffix="D")

        ipt = np.sum(fov.fields[0]["flux"]) + np.sum(fov.fields[1].data)
        opt = np.sum(imp.image)

        assert ipt == approx(opt)

        if PLOTS:
            plt.subplot(131)
            plt.imshow(comb_src.fields[3].data.T,
                       origin="lower",
                       norm=LogNorm())

            plt.subplot(132)
            plt.imshow(fov.image.T, origin="lower", norm=LogNorm())

            plt.subplot(133)
            plt.imshow(imp.image.T, origin="lower", norm=LogNorm())
            plt.show()
Пример #12
0
    def test_views_with_only_image(self, basic_fov_header):
        src = _image_source()
        flux = src.photons_in_range(1 * u.um, 2 * u.um).value
        orig_sum = np.sum(src.fields[0].data * flux)

        the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
        the_fov.extract_from(src)
        the_fov.view()

        assert np.isclose(np.sum(the_fov.hdu.data), orig_sum)

        if PLOTS:
            plt.imshow(src.fields[0].data, origin="lower", norm=LogNorm())
            plt.colorbar()
            plt.show()

            plt.imshow(the_fov.hdu.data, origin="lower", norm=LogNorm())
            plt.colorbar()
            plt.show()
    def test_can_extract_the_source_in_a_fov(self, fov_hdr, comb_src,
                                             implane_hdr):

        fov = FieldOfView(fov_hdr,
                          waverange=[0.5, 2.5] * u.um,
                          area=1 * u.m**2)
        imp = ImagePlane(implane_hdr)

        fov.extract_from(comb_src)
        fov.view()
        imp.add(fov.hdu, wcs_suffix="D")

        assert np.sum(imp.image) > 0

        if PLOTS:
            plt.subplot(131)
            plt.imshow(comb_src.fields[3].data, origin="lower", norm=LogNorm())

            plt.subplot(132)
            plt.imshow(fov.hdu.data, origin="lower", norm=LogNorm())

            plt.subplot(133)
            plt.imshow(imp.hdu.data, origin="lower", norm=LogNorm())
            plt.show()
Пример #14
0
def _fov_190_210_um():
    """ A FOV compatible with 11 slices of so._cube_source()"""
    hdr = ho._fov_header()  # 20x20" @ 0.2" --> [-10, 10]"
    wav = [1.9, 2.1] * u.um
    fov = FieldOfView(hdr, wav, area=1 * u.m ** 2)
    return fov
Пример #15
0
def _fov_197_202_um():
    """ A FOV compatible with 3 slices of so._cube_source()"""
    hdr = ho._fov_header()  # 20x20" @ 0.2" --> [-10, 10]"
    wav = [1.97000000001, 2.02] * u.um  # Needs [1.98, 2.00, 2.02] µm --> 3 slices
    fov = FieldOfView(hdr, wav, area=1*u.m**2)
    return fov
Пример #16
0
 def test_throws_error_if_no_wcs_in_header(self):
     with pytest.raises(ValueError):
         FieldOfView(fits.Header(), (1, 2) * u.um, area=1 * u.m**2)
Пример #17
0
 def test_initialises_with_header_and_waverange(self, basic_fov_header):
     print(dict(basic_fov_header))
     the_fov = FieldOfView(basic_fov_header, (1, 2) * u.um, area=1 * u.m**2)
     assert isinstance(the_fov, FieldOfView)
Пример #18
0
 def test_initialises_with_nothing_raise_error(self):
     with pytest.raises(TypeError):
         FieldOfView()
Пример #19
0
 def test_initialises_with_header_and_waverange(self):
     hdr = _fov_190_210_um().header
     the_fov = FieldOfView(hdr, (1, 2)*u.um, area=1*u.m**2)
     assert isinstance(the_fov, FieldOfView)