예제 #1
0
    def test_create_instance(self):
        with pytest.raises(ValueError) as error:
            OutputPort("config", self.storage)

        assert str(error.value) == "The tag name 'config' is reserved for the central " \
                                   "configuration of PynPoint."

        with pytest.raises(ValueError) as error:
            OutputPort("fits_header", self.storage)

        assert str(error.value) == "The tag name 'fits_header' is reserved for storage of the " \
                                   "FITS headers."

        active_port = OutputPort("test", self.storage, activate_init=True)
        deactive_port = OutputPort("test", self.storage, activate_init=False)
        control_port = InputPort("test", self.storage)

        deactive_port.open_port()
        deactive_port.set_all(np.asarray([0, 1, 2, 3]))
        deactive_port.flush()

        with pytest.warns(UserWarning) as warning:
            control_port.get_all()

        assert len(warning) == 1
        assert warning[0].message.args[0] == "No data under the tag which is linked by the " \
                                             "InputPort."

        active_port.set_all(np.asarray([0, 1, 2, 3]))
        active_port.flush()

        assert np.array_equal(np.asarray([0, 1, 2, 3]), control_port.get_all())

        active_port.del_all_data()
예제 #2
0
    def add_output_port(self,
                        tag,
                        activation=True):
        """
        Function which creates an OutputPort for a ReadingModule and appends it to the internal
        OutputPort dictionary. This function should be used by classes inheriting from
        ReadingModule to make sure that only output ports with unique tags are added. The new
        port can be used as: ::

             port = self._m_output_ports[tag]

        or by using the returned Port.

        :param tag: Tag of the new output port.
        :type tag: str
        :param activation: Activation status of the Port after creation. Deactivated ports
                           will not save their results until they are activated.
        :type activation: bool

        :return: The new OutputPort for the ReadingModule.
        :rtype: OutputPort
        """

        port = OutputPort(tag, activate_init=activation)

        if tag in self._m_output_ports:
            warnings.warn("Tag '%s' of ReadingModule '%s' is already used."
                          % (tag, self._m_name))

        if self._m_data_base is not None:
            port.set_database_connection(self._m_data_base)

        self._m_output_ports[tag] = port

        return port
예제 #3
0
    def test_set_all_error(self) -> None:

        # ---- Test database not set -----

        data = [1, 2, 3, 4, 0]

        with pytest.warns(UserWarning) as record:
            out_port = OutputPort('some_data')
            out_port.set_all(data)

        assert len(record) == 1

        assert record[0].message.args[0] == 'OutputPort can not store data unless a database is ' \
                                            'connected.'

        # ---- Test data dim of actual data for new data entry is < 1 or > 5

        out_port = self.create_output_port('new_data')

        data = [[[[[[2, 2], ], ], ], ]]

        with pytest.raises(ValueError) as error:
            out_port.set_all(data, data_dim=2)

        assert str(error.value) == 'Output port can only save numpy arrays from 1D to 5D. Use ' \
                                   'Port attributes to save as int, float, or string.'

        # ---- Test data dim of data_dim for new data entry is < 1 or > 5

        out_port = self.create_output_port('new_data')

        data = [1, 2, 4]

        with pytest.raises(ValueError) as error:
            out_port.set_all(data, data_dim=0)

        assert str(error.value) == 'The data dimensions should be 1D, 2D, 3D, 4D, or 5D.'

        # ---- Test data_dim for new data entry is smaller than actual data

        out_port = self.create_output_port('new_data')

        data = [[1], [2]]

        with pytest.raises(ValueError) as error:
            out_port.set_all(data, data_dim=1)

        assert str(error.value) == 'The dimensions of the data should be equal to or larger ' \
                                   'than the dimensions of the input data.'

        # ---- Test data_dim == 3 and actual size == 1

        out_port = self.create_output_port('new_data')

        data = [1, 2]

        with pytest.raises(ValueError) as error:
            out_port.set_all(data, data_dim=3)

        assert str(error.value) == 'Cannot initialize 1D data in 3D data container.'
예제 #4
0
    def test_get_all_attributes(self):
        port = InputPort('images', self.storage)

        assert port.get_all_static_attributes() == {'PIXSCALE': 0.01}
        assert port.get_all_non_static_attributes() == ['PARANG', ]

        port = OutputPort('images', self.storage)
        assert port.del_all_attributes() is None

        port = InputPort('images', self.storage)
        assert port.get_all_non_static_attributes() is None
예제 #5
0
    def add_output_port(self, tag: str, activation: bool = True) -> OutputPort:
        """
        Function which creates an :class:`~pynpoint.core.dataio.OutputPort` for a
        :class:`~pynpoint.core.processing.ProcessingModule` and appends it to the internal
        :class:`~pynpoint.core.dataio.OutputPort` dictionary. This function should be used by
        classes inheriting from :class:`~pynpoint.core.processing.ProcessingModule` to make sure
        that only output ports with unique tags are added. The new port can be used as:

        .. code-block:: python

             port = self._m_output_ports[tag]

        or by using the returned :class:`~pynpoint.core.dataio.Port`.

        Parameters
        ----------
        tag : str
            Tag of the new output port.
        activation : bool
            Activation status of the :class:`~pynpoint.core.dataio.Port` after creation.
            Deactivated ports will not save their results until they are activated.

        Returns
        -------
        pynpoint.core.dataio.OutputPort
            The new :class:`~pynpoint.core.dataio.OutputPort` for the
            :class:`~pynpoint.core.processing.ProcessingModule`.
        """

        port = OutputPort(tag, activate_init=activation)

        if tag in self._m_output_ports:
            warnings.warn(
                f'Tag \'{tag}\' of ProcessingModule \'{self._m_name}\' is already used.'
            )

        if self._m_data_base is not None:
            port.set_database_connection(self._m_data_base)

        self._m_output_ports[tag] = port

        return port
예제 #6
0
    def add_output_port(self,
                        tag,
                        activation=True):
        """
        Function which creates an OutputPort for a ReadingModule and appends it to the internal
        OutputPort dictionary. This function should be used by classes inheriting from
        ReadingModule to make sure that only output ports with unique tags are added. The new
        port can be used as: ::

             port = self._m_output_ports[tag]

        or by using the returned Port.

        Parameters
        ----------
        tag : str
            Tag of the new output port.
        activation : bool
            Activation status of the Port after creation. Deactivated ports will not save their
            results until they are activated.

        Returns
        -------
        pynpoint.core.dataio.OutputPort
            The new OutputPort for the ReadingModule.
        """

        port = OutputPort(tag, activate_init=activation)

        if tag in self._m_output_ports:
            warnings.warn(f'Tag \'{tag}\' of ReadingModule \'{self._m_name}\' is already used.')

        if self._m_data_base is not None:
            port.set_database_connection(self._m_data_base)

        self._m_output_ports[tag] = port

        return port
예제 #7
0
    def create_output_port(self, tag_name):
        outport = OutputPort(tag_name, self.storage)

        return outport