Skip to content

Commit

Permalink
Add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Jul 14, 2020
1 parent be5459b commit 0fa0fcd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions healpix_alchemy/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,33 @@ def __init__(self, ra, dec):

@property
def cartesian(self):
"""Convert to Cartesian coordinates.
Returns
-------
x, y, z : float
A tuple of the x, y, and z coordinates.
"""
return (cosd(self._ra) * cosd(self._dec),
sind(self._ra) * cosd(self._dec),
sind(self._dec))

def within(self, other, radius):
"""Test if this point is within a given radius of another point.
Parameters
----------
other : Point
The other point.
radius : float
The match radius in degrees.
Returns
-------
bool
"""
sin_radius = sind(radius)
cos_radius = cosd(radius)
carts = (obj.cartesian for obj in (self, other))
Expand All @@ -33,6 +55,7 @@ def within(self, other, radius):


class HasPoint:
"""Mixin class to add a point to a an SQLAlchemy declarative model."""

ra = Column(Float, nullable=False)
dec = Column(Float, nullable=False)
Expand Down

0 comments on commit 0fa0fcd

Please sign in to comment.