Sample exceptions for astroplan


In [8]:
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import numpy as np
import astropy.units as u

class AlwaysUpError(ValueError):
    '''Target is circumpolar'''
    
class NeverUpError(ValueError):
    '''Target never rises above horizon'''
    
t = np.linspace(0, 2*np.pi, 10)
altitudes_1 = (np.pi/2*np.sin(t))*u.rad + np.pi/2*u.rad
altitudes_2 = (np.pi/2*np.sin(t))*u.rad - np.pi/2*u.rad

horizon = 0*u.deg

def do_something(altitudes):
    if (altitudes > horizon).all():
        raise AlwaysUpError("Target always above ``horizon``={}".format(horizon))

    if (altitudes < horizon).all():
        raise NeverUpError("Target never above ``horizon``={}".format(horizon))

In [9]:
do_something(altitudes_1)


---------------------------------------------------------------------------
AlwaysUpError                             Traceback (most recent call last)
<ipython-input-9-819fe633e240> in <module>()
----> 1 do_something(altitudes_1)

<ipython-input-8-37860838e4c6> in do_something(altitudes)
     18 def do_something(altitudes):
     19     if (altitudes > horizon).all():
---> 20         raise AlwaysUpError("Target always above ``horizon``={}".format(horizon))
     21 
     22     if (altitudes < horizon).all():

AlwaysUpError: Target always above ``horizon``=0.0 deg

In [10]:
do_something(altitudes_2)


---------------------------------------------------------------------------
NeverUpError                              Traceback (most recent call last)
<ipython-input-10-930d1d835c3f> in <module>()
----> 1 do_something(altitudes_2)

<ipython-input-8-37860838e4c6> in do_something(altitudes)
     21 
     22     if (altitudes < horizon).all():
---> 23         raise NeverUpError("Target never above ``horizon``={}".format(horizon))

NeverUpError: Target never above ``horizon``=0.0 deg

In [ ]: