Beispiel #1
0
    def getSOM(self, som_id=None, **kwargs):
        """
        This method parses the resource and creates a SOM from the information.

        @param som_id: The name of the SOM. The default value is C{None}. This
        retrieves all information.

        @param kwargs: A list of keyword arguments that the function accepts:

        @keyword no_sqr: Do not square the error values from the file. This is
                         important if the data will be subsequently plotted.
                         The default value is I{False}.
        @type no_sqr: C{boolean}        
        """
        try:
            self.__no_sqr__ = kwargs["no_sqr"]
        except KeyError:
            self.__no_sqr__ = False
        
        som = SOM.SOM()
        som.setDataSetType("density")

        self.__set_axes(som)
        self.__readData(som)

        som.setYLabel("Counts")
        uscale = som.getAxisUnits(1) + " " + som.getAxisUnits(0)
        som.setYUnits("Counts / " + uscale)

        som.attr_list = dst_utils.parse_spec_header(self.__file)

        return som
Beispiel #2
0
    def getSOM(self, som_id=None, **kwargs):
        """
        This method parses the resource and creates a SOM from the information.

        @param som_id: The name of the SOM. The default value is C{None}. This
        retrieves all information.

        @param kwargs: A list of keyword arguments that the function accepts:

        @keyword no_sqr: Do not square the error values from the file. This is
                         important if the data will be subsequently plotted.
                         The default value is I{False}.
        @type no_sqr: C{boolean}        
        """
        try:
            self.__no_sqr__ = kwargs["no_sqr"]
        except KeyError:
            self.__no_sqr__ = False

        som = SOM.SOM()
        som.setDataSetType("density")

        self.__set_axes(som)
        self.__readData(som)

        som.setYLabel("Counts")
        uscale = som.getAxisUnits(1) + " " + som.getAxisUnits(0)
        som.setYUnits("Counts / " + uscale)

        som.attr_list = dst_utils.parse_spec_header(self.__file)

        return som
Beispiel #3
0
    def getSOM(self, som_id=None, **kwargs):
        """
        This method parses the resource and creates a SOM from the information.

        @param som_id: The name of the SOM. The default value is C{None}. This
                       retrieves all information. If multiple detector IDs are
                       specified, they should be comma-separated.
        @type som_id: C{string}

        @param kwargs: A list of keyword arguments that the function accepts:

        @keyword roi_file: A list of spectrum IDs to filter the data on
        @type roi_file: C{string}

        @keyword mask_file: A list of spectrum IDs to filter (exclude) the
                            data on
        @type mask_file: C{string}        

        @keyword no_sqr: Do not square the error values from the file. This is
                         important if the data will be subsequently plotted.
                         The default value is I{False}.
        @type no_sqr: C{boolean}        
        """
        # Check for list of detector IDs
        if som_id is not None:
            if "," in som_id:
                som_ids = som_id.split(',')
            else:
                som_ids = [som_id]
        # Check to see if an ROI file was passed
        try:
            roi_filename = kwargs["roi_file"]
            try:
                roi = SOM.Roi(roi_filename)
            except TypeError:
                # roi_filename is None
                roi = None
        except KeyError:
            roi = None

        # Check to see if a mask file was passed
        try:
            mask_filename = kwargs["mask_file"]
            try:
                mask = SOM.Roi(mask_filename)
            except TypeError:
                # mask_filename is None
                mask = None
        except KeyError:
            mask = None            

        try:
            self.__no_sqr__ = kwargs["no_sqr"]
        except KeyError:
            self.__no_sqr__ = False
        
        som = SOM.SOM()

        som.attr_list = dst_utils.parse_spec_header(self.__file)

        # Reset file read to not miss #L line
        fname = self.__file.name
        self.release_resource
        self.__file = open(fname, "r")

        for line in self.__file:
            if line.startswith("#L"):
                self.readSOM(som, line)
            elif line.startswith("("):
                lparts = line.split()
                # The spectrum ID is the first three slots
                so_id = SOM.NeXusId.fromList(lparts[0:3])

                filter_so = False
                # Check the list of detector IDs
                if som_id is not None:
                    if so_id.getDetId() not in som_ids:
                        filter_so = True

                # Check the ROI list
                if roi is not None:
                    if so_id not in roi:
                        filter_so = True

                # Check the Mask list
                if mask is not None:
                    if so_id in mask:
                        filter_so = True

                if not filter_so:
                    self.readSO(som, so_id.toTuple(), lparts)

        return som
Beispiel #4
0
    def getSOM(self, som_id=None, **kwargs):
        """
        This method parses the resource and creates a SOM from the information.

        @param som_id: The name of the SOM. The default value is C{None}. This
        retrieves all information.

        @param kwargs: A list of keyword arguments that the function accepts:

        @keyword roi_file: A list of spectrum IDs to filter the data on
        @type roi_file: C{string}

        @keyword no_sqr: Do not square the error values from the file. This is
                         important if the data will be subsequently plotted.
                         The default value is I{False}.
        @type no_sqr: C{boolean}
        """
        import os

        try:
            roi_filename = kwargs["roi_file"]
            try:
                roi = SOM.Roi(roi_filename)
            except TypeError:
                # roi_filename is None
                roi = None
        except KeyError:
            roi = None

        try:
            self.__no_sqr__ = kwargs["no_sqr"]
        except KeyError:
            self.__no_sqr__ = False

        som = SOM.SOM()

        som.attr_list = dst_utils.parse_spec_header(self.__file)

        # Setup some things for working through the data
        got_columns = False
        got_header = False
        nexus_id = None
        data_lines = []

        for line in self.__file:
            if line.startswith("#S"):
                self.__readSO(data_lines, nexus_id, som)
                data_lines = []
                parts = line.split()
                try:
                    nexus_id = SOM.NeXusId.fromList(parts[4:])
                except TypeError:
                    # ID is not a pixel format
                    nexus_id = parts[-1]
                # Check the ROI list
                if roi is not None:
                    if nexus_id not in roi:
                        nexus_id = None
            elif line.startswith("#L"):
                if not got_header:
                    self.__readSOM(som, line.lstrip("#L "))
                got_header = True
            elif line.startswith("#N"):
                if not got_columns:
                    self.__columns = int(line.split()[-1].strip())
                got_columns = True
            elif line.startswith(os.linesep):
                continue
            else:
                data_lines.append(line)

        # One spectrum or final spectrum won't get processed in the above
        # so we must force processing
        self.__readSO(data_lines, nexus_id, som)

        return som