当前位置: 首页>>代码示例>>Python>>正文


Python DataCollection.new_subset_group方法代码示例

本文整理汇总了Python中glue.core.DataCollection.new_subset_group方法的典型用法代码示例。如果您正苦于以下问题:Python DataCollection.new_subset_group方法的具体用法?Python DataCollection.new_subset_group怎么用?Python DataCollection.new_subset_group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在glue.core.DataCollection的用法示例。


在下文中一共展示了DataCollection.new_subset_group方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestExportPython

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
class TestExportPython(BaseTestExportPython):

    def setup_method(self, method):

        with NumpyRNGContext(12345):
            self.data = Data(cube=np.random.random((30, 50, 20)))
        self.data_collection = DataCollection([self.data])
        self.app = GlueApplication(self.data_collection)
        self.viewer = self.app.new_data_viewer(ImageViewer)
        self.viewer.add_data(self.data)
        # FIXME: On some platforms, using an integer label size
        # causes some of the labels to be non-deterministically
        # shifted by one pixel, so we pick a non-round font size
        # to avoid this.
        self.viewer.state.x_ticklabel_size = 8.21334111
        self.viewer.state.y_ticklabel_size = 8.21334111

    def teardown_method(self, method):
        self.viewer.close()
        self.viewer = None
        self.app.close()
        self.app = None

    def test_simple(self, tmpdir):
        self.assert_same(tmpdir)

    def test_simple_att(self, tmpdir):
        self.viewer.state.x_att = self.data.pixel_component_ids[1]
        self.viewer.state.y_att = self.data.pixel_component_ids[0]
        self.assert_same(tmpdir)

    def test_simple_visual(self, tmpdir):
        self.viewer.state.layers[0].cmap = plt.cm.RdBu
        self.viewer.state.layers[0].v_min = 0.2
        self.viewer.state.layers[0].v_max = 0.8
        self.viewer.state.layers[0].stretch = 'sqrt'
        self.viewer.state.layers[0].stretch = 'sqrt'
        self.viewer.state.layers[0].contrast = 0.9
        self.viewer.state.layers[0].bias = 0.6
        self.assert_same(tmpdir)

    def test_slice(self, tmpdir):
        self.viewer.state.x_att = self.data.pixel_component_ids[1]
        self.viewer.state.y_att = self.data.pixel_component_ids[0]
        self.viewer.state.slices = (2, 3, 4)
        self.assert_same(tmpdir)

    def test_aspect(self, tmpdir):
        self.viewer.state.aspect = 'auto'
        self.assert_same(tmpdir)

    def test_subset(self, tmpdir):
        self.data_collection.new_subset_group('mysubset', self.data.id['cube'] > 0.5)
        self.assert_same(tmpdir)

    def test_subset_slice(self, tmpdir):
        self.data_collection.new_subset_group('mysubset', self.data.id['cube'] > 0.5)
        self.test_slice(tmpdir)
开发者ID:jzuhone,项目名称:glue,代码行数:60,代码来源:test_python_export.py

示例2: TestExportPython

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
class TestExportPython(BaseTestExportPython):

    def setup_method(self, method):

        with NumpyRNGContext(12345):
            self.data = Data(**dict((name, random_with_nan(100, nan_index=idx + 1)) for idx, name in enumerate('abcdefgh')))
        self.data_collection = DataCollection([self.data])
        self.app = GlueApplication(self.data_collection)
        self.viewer = self.app.new_data_viewer(HistogramViewer)
        self.viewer.add_data(self.data)
        self.viewer.state.x_att = self.data.id['a']

    def teardown_method(self, method):
        self.viewer.close()
        self.viewer = None
        self.app.close()
        self.app = None

    def test_simple(self, tmpdir):
        self.assert_same(tmpdir)

    def test_simple_visual(self, tmpdir):
        self.viewer.state.layers[0].color = 'blue'
        self.viewer.state.layers[0].alpha = 0.5
        self.assert_same(tmpdir)

    def test_cumulative(self, tmpdir):
        self.viewer.state.cumulative = True
        self.assert_same(tmpdir)

    def test_normalize(self, tmpdir):
        self.viewer.state.normalize = True
        self.assert_same(tmpdir)

    def test_subset(self, tmpdir):
        self.data_collection.new_subset_group('mysubset', self.data.id['a'] > 0.5)
        self.assert_same(tmpdir)

    def test_empty(self, tmpdir):
        self.viewer.state.x_min = 10
        self.viewer.state.x_max = 11
        self.viewer.state.hist_x_min = 10
        self.viewer.state.hist_x_max = 11
        self.assert_same(tmpdir)
