Пример #1
0
 def __init__(self, ds):
     super(YTGlueData, self).__init__()
     self.ds = ds
     self.grid = ds.arbitrary_grid(ds.domain_left_edge,
                                   ds.domain_right_edge, (256, ) * 3)
     self.region = ds.all_data()
     self.cids = [
         ComponentID('{} {}'.format(*f.name), parent=self)
         for f in ds.fields.gas
     ]
     w = astropy.wcs.WCS(naxis=3)
     c = 0.5 * (self.grid.left_edge + self.grid.right_edge)
     c = c.in_units('kpc')
     w.wcs.cunit = [str(c.units)] * 3
     w.wcs.crpix = 0.5 * (np.array(self.grid.shape) + 1)
     w.wcs.cdelt = self.grid.dds.in_units('kpc').d
     w.wcs.crval = c.d
     self.coords = coordinates_from_wcs(w)
     wcids = []
     for i in range(self.ndim):
         label = self.coords.axis_label(i)
         wcids.append(ComponentID(label, parent=self))
     self._world_component_ids = wcids
     self._dds = (ds.domain_width / self.shape).to_value("code_length")
     self._left_edge = self.ds.domain_left_edge.to_value("code_length")
     self._right_edge = self.ds.domain_right_edge.to_value("code_length")
Пример #2
0
 def test_make_link_helper(self):
     widget = LinkEquation()
     f1 = [f for f in link_helper if f[0] is helper][0]
     widget.function = f1
     x, y = ComponentID('x'), ComponentID('y')
     widget.signature = [x, y], None
     links = widget.links()
     assert links == helper(x, y)
Пример #3
0
 def __init__(self, uri, datasource):
     self.uri = uri
     self.datasource = datasource
     self.cids = [
         ComponentID('passenger_count'),
         ComponentID('trip_distance'),
         ComponentID('trip_time_in_secs')
     ]
     super(DruidData, self).__init__(label=self.datasource)
Пример #4
0
    def test_clear_inputs(self):
        widget = LinkEquation()
        f1 = [f for f in link_helper if f[0] is helper][0]
        widget.function = f1
        x, y = ComponentID('x'), ComponentID('y')

        widget.signature = [x, y], None
        assert widget.signature == ([x, y], None)

        widget.clear_inputs()
        assert widget.signature == ([None, None], None)
Пример #5
0
 def test_make_link_function(self):
     widget = LinkEquation()
     f1 = [f for f in link_function if f[0] is func1][0]
     widget.function = f1
     x, y = ComponentID('x'), ComponentID('y')
     widget.signature = [x], y
     links = widget.links()
     assert len(links) == 1
     assert links[0].get_from_ids() == [x]
     assert links[0].get_to_id() == y
     assert links[0].get_using() is func1
Пример #6
0
def test_toid():
    assert lh._toid('test').label == 'test'

    cid = ComponentID('test2')
    assert lh._toid(cid) is cid

    with pytest.raises(TypeError) as exc:
        lh._toid(None)
Пример #7
0
 def test_drop(self):
     target_id = ComponentID('test')
     event = MagicMock()
     event.mimeData().data.return_value = target_id
     a = ArgumentWidget('test')
     a.dropEvent(event)
     assert a.component_id is target_id
     assert a.editor_text == 'test'
Пример #8
0
 def test_clear(self):
     from glue.core import ComponentID
     target_id = ComponentID('test')
     event = MagicMock()
     event.mimeData().data.return_value = target_id
     a = ArgumentWidget('test')
     a.dropEvent(event)
     assert a.component_id is target_id
     a.clear()
     assert a.component_id is None
     assert a.editor_text == ''
Пример #9
0
    def __init__(self, ds_all, units=None):
        super(YTGlueData, self).__init__()
        self.ds_all = ds_all
        self.ds = ds_all[0]
        self._current_step = 0
        if units is None:
            self.units = self.ds.get_smallest_appropriate_unit(
                self.ds.domain_width[0])
        else:
            self.units = units
        self.region = self.ds.all_data()
        self.cids = [
            ComponentID('"{}","{}"'.format(*f.name), parent=self)
            for f in self.ds.fields.gas
        ]
        self._dds = (self.ds.domain_width / self.shape).d
        self._left_edge = self.ds.domain_left_edge.d
        self._right_edge = self.ds.domain_right_edge.d
        w = astropy.wcs.WCS(naxis=3)
        c = 0.5 * (self.ds.domain_left_edge + self.ds.domain_right_edge)
        w.wcs.cunit = [self.units] * 3
        w.wcs.crpix = 0.5 * (np.array(self.shape) + 1)
        w.wcs.cdelt = self.ds.arr(self._dds,
                                  "code_length").to_value(self.units)
        w.wcs.crval = c.to_value(self.units)
        self.wcs = w
        self.coords = coordinates_from_wcs(w)
        wcids = []
        for i in range(self.ndim):
            label = self.coords.axis_label(i)
            wcids.append(ComponentID(label, parent=self))
        self._world_component_ids = wcids
        for i, ax in enumerate("xyz"):

            def _pixel_c(field, data):
                return self._get_pix(data["index", ax].d, ax=i)

            self.ds.add_field(("index", "pixel_{}".format(ax)),
                              _pixel_c,
                              units="")
