Example #1
0
    def load(self, time_stamp, channel, **kwarg):
        if channel not in self._config_reader.channel_names:
            raise mipp.ReaderError("unknown channel name '%s'" % channel)
        opt = self._config_reader('level1')
        val = {}
        val["channel"] = channel + '*'

        # Prologue

        val["segment"] = "PRO".ljust(9, '_')

        filename_pro = opt.get('filename_pro', opt['filename'])
        prologue = glob.glob(opt['dir'] + '/' + \
                             (time_stamp.strftime(filename_pro)%val))
        if not prologue:
            raise mipp.NoFiles("missing prologue file: '%s'" %
                               (time_stamp.strftime(filename_pro) % val))
        prologue = prologue[0]

        # Regular channels

        val["segment"] = "0????????"
        image_files = glob.glob(opt['dir'] + '/' + \
                                time_stamp.strftime(opt['filename'])%val)

        if not image_files:
            raise mipp.NoFiles("no data files: '%s'" %
                               (time_stamp.strftime(opt['filename']) % val))
        image_files.sort()

        # Check if the files are xrit-compressed, and decompress them
        # accordingly:
        decomp_files = decompress(image_files)

        logger.info("Read %s" % prologue)
        prologue = _xrit.read_prologue(prologue)

        # Epilogue

        val["segment"] = "EPI".ljust(9, '_')

        filename_epi = opt.get('filename_epi', opt['filename'])
        epilogue = glob.glob(opt['dir'] + '/' + \
                             (time_stamp.strftime(filename_epi)%val))

        if not epilogue:
            logger.info("No epilogue file to read.")
        else:
            epilogue = epilogue[0]
            logger.info("Read %s" % epilogue)
            epilogue = _xrit.read_epilogue(epilogue)
            return self.load_files(prologue,
                                   decomp_files,
                                   epilogue=epilogue,
                                   **kwarg)

        return self.load_files(prologue, decomp_files, **kwarg)
Example #2
0
 def _find_tarfile(self, time_stamp):
     opt = self._config_reader('level1')
     if not os.path.isdir(opt['dir']):
         raise IOError, "No such directory: %s" % opt['dir']
     tar_file = glob.glob(opt['dir'] + '/' +
                          time_stamp.strftime(opt['filename_archive']))
     if not tar_file:
         raise mipp.NoFiles("found no archive file: '%s'" %
                            (time_stamp.strftime(opt['filename_archive'])))
     elif len(tar_file) > 1:
         raise mipp.NoFiles("found multiple archive files: '%s'" %
                            str(tar_file))
     return tar_file[0]
Example #3
0
def _find_in_tarfile(tfile, fname):
    tar = tarfile.open(tfile)
    try:
        for name in tar.getnames():
            if name.endswith(fname):
                return name
    finally:
        tar.close()
    raise mipp.NoFiles("found no archive file '%s'" % fname)
Example #4
0
 def _load_metadata(self, channel):
     del channel
     opt = self._config_reader('level1')
     mda_file = opt['filename_metadata']
     tar = tarfile.open(self._tar_file)
     names = []
     try:
         for name in tar.getnames():
             if fnmatch.fnmatch(os.path.basename(name), mda_file):
                 names.append(name)
         if len(names) == 0:
             raise mipp.NoFiles("found no metadata file: '%s'" % mda_file)
         elif len(names) > 1:
             raise mipp.NoFiles("found multiple metadata files: '%s'" %
                                str(names))
         logger.info("Extracting '%s'" % names[0])
         xmldata = tar.extractfile(names[0]).read()
     finally:
         tar.close()
     return self._metadata_reader(xmldata)
Example #5
0
    def load(self, time_stamp, channel, **kwarg):
        if channel not in self._config_reader.channel_names:
            raise mipp.ReaderError("unknown channel name '%s'" % channel)
        opt = self._config_reader('level1')
        val = {}
        val["channel"] = channel + '*'

        if isinstance(time_stamp, (tuple, list)):
            start_time, end_time = time_stamp
        else:
            start_time = time_stamp
            end_time = time_stamp

        # Prologue

        val["segment"] = "PRO".ljust(9, '_')

        filename_pro = opt.get('filename_pro', opt['filename'])
        prologue = glob.glob(
            start_time.strftime(os.path.join(opt['dir'], filename_pro)) % val)

        if not prologue:
            logger.info("No prologue file to read.")
            prologue = None
        else:
            prologue = prologue[0]
            logger.info("Read %s" % prologue)
            prologue = _xrit.read_prologue(prologue)

        # Regular channels

        val["segment"] = "0??*"
        dt = timedelta(minutes=1)
        image_files = []
        while start_time <= end_time:
            image_files.extend(
                glob.glob(
                    start_time.strftime(
                        os.path.join(opt['dir'], opt['filename'])) % val))
            start_time += dt

        if not image_files:
            raise mipp.NoFiles("no data files: '%s'" %
                               (start_time.strftime(opt['filename']) % val))
        image_files.sort()

        # Check if the files are xrit-compressed, and decompress them
        # accordingly:
        decomp_files = decompress(image_files)

        # Epilogue

        val["segment"] = "EPI".ljust(9, '_')

        filename_epi = opt.get('filename_epi', opt['filename'])
        epilogue = glob.glob(
            end_time.strftime(os.path.join(opt['dir'], filename_epi)) % val)

        if not epilogue:
            logger.info("No epilogue file to read.")
        else:
            epilogue = epilogue[0]
            logger.info("Read %s" % epilogue)
            epilogue = _xrit.read_epilogue(epilogue)
            return self.load_files(prologue,
                                   decomp_files,
                                   epilogue=epilogue,
                                   **kwarg)

        return self.load_files(prologue, decomp_files, **kwarg)