Beispiel #1
0
def test_link_aligned(ndata, ndim):
    ds = []
    shp = tuple([2] * ndim)
    for i in range(ndata):
        d = Data()
        c = Component(np.random.random(shp))
        d.add_component(c, 'test')
        ds.append(d)

    # assert that all componentIDs are interchangeable
    links = LinkAligned(ds)
    dc = DataCollection(ds)
    dc.add_link(links)

    for i in range(ndim):
        id0 = ds[0].pixel_component_ids[i]
        for j in range(1, ndata):
            id1 = ds[j].pixel_component_ids[i]
            np.testing.assert_array_equal(ds[j][id0], ds[j][id1])
Beispiel #2
0
 def cube_to_data(self, cube, output_label=None, output_component_id=None):
     """
     Convert SpectralCube to final output.
     self.output_as_component is checked here.
     if self.output_as_component:
         add new component to self.data
     else:
         create new data and return it.
     :param cube: SpectralCube
     :param output_label: Name of new Data.
     :param output_component_id: label of new component
     :return:
     """
     original_data = self.data
     new_component = Component(cube._data.copy(), self.component_unit)
     if self.output_as_component:
         original_data.add_component(new_component, output_component_id)
         return None
     else:
         new_data = Data(label=output_label)
         new_data.coords = coordinates_from_header(cube.header)
         new_data.add_component(new_component, output_component_id)
         return new_data
Beispiel #3
0
def add_to_2d_container(cubeviz_layout, data, component_data, component_unit,
                        label):
    """
    Given the cubeviz layout, a data object, a new 2D layer and a label, add
    the 2D layer to the data object and update the cubeviz layout accordingly.
    This creates the 2D container dataset if needed.
    """

    # If the 2D container doesn't exist, we create it here. This container is
    # basically just a Data object but we keep it in an attribute
    # ``container_2d`` on its parent dataset.
    if getattr(data, 'container_2d', None) is None:

        # For now, we assume that the 2D maps are always computed along the
        # spectral axis, so that the resulting WCS is always celestial
        coords = WCSCoordinates(wcs=data.coords.wcs.celestial)

        data.container_2d = Data(label=data.label + " [2d]", coords=coords)

        # manually create the component so we can add the units too
        new_component_data_with_units = Component(component_data,
                                                  component_unit)

        component_id = data.container_2d.add_component(
            new_component_data_with_units, label)

        cubeviz_layout._flux_unit_controller.add_component_unit(
            component_id, str(component_unit))

        cubeviz_layout.session.data_collection.append(data.container_2d)

        # NOTE: the following is disabled for now but can be uncommented once
        # we are ready to use the glue overlay infrastructure.
        # Set up pixel links so that selections in the image plane propagate
        # between 1D and 2D views. Again this assumes as above that the
        # moments are computed along the spectral axis
        # link1 = LinkSame(data.pixel_component_ids[2],
        #                  data.container_2d.pixel_component_ids[1])
        # link2 = LinkSame(data.pixel_component_ids[1],
        #                  data.container_2d.pixel_component_ids[0])
        # cubeviz_layout.session.data_collection.add_link(link1)
        # cubeviz_layout.session.data_collection.add_link(link2)

        for helper in cubeviz_layout._viewer_combo_helpers:
            helper.append_data(data.container_2d)

        for viewer in cubeviz_layout.cube_views:
            viewer._widget.add_data(data.container_2d)

    else:
        # Make sure we don't add duplicate data components
        if label in data.container_2d.component_ids():
            raise ValueError("Data component with label '{}' already exists, "
                             "and cannot be created again".format(label))

        new_component_data_with_units = Component(component_data,
                                                  component_unit)
        component_id = data.container_2d.add_component(
            new_component_data_with_units, label)

        cubeviz_layout._flux_unit_controller.add_component_unit(
            component_id, str(component_unit))
Beispiel #4
0
 def load_stacked_sequence(self, raster_data):
     for window, window_data in raster_data.items():
         w_data = Data(label=f"{window.replace(' ', '_')}")
         w_data.coords = window_data.wcs
         w_data.add_component(Component(window_data.data), f"{window}")
         self.datasets.append(w_data)