Ejemplo n.º 1
0
def test_conversion(conv_class, expected):

    result = conv_class([lon1, lat1], [lon2, lat2])

    assert len(result) == 4

    # Check links are correct
    check_link(result[0], [lon1, lat1], lon2)
    check_link(result[1], [lon1, lat1], lat2)
    check_link(result[2], [lon2, lat2], lon1)
    check_link(result[3], [lon2, lat2], lat1)

    # Check string representation
    assert str(result[0]) == "lon_out <- " + conv_class.__name__ + ".forwards_1(lon_in, lat_in)"
    assert str(result[1]) == "lat_out <- " + conv_class.__name__ + ".forwards_2(lon_in, lat_in)"
    assert str(result[2]) == "lon_in <- " + conv_class.__name__ + ".backwards_1(lon_out, lat_out)"
    assert str(result[3]) == "lat_in <- " + conv_class.__name__ + ".backwards_2(lon_out, lat_out)"

    # Check numerical accuracy

    x = np.array([45])
    y = np.array([50])

    check_using(result[0], (x, y), expected[0][0])
    check_using(result[1], (x, y), expected[0][1])
    check_using(result[2], (x, y), expected[1][0])
    check_using(result[3], (x, y), expected[1][1])

    # Check that state saving works

    check_using(clone(result[0]), (x, y), expected[0][0])
    check_using(clone(result[1]), (x, y), expected[0][1])
    check_using(clone(result[2]), (x, y), expected[1][0])
    check_using(clone(result[3]), (x, y), expected[1][1])
Ejemplo n.º 2
0
def test_conversion(conv_class, expected):

    result = conv_class(lon1, lat1, lon2, lat2)

    assert len(result) == 4

    # Check links are correct
    check_link(result[0], [lon1, lat1], lon2)
    check_link(result[1], [lon1, lat1], lat2)
    check_link(result[2], [lon2, lat2], lon1)
    check_link(result[3], [lon2, lat2], lat1)

    # Check string representation
    assert str(result[0]) == "lon_out <- " + conv_class.__name__ + ".forward_1(lon_in, lat_in)"
    assert str(result[1]) == "lat_out <- " + conv_class.__name__ + ".forward_2(lon_in, lat_in)"
    assert str(result[2]) == "lon_in <- " + conv_class.__name__ + ".backward_1(lon_out, lat_out)"
    assert str(result[3]) == "lat_in <- " + conv_class.__name__ + ".backward_2(lon_out, lat_out)"

    # Check numerical accuracy

    x = np.array([45])
    y = np.array([50])

    check_using(result[0], (x, y), expected[0][0])
    check_using(result[1], (x, y), expected[0][1])
    check_using(result[2], (x, y), expected[1][0])
    check_using(result[3], (x, y), expected[1][1])

    # Check that state saving works

    check_using(clone(result[0]), (x, y), expected[0][0])
    check_using(clone(result[1]), (x, y), expected[0][1])
    check_using(clone(result[2]), (x, y), expected[1][0])
    check_using(clone(result[3]), (x, y), expected[1][1])
Ejemplo n.º 3
0
def test_affine():

    matrix = np.array([[2, 3, -1], [1, 2, 2], [0, 0, 1]])

    coords = AffineCoordinates(matrix)

    assert coords.axis_label(1) == 'World 1'
    assert coords.axis_label(0) == 'World 0'

    assert coords.world_axis_unit(1) == ''
    assert coords.world_axis_unit(0) == ''

    xp = np.array([1, 2, 3])
    yp = np.array([2, 3, 4])

    xw, yw = coords.pixel2world(xp, yp)

    assert_allclose(xw, 2 * xp + 3 * yp - 1)
    assert_allclose(yw, 1 * xp + 2 * yp + 2)

    coords2 = clone(coords)

    xw, yw = coords2.pixel2world(xp, yp)

    assert_allclose(xw, 2 * xp + 3 * yp - 1)
    assert_allclose(yw, 1 * xp + 2 * yp + 2)
