Example #1
0
    def test_spectrum_raw(self):

        filename = "test-spec-spot.csv"

        self.spec_stream.selectionWidth.value = 1
        proj = SinglePointSpectrumProjection(self.spec_stream)
        exported_data = img.spectrum_to_export_data(proj, True)
        self.assertEqual(exported_data.shape[0], self.spec_data.shape[0])  # exported image includes only raw data

        # Save into a CSV file
        exporter = dataio.get_converter("CSV")
        exporter.export(filename, exported_data)
        st = os.stat(filename)  # this test also that the file is created
        self.assertGreater(st.st_size, 10)

        self.spec_stream.selectionWidth.value = 3
        exported_data = img.spectrum_to_export_data(proj, True)
        self.assertEqual(exported_data.shape[0], self.spec_data.shape[0])  # exported image includes only raw data

        # Save into a CSV file
        exporter = dataio.get_converter("CSV")
        exporter.export(filename, exported_data)
        st = os.stat(filename)  # this test also that the file is created
        self.assertGreater(st.st_size, 10)

        # clean up
        try:
            os.remove(filename)
        except Exception:
            pass
Example #2
0
    def test_spectrum_raw(self):

        filename = "test-spec-spot.csv"

        self.spec_stream.selectionWidth.value = 1
        proj = SinglePointSpectrumProjection(self.spec_stream)
        exported_data = img.spectrum_to_export_data(proj, True)
        self.assertEqual(
            exported_data.shape[0],
            self.spec_data.shape[0])  # exported image includes only raw data

        # Save into a CSV file
        exporter = dataio.get_converter("CSV")
        exporter.export(filename, exported_data)
        st = os.stat(filename)  # this test also that the file is created
        self.assertGreater(st.st_size, 10)

        self.spec_stream.selectionWidth.value = 3
        exported_data = img.spectrum_to_export_data(proj, True)
        self.assertEqual(
            exported_data.shape[0],
            self.spec_data.shape[0])  # exported image includes only raw data

        # Save into a CSV file
        exporter = dataio.get_converter("CSV")
        exporter.export(filename, exported_data)
        st = os.stat(filename)  # this test also that the file is created
        self.assertGreater(st.st_size, 10)

        # clean up
        try:
            os.remove(filename)
        except Exception:
            pass
Example #3
0
    def test_spectrum_ready(self):
        self.spec_stream.selectionWidth.value = 1
        exported_data = img.spectrum_to_export_data(self.spec_stream, False)
        self.assertEqual(exported_data.metadata[model.MD_DIMS], 'YXC')  # ready for RGB export
        self.assertEqual(exported_data.shape[:2],
                         (img.SPEC_PLOT_SIZE + img.SPEC_SCALE_HEIGHT + img.SMALL_SCALE_WIDTH,
                          img.SPEC_PLOT_SIZE + img.SPEC_SCALE_WIDTH + img.SMALL_SCALE_WIDTH))  # exported image includes scale bars

        self.spec_stream.selectionWidth.value = 4
        exported_data = img.spectrum_to_export_data(self.spec_stream, False)
        self.assertEqual(exported_data.metadata[model.MD_DIMS], 'YXC')  # ready for RGB export
        self.assertEqual(exported_data.shape[:2],
                         (img.SPEC_PLOT_SIZE + img.SPEC_SCALE_HEIGHT + img.SMALL_SCALE_WIDTH,
                          img.SPEC_PLOT_SIZE + img.SPEC_SCALE_WIDTH + img.SMALL_SCALE_WIDTH))  # exported image includes scale bars
