コード例 #1
0
ファイル: mapping.py プロジェクト: gcmshadow/obs_base
    def map(self, mapper, dataId, write=False):
        """Standard implementation of map function.

        Parameters
        ----------
        mapper: `lsst.daf.persistence.Mapper`
            Object to be mapped.
        dataId: `dict`
            Dataset identifier.

        Returns
        -------
        lsst.daf.persistence.ButlerLocation
            Location of object that was mapped.
        """
        actualId = self.need(iter(self.keyDict.keys()), dataId)
        usedDataId = {key: actualId[key] for key in self.keyDict.keys()}
        path = mapper._mapActualToPath(self.template, actualId)
        if os.path.isabs(path):
            raise RuntimeError("Mapped path should not be absolute.")
        if not write:
            # This allows mapped files to be compressed, ending in .gz or .fz,
            # without any indication from the policy that the file should be
            # compressed, easily allowing repositories to contain a combination
            # of comporessed and not-compressed files.
            # If needed we can add a policy flag to allow compressed files or
            # not, and perhaps a list of  allowed extensions that may exist
            # at the end of the template.
            for ext in (None, '.gz', '.fz'):
                if ext and path.endswith(ext):
                    continue  # if the path already ends with the extension
                extPath = path + ext if ext else path
                newPath = self.rootStorage.instanceSearch(extPath)
                if newPath:
                    path = newPath
                    break
        assert path, "Fully-qualified filename is empty."

        addFunc = "add_" + self.datasetType  # Name of method for additionalData
        if hasattr(mapper, addFunc):
            addFunc = getattr(mapper, addFunc)
            additionalData = addFunc(self.datasetType, actualId)
            assert isinstance(additionalData, PropertySet), \
                "Bad type for returned data: %s" % (type(additionalData),)
        else:
            additionalData = None

        return ButlerLocation(pythonType=self.python,
                              cppType=self.persistable,
                              storageName=self.storage,
                              locationList=path,
                              dataId=actualId.copy(),
                              mapper=mapper,
                              storage=self.rootStorage,
                              usedDataId=usedDataId,
                              datasetType=self.datasetType,
                              additionalData=additionalData)
コード例 #2
0
 def map(self, datasetType, dataId):
     print('Mapping', datasetType, 'with keys', dataId)
     path = self.getPath(datasetType, dataId)
     (pattern, cname, pyname) = self.filenames[datasetType]
     # wow, this is rocket science
     storagetype = None
     if path.endswith('.fits'):
         storagetype = 'FitsStorage'
     elif path.endswith('.pickle'):
         storagetype = 'PickleStorage'
     return ButlerLocation(cname, pyname, storagetype, path, dataId)
コード例 #3
0
 def map_linearizer(self, dataId, write=False):
     """Map a linearizer."""
     actualId = self._transformId(dataId)
     return ButlerLocation(
         pythonType="lsst.ip.isr.LinearizeSquared",
         cppType="Config",
         storageName="PickleStorage",
         locationList="ignored",
         dataId=actualId,
         mapper=self,
         storage=self.rootStorage)
コード例 #4
0
 def map_linearizer(self, dataId, write=False):
     """Map a linearizer"""
     actualId = self._transformId(dataId)
     location = "%02d.fits" % (dataId["ccdnum"])
     return ButlerLocation(pythonType="lsst.ip.isr.LinearizeSquared",
                           cppType="Config",
                           storageName="PickleStorage",
                           locationList=[location],
                           dataId=actualId,
                           mapper=self,
                           storage=Storage.makeFromURI(
                               self.getLinearizerDir()))
コード例 #5
0
    def map_repo(self, dataId, write):
        if write:
            return None

        # todo check: do we need keys to complete dataId? (search Registry)

        template = self.policy['repositories.repo.template']
        location = template % dataId
        if self.storage.exists(location):
            bl = ButlerLocation(
                pythonType=self.policy['repositories.repo.python'],
                cppType=None,
                storageName=None,
                locationList=(location, ),
                dataId=dataId,
                mapper=self)
            return bl
        return None
コード例 #6
0
    def map_cfg(self, dataId, write):
        """Map a location for a cfg file.

        :param dataId: keys & values to be applied to the template.
        :param write: True if this map is being done do perform a write operation, else assumes read. Will
                      verify location exists if write is True.
        :return: a butlerLocation that describes the mapped location.
        """
        # todo check: do we need keys to complete dataId? (search Registry)
        template = self.policy['repositories.cfg.template']
        location = template % dataId
        if not write and not self.storage.exists(location):
            return None
        bl = ButlerLocation(
            pythonType=self.policy['repositories.cfg.python'],
            cppType=None,
            storageName=self.policy['repositories.cfg.storage'],
            locationList=(self.storage.locationWithRoot(location), ),
            dataId=dataId,
            mapper=self)
        return bl
コード例 #7
0
 def _pathMapper(self, datasetType, root, dataId):
     pathId = self._mapActualToPath(self._mapIdToActual(dataId))
     path = os.path.join(getattr(self, root),
                         getattr(self, datasetType + 'Template') % pathId)
     return ButlerLocation("lsst.afw.image.DecoratedImageU",
                           "DecoratedImageU", "FitsStorage", path, dataId)