Ejemplo n.º 4
0
def test_affine_labels_units():

    matrix = np.array([[2, 3, -1], [1, 2, 2], [0, 0, 1]])

    coords = AffineCoordinates(matrix, units=['km', 'km'], labels=['xw', 'yw'])

    assert coords.axis_label(1) == 'Xw'
    assert coords.axis_label(0) == 'Yw'

    assert coords.world_axis_unit(1) == 'km'
    assert coords.world_axis_unit(0) == 'km'

    xp = np.array([1, 2, 3])
    yp = np.array([2, 3, 4])

    xw, yw = coords.pixel2world(xp, yp)

    assert_allclose(xw, 2 * xp + 3 * yp - 1)
    assert_allclose(yw, 1 * xp + 2 * yp + 2)

    coords2 = clone(coords)

    xw, yw = coords2.pixel2world(xp, yp)

    assert_allclose(xw, 2 * xp + 3 * yp - 1)
    assert_allclose(yw, 1 * xp + 2 * yp + 2)
Ejemplo n.º 5
0
def test_affine():

    matrix = np.array([[2, 3, -1], [1, 2, 2], [0, 0, 1]])

    coords = AffineCoordinates(matrix)

    assert axis_label(coords, 1) == 'World 1'
    assert axis_label(coords, 0) == 'World 0'

    assert coords.world_axis_units[1] == ''
    assert coords.world_axis_units[0] == ''

    # First the scalar case

    xp, yp = 1, 2

    xw, yw = coords.pixel_to_world_values(xp, yp)

    assert_allclose(xw, 2 * 1 + 3 * 2 - 1)
    assert_allclose(yw, 1 * 1 + 2 * 2 + 2)

    assert np.ndim(xw) == 0
    assert np.ndim(yw) == 0

    xpc, ypc = coords.world_to_pixel_values(xw, yw)

    assert_allclose(xpc, 1)
    assert_allclose(ypc, 2)

    assert np.ndim(xpc) == 0
    assert np.ndim(ypc) == 0

    # Next the array case

    xp = np.array([1, 2, 3])
    yp = np.array([2, 3, 4])

    xw, yw = coords.pixel_to_world_values(xp, yp)

    assert_allclose(xw, 2 * xp + 3 * yp - 1)
    assert_allclose(yw, 1 * xp + 2 * yp + 2)

    xpc, ypc = coords.world_to_pixel_values(xw, yw)

    assert_allclose(xpc, [1, 2, 3])
    assert_allclose(ypc, [2, 3, 4])

    # Check that serialization/deserialization works

    coords2 = clone(coords)

    xw, yw = coords2.pixel_to_world_values(xp, yp)

    assert_allclose(xw, 2 * xp + 3 * yp - 1)
    assert_allclose(yw, 1 * xp + 2 * yp + 2)

    xpc, ypc = coords.world_to_pixel_values(xw, yw)

    assert_allclose(xpc, [1, 2, 3])
    assert_allclose(ypc, [2, 3, 4])
Ejemplo n.º 6
0
def test_clone_wcs_link():

    # Make sure that WCSLink can be serialized/deserialized

    wcs1 = WCS(naxis=2)
    wcs1.wcs.ctype = 'DEC--TAN', 'RA---TAN'
    wcs1.wcs.set()

    data1 = Data(label='Data 1')
    data1.coords = WCSCoordinates(wcs=wcs1)
    data1['x'] = np.ones((2, 3))

    wcs2 = WCS(naxis=3)
    wcs2.wcs.ctype = 'GLON-CAR', 'FREQ', 'GLAT-CAR'
    wcs2.wcs.set()

    data2 = Data(label='Data 2')
    data2.coords = WCSCoordinates(wcs=wcs2)
    data2['x'] = np.ones((2, 3, 4))

    link1 = WCSLink(data1, data2)
    link2 = clone(link1)

    assert isinstance(link2, WCSLink)
    assert link2.data1.label == 'Data 1'
    assert link2.data2.label == 'Data 2'
Ejemplo n.º 7
0
    def test_clone(self):

        self.viewer.add_data(self.d)
        self.viewer.state.layers[0].ra_att = self.d.id['y']
        self.viewer.state.layers[0].dec_att = self.d.id['x']

        application2 = clone(self.application)

        viewer2 = application2.viewers[0][0]
