本文整理汇总了Python中glue.core.state.GlueUnSerializer.loads方法的典型用法代码示例。如果您正苦于以下问题:Python GlueUnSerializer.loads方法的具体用法?Python GlueUnSerializer.loads怎么用?Python GlueUnSerializer.loads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glue.core.state.GlueUnSerializer
的用法示例。
在下文中一共展示了GlueUnSerializer.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_session_cube_back_compat
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_session_cube_back_compat(self, protocol):
filename = os.path.join(DATA, 'image_cube_v{0}.glu'.format(protocol))
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 1
assert dc[0].label == 'array'
viewer1 = ga.viewers[0][0]
assert len(viewer1.state.layers) == 1
assert viewer1.state.x_att_world is dc[0].id['World 2']
assert viewer1.state.y_att_world is dc[0].id['World 1']
assert viewer1.state.slices == [2, 0, 0, 1]
ga.close()
示例2: test_load_hdf5_grids_04
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_hdf5_grids_04():
# This loads a session file made with Glue v0.4. In this session, we have
# loaded two gridded datasets from an HDF5 datafile: the first one loaded
# via the auto loader and the other via the FITS/HDF5 loader.
with open(os.path.join(DATA, 'simple_hdf5_grid.glu'), 'r') as f:
template = f.read()
content = template.replace('{DATA_PATH}', (DATA + os.sep).replace('\\', '\\\\'))
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 2
assert dc[0].label == 'single_grid_auto'
assert dc[1].label == 'single_grid'
np.testing.assert_equal(dc[0]['/array1'], 1)
np.testing.assert_equal(dc[0]['/array1'].shape, (2, 3, 4))
ga.close()
示例3: test_load_coordinate_link_helpers_013
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_coordinate_link_helpers_013():
# This loads a session file made with Glue v0.13. In this session, we have
# two tables, and we use all the celestial link functions that were present
# in Glue v0.13. We now check that the paths are patched when loading the
# session (since the functions have been moved to a deprecated location)
with open(os.path.join(DATA, 'session_coordinate_links_013.glu'), 'r') as f:
content = f.read()
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
data1, data2 = ga.session.data_collection
print(data1)
print(data2)
# Check that the links works
data1[data2.id['x']]
data1[data2.id['y']]
data2[data1.id['x']]
data2[data1.id['y']]
ga.close()
示例4: test_session_categorical
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_session_categorical(self, tmpdir):
def visible_xaxis_labels(ax):
# Due to a bug in Matplotlib the labels returned outside the field
# of view may be incorrect: https://github.com/matplotlib/matplotlib/issues/9397
pos = ax.xaxis.get_ticklocs()
labels = [tick.get_text() for tick in ax.xaxis.get_ticklabels()]
xmin, xmax = ax.get_xlim()
return [labels[i] for i in range(len(pos)) if pos[i] >= xmin and pos[i] <= xmax]
# Regression test for a bug that caused a restored scatter viewer
# with a categorical component to not show the categorical labels
# as tick labels.
filename = tmpdir.join('test_session_categorical.glu').strpath
self.viewer.add_data(self.data)
self.viewer.state.x_att = self.data.id['z']
assert visible_xaxis_labels(self.viewer.axes) == ['a', 'b', 'c']
self.session.application.save_session(filename)
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
dc = ga.session.data_collection
viewer = ga.viewers[0][0]
assert viewer.state.x_att is dc[0].id['z']
assert visible_xaxis_labels(self.viewer.axes) == ['a', 'b', 'c']
示例5: test_session_line_back_compat
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_session_line_back_compat(self):
# Backward-compatibility for v0.11 files in which the line and scatter
# plots were defined as separate styles.
filename = os.path.join(DATA, 'scatter_and_line_v1.glu')
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 1
assert dc[0].label == 'table'
viewer1 = ga.viewers[0][0]
assert len(viewer1.state.layers) == 1
assert viewer1.state.x_att is dc[0].id['a']
assert viewer1.state.y_att is dc[0].id['b']
assert viewer1.state.layers[0].markers_visible
assert not viewer1.state.layers[0].line_visible
viewer1 = ga.viewers[0][1]
assert len(viewer1.state.layers) == 1
assert viewer1.state.x_att is dc[0].id['a']
assert viewer1.state.y_att is dc[0].id['b']
assert not viewer1.state.layers[0].markers_visible
assert viewer1.state.layers[0].line_visible
ga.close()
示例6: test_session_back_compat
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_session_back_compat(self, protocol):
filename = os.path.join(DATA, 'scatter_v{0}.glu'.format(protocol))
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 1
assert dc[0].label == 'basic'
viewer1 = ga.viewers[0][0]
assert len(viewer1.state.layers) == 3
assert viewer1.state.x_att is dc[0].id['a']
assert viewer1.state.y_att is dc[0].id['b']
assert_allclose(viewer1.state.x_min, -1.04)
assert_allclose(viewer1.state.x_max, 1.04)
assert_allclose(viewer1.state.y_min, 1.98)
assert_allclose(viewer1.state.y_max, 3.02)
assert not viewer1.state.x_log
assert not viewer1.state.y_log
assert viewer1.state.layers[0].visible
assert viewer1.state.layers[1].visible
assert viewer1.state.layers[2].visible
viewer2 = ga.viewers[0][1]
assert len(viewer2.state.layers) == 3
assert viewer2.state.x_att is dc[0].id['a']
assert viewer2.state.y_att is dc[0].id['c']
assert_allclose(viewer2.state.x_min, 9.5e-6)
assert_allclose(viewer2.state.x_max, 1.05)
assert_allclose(viewer2.state.y_min, 0.38)
assert_allclose(viewer2.state.y_max, 5.25)
assert viewer2.state.x_log
assert viewer2.state.y_log
assert viewer2.state.layers[0].visible
assert not viewer2.state.layers[1].visible
assert viewer2.state.layers[2].visible
viewer3 = ga.viewers[0][2]
assert len(viewer3.state.layers) == 3
assert viewer3.state.x_att is dc[0].id['b']
assert viewer3.state.y_att is dc[0].id['a']
assert_allclose(viewer3.state.x_min, 0)
assert_allclose(viewer3.state.x_max, 5)
assert_allclose(viewer3.state.y_min, -5)
assert_allclose(viewer3.state.y_max, 5)
assert not viewer3.state.x_log
assert not viewer3.state.y_log
assert viewer3.state.layers[0].visible
assert viewer3.state.layers[1].visible
assert not viewer3.state.layers[2].visible
ga.close()
示例7: test_session_back_compat
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_session_back_compat(self, protocol):
filename = os.path.join(DATA, 'dendro_v{0}.glu'.format(protocol))
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 1
assert dc[0].label == 'data'
viewer1 = ga.viewers[0][0]
assert len(viewer1.state.layers) == 2
assert viewer1.state.parent_att is dc[0].id['parent']
assert viewer1.state.height_att is dc[0].id['height']
assert viewer1.state.order_att is dc[0].id['height']
layer_state = viewer1.state.layers[0]
assert layer_state.visible
assert layer_state.layer is dc[0]
layer_state = viewer1.state.layers[1]
assert layer_state.visible
assert layer_state.layer is dc[0].subsets[0]
ga.close()
示例8: test_load_link_helpers_04
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_link_helpers_04():
# This loads a session file made with Glue v0.4. In this session, we have
# two tables, and we use all the celestial link functions that were present
# in Glue v0.4. We now check that the paths are patched when loading the
# session (since the functions have been moved to a deprecated location)
with open(os.path.join(DATA, 'session_links.glu'), 'r') as f:
content = f.read()
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
示例9: test_datetime64_support
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_datetime64_support(self, tmpdir):
self.data.add_component(np.array([100, 200, 300, 400], dtype='M8[D]'), 't1')
self.viewer.add_data(self.data)
self.viewer.state.x_att = self.data.id['t1']
wait_for_layers(self.viewer)
# Matplotlib deals with dates by converting them to the number of days
# since 01-01-0001, so we can check that the limits are correctly
# converted (and not 100 to 400)
assert self.viewer.axes.get_xlim() == (719263.0, 719563.0)
# Apply an ROI selection in plotting coordinates
roi = XRangeROI(719313, 719513)
self.viewer.apply_roi(roi)
wait_for_layers(self.viewer)
# Check that the two middle elements are selected
assert_equal(self.data.subsets[0].to_mask(), [0, 1, 1, 0])
# Make sure that the Qt labels look ok
options = self.viewer.options_widget().ui
assert options.valuetext_x_min.text() == '1970-04-11'
assert options.valuetext_x_max.text() == '1971-02-05'
# Make sure that we can set the xmin/xmax to a string date
assert_equal(self.viewer.state.x_min, np.datetime64('1970-04-11', 'D'))
options.valuetext_x_min.setText('1970-04-14')
options.valuetext_x_min.editingFinished.emit()
assert self.viewer.axes.get_xlim() == (719266.0, 719563.0)
assert_equal(self.viewer.state.x_min, np.datetime64('1970-04-14', 'D'))
# Make sure that everything works fine after saving/reloading
filename = tmpdir.join('test_datetime64.glu').strpath
self.session.application.save_session(filename)
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
viewer = ga.viewers[0][0]
options = viewer.options_widget().ui
wait_for_layers(viewer)
assert_equal(self.viewer.state.x_min, np.datetime64('1970-04-14', 'D'))
assert options.valuetext_x_min.text() == '1970-04-14'
assert options.valuetext_x_max.text() == '1971-02-05'
示例10: test_load_pixel_components_07
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_pixel_components_07():
# This loads a session file made with Glue v0.7. In 0.7 and before,
# PixelComponentID did not exist, so we need to make sure that when loading
# in such files, we transform the appropriate ComponentIDs to
# PixelComponentIDs.
with open(os.path.join(DATA, 'glue_v0.7_pixel_roi_selection.glu'), 'r') as f:
content = f.read()
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
assert isinstance(ga.data_collection[0].pixel_component_ids[0], PixelComponentID)
assert isinstance(ga.data_collection[0].pixel_component_ids[1], PixelComponentID)
示例11: test_load_viewers_04
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_viewers_04():
# FIXME - for some reason this test with PySide2 causes a leftover reference
# to GlueApplication and appears to be due to x_log being True in the
# scatter plot. I suspect maybe there is some kind of circular reference
# This loads a session file made with Glue v0.4. In this session, we have
# three viewers: one scatter viewer, one image viewer, and one histogram
# viewer.
with open(os.path.join(DATA, 'simple_viewers.glu'), 'r') as f:
content = f.read()
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
assert len(ga.viewers[0]) == 3
labels = sorted([x.LABEL for x in ga.viewers[0]])
assert labels == ['1D Histogram', '2D Image', '2D Scatter']
viewers = {}
for x in ga.viewers[0]:
viewers[x.LABEL] = x
h = viewers['1D Histogram']
assert h.viewer_size == (1235, 531)
assert h.position == (0, 535)
assert h.state.x_att.label == 'b'
i = viewers['2D Image']
assert i.viewer_size == (562, 513)
assert i.position == (672, 0)
assert i.state.layers[0].attribute.label == "image"
s = viewers['2D Scatter']
assert s.viewer_size == (670, 512)
assert s.position == (0, 0)
assert s.state.x_att.label == 'b'
assert s.state.y_att.label == 'a'
assert s.state.x_log
assert not s.state.y_log
ga.close()
示例12: test_load_log
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_log(protocol):
# Prior to Glue v0.13, components were added to the data as: first
# non-coordinate component, then coordinate components, then remaining non-
# coordinate components. In Glue v0.13, this changed to be coordinate
# components then non-coordinate components. The LoadLog functionality
# relies on an absolute component index, so we need to be careful - if the
# session file was created prior to Glue v0.13, we need to load the
# components in the log using the old order. The load_log_1.glu file was
# made with Glue v0.12.2, while the load_log_2.glu file was made with
# Glue v0.13.
with open(os.path.join(DATA, 'load_log_{0}.glu'.format(protocol)), 'r') as f:
template = f.read()
content = template.replace('{DATA_PATH}', (DATA + os.sep).replace('\\', '\\\\'))
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 1
data = dc[0]
assert data.label == 'simple'
np.testing.assert_equal(data['Pixel Axis 0 [x]'], [0, 1, 2])
np.testing.assert_equal(data['World 0'], [0, 1, 2])
np.testing.assert_equal(data['a'], [1, 3, 5])
np.testing.assert_equal(data['b'], [2, 2, 3])
if protocol == 0:
assert data.components == [data.id['a'], data.id['Pixel Axis 0 [x]'], data.id['World 0'], data.id['b']]
else:
assert data.components == [data.id['Pixel Axis 0 [x]'], data.id['World 0'], data.id['a'], data.id['b']]
assert type(data.get_component('Pixel Axis 0 [x]')) == CoordinateComponent
assert type(data.get_component('World 0')) == CoordinateComponent
assert type(data.get_component('a')) == Component
assert type(data.get_component('b')) == Component
ga.close()
示例13: test_load_viewers_04
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_viewers_04():
# This loads a session file made with Glue v0.4. In this session, we have
# three viewers: one scatter viewer, one image viewer, and one histogram
# viewer.
with open(os.path.join(DATA, 'simple_viewers.glu'), 'r') as f:
content = f.read()
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
assert len(ga.viewers[0]) == 3
labels = sorted([x.LABEL for x in ga.viewers[0]])
assert labels == ['1D Histogram', '2D Image Viewer', '2D Scatter Plot']
viewers = {}
for x in ga.viewers[0]:
viewers[x.LABEL] = x
h = viewers['1D Histogram']
assert h.viewer_size == (1235, 531)
assert h.position == (0, 535)
assert h.component.label == 'b'
i = viewers['2D Image Viewer']
assert i.viewer_size == (562, 513)
assert i.position == (672, 0)
assert i.attribute.label == "image"
s = viewers['2D Scatter Plot']
assert s.viewer_size == (670, 512)
assert s.position == (0, 0)
assert s.xatt.label == 'b'
assert s.yatt.label == 'a'
assert s.xlog
assert not s.ylog
assert not s.xflip
assert s.yflip
示例14: test_load_simple_tables_04
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_load_simple_tables_04():
# This loads a session file made with Glue v0.4. In this session, we have
# loaded four tables. The first two are from the same file, but one loaded
# via the auto loader and the other via the Astropy FITS table loader. The
# second two were loaded similarly to the first two, but the file contains
# two HDUs this time. However, in Glue v0.4, only the first HDU was read so
# we shouldn't have access to columns c and d in ``double_tables.fits``.
with open(os.path.join(DATA, 'simple_tables.glu'), 'r') as f:
template = f.read()
content = template.replace('{DATA_PATH}', (DATA + os.sep).replace('\\', '\\\\'))
state = GlueUnSerializer.loads(content)
ga = state.object('__main__')
dc = ga.session.data_collection
# All tables should actually be the same because the FITS reader back at
# 0.4 only read in the first HDU so the new reader is back-compatible
# since it preserves HDU order.
assert len(dc) == 4
assert dc[0].label == 'single_table_auto'
assert dc[1].label == 'single_table'
assert dc[2].label == 'double_tables_auto'
assert dc[3].label == 'double_tables'
np.testing.assert_equal(dc[0]['a'], [1, 2, 3])
np.testing.assert_equal(dc[0]['b'], [4, 5, 6])
np.testing.assert_equal(dc[0]['a'], dc[1]['a'])
np.testing.assert_equal(dc[0]['b'], dc[1]['b'])
np.testing.assert_equal(dc[0]['a'], dc[2]['a'])
np.testing.assert_equal(dc[0]['b'], dc[2]['b'])
np.testing.assert_equal(dc[0]['a'], dc[3]['a'])
np.testing.assert_equal(dc[0]['b'], dc[3]['b'])
ga.close()
示例15: test_session_rgb_back_compat
# 需要导入模块: from glue.core.state import GlueUnSerializer [as 别名]
# 或者: from glue.core.state.GlueUnSerializer import loads [as 别名]
def test_session_rgb_back_compat(self, protocol):
filename = os.path.join(DATA, 'image_rgb_v{0}.glu'.format(protocol))
with open(filename, 'r') as f:
session = f.read()
state = GlueUnSerializer.loads(session)
ga = state.object('__main__')
dc = ga.session.data_collection
assert len(dc) == 1
assert dc[0].label == 'rgbcube'
viewer1 = ga.viewers[0][0]
assert len(viewer1.state.layers) == 3
assert viewer1.state.color_mode == 'One color per layer'
layer_state = viewer1.state.layers[0]
assert layer_state.visible
assert layer_state.attribute.label == 'a'
assert layer_state.color == 'r'
layer_state = viewer1.state.layers[1]
assert not layer_state.visible
assert layer_state.attribute.label == 'c'
assert layer_state.color == 'g'
layer_state = viewer1.state.layers[2]
assert layer_state.visible
assert layer_state.attribute.label == 'b'
assert layer_state.color == 'b'
ga.close()