Пример #10
0
    def setup_method(self):
        self.app = get_qapp()
        self.data1 = Data(x=[1, 2, 3], y=[3.5, 4.5, -1.0], z=['a', 'r', 'w'])
        self.data2 = Data(a=[3, 4, 1], b=[1.5, -2.0, 3.5], c=['y', 'e', 'r'])

        # Add a derived component so that we can test how we deal with existing ones
        components = dict((cid.label, cid) for cid in self.data2.components)
        pc = ParsedCommand('{a}', components)
        link = ParsedComponentLink(ComponentID('d'), pc)
        self.data2.add_component_link(link)

        self.data_collection = DataCollection([self.data1, self.data2])
        self.listener1 = ChangeListener(self.data1)
        self.listener2 = ChangeListener(self.data2)
Пример #11
0
    def _add_derived_component(self, *args):

        comp_state = {}
        comp_state['cid'] = ComponentID('')
        comp_state['label'] = 'New component'
        comp_state['equation'] = None

        self._components[self.data]['derived'].append(comp_state['cid'])
        self._state[self.data][comp_state['cid']] = comp_state

        self._update_component_lists()

        self.list['derived'].select_cid(comp_state['cid'])

        self._edit_derived_component()
Пример #12
0
    def _add_derived_component(self, *args):

        comp_state = {}
        comp_state['cid'] = ComponentID('')
        comp_state['label'] = ''
        comp_state['equation'] = None

        self._components_derived[self.data].append(comp_state['cid'])
        self._state[self.data][comp_state['cid']] = comp_state

        self._update_component_lists()

        self.list.select_cid(comp_state['cid'])

        result = self._edit_derived_component()

        if not result:  # user cancelled
            self._components_derived[self.data].remove(comp_state['cid'])
            self._state[self.data].pop(comp_state['cid'])
            self._update_component_lists()
Пример #13
0
# pylint: disable=I0011,W0613,W0201,W0212,E1101,E1103

from __future__ import absolute_import, division, print_function

import pytest
import numpy as np

from glue.core import ComponentID, Data, Component, DataCollection

from .. import link_helpers as lh
from ..link_helpers import (LinkTwoWay, MultiLink,
                            LinkSame, LinkAligned)


R, D, L, B = (ComponentID('ra'), ComponentID('dec'),
              ComponentID('lon'), ComponentID('lat'))


def forwards(x, y):
    print('forwads inputs', x, y)
    return x * 3, y * 5


def backwards(x, y):
    print('backwards inputs', x, y)
    return x / 3, y / 5


def check_link(link, from_, to, using=None):
    assert link.get_from_ids() == from_
    assert link.get_to_id() == to
Пример #14
0
                            Galactic_to_FK4, ICRS_to_FK4, ICRS_to_Galactic,
                            GalactocentricToGalactic)

# We now store for each class the expected result of the conversion of (45,50)
# from the input frame to output frame and then from the output frame to the
# input frame.
EXPECTED = {
    Galactic_to_FK5: [(238.23062386, 27.96352696), (143.12136866, -7.76422226)],
    FK4_to_FK5: [(45.87780898, 50.19529421), (44.12740884, 49.80169907)],
    ICRS_to_FK5: [(45.00001315, 49.99999788), (44.99998685, 50.00000212)],
    Galactic_to_FK4: [(237.71557513, 28.11113265), (143.52337155, -7.32105993)],
    ICRS_to_FK4: [(44.12742195, 49.801697), (45.87779583, 50.19529642)],
    ICRS_to_Galactic: [(143.12137717, -7.76422008), (238.23062019, 27.96352359)],
}

lon1, lat1, lon2, lat2 = (ComponentID('lon_in'), ComponentID('lat_in'),
                          ComponentID('lon_out'), ComponentID('lat_out'))


@pytest.mark.parametrize(('conv_class', 'expected'), list(EXPECTED.items()))
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)
Пример #15
0

# We now store for each class the expected result of the conversion of (45,50)
# from the input frame to output frame and then from the output frame to the
# input frame.
EXPECTED = {
    Galactic_to_FK5: [(238.23062386, 27.96352696), (143.12136866, -7.76422226)],
    FK4_to_FK5: [(45.87780898, 50.19529421), (44.12740884, 49.80169907)],
    ICRS_to_FK5: [(45.00001315, 49.99999788), (44.99998685, 50.00000212)],
    Galactic_to_FK4: [(237.71557513, 28.11113265), (143.52337155, -7.32105993)],
    ICRS_to_FK4: [(44.12742195, 49.801697), (45.87779583, 50.19529642)],
    ICRS_to_Galactic: [(143.12137717, -7.76422008), (238.23062019, 27.96352359)],
}


lon1, lat1, lon2, lat2 = (ComponentID('lon_in'), ComponentID('lat_in'),
                          ComponentID('lon_out'), ComponentID('lat_out'))


@pytest.mark.parametrize(('conv_class', 'expected'), list(EXPECTED.items()))
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)