Skip to content

Commit

Permalink
Adding tests for initial NonFixedTarget
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Aug 17, 2015
1 parent 52b69e7 commit 54ed66b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
33 changes: 21 additions & 12 deletions astroplan/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,10 @@ def ra(self):
"""
if isinstance(self, FixedTarget):
return self.coord.ra
raise NotImplementedError()
if isinstance(self. NonFixedTarget):
raise ValueError("NonFixedTarget objects require a time and/or "
"other specifications to calculate a position. "
"Did you mean to do NonFixedTarget.at(args).ra?")

@property
def dec(self):
Expand All @@ -1462,8 +1465,10 @@ def dec(self):
"""
if isinstance(self, FixedTarget):
return self.coord.dec
raise NotImplementedError()

if isinstance(self. NonFixedTarget):
raise ValueError("NonFixedTarget objects require a time and/or "
"other specifications to calculate a position. "
"Did you mean to do NonFixedTarget.at(args).dec?")

class FixedTarget(Target):
"""
Expand Down Expand Up @@ -1525,24 +1530,28 @@ def __init__(self, coord_function=None, name=None):
self.name = name.lower() if name is not None else name
self.coord_function = coord_function

@classmethod
def from_function(cls, coord_function, name=None):
"""
Initialize a `~astropy.NonFixedTarget` by passing in a function that
computes a `~astropy.coordinates.SkyCoord` for the target object.
"""
return cls(coord_function=coord_function, name=name)

def at(self, *args, **kwargs):
"""
Get `~astropy.coordinates.SkyCoord` for the `~astroplan.NonFixedTarget`
at a given time, location, etc.
Parameters
----------
Any parameters passed to the
"""
return self.coord_function(*args, **kwargs)
All parameters passed to ``coord_function``.
@classmethod
def from_function(cls, coord_function, name=None):
"""
Initialize a `~astropy.NonFixedTarget` by passing in a function that
computes a `~astropy.coordinates.SkyCoord` for the target object.
Returns
-------
A `~astropy.coordinates.SkyCoord` object as specified by the parameters.
"""
return cls(coord_function=coord_function, name=name)
return self.coord_function(*args, **kwargs)

class Constraint(object):
"""
Expand Down
33 changes: 30 additions & 3 deletions astroplan/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
unicode_literals)

from astropy.coordinates import (EarthLocation, Latitude, Longitude, SkyCoord,
AltAz)
AltAz, get_sun)
import astropy.units as u
from astropy.time import Time
from astropy.tests.helper import remote_data
from astropy.tests.helper import remote_data, assert_quantity_allclose
import numpy as np
from numpy.testing import assert_allclose
import pytz
Expand All @@ -14,7 +14,8 @@

from ..sites import get_site
from ..core import (FixedTarget, Observer, list_FixedTarget_to_SkyCoord,
MAGIC_TIME)
MAGIC_TIME, NonFixedTarget)
from ..moon import get_moon
from ..exceptions import TargetAlwaysUpWarning, TargetNeverUpWarning

def test_Observer_constructor_location():
Expand Down Expand Up @@ -62,6 +63,32 @@ def test_FixedTarget_from_name():
# Make sure separation is small
assert polaris_from_name.coord.separation(polaris_from_SIMBAD) < 1*u.arcsec

def test_NonFixedTarget_sun():
time = Time("1995-08-31 02:03:04")
sun = NonFixedTarget(coord_function=get_sun, name="Sun")
sun_skycoord_nft = sun.at(time)

sun_skycoord_getsun = get_sun(time)
tolerance = 0.1*u.arcsec
assert_quantity_allclose(sun_skycoord_nft.ra, sun_skycoord_getsun.ra,
atol=tolerance)
assert_quantity_allclose(sun_skycoord_nft.dec, sun_skycoord_getsun.dec,
atol=tolerance)

def test_NonFixedTarget_moon():
time = Time("1995-08-31 02:03:04")
location = get_site("Subaru")
pressure = 0*u.bar
moon = NonFixedTarget(coord_function=get_moon, name="Moon")
moon_skycoord_nft = moon.at(time, location, pressure)

moon_skycoord_getmoon = get_moon(time, location, pressure)
tolerance = 0.1*u.arcsec
assert_quantity_allclose(moon_skycoord_nft.alt, moon_skycoord_getmoon.alt,
atol=tolerance)
assert_quantity_allclose(moon_skycoord_nft.az, moon_skycoord_getmoon.az,
atol=tolerance)

def test_Observer_altaz():
"""
Check that the altitude/azimuth computed by `Observer.altaz` is similar
Expand Down

0 comments on commit 54ed66b

Please sign in to comment.