def averageRaDec(ra, dec): """Calculate average RA, Dec from input lists using spherical geometry. Parameters ---------- ra : `list` [`float`] RA in [radians] dec : `list` [`float`] Dec in [radians] Returns ------- float, float meanRa, meanDec -- Tuple of average RA, Dec [radians] """ assert (len(ra) == len(dec)) angleRa = [geom.Angle(r, geom.radians) for r in ra] angleDec = [geom.Angle(d, geom.radians) for d in dec] coords = [ geom.SpherePoint(ar, ad, geom.radians) for (ar, ad) in zip(angleRa, angleDec) ] meanRa, meanDec = geom.averageSpherePoint(coords) return meanRa.asRadians(), meanDec.asRadians()
def checkCircle(center, start, numPts, maxSep=1.0e-9*geom.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 = geom.averageSpherePoint(coords) self.assertSpherePointsAlmostEqual(center, result, maxSep=maxSep)
def updateCatalogs(self, matchIndex, diaSrc, diaSources, ccdVisit, diaSourceId, diaObjCat, diaObjCoords, healPixIndices): """Update DiaObject and DiaSource values after an association. Parameters ---------- matchIndex : `int` Array index location of the DiaObject that ``diaSrc`` was associated to. diaSrc : `pandas.Series` Full unassociated DiaSource to create a DiaObject from. diaSources : `pandas.DataFrame` DiaSource catalog to update information in. The catalog is modified in place. ccdVisit : `int` Unique identifier of the ccdVisit where ``diaSrc`` was observed. diaSourceId : `int` Unique identifier of the DiaSource. diaObjectCat : `list` of `dict`s Catalog of diaObjects to append the new object o. diaObjectCoords : `list` of `list`s of `lsst.geom.SpherePoint`s Set of coordinates of DiaSource locations that make up the DiaObject average coordinate. healPixIndices : `list` of `int`s HealPix indices representing the locations of each currently existing DiaObject. """ # Update location and healPix index. sphPoint = geom.SpherePoint(diaSrc["ra"], diaSrc["decl"], geom.degrees) diaObjCoords[matchIndex].append(sphPoint) aveCoord = geom.averageSpherePoint(diaObjCoords[matchIndex]) diaObjCat[matchIndex]["ra"] = aveCoord.getRa().asDegrees() diaObjCat[matchIndex]["decl"] = aveCoord.getDec().asDegrees() nSources = diaObjCat[matchIndex]["nDiaSources"] diaObjCat[matchIndex]["nDiaSources"] = nSources + 1 healPixIndices[matchIndex] = toIndex(self.config.nside, diaObjCat[matchIndex]["ra"], diaObjCat[matchIndex]["decl"]) # Update DiaObject Id that this source is now associated to. diaSources.loc[(ccdVisit, diaSourceId), "diaObjectId"] = \ diaObjCat[matchIndex]["diaObjectId"]
def _computeMeanPos(df): aveCoord = geom.averageSpherePoint( list( geom.SpherePoint(src["ra"], src["decl"], geom.degrees) for idx, src in df.iterrows())) ra = aveCoord.getRa().asDegrees() decl = aveCoord.getDec().asDegrees() if np.isnan(ra) or np.isnan(decl): radecTai = np.nan else: radecTai = df["midPointTai"].max() return pd.Series({ "ra": aveCoord.getRa().asDegrees(), "decl": aveCoord.getDec().asDegrees(), "radecTai": radecTai })
def _set_mean_position(dia_object_record, dia_sources): """Compute and set the mean position of the input dia_object_record using the positions of the input catalog of DIASources. Parameters ---------- dia_object_record : `dict` or `pandas.Series` SourceRecord of the DIAObject to edit. dia_sources : `pandas.DataFrame` Catalog of DIASources to compute a mean position from. """ coord_list = [ geom.SpherePoint(src["ra"], src["decl"], geom.degrees) for idx, src in dia_sources.iterrows() ] ave_coord = geom.averageSpherePoint(coord_list) dia_object_record["ra"] = ave_coord.getRa().asDegrees() dia_object_record["decl"] = ave_coord.getDec().asDegrees()
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)