开发者ID:glue-viz,项目名称:glue,代码行数:46,代码来源:test_python_export.py

示例3: test_scatter_remove_layer_artists

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
def test_scatter_remove_layer_artists(tmpdir):

    # Regression test for a bug that caused layer states to not be removed
    # when the matching layer artist was removed. This then caused issues when
    # loading session files.

    # Create fake data
    data = make_test_data()

    # Create fake session

    dc = DataCollection([data])
    ga = GlueApplication(dc)
    ga.show()

    scatter = ga.new_data_viewer(VispyScatterViewer)
    scatter.add_data(data)

    dc.new_subset_group(subset_state=data.id['x'] > 0.5, label='subset 1')

    scatter.add_subset(data.subsets[0])

    assert len(scatter.layers) == 2
    assert len(scatter.state.layers) == 2

    dc.remove_subset_group(dc.subset_groups[0])

    assert len(scatter.layers) == 1
    assert len(scatter.state.layers) == 1

    # Check that writing a session works as expected.

    session_file = tmpdir.join('test_scatter_viewer.glu').strpath
    ga.save_session(session_file)
    ga.close()

    # Now we can check that everything is restored correctly

    ga2 = GlueApplication.restore_session(session_file)
    ga2.show()
开发者ID:PennyQ,项目名称:glue-3d-viewer,代码行数:42,代码来源:test_scatter_viewer.py

示例4: TestExporter

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
class TestExporter():

    def setup_method(self, method):
        self.exporter = MySubsetMaskExporter()
        self.exporter.filename = 'test-filename'
        self.exporter.writer = MagicMock()
        self.data = Data(x=[1, 2, 3])
        self.data_collection = DataCollection([self.data])

    def test_no_subsets(self):
        with pytest.raises(ValueError) as exc:
            self.exporter.run(self.data)
        assert exc.value.args[0] == 'Data has no subsets'

    def test_multiple_valid(self):
        self.subset1 = self.data_collection.new_subset_group(subset_state=self.data.id['x'] >= 2,
                                                             label='subset a')
        self.subset2 = self.data_collection.new_subset_group(subset_state=self.data.id['x'] >= 3,
                                                             label='subset b')
        self.exporter.run(self.data)
        assert self.exporter.writer.call_count == 1
        assert self.exporter.writer.call_args[0][0] == 'test-filename'
        masks = self.exporter.writer.call_args[0][1]
        assert len(masks) == 2
        assert_equal(masks['subset a'], [0, 1, 1])
        assert_equal(masks['subset b'], [0, 0, 1])

    def test_single_subset_valid(self):
        self.subset = self.data_collection.new_subset_group(subset_state=self.data.id['x'] >= 2,
                                                            label='subset a')
        self.exporter.run(self.data.subsets[0])
        assert self.exporter.writer.call_count == 1
        assert self.exporter.writer.call_args[0][0] == 'test-filename'
        masks = self.exporter.writer.call_args[0][1]
        assert len(masks) == 1
        assert_equal(masks['subset a'], [0, 1, 1])
开发者ID:glue-viz,项目名称:glue,代码行数:38,代码来源:test_subset_mask.py

