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
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()
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_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()
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()
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()
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()