Esempio n. 1
0
def averageRaDec(ra, dec):
    """Calculate average RA, Dec from input lists using spherical geometry.

    Parameters
    ----------
    ra : list of float
        RA in [radians]
    dec : list of float
        Dec in [radians]

    Returns
    -------
    float, float
       meanRa, meanDec -- Tuple of average RA, Dec [radians]
    """
    assert (len(ra) == len(dec))

    angleRa = [afwGeom.Angle(r, afwGeom.radians) for r in ra]
    angleDec = [afwGeom.Angle(d, afwGeom.radians) for d in dec]
    coords = [
        afwGeom.SpherePoint(ar, ad, afwGeom.radians)
        for (ar, ad) in zip(angleRa, angleDec)
    ]

    meanRa, meanDec = afwGeom.averageSpherePoint(coords)

    return meanRa.asRadians(), meanDec.asRadians()
Esempio n. 2
0
    def calculateCircle(self, catalog):
        """!Calculate a circle enclosing the catalog

        @param[in] catalog  Catalog we will encircle (lsst.afw.table.SourceCatalog)
        @return Struct with ICRS center (lsst.afw.geom.SpherePoint) and radius (lsst.afw.geom.Angle)
        """
        coordList = [src.getCoord() for src in catalog]
        center = averageSpherePoint(coordList)
        radius = max(center.separation(coord) for coord in coordList)
        return Struct(center=center, radius=radius + self.config.matchRadius*arcseconds)
Esempio n. 3
0
 def checkCircle(center,
                 start,
                 numPts,
                 maxSep=1.0e-9 * afwGeom.arcseconds):
     """Generate points in a circle; test that average is in the center
     """
     coords = []
     deltaAngle = 360 * degrees / numPts
     for ii in range(numPts):
         new = start.rotated(center, ii * deltaAngle)
         coords.append(new)
     result = afwGeom.averageSpherePoint(coords)
     self.assertSpherePointsAlmostEqual(center, result, maxSep=maxSep)
Esempio n. 4
0
    def getTargetData(self, target, pfsConfigList, indices):
        """Generate a ``TargetData`` for this target

        We combine the various declarations about the target in the
        ``PfsConfig``s.

        Parameters
        ----------
        target : `types.SimpleNamespace`
            Struct with target identity (with ``catId``, ``tract``, ``patch``
            and ``objId``).
        pfsConfigList : iterable of `pfs.datamodel.PfsConfig`
            List of top-end configurations.
        indices : `numpy.ndarray` of `int`
            Indices for the fiber of interest in each of the ``pfsConfigList``.

        Returns
        -------
        result : `pfs.datamodel.TargetData`
            ``TargetData`` for this target
        """
        radec = [SpherePoint(pfsConfig.ra[ii]*degrees, pfsConfig.dec[ii]*degrees) for
                 pfsConfig, ii in zip(pfsConfigList, indices)]
        radec = averageSpherePoint(radec)

        targetType = Counter([pfsConfig.targetType[ii] for pfsConfig, ii in zip(pfsConfigList, indices)])
        if len(targetType) > 1:
            self.log.warn("Multiple targetType for target %s (%s); using most common" % (target, targetType))
        targetType = targetType.most_common(1)[0][0]

        fiberMags = defaultdict(list)
        for pfsConfig, ii in zip(pfsConfigList, indices):
            for ff, mag in zip(pfsConfig.filterNames[ii], pfsConfig.fiberMag[ii]):
                fiberMags[ff].append(mag)
        for ff in fiberMags:
            mag = set(fiberMags[ff])
            if len(mag) > 1:
                self.log.warn("Multiple %s mag for target %s (%s); using average" % (ff, target, mag))
                mag = np.average(np.array(fiberMags[ff]))
            else:
                mag = mag.pop()
            fiberMags[ff] = mag

        return TargetData(target.catId, target.tract, target.patch, target.objId,
                          radec.getRa().asDegrees(), radec.getDec().asDegrees(),
                          targetType, dict(**fiberMags))
    def calculateCircle(self, catalog):
        """Calculate a circle enclosing the catalog.

        Parameters
        ----------
        catalog : `lsst.afw.table.SourceCatalog`
            Catalog to encircle.

        Returns
        -------
        result : `lsst.pipe.base.Struct`
            Result struct with components:

            ``center``
                ICRS center coordinate (`lsst.afw.geom.SpherePoint`).
            ``radius``
                Radius of the circle (`lsst.geom.Angle`).
        """
        coordList = [src.getCoord() for src in catalog]
        center = averageSpherePoint(coordList)
        radius = max(center.separation(coord) for coord in coordList)
        return Struct(center=center, radius=radius + self.config.matchRadius*arcseconds)
Esempio n. 6
0
    def calculateCircle(self, catalog):
        """Calculate a circle enclosing the catalog.

        Parameters
        ----------
        catalog : `lsst.afw.table.SourceCatalog`
            Catalog to encircle.

        Returns
        -------
        result : `lsst.pipe.base.Struct`
            Result struct with components:

            ``center``
                ICRS center coordinate (`lsst.afw.geom.SpherePoint`).
            ``radius``
                Radius of the circle (`lsst.geom.Angle`).
        """
        coordList = [src.getCoord() for src in catalog]
        center = averageSpherePoint(coordList)
        radius = max(center.separation(coord) for coord in coordList)
        return Struct(center=center,
                      radius=radius + self.config.matchRadius * arcseconds)