示例5: test_table_widget

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
def test_table_widget(tmpdir):

    # Start off by creating a glue application instance with a table viewer and
    # some data pre-loaded.

    app = get_qapp()

    d = Data(a=[1, 2, 3, 4, 5],
             b=[3.2, 1.2, 4.5, 3.3, 2.2],
             c=['e', 'b', 'c', 'a', 'f'])

    dc = DataCollection([d])

    gapp = GlueApplication(dc)

    widget = gapp.new_data_viewer(TableViewer)
    widget.add_data(d)

    subset_mode = gapp._session.edit_subset_mode

    # Create two subsets

    sg1 = dc.new_subset_group('D <= 3', d.id['a'] <= 3)
    sg1.style.color = '#aa0000'
    sg2 = dc.new_subset_group('1 < D < 4', (d.id['a'] > 1) & (d.id['a'] < 4))
    sg2.style.color = '#0000cc'

    model = widget.ui.table.model()

    # We now check what the data and colors of the table are, and try various
    # sorting methods to make sure that things are still correct.

    data = {'a': [1, 2, 3, 4, 5],
            'b': [3.2, 1.2, 4.5, 3.3, 2.2],
            'c': ['e', 'b', 'c', 'a', 'f']}

    colors = ['#aa0000', '#380088', '#380088', None, None]

    check_values_and_color(model, data, colors)

    model.sort(1, Qt.AscendingOrder)

    data = {'a': [2, 5, 1, 4, 3],
            'b': [1.2, 2.2, 3.2, 3.3, 4.5],
            'c': ['b', 'f', 'e', 'a', 'c']}

    colors = ['#380088', None, '#aa0000', None, '#380088']

    check_values_and_color(model, data, colors)

    model.sort(2, Qt.AscendingOrder)

    data = {'a': [4, 2, 3, 1, 5],
            'b': [3.3, 1.2, 4.5, 3.2, 2.2],
            'c': ['a', 'b', 'c', 'e', 'f']}

    colors = [None, '#380088', '#380088', '#aa0000', None]

    check_values_and_color(model, data, colors)

    model.sort(0, Qt.DescendingOrder)

    data = {'a': [5, 4, 3, 2, 1],
            'b': [2.2, 3.3, 4.5, 1.2, 3.2],
            'c': ['f', 'a', 'c', 'b', 'e']}

    colors = [None, None, '#380088', '#380088', '#aa0000']

    check_values_and_color(model, data, colors)

    model.sort(0, Qt.AscendingOrder)

    # We now modify the subsets using the table.

    selection = widget.ui.table.selectionModel()

    widget.toolbar.actions['table:rowselect'].toggle()

    def press_key(key):
        event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, key, Qt.NoModifier)
        app.postEvent(widget.ui.table, event)
        app.processEvents()

    process_events()

    # We now use key presses to navigate down to the third row

    press_key(Qt.Key_Tab)
    press_key(Qt.Key_Down)
    press_key(Qt.Key_Down)

    process_events()

    indices = selection.selectedRows()

    # We make sure that the third row is selected

    assert len(indices) == 1
    assert indices[0].row() == 2

#.........这里部分代码省略.........
开发者ID:glue-viz,项目名称:glue,代码行数:103,代码来源:test_data_viewer.py

示例6:

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
    pv_viewer = app.add_widget(pvwidget, label="Orbit PV Slice")
    ax2 = pvwidget.axes

    dl = (table['l'][1:]-table['l'][:-1])
    db = (table['b'][1:]-table['b'][:-1])
    dist = (dl**2+db**2)**0.5
    cdist = np.zeros(dist.size+1) * u.deg
    cdist[1:] = dist.cumsum() * u.deg
    #pixscale = ((x[1]-x[0])**2+(y[1]-y[0])**2)**0.5
    pixscale = wcs.utils.celestial_pixel_scale(cube.data.coords.wcs)
    spwcs = cube.data.coords.wcs.sub([wcs.WCSSUB_SPECTRAL])
    spax = spwcs.wcs_world2pix(table["v'los"]*1e3, 0)[0]
    ax2.plot(cdist/pixscale, spax, 'r-', linewidth=2, alpha=0.5)
    ax2.set_axis_bgcolor('black')

    # SERIOUSLY, DO IT
    ax.axis([x.min(),x.max(),y.min(),y.max()])

dc.new_subset_group(label='T < 60', subset_state=subset_tem_lt_60)
dc.new_subset_group(label='T > 60', subset_state=subset_tem_gt_60)

dc.subset_groups[0].style.markersize=15
dc.subset_groups[0].style.marker='+'
dc.subset_groups[0].style.color='blue'
dc.subset_groups[1].style.markersize=15
dc.subset_groups[1].style.marker='*'
dc.subset_groups[1].style.color='orange'


app.start()
开发者ID:bsipocz,项目名称:APEX_CMZ_H2CO,代码行数:32,代码来源:glue_cat.py

