Example #1
0
    def __init__(self, foldername):

        # Check if the folder exists. If it doesn't, throw an exception.
        if not os.path.exists(foldername):
            #raise IOError("The folder doesn't exist.")
            raise IOError("NOT_EXIST")

        ## The folder name.
        self.foldername = foldername

        ## The list of names of files in the folder (sorted).
        self.filenames = sorted(glob.glob(foldername + "/*"))

        # Throw an exception if the supplied folder is empty.
        if len(self.filenames) == 0:
            #raise IOError("The folder is empty.")
            raise IOError("FOLDER_EMPTY")

        ## The datafile names.
        self.datfilenames = {}

        ## The DSC file names.
        self.dscfilenames = {}

        ## The datafile formats.
        self.datfileformats = {}

        # Loop over the files found in the folder.
        lg.debug("")
        lg.debug(" Files found in '%s':" % (foldername))
        lg.debug("")
        for i, fn in enumerate(self.filenames):

            ## The basename of the file.
            bn = os.path.basename(fn)

            lg.debug(" * '%s'" % (bn))

            # If the "file" is a directory, raise an exception.
            if os.path.isdir(fn):
                raise IOError("CONTAINS_DIR")

            formatval = getFormat(fn)

            ## If the file isn't recognised, raise an exception.
            if formatval == 0:
                lg.debug("'%s' is in an unrecognised format." % (bn))
                raise IOError("BAD_FORMAT")
            elif formatval > 0:
                lg.debug(" *--> Adding '%s' ('%s' format) to the data files." \
                    % (bn, DATA_FILE_TYPES[formatval]))

                self.datfilenames[i] = bn

                self.datfileformats[i] = formatval

            else:
                lg.debug(" *--> Adding '%s' ('%s' format) to the DSC files." \
                    % (bn, DATA_FILE_TYPES[formatval]))

                self.dscfilenames[i] = bn

        lg.debug("")

        # Check the consistency of the data file formats.
        if not self.areFormatsConsistent():
            lg.debug(" The file formats are inconsistent!")
            raise IOError("FORMAT_MISMATCH")

        # Check that each data file has a matching DSC file.
        if not self.dscFilesPresent():
            lg.debug(" There are DSC files missing!")
            raise IOError("MISSING_DSC")

        lg.debug(" There are %d data files." % (self.getNumberOfDataFiles())); lg.debug("")

        # Now process the DSC files to extract the information we need
        # to build the data set information.

        ## The DSC file wrappers.
        self.dscfiles = sorted([DscFile(foldername + "/" + fn) for fn in self.dscfilenames.values()])
Example #2
0
    def __init__(self, dscfilename):
        """ The constructor. """

        # Check if the file exists. If it doesn't, throw an exception.
        if not os.path.exists(dscfilename):
            raise IOError("NOT_EXIST")

        # Check that the file is, indeed, a file.
        if not os.path.isfile(dscfilename):
            raise IOError("NOT_FILE")

        ## The frame width.
        self.__fWidth = None

        ## The frame height.
        self.__fHeight = None

        ## The acquisition mode.
        self.__acqMode = None

        ## The acquisition time.
        self.__acqTime = None

        ## The chip ID.
        self.__chipid = None

        ## The DAC values.
        self.__dacs = None

        ## The firmware version.
        self.__firmwarev = None

        ## The bias voltage.
        self.__hv = None

        ## The HW timer mode.
        self.__hwTimerMode = None

        ## The interface.
        self.__interface = None

        ## The Medipix clock value.
        self.__mpxClock = None

        ## The Medipix type.
        self.__mpxType = None

        ## The Pixelman version.
        self.__pixelmanv = None

        ## The polarity.
        self.__polarity = None

        ## The start time.
        self.__startTime = None

        ## The start time (string).
        self.__startTimeS = None

        ## The Timepix clock value.
        self.__tpxClock = None

        ## The name and serial number.
        self.__nameAndSN = None

        ## The DSC file name.
        self.__dscfilename = dscfilename

        ## The data file name.
        self.__datafilename = dscfilename[:-4]

        if not os.path.exists(self.__datafilename):
            raise IOError  #("MISSING_DAT")

        # Process the DSC file.
        self.processDscFile()

        ## The pixel map.
        self.__pixelmap = {}

        ## The data file format.
        self.__format = getFormat(self.__datafilename)

        # Process the data file.
        self.processDataFile()