Example #4
0
    def test_spectrum_ready(self):
        self.spec_stream.selectionWidth.value = 1
        exported_data = img.spectrum_to_export_data(self.spec_stream, False)
        self.assertEqual(exported_data.metadata[model.MD_DIMS], 'YXC')  # ready for RGB export
        self.assertEqual(exported_data.shape[:2],
                         (img.SPEC_PLOT_SIZE + img.SPEC_SCALE_HEIGHT + img.SMALL_SCALE_WIDTH,
                          img.SPEC_PLOT_SIZE + img.SPEC_SCALE_WIDTH + img.SMALL_SCALE_WIDTH))  # exported image includes scale bars

        self.spec_stream.selectionWidth.value = 4
        exported_data = img.spectrum_to_export_data(self.spec_stream, False)
        self.assertEqual(exported_data.metadata[model.MD_DIMS], 'YXC')  # ready for RGB export
        self.assertEqual(exported_data.shape[:2],
                         (img.SPEC_PLOT_SIZE + img.SPEC_SCALE_HEIGHT + img.SMALL_SCALE_WIDTH,
                          img.SPEC_PLOT_SIZE + img.SPEC_SCALE_WIDTH + img.SMALL_SCALE_WIDTH))  # exported image includes scale bars
Example #5
0
    def export(self, export_type, raw=False):
        """
        Returns the data to be exported with respect to the settings and options.

        :param export_type (string): spatial, AR, spectrum or spectrum-line
        :param raw (boolean): raw data format if True
        :param interpolate_data (boolean): apply interpolation on data if True

        returns DataArray or list of DataArray: the data to be exported, either
          an RGB image or raw data.
        raises:
            LookupError: if no data found to export
        """
        fview = self._data_model.focussedView.value
        vp = self.get_viewport_by_view(fview)
        streams = fview.getStreams()
        if export_type == 'AR':
            # TODO: set MD_ACQ_TYPE in stream code
            for i, _ in enumerate(streams):
                for r in streams[i].raw:
                    r.metadata[model.MD_ACQ_TYPE] = model.MD_AT_AR
            exported_data = ar_to_export_data(streams, raw)
        elif export_type == 'spectrum':
            spectrum = vp.stream.get_pixel_spectrum()
            spectrum_range, unit = vp.stream.get_spectrum_range()
            spectrum.metadata[model.MD_ACQ_TYPE] = model.MD_AT_SPECTRUM
            exported_data = spectrum_to_export_data(spectrum, raw, unit, spectrum_range)
        elif export_type == 'spectrum-line':
            spectrum_md = vp.stream.get_pixel_spectrum().metadata
            spectrum = vp.stream.get_line_spectrum()
            # copy only non existed values (we mainly care about MD_WL_*)
            spectrum.metadata.update({k: v for k, v in spectrum_md.iteritems() if k not in spectrum.metadata})
            spectrum_range, unit = vp.stream.get_spectrum_range()
            spectrum.metadata[model.MD_ACQ_TYPE] = model.MD_AT_SPECTRUM
            exported_data = line_to_export_data(spectrum, raw, unit, spectrum_range)
        else:
            export_type = 'spatial'
            view_px = tuple(vp.canvas.ClientSize)
            view_mpp = fview.mpp.value
            view_hfw = (view_mpp * view_px[0], view_mpp * view_px[1])
            view_pos = fview.view_pos.value
            draw_merge_ratio = fview.stream_tree.kwargs.get("merge", 0.5)
            interpolate_data = fview.interpolate_content.value
            exported_data = images_to_export_data(streams,
                                                  view_hfw, view_pos,
                                                  draw_merge_ratio, raw,
                                                  interpolate_data=interpolate_data,
                                                  logo=self._main_frame.legend_logo)

        return exported_data
Example #6
0
    def export(self, export_type, raw=False):
        """
        Returns the data to be exported with respect to the settings and options.

        :param export_type (string): spatial, AR, spectrum, spectrum-temporal,
            spectrum-time, or spectrum-line
        :param raw (boolean): raw data format if True
        :param interpolate_data (boolean): apply interpolation on data if True

        returns DataArray or list of DataArray: the data to be exported, either
          an RGB image or raw data.
        raises:
            LookupError: if no data found to export
        """
        fview = self._data_model.focussedView.value
        vp = self.get_viewport_by_view(fview)
        streams = fview.stream_tree.getProjections(
        )  # Stream tree to get the DataProjection
        if export_type == 'AR':
            exported_data = ar_to_export_data(streams, raw)
        elif export_type == 'spectrum':
            exported_data = spectrum_to_export_data(streams[0], raw, vp)
        elif export_type == 'spectrum-line':
            exported_data = line_to_export_data(streams[0], raw)
        elif export_type == 'spectrum-temporal':
            exported_data = temporal_spectrum_to_export_data(streams[0], raw)
        elif export_type == 'spectrum-time':
            exported_data = chronogram_to_export_data(streams[0], raw, vp)
        else:
            view_px = tuple(vp.canvas.ClientSize)
            view_mpp = fview.mpp.value
            view_hfw = (view_mpp * view_px[0], view_mpp * view_px[1])
            view_pos = fview.view_pos.value
            draw_merge_ratio = fview.stream_tree.kwargs.get("merge", 0.5)
            interpolate_data = fview.interpolate_content.value
            exported_data = images_to_export_data(
                streams,
                view_hfw,
                view_pos,
                draw_merge_ratio,
                raw,
                vp.canvas,
                interpolate_data=interpolate_data,
                logo=self._main_frame.legend_logo)

        return exported_data
