# Path: tests/convenience.py
# def plot_aa_style(cols=1):
#     """Use a plotting style specifically for Astronomy & Astrophyiscs."""
#     # Use a style file
#     dir = os.path.abspath(os.path.dirname(__file__))
#     style_file = os.path.join(dir, './aa.mplstyle')
#     plt.style.use(style_file)
# 
#     # Check whether interactive backend is present
#     if os.name == 'posix' and "DISPLAY" not in os.environ:
#         # On a cluster
#         plt.switch_backend('Agg')
#         # Use just the basic latex package allowing \text to be used
#         plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
# 
#     if cols == 2:
#         plt.rcParams["figure.figsize"] = (5.75373, 3.556)
# 
# def rel_path(path):
#     """Return the relative path name for this directory."""
#     return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)


import numpy as np
import matplotlib.pyplot as plt
import os
from tests.convenience import plot_aa_style, rel_path
    Args:
        lat (float): Latitude of observatory in radians.
        dec (array): Declination of celestial object in radians.
        unit (str): 'deg' or 'rad'
        beamsize (float): Beam size in sq. deg

    Returns:
        float: Fraction of time above horizon in fractional days

    """
    if unit == 'deg':
        lat = np.deg2rad(lat)
        dec = np.deg2rad(dec)

    times = np.ones_like(dec)
    lim = np.pi/2. - lat
    always_visible = dec > lim
    never_visible = dec < -lim
    sometimes_visible = ((dec > -lim) & (dec < lim))

    sm = sometimes_visible
    times[sm] = 2*np.rad2deg(np.arccos(-np.tan(dec[sm])*np.tan(lat)))/360.

    times[always_visible] = 1.
    times[never_visible] = 0.

    return times


if TEST_TRANSIT:

# Path: tests/convenience.py
# def plot_aa_style(cols=1):
#     """Use a plotting style specifically for Astronomy & Astrophyiscs."""
#     # Use a style file
#     dir = os.path.abspath(os.path.dirname(__file__))
#     style_file = os.path.join(dir, './aa.mplstyle')
#     plt.style.use(style_file)
# 
#     # Check whether interactive backend is present
#     if os.name == 'posix' and "DISPLAY" not in os.environ:
#         # On a cluster
#         plt.switch_backend('Agg')
#         # Use just the basic latex package allowing \text to be used
#         plt.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}'
# 
#     if cols == 2:
#         plt.rcParams["figure.figsize"] = (5.75373, 3.556)
# 
# def rel_path(path):
#     """Return the relative path name for this directory."""
#     return os.path.join(os.path.abspath(os.path.dirname(__file__)), path)


# Path: tests/misc/transit_times.py
import numpy as np
import matplotlib.pyplot as plt
import os
from tests.convenience import plot_aa_style, rel_path

    Args:
        lat (float): Latitude of observatory in radians.
        dec (array): Declination of celestial object in radians.
        unit (str): 'deg' or 'rad'
        beamsize (float): Beam size in sq. deg

    Returns:
        float: Fraction of time above horizon in fractional days

    """
    if unit == 'deg':
        lat = np.deg2rad(lat)
        dec = np.deg2rad(dec)

    times = np.ones_like(dec)
    lim = np.pi/2. - lat
    always_visible = dec > lim
    never_visible = dec < -lim
    sometimes_visible = ((dec > -lim) & (dec < lim))

    sm = sometimes_visible
    times[sm] = 2*np.rad2deg(np.arccos(-np.tan(dec[sm])*np.tan(lat)))/360.

    times[always_visible] = 1.
    times[never_visible] = 0.

    return times


if TEST_TRANSIT:

    plot_aa_style()