示例7: update_combobox

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
        self.layer_combo.setEnabled(True)

        # Set up contents of combo box
        labeldata = []

        # First include the dataset itself
        labeldata.append(('Full dataset', self.data))

        for subset in self.data.subsets:
            labeldata.append((subset.label, subset))

        update_combobox(self.layer_combo, labeldata)


if __name__ == "__main__":

    from glue.utils.qt import get_qapp
    from glue.core import Data, DataCollection

    data_collection = DataCollection()
    data = Data(x=[1, 2, 3], label='banana')
    data_collection.append(data)
    data_collection.new_subset_group('a', data.id['x'] > 0)

    app = get_qapp()
    widget = SimpleLayerWidget()
    widget.show()
    widget.data = data
    app.exec_()
开发者ID:spacetelescope,项目名称:mosviz,代码行数:31,代码来源:layer_widget.py

示例8: GlueApplication

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
app = GlueApplication(dc)

cube_viewer = app.new_data_viewer(ImageWidget)
cube_viewer.add_data(h2cocube)

h2cocube.join_on_key(dendro, 'structure', dendro.pixel_component_ids[0])

scatter = app.new_data_viewer(ScatterWidget)
scatter.add_data(dendro)
scatter.yatt = dendro.id['temperature_chi2']
scatter.xatt = catalog.id['r321303']

dendview = app.new_data_viewer(DendroWidget)
dendview.add_data(dendro)

subset_tem_bt_40_60 = ((catalog.id['temperature_chi2'] < 60) &
                    (catalog.id['temperature_chi2'] > 40))
subset_tem_lt_40 = ((catalog.id['temperature_chi2'] < 40) &
                    (catalog.id['temperature_chi2'] > 10))
subset_tem_gt_60 = (catalog.id['temperature_chi2'] > 60)
sg0 = dc.new_subset_group(label='T < 40', subset_state=subset_tem_lt_40)
sg1 = dc.new_subset_group(label='40 < T < 60', subset_state=subset_tem_bt_40_60)
sg2 = dc.new_subset_group(label='T > 60', subset_state=subset_tem_gt_60)
sg0.style.color = 'blue'
sg1.style.color = 'green'
sg2.style.color = 'red'


#start Glue
app.start()
开发者ID:bsipocz,项目名称:APEX_CMZ_H2CO,代码行数:32,代码来源:dendro_glue.py

示例9: make_model

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
 def make_model(self, n_data=1, n_subsets=0):
     dc = DataCollection([Data(x=[1, 2, 3]) for _ in range(n_data)])
     for _ in range(n_subsets):
         dc.new_subset_group()
     return DataCollectionModel(dc)
开发者ID:astrofrog,项目名称:glue,代码行数:7,代码来源:test_data_collection_model.py

示例10: setup_method

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]
 def setup_method(self, method):
     d = Data(x=[1, 2, 3])
     dc = DataCollection([d])
     self.collect = dc
     self.s = dc.new_subset_group()
开发者ID:PennyQ,项目名称:glue,代码行数:7,代码来源:test_subset_facet.py

示例11: TestExportPython

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import new_subset_group [as 别名]

