Beispiel #1
0
def test_custom_model_n_outputs():
    """
    Test creating a custom_model which has more than one output, which
    requires special handling.
        Demonstrates issue #11791's ``n_outputs`` error has been solved
    """

    @custom_model
    def model(x, y, n_outputs=2):
        return x+1, y+1

    m = model()
    assert not isinstance(m.n_outputs, Parameter)
    assert isinstance(m.n_outputs, int)
    assert m.n_outputs == 2
    assert m.outputs == ('x0', 'x1')
    assert (separability_matrix(m) == [[True, True],
                                       [True, True]]).all()

    @custom_model
    def model(x, y, z, n_outputs=3):
        return x+1, y+1, z+1

    m = model()
    assert not isinstance(m.n_outputs, Parameter)
    assert isinstance(m.n_outputs, int)
    assert m.n_outputs == 3
    assert m.outputs == ('x0', 'x1', 'x2')
    assert (separability_matrix(m) == [[True, True, True],
                                       [True, True, True],
                                       [True, True, True]]).all()
def test_coupled_sep(linear_time, vct_crval):
    if not hasattr(Model, "_calculate_separability_matrix"):
        pytest.skip()

    tfrm = CoupledCompoundModel("&", vct_crval, linear_time, shared_inputs=1)
    smatrix = separability_matrix(tfrm)
    assert np.allclose(smatrix, np.array([[1, 1, 1], [1, 1, 1], [0, 0, 1]]))
Beispiel #3
0
 def axis_correlation_matrix(self):
     """
     Returns an (`~BaseLowLevelWCS.world_n_dim`,
     `~BaseLowLevelWCS.pixel_n_dim`) matrix that indicates using booleans
     whether a given world coordinate depends on a given pixel coordinate.
     This defaults to a matrix where all elements are `True` in the absence of
     any further information. For completely independent axes, the diagonal
     would be `True` and all other entries `False`.
     """
     return separable.separability_matrix(self.forward_transform)
Beispiel #4
0
Datei: api.py Projekt: pllim/gwcs
    def axis_correlation_matrix(self):
        """
        Returns an (`~BaseLowLevelWCS.world_n_dim`,
        `~BaseLowLevelWCS.pixel_n_dim`) matrix that indicates using booleans
        whether a given world coordinate depends on a given pixel coordinate.
        This defaults to a matrix where all elements are `True` in the absence of
        any further information. For completely independent axes, the diagonal
        would be `True` and all other entries `False`.
        """

        return separable.separability_matrix(self.forward_transform)
def test_coupled_sep_2d(vct_2d_pc, linear_time):
    if not hasattr(Model, "_calculate_separability_matrix"):
        pytest.skip()
    linear_spectral = m.Linear1D(slope=10 * u.nm / u.pix)
    right = linear_time & linear_spectral
    tfrm = CoupledCompoundModel("&", vct_2d_pc, right, shared_inputs=2)

    smatrix = separability_matrix(tfrm)
    assert np.allclose(
        smatrix,
        np.array([[1, 1, 1, 1], [1, 1, 1, 1], [0, 0, 1, 0], [0, 0, 0, 1]]))
Beispiel #6
0
def test_custom_model_separable():
    @custom_model
    def model_a(x):
        return x

    assert model_a().separable

    @custom_model
    def model_c(x, y):
        return x + y

    assert not model_c().separable
    assert np.all(separability_matrix(model_c()) == [True, True])
Beispiel #7
0
def test_coupled_sep(linear_time):
    if not hasattr(Model, "_calculate_separability_matrix"):
        pytest.skip()

    crval_table = ((0, 1), (2, 3), (4, 5)) * u.arcsec
    vct = VaryingCelestialTransform(crpix=(5, 5) * u.pix,
                                    cdelt=(1, 1) * u.arcsec / u.pix,
                                    crval_table=crval_table,
                                    pc_table=np.identity(2) * u.arcsec,
                                    lon_pole=180 * u.deg)

    tfrm = CoupledCompoundModel("&", vct, linear_time, shared_inputs=1)
    smatrix = separability_matrix(tfrm)
    assert np.allclose(
        smatrix,
        np.array([[True, True, True], [True, True, True], [False, False,
                                                           True]]))
Beispiel #8
0
def test_custom_separability_matrix():
    original = separability_matrix(ModelDefault(slope=1, intercept=2))
    assert original.all()

    custom = separability_matrix(ModelCustom(slope=1, intercept=2))
    assert not custom.any()
Beispiel #9
0
def test_separable(compound_model, result):
    assert_allclose(is_separable(compound_model), result[0])
    assert_allclose(separability_matrix(compound_model), result[1])
Beispiel #10
0
def test_separable(compound_model, result):
    assert_allclose(is_separable(compound_model), result[0])
    assert_allclose(separability_matrix(compound_model), result[1])