Пример #1
0
    def setUp(self):
        self.config = MakeDiscreteSkyMapConfig()
        self.task = MakeDiscreteSkyMapTask(config=self.config)

        self.cd_matrix = afwGeom.makeCdMatrix(scale=0.2*lsst.geom.arcseconds)
        self.crpix = lsst.geom.Point2D(100, 100)
        self.crval1 = lsst.geom.SpherePoint(10.0*lsst.geom.degrees, 0.0*lsst.geom.degrees)
        self.wcs1 = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval1, cdMatrix=self.cd_matrix)
        self.bbox = lsst.geom.Box2I(corner=lsst.geom.Point2I(0, 0), dimensions=lsst.geom.Extent2I(200, 200))
        self.crval2 = lsst.geom.SpherePoint(11.0*lsst.geom.degrees, 1.0*lsst.geom.degrees)
        self.wcs2 = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval2, cdMatrix=self.cd_matrix)
        self.crval3 = lsst.geom.SpherePoint(20.0*lsst.geom.degrees, 10.0*lsst.geom.degrees)
        self.wcs3 = afwGeom.makeSkyWcs(crpix=self.crpix, crval=self.crval3, cdMatrix=self.cd_matrix)
Пример #2
0
def makeDiscreteSkyMap(repo,
                       config_file,
                       collections,
                       instrument,
                       skymap_id='discrete',
                       old_skymap_id=None):
    """Implements the command line interface `butler make-discrete-skymap` subcommand,
    should only be called by command line tools and unit test code that tests
    this function.

    Constructs a skymap from calibrated exposure in the butler repository

    Parameters
    ----------
    repo : `str`
        URI to the location to read the repo.
    config_file : `str` or `None`
        Path to a config file that contains overrides to the skymap config.
    collections : `list` [`str`]
        An expression specifying the collections to be searched (in order) when
        reading datasets, and optionally dataset type restrictions on them.
        At least one collection must be specified.  This is the collection
        with the calibrated exposures.
    instrument : `str`
        The name or fully-qualified class name of an instrument.
    skymap_id : `str`, optional
        The identifier of the skymap to save.  Default is 'discrete'.
    old_skymap_id : `str`, optional
        The identifer of the skymap to append to.  Must differ from
        ``skymap_id``.  Ignored unless ``config.doAppend=True``.
    """
    butler = Butler(repo, collections=collections, writeable=True)
    instr = getInstrument(instrument, butler.registry)
    config = MakeDiscreteSkyMapConfig()
    instr.applyConfigOverrides(MakeDiscreteSkyMapTask._DefaultName, config)

    if config_file is not None:
        config.load(config_file)
    # The coaddName for a SkyMap is only relevant in Gen2, and we completely
    # ignore it here; once Gen2 is gone it can be removed.
    oldSkyMap = None
    if config.doAppend:
        if old_skymap_id is None:
            raise ValueError(
                "old_skymap_id must be provided if config.doAppend is True.")
        dataId = {'skymap': old_skymap_id}
        try:
            oldSkyMap = butler.get(BaseSkyMap.SKYMAP_DATASET_TYPE_NAME,
                                   collections=collections,
                                   dataId=dataId)
        except LookupError as e:
            msg = (
                f"Could not find seed skymap with dataId {dataId} "
                f"in collections {collections} but doAppend is {config.doAppend}.  Aborting..."
            )
            raise LookupError(msg, *e.args[1:])

    datasets = butler.registry.queryDatasets('calexp', collections=collections)
    wcs_md_tuple_list = [(butler.getDirect('calexp.metadata', ref),
                          butler.getDirect('calexp.wcs', ref))
                         for ref in datasets]
    task = MakeDiscreteSkyMapTask(config=config)
    result = task.run(wcs_md_tuple_list, oldSkyMap)
    result.skyMap.register(skymap_id, butler)
    butler.put(result.skyMap,
               BaseSkyMap.SKYMAP_DATASET_TYPE_NAME,
               dataId={'skymap': skymap_id},
               run=BaseSkyMap.SKYMAP_RUN_COLLECTION_NAME)