Example #3
0
    def __init__(self, foldername):

        # Check if the folder exists. If it doesn't, throw an exception.
        if not os.path.exists(foldername):
            #raise IOError("The folder doesn't exist.")
            raise IOError("NOT_EXIST")

        ## The folder name.
        self.foldername = foldername

        ## The list of names of files in the folder (sorted).
        self.filenames = sorted(glob.glob(foldername + "/*"))

        # Throw an exception if the supplied folder is empty.
        if len(self.filenames) == 0:
            #raise IOError("The folder is empty.")
            raise IOError("FOLDER_EMPTY")

        ## The datafile names.
        self.datfilenames = {}

        ## The DSC file names.
        self.dscfilenames = {}

        ## The datafile formats.
        self.datfileformats = {}

        # Loop over the files found in the folder.
        lg.debug("")
        lg.debug(" Files found in '%s':" % (foldername))
        lg.debug("")
        for i, fn in enumerate(self.filenames):

            ## The basename of the file.
            bn = os.path.basename(fn)

            lg.debug(" * '%s'" % (bn))

            # If the "file" is a directory, raise an exception.
            if os.path.isdir(fn):
                raise IOError("CONTAINS_DIR")

            formatval = getFormat(fn)

            ## If the file isn't recognised, raise an exception.
            if formatval == 0:
                lg.debug("'%s' is in an unrecognised format." % (bn))
                raise IOError("BAD_FORMAT")
            elif formatval > 0:
                lg.debug(" *--> Adding '%s' ('%s' format) to the data files." \
                    % (bn, DATA_FILE_TYPES[formatval]))

                self.datfilenames[i] = bn

                self.datfileformats[i] = formatval

            else:
                lg.debug(" *--> Adding '%s' ('%s' format) to the DSC files." \
                    % (bn, DATA_FILE_TYPES[formatval]))

                self.dscfilenames[i] = bn

        lg.debug("")

        # Check the consistency of the data file formats.
        if not self.areFormatsConsistent():
            lg.debug(" The file formats are inconsistent!")
            raise IOError("FORMAT_MISMATCH")

        # Check that each data file has a matching DSC file.
        if not self.dscFilesPresent():
            lg.debug(" There are DSC files missing!")
            raise IOError("MISSING_DSC")

        lg.debug(" There are %d data files." % (self.getNumberOfDataFiles()))
        lg.debug("")

        # Now process the DSC files to extract the information we need
        # to build the data set information.

        ## The DSC file wrappers.
        self.dscfiles = sorted([
            DscFile(foldername + "/" + fn)
            for fn in self.dscfilenames.values()
        ])
Example #4
0
    def __init__(self, dscfilename):
        """ The constructor. """

        # Check if the file exists. If it doesn't, throw an exception.
        if not os.path.exists(dscfilename):
            raise IOError("NOT_EXIST")

        # Check that the file is, indeed, a file.
        if not os.path.isfile(dscfilename):
            raise IOError("NOT_FILE")

        ## The frame width.
        self.__fWidth = None

        ## The frame height.
        self.__fHeight = None

        ## The acquisition mode.
        self.__acqMode = None

        ## The acquisition time.
        self.__acqTime = None

        ## The chip ID.
        self.__chipid = None

        ## The DAC values.
        self.__dacs = None

        ## The firmware version.
        self.__firmwarev = None

        ## The bias voltage.
        self.__hv = None

        ## The HW timer mode.
        self.__hwTimerMode = None

        ## The interface.
        self.__interface = None

        ## The Medipix clock value.
        self.__mpxClock = None

        ## The Medipix type.
        self.__mpxType = None

        ## The Pixelman version.
        self.__pixelmanv = None

        ## The polarity.
        self.__polarity = None

        ## The start time.
        self.__startTime = None

        ## The start time (string).
        self.__startTimeS = None

        ## The Timepix clock value.
        self.__tpxClock = None

        ## The name and serial number.
        self.__nameAndSN = None

        ## The DSC file name.
        self.__dscfilename = dscfilename

        ## The data file name.
        self.__datafilename = dscfilename[:-4]

        if not os.path.exists(self.__datafilename):
            raise IOError #("MISSING_DAT")

        # Process the DSC file.
        self.processDscFile()

        ## The pixel map.
        self.__pixelmap = {}

        ## The data file format.
        self.__format = getFormat(self.__datafilename)

        # Process the data file.
        self.processDataFile()