#.........这里部分代码省略.........
        self.assert_same(tmpdir, tol=5)

    def test_line_cmap(self, tmpdir):
        self.viewer.state.layers[0].cmap_mode = 'Linear'
        self.viewer.state.layers[0].cmap_vmin = 0.2
        self.viewer.state.layers[0].cmap_vmax = 0.7
        self.viewer.state.layers[0].cmap = plt.cm.BuGn
        self.test_line(tmpdir)

    def test_errorbarx(self, tmpdir):
        self.viewer.state.layers[0].xerr_visible = True
        self.viewer.state.layers[0].xerr_att = self.data.id['e']
        self.viewer.state.layers[0].color = 'purple'
        self.viewer.state.layers[0].alpha = 0.5
        self.assert_same(tmpdir)

    def test_errorbary(self, tmpdir):
        self.viewer.state.layers[0].yerr_visible = True
        self.viewer.state.layers[0].yerr_att = self.data.id['f']
        self.viewer.state.layers[0].color = 'purple'
        self.viewer.state.layers[0].alpha = 0.5
        self.assert_same(tmpdir)

    def test_errorbarxy(self, tmpdir):
        self.viewer.state.layers[0].xerr_visible = True
        self.viewer.state.layers[0].xerr_att = self.data.id['e']
        self.viewer.state.layers[0].yerr_visible = True
        self.viewer.state.layers[0].yerr_att = self.data.id['f']
        self.viewer.state.layers[0].color = 'purple'
        self.viewer.state.layers[0].alpha = 0.5
        self.assert_same(tmpdir)

    def test_errorbarxy_cmap(self, tmpdir):
        self.viewer.state.layers[0].cmap_mode = 'Linear'
        self.viewer.state.layers[0].cmap_vmin = 0.2
        self.viewer.state.layers[0].cmap_vmax = 0.7
        self.viewer.state.layers[0].cmap = plt.cm.BuGn
        self.test_errorbarxy(tmpdir)

    def _vector_common(self, tmpdir):
        self.viewer.state.layers[0].vector_visible = True
        self.viewer.state.layers[0].vy_att = self.data.id['g']
        self.viewer.state.layers[0].vector_arrowhead = True
        self.viewer.state.layers[0].vector_origin = 'tail'
        self.viewer.state.layers[0].vector_scaling = 1.5
        self.viewer.state.layers[0].color = 'teal'
        self.viewer.state.layers[0].alpha = 0.9
        self.assert_same(tmpdir)

    def test_vector_cartesian(self, tmpdir):
        self.viewer.state.layers[0].vector_mode = 'Cartesian'
        self.viewer.state.layers[0].vx_att = self.data.id['h']
        self._vector_common(tmpdir)

    def test_vector_polar(self, tmpdir):
        self.viewer.state.layers[0].vector_mode = 'Polar'
        self.viewer.state.layers[0].vx_att = self.data.id['angle']
        self._vector_common(tmpdir)

    def test_vector_cartesian_cmap(self, tmpdir):
        self.viewer.state.layers[0].cmap_mode = 'Linear'
        self.viewer.state.layers[0].cmap_vmin = 0.2
        self.viewer.state.layers[0].cmap_vmax = 0.7
        self.viewer.state.layers[0].cmap = plt.cm.BuGn
        self.test_vector_cartesian(tmpdir)

    def test_vector_cartesian_xflip(self, tmpdir):
        # Regression test for a bug that caused vectors to not be flipped
        self.viewer.state.layers[0].vector_mode = 'Cartesian'
        self.viewer.state.layers[0].vx_att = self.data.id['h']
        self.viewer.state.flip_x()
        self._vector_common(tmpdir)

    def test_subset(self, tmpdir):
        self.data_collection.new_subset_group('mysubset', self.data.id['a'] > 0.5)
        self.assert_same(tmpdir)

    def test_density_map_with_subset(self, tmpdir):
        self.viewer.state.dpi = 2
        self.viewer.state.layers[0].density_map = True
        self.data_collection.new_subset_group('mysubset', self.data.id['a'] > 0.5)
        self.assert_same(tmpdir)

    def test_density_map_cmap_with_subset(self, tmpdir):
        self.viewer.state.dpi = 2
        self.viewer.state.layers[0].density_map = True
        self.viewer.state.layers[0].cmap_mode = 'Linear'
        self.viewer.state.layers[0].cmap_vmin = 0.2
        self.viewer.state.layers[0].cmap_vmax = 0.7
        self.viewer.state.layers[0].cmap = plt.cm.BuGn
        self.data_collection.new_subset_group('mysubset', self.data.id['a'] > 0.5)
        self.assert_same(tmpdir)

    def test_cmap_mode_change(self, tmpdir):
        # Regression test for a bug that caused scatter markers to not change
        # color when going from Linear to Fixed mode
        self.viewer.state.layers[0].size_mode = 'Linear'
        self.viewer.state.layers[0].cmap_mode = 'Linear'
        self.viewer.state.layers[0].cmap_mode = 'Fixed'
        self.assert_same(tmpdir)
开发者ID:glue-viz,项目名称:glue,代码行数:104,代码来源:test_python_export.py


注:本文中的glue.core.DataCollection.new_subset_group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。