Пример #1
0
def test_stats_box_with_subset(cubeviz_layout):
    """
    Tests the stat box underneath the ImageViewer when there is an ROI
    """
    cl_viewer = cubeviz_layout.split_views[1]._widget

    # Create a subset (ROI) if there is none
    cl_viewer.apply_roi(roi.CircularROI(xc=6, yc=10, radius=3))

    assert cl_viewer._subset is not None

    mask = cl_viewer._subset.to_mask()[cl_viewer._slice_index]
    data = cl_viewer._data[0][cl_viewer.current_component_id][
        cl_viewer._slice_index][mask]

    wave = cl_viewer.cubeviz_layout.get_wavelength(cl_viewer.slice_index)
    data_wave = cl_viewer.cubeviz_unit.convert_value(data, wave=wave)

    assert data_wave is not None

    results = (np.nanmin(data_wave), np.nanmax(data_wave),
               np.median(data_wave), data_wave.mean(), data_wave.std())
    results_string = r"min={:.4}, max={:.4}, median={:.4}, μ={:.4}, σ={:.4}".format(
        *results)

    assert results_string == cl_viewer.parent().stats_text.text()

    # Remove the ROI/subset
    dc = cubeviz_layout.session.application.data_collection
    dc.remove_subset_group(dc.subset_groups[0])
Пример #2
0
def ginga_graphic_to_roi(obj):
    if obj.kind == 'rectangle':
        # make sure x2, y2 are the upper right corner
        x1, y1, x2, y2 = obj.swapxy(obj.x1, obj.y1, obj.x2, obj.y2)
        roi = roimod.RectangularROI(xmin=x1, xmax=x2, ymin=y1, ymax=y2)
    elif obj.kind == 'circle':
        roi = roimod.CircularROI(xc=obj.x, yc=obj.y, radius=obj.radius)
    elif obj.kind in ('polygon', 'freepolygon'):
        vx, vy = zip(*obj.points)
        roi = roimod.PolygonalROI(vx=vx, vy=vy)

    elif obj.kind in ('path', 'freepath', 'line'):
        vx, vy = zip(*obj.points)
        roi = roimod.Path(vx=vx, vy=vy)

    elif obj.kind == 'xrange':
        x1, y1, x2, y2 = obj.swapxy(obj.x1, 0, obj.x2, 0)
        roi = roimod.XRangeROI(min=x1, max=x2)

    elif obj.kind == 'yrange':
        x1, y1, x2, y2 = obj.swapxy(0, obj.y1, 0, obj.y2)
        roi = roimod.YRangeROI(min=y1, max=y2)

    elif obj.kind == 'point':
        roi = roimod.PointROI(x=obj.x, y=obj.y)

    else:
        raise Exception("Don't know how to convert shape '%s' to a ROI" %
                        (obj.kind))

    return roi
Пример #3
0
def test_regions(qtbot, cubeviz_layout):

    viewer = cubeviz_layout.split_views[0]._widget
    # Create a pretty arbitrary circular ROI
    viewer.apply_roi(roi.CircularROI(xc=6, yc=10, radius=3))

    # Don't use the fixture here since we modified the underlying viewer state
    # above first.
    cc = create_collapsed_cube(cubeviz_layout)

    start_index = 682
    end_index = 1364

    # Set the values and do the calculation through the GUI
    cc.ui.data_combobox.setCurrentIndex(0)
    cc.ui.operation_combobox.setCurrentIndex(0)
    cc.ui.spatial_region_combobox.setCurrentIndex(1)
    cc.ui.region_combobox.setCurrentIndex(1)  # indices
    cc.ui.start_input.setText('{}'.format(start_index))
    cc.ui.end_input.setText('{}'.format(end_index))
    cc.ui.sigma_combobox.setCurrentIndex(0)
    qtbot.mouseClick(cc.ui.calculate_button, QtCore.Qt.LeftButton)

    # Calculate what we expect
    np_data = cubeviz_layout._data[DATA_LABELS[0]]
    mask = cubeviz_layout._data.subsets[0].to_mask()
    np_data_sum = np.sum(np_data[start_index:end_index] *
                         mask[start_index:end_index],
                         axis=0)

    # Get the result
    collapse_component_id = [
        str(x) for x in cubeviz_layout._data.container_2d.component_ids()
        if str(x).startswith('018.DATA-collap')
    ][0]
    np_result = cubeviz_layout._data.container_2d[collapse_component_id]

    # Delete the ROI first, in case the assert fails
    dc = cubeviz_layout.session.application.data_collection
    dc.remove_subset_group(dc.subset_groups[0])

    print('combo box items {}'.format([
        cc.ui.operation_combobox.itemText(i)
        for i in range(cc.ui.operation_combobox.count())
    ]))
    print('combo box selected {}'.format(
        cc.ui.operation_combobox.currentText()))
    print('np_data_sum {}'.format(np_data_sum))
    print('np_result {}'.format(np_result))
    assert np.allclose(np_data_sum, np_result, atol=1.0)
Пример #4
0
def ginga_graphic_to_roi(obj):
    if obj.kind == 'rectangle':
        roi = roimod.RectangularROI(xmin=obj.x1,
                                    xmax=obj.x2,
                                    ymin=obj.y1,
                                    ymax=obj.y2)
    elif obj.kind == 'circle':
        roi = roimod.CircularROI(xc=obj.x, yc=obj.y, radius=obj.radius)
    elif obj.kind == 'polygon':
        vx = map(lambda xy: xy[0], obj.points)
        vy = map(lambda xy: xy[1], obj.points)
        roi = roimod.PolygonalROI(vx=vx, vy=vy)

    else:
        raise Exception("Don't know how to convert shape '%s' to a ROI" %
                        (obj.kind))

    return roi
Пример #5
0
def test_cubeviz_roi(cubeviz_layout):
    """
    Test whether ROI creation in cubeviz propagates to specviz
    """
    specviz = cubeviz_layout.specviz._widget
    assert len(specviz._layer_artist_container.layers) == 1

    # Create ROI/subset
    cl_viewer = cubeviz_layout.split_views[1]._widget
    cl_viewer.apply_roi(roi.CircularROI(xc=6, yc=10, radius=3))

    assert len(specviz._layer_artist_container.layers) == 2

    # Remove the ROI/subset
    dc = cubeviz_layout.session.application.data_collection
    dc.remove_subset_group(dc.subset_groups[0])

    assert len(specviz._layer_artist_container.layers) == 1
Пример #6
0
def test_default_contour(cubeviz_layout):
    """
    Make sure that default contour works
    """
    # Keep track of children in viewer to check that number increases later
    cl_viewer = cubeviz_layout.split_views[1]._widget
    cl_viewer_children = len(cl_viewer.axes.get_children())

    # Create a subset (ROI) if there is none
    cl_viewer.apply_roi(roi.CircularROI(xc=6, yc=10, radius=3))
    cl_viewer.default_contour()

    assert len(cl_viewer.axes.get_children()) > cl_viewer_children
    assert cl_viewer.is_contour_active

    cl_viewer.remove_contour()

    # Remove the ROI/subset
    dc = cubeviz_layout.session.application.data_collection
    dc.remove_subset_group(dc.subset_groups[0])

    assert cl_viewer.is_contour_active == False
    assert len(cl_viewer.axes.get_children()) == cl_viewer_children