Ejemplo n.º 8
0
    def test_clone(self):

        self.viewer.add_data(self.d)
        self.viewer.state.layers[0].ra_att = self.d.id['y']
        self.viewer.state.layers[0].dec_att = self.d.id['x']

        application2 = clone(self.application)

        viewer2 = application2.viewers[0][0]
Ejemplo n.º 9
0
    def test_save_load(self):
        w = self.build()
        v = w._coordinator
        roi = None
        s = CustomSubsetState(type(v), roi, v.settings())

        s2 = clone(s)

        assert_array_equal(s2.to_mask(self.data), [False, True, True])
Ejemplo n.º 10
0
    def test_save_load(self):
        w = self.build()
        v = w._coordinator
        roi = None
        s = CustomSubsetState(type(v), roi, v.settings())

        s2 = clone(s)

        assert_array_equal(s2.to_mask(self.data), [False, True, True])
Ejemplo n.º 11
0
 def test_save_load(self):
     app = GlueApplication(session=self.session)
     w = app.new_data_viewer(self.viewer._viewer_cls)
     v = w._coordinator
     roi = None
     s = CustomSubsetState(v, roi)
     app.data_collection.new_subset_group(subset_state=s, label='test')
     app2 = clone(app)
     s2 = app2.data_collection[0].subsets[0].subset_state
     assert_array_equal(s2.to_mask(self.data), [False, True, True])
Ejemplo n.º 12
0
 def test_save_load(self):
     app = GlueApplication(session=self.session)
     w = app.new_data_viewer(self.viewer._viewer_cls)
     v = w._coordinator
     roi = None
     s = CustomSubsetState(v, roi)
     app.data_collection.new_subset_group(subset_state=s, label='test')
     app2 = clone(app)
     s2 = app2.data_collection[0].subsets[0].subset_state
     assert_array_equal(s2.to_mask(self.data), [False, True, True])
Ejemplo n.º 13
0
    def test_subset_groups_remain_synced_after_restore(self):
        # regrssion test for 352
        d = Data(label='hist', x=[[1, 2], [2, 3]])
        dc = DataCollection([d])
        dc.new_subset_group()
        app = GlueApplication(dc)

        app2 = clone(app)
        sg = app2.data_collection.subset_groups[0]
        assert sg.style.parent is sg

        sg.style.color = '#112233'
        assert sg.subsets[0].style.color == '#112233'
Ejemplo n.º 14
0
    def test_subset_groups_remain_synced_after_restore(self):
        # regrssion test for 352
        d = Data(label='hist', x=[[1, 2], [2, 3]])
        dc = DataCollection([d])
        dc.new_subset_group()
        app = GlueApplication(dc)

        app2 = clone(app)
        sg = app2.data_collection.subset_groups[0]
        assert sg.style.parent is sg

        sg.style.color = '#112233'
        assert sg.subsets[0].style.color == '#112233'
Ejemplo n.º 15
0
    def test_clone(self):

        self.viewer_state.x_att = self.data.pixel_component_ids[1]
        self.viewer_state.function = 'median'

        self.layer_state.attribute = self.data.id['x']
        self.layer_state.linewidth = 3

        viewer_state_new = clone(self.viewer_state)

        assert viewer_state_new.x_att.label == 'Pixel Axis 1 [y]'
        assert viewer_state_new.function == 'median'

        assert self.layer_state.attribute.label == 'x'
        assert self.layer_state.linewidth == 3
Ejemplo n.º 16
0
    def test_clone(self):

        self.viewer_state.x_att = self.data.pixel_component_ids[1]
        self.viewer_state.function = 'median'

        self.layer_state.attribute = self.data.id['x']
        self.layer_state.linewidth = 3

        viewer_state_new = clone(self.viewer_state)

        assert viewer_state_new.x_att.label == 'Pixel Axis 1 [y]'
        assert viewer_state_new.function == 'median'

        assert self.layer_state.attribute.label == 'x'
        assert self.layer_state.linewidth == 3
