Exemplo n.º 1
0
    def test_returns_proper_shear_and_rotation_for_square(
            self, rot_ang, shear_ang):
        x0 = -np.ones(5)
        x1 = np.ones(5)
        y0 = np.arange(5)
        y1 = np.arange(5)

        t = np.tan(shear_ang / 57.29578)
        x0 = x0 + t * y0
        x1 = x1 + t * y1

        c = np.cos(rot_ang / 57.29578)
        s = np.sin(rot_ang / 57.29578)
        x0a = c * x0 + -s * y0
        y0a = s * x0 + c * y0
        x1a = c * x1 + -s * y1
        y1a = s * x1 + c * y1

        coords = {"x": np.array([x0a, x1a]), "y": np.array([y0a, y1a])}
        rot, shear = get_affine_parameters(coords)

        assert np.average(rot) == approx(rot_ang, abs=1e-5)
        assert -np.average(shear) == approx(shear_ang, abs=1e-5)
        # ..todo:: work out why this is negative? Definitionssache?

        if PLOTS:
            plt.figure(figsize=(6, 6))
            plt.plot(coords["x"][0], coords["y"][0])
            plt.plot(coords["x"][-1], coords["y"][-1])
            plt.xlim(-5, 5)
            plt.ylim(-5, 5)
            plt.show()
Exemplo n.º 2
0
def test_all_zero_spectra_line_up():
    mag = 0
    vega = src_ts.vega_spectrum(mag)
    ab = src_ts.ab_spectrum(mag)
    st = src_ts.st_spectrum(mag)

    wave = 0.55 * u.um
    assert st(wave).value == approx(vega(wave).value, rel=0.03)
    assert ab(wave).value == approx(vega(wave).value, rel=0.03)
Exemplo n.º 3
0
 def _remove_unwanted_precision(self, want: str, got: str) -> str:
     wants = list(self._number_re.finditer(want))
     gots = list(self._number_re.finditer(got))
     if len(wants) != len(gots):
         return got
     offset = 0
     for w, g in zip(wants, gots):
         fraction: Optional[str] = w.group("fraction")
         exponent: Optional[str] = w.group("exponent1")
         if exponent is None:
             exponent = w.group("exponent2")
         if fraction is None:
             precision = 0
         else:
             precision = len(fraction)
         if exponent is not None:
             precision -= int(exponent)
         if float(w.group()) == approx(float(g.group()), abs=10 ** -precision):
             # They're close enough. Replace the text we actually
             # got with the text we want, so that it will match when we
             # check the string literally.
             got = (
                 got[: g.start() + offset] + w.group() + got[g.end() + offset :]
             )
             offset += w.end() - w.start() - (g.end() - g.start())
     return got
Exemplo n.º 4
0
    def test_dispersion_for_horizontally_aligned_trace(self, horizontal_trace):
        spt = SpectralTrace(horizontal_trace)
        disp, wave = spt.get_max_dispersion()
        dx = np.abs(np.diff(horizontal_trace["x"]))
        dw = np.abs(np.diff(horizontal_trace["wavelength"]))

        assert np.average(disp) == approx(np.average(dx / dw), rel=1e-5)
Exemplo n.º 5
0
 def test_diagonal_headers_are_all_one_pixel_apart(self, horizontal_trace):
     spt = SpectralTrace(horizontal_trace)
     pixel_size = 0.015
     hdrs = spt.get_curve_headers(pixel_size)
     x = [hdr["CRVAL1D"] / pixel_size for hdr in hdrs]
     y = [hdr["CRVAL2D"] / pixel_size for hdr in hdrs]
     assert np.all(np.abs(np.diff(x)) == approx(1, rel=1e-5))
Exemplo n.º 6
0
    def test_combined_shifts_reduced_to_usable_number(self, sub_pix_frac):
        ad_am_1_05 = eo._atmospheric_dispersion(airmass=1.05)
        ad_am_neg_1_04 = eo._atmospheric_dispersion(airmass=-1.04)
        shifts = fm_utils.get_3d_shifts([ad_am_1_05, ad_am_neg_1_04],
                                        pixel_scale=0.004,
                                        sub_pixel_fraction=sub_pix_frac)

        assert len(shifts["y_shifts"]) == approx(10 / sub_pix_frac, rel=0.2)