Example #7
0
    def test_spectrum_raw(self):

        filename = "test-spec-spot.csv"

        exported_data = img.spectrum_to_export_data(self.spectrum, True, self.unit, self.spectrum_range)
        self.assertEqual(exported_data.shape[0], len(self.spectrum_range))  # exported image includes only raw data

        # Save into a CSV file
        exporter = dataio.get_converter("CSV")
        exporter.export(filename, exported_data)
        st = os.stat(filename)  # this test also that the file is created
        self.assertGreater(st.st_size, 10)

        # clean up
        try:
            os.remove(filename)
        except Exception:
            pass
Example #8
0
    def export(self, export_type, raw=False):
        """
        Returns the data to be exported with respect to the settings and options.

        :param export_type (string): spatial, AR, spectrum, spectrum-temporal,
            spectrum-time, or spectrum-line
        :param raw (boolean): raw data format if True
        :param interpolate_data (boolean): apply interpolation on data if True

        returns DataArray or list of DataArray: the data to be exported, either
          an RGB image or raw data.
        raises:
            LookupError: if no data found to export
        """
        fview = self._data_model.focussedView.value
        vp = self.get_viewport_by_view(fview)
        streams = fview.stream_tree.getProjections()  # Stream tree to get the DataProjection
        if export_type == 'AR':
            exported_data = ar_to_export_data(streams, raw)
        elif export_type == 'spectrum':
            exported_data = spectrum_to_export_data(streams[0], raw, vp)
        elif export_type == 'spectrum-line':
            exported_data = line_to_export_data(streams[0], raw)
        elif export_type == 'spectrum-temporal':
            exported_data = temporal_spectrum_to_export_data(streams[0], raw)
        elif export_type == 'spectrum-time':
            exported_data = chronogram_to_export_data(streams[0], raw, vp)
        else:
            view_px = tuple(vp.canvas.ClientSize)
            view_mpp = fview.mpp.value
            view_hfw = (view_mpp * view_px[0], view_mpp * view_px[1])
            view_pos = fview.view_pos.value
            draw_merge_ratio = fview.stream_tree.kwargs.get("merge", 0.5)
            interpolate_data = fview.interpolate_content.value
            exported_data = images_to_export_data(streams,
                                                  view_hfw, view_pos,
                                                  draw_merge_ratio, raw,
                                                  interpolate_data=interpolate_data,
                                                  logo=self._main_frame.legend_logo)

        return exported_data
Example #9
0
 def test_spectrum_ready(self):
     exported_data = img.spectrum_to_export_data(self.spectrum, False, self.unit, self.spectrum_range)
     self.assertEqual(exported_data.metadata[model.MD_DIMS], 'YXC')  # ready for RGB export
     self.assertEqual(exported_data.shape[:2],
                      (img.SPEC_PLOT_SIZE + img.SPEC_SCALE_HEIGHT + img.SMALL_SCALE_WIDTH,
                       img.SPEC_PLOT_SIZE + img.SPEC_SCALE_WIDTH + img.SMALL_SCALE_WIDTH))  # exported image includes scale bars
Example #10
0
 def test_spectrum_raw(self):
     exported_data = img.spectrum_to_export_data(self.spectrum, True, self.unit, self.spectrum_range)
     self.assertEqual(exported_data.shape[0], len(self.spectrum_range))  # exported image includes only raw data