Ejemplo n.º 17
0
    def test_clone(self):

        # Regression test for a bug that meant that deserializing a profile
        # viewer resulted in disabled layers

        self.viewer.add_data(self.data)

        subset = self.data.new_subset()
        subset.subset_state = SliceSubsetState(self.data, [slice(1, 2), slice(None)])

        app = clone(self.app)

        assert app.viewers[0][0].layers[0].enabled
        assert app.viewers[0][0].layers[1].enabled

        app.close()
Ejemplo n.º 18
0
    def test_clone(self):

        # Regression test for a bug that meant that deserializing a profile
        # viewer resulted in disabled layers

        self.viewer.add_data(self.data)

        subset = self.data.new_subset()
        subset.subset_state = SliceSubsetState(
            self.data, [slice(1, 2), slice(None)])

        app = clone(self.app)

        assert app.viewers[0][0].layers[0].enabled
        assert app.viewers[0][0].layers[1].enabled

        app.close()
Ejemplo n.º 19
0
def test_affine_labels_units():

    matrix = np.array([[2, 3, -1], [1, 2, 2], [0, 0, 1]])

    coords = AffineCoordinates(matrix, units=['km', 'km'], labels=['xw', 'yw'])

    assert axis_label(coords, 1) == 'Xw'
    assert axis_label(coords, 0) == 'Yw'

    assert coords.world_axis_units[1] == 'km'
    assert coords.world_axis_units[0] == 'km'

    coords2 = clone(coords)

    assert axis_label(coords2, 1) == 'Xw'
    assert axis_label(coords2, 0) == 'Yw'

    assert coords2.world_axis_units[1] == 'km'
    assert coords2.world_axis_units[0] == 'km'
Ejemplo n.º 20
0
def test_galactocentric():

    result = GalactocentricToGalactic([x, y, z], [l, b, d])

    assert len(result) == 6

    # Check links are correct
    check_link(result[0], [x, y, z], l)
    check_link(result[1], [x, y, z], b)
    check_link(result[2], [x, y, z], d)
    check_link(result[3], [l, b, d], x)
    check_link(result[4], [l, b, d], y)
    check_link(result[5], [l, b, d], z)

    # Check string representation
    assert str(result[0]) == "l <- GalactocentricToGalactic.forwards_1(x, y, z)"
    assert str(result[1]) == "b <- GalactocentricToGalactic.forwards_2(x, y, z)"
    assert str(result[2]) == "d <- GalactocentricToGalactic.forwards_3(x, y, z)"
    assert str(result[3]) == "x <- GalactocentricToGalactic.backwards_1(l, b, d)"
    assert str(result[4]) == "y <- GalactocentricToGalactic.backwards_2(l, b, d)"
    assert str(result[5]) == "z <- GalactocentricToGalactic.backwards_3(l, b, d)"

    # Check numerical accuracy

    ref = (1., 1., 2.)

    check_using(result[0], ref, 6.141592406648453)
    check_using(result[1], ref, 12.096336453181067)
    check_using(result[2], ref, 9.559388692193782)
    check_using(result[3], ref, -6.30046229834067)
    check_using(result[4], ref, 0.03489758558640843)
    check_using(result[5], ref, 0.055403498825152414)

    # Check that state saving works

    check_using(clone(result[0]), ref, 6.141592406648453)
    check_using(clone(result[1]), ref, 12.096336453181067)
    check_using(clone(result[2]), ref, 9.559388692193782)
    check_using(clone(result[3]), ref, -6.30046229834067)
    check_using(clone(result[4]), ref, 0.03489758558640843)
    check_using(clone(result[5]), ref, 0.055403498825152414)
Ejemplo n.º 21
0
def test_save_meta():
    # Regression test for a bug that causes Data.meta to contain non-string
    # items when FITS comments were present.
    from glue.core.tests.test_state import clone
    data = df.load_data(os.path.join(DATA, 'comment.fits'))
    clone(data)
Ejemplo n.º 22
0
def test_save_meta():
    # Regression test for a bug that causes Data.meta to contain non-string
    # items when FITS comments were present.
    from glue.core.tests.test_state import clone
    data = df.load_data(os.path.join(DATA, 'comment.fits'))
    clone(data)