Exemplo n.º 7
0
    def test_mtc_one_pixel_apart_for_diagonal_traces(self, diagonal_trace):
        pixel_size = 0.015
        spt = SpectralTrace(diagonal_trace)
        disp, wave = spt.get_max_dispersion()
        wave_edges = spt.get_pixel_wavelength_edges(pixel_size)  # wavelength edges
        dist_between_mtc = np.average(disp) * np.average(np.diff(wave_edges))

        assert dist_between_mtc == approx(pixel_size, rel=1e-5)
Exemplo n.º 8
0
    def test_monochromatic_trace_curves_are_one_pixel_apart(self, basic_trace):
        pixel_size = 0.015
        spt = SpectralTrace(basic_trace)
        disp, wave = spt.get_max_dispersion()
        wbedges = spt.get_pixel_wavelength_edges(pixel_size)     # wavelength edges
        dist_between_mtc = np.average(disp) * np.average(np.diff(wbedges))

        assert dist_between_mtc == approx(pixel_size, rel=1e-5)
Exemplo n.º 9
0
def test_numba_mult_vec(data):
    A = data.draw(csrs())
    vals = st.floats(-100, 100)
    x = data.draw(nph.arrays(np.float64, A.ncols, elements=vals))

    y = _mult_vec(A, x)

    assert y.shape == (A.nrows,)
    assert y == approx(A.to_scipy() @ x, nan_ok=True, rel=1.0e-5)
Exemplo n.º 10
0
 def test_dispersion_for_vertically_aligned_trace(self, basic_trace):
     # ..todo: accuracy of get_max_dispersion should be tested in a trace_list_utils tests file
     spt = SpectralTrace(basic_trace)
     disp, wave = spt.get_max_dispersion()
     # dispersion is calculated by distance [mm] / wavelength coverage [um]
     dy = np.diff(basic_trace["y"])
     dw = np.diff(basic_trace["wavelength"])
     assert np.average(disp) == approx(np.average(dy / dw), rel=1e-5)
     assert len(disp) == len(wave)
     assert all(np.diff(wave) > 0)
Exemplo n.º 11
0
    def test_mtc_distances_are_one_pixel_horiz_trace(self, horizontal_trace):
        spt = SpectralTrace(horizontal_trace)
        mtcs = spt.get_trace_curves(0.015)
        pix_cen_x = [mtc.header["CRVAL1D"] / 0.015 for mtc in mtcs]
        pix_cen_y = [mtc.header["CRVAL2D"] / 0.015 for mtc in mtcs]
        assert np.abs(np.average(np.diff(pix_cen_x))) == approx(1, rel=1e-5)

        if PLOTS:
            plt.plot(pix_cen_x, pix_cen_y)
            plt.show()
Exemplo n.º 12
0
    def test_mtc_distances_are_one_pixel_diagonal_trace(self, diagonal_trace):
        # diagonal trace is 30 degrees off vertical
        spt = SpectralTrace(diagonal_trace)
        mtcs = spt.get_trace_curves(0.015)
        pix_cen_x = [mtc.header["CRVAL1D"] / 0.015 for mtc in mtcs]
        pix_cen_y = [mtc.header["CRVAL2D"] / 0.015 for mtc in mtcs]
        assert np.abs(np.average(np.diff(pix_cen_y))) == approx(1, rel=1e-5)

        if PLOTS:
            plt.plot(pix_cen_x, pix_cen_y, "o")
            plt.show()
Exemplo n.º 13
0
 def test_mtc_are_one_pixel_removed_from_each_other(self, basic_trace):
     spt = SpectralTrace(basic_trace)
     mtcs = spt.get_trace_curves(0.015)
     pix_cen_x = [mtc.header["CRVAL1D"] / 0.015 for mtc in mtcs]
     pix_cen_y = [mtc.header["CRVAL2D"] / 0.015 for mtc in mtcs]
     assert np.average(np.diff(pix_cen_y)) == approx(1, rel=1e-5)
Exemplo n.º 14
0
def test_ometiff_reader_gets_resolution_from_example_files():
    filename = "data/RA_10X_scans/MeA/S1_09032020.ome.tiff"
    resolution = 2.77
    image = OmeTiffImageReader().read(filename=filename)
    assert image.resolution_um == approx(resolution, abs=1e-2)