def calc_time(lower_bound, upper_bound, latitude, longitude, attribute, value,<EOL>altitude=<NUM_LIT:0>, pressure=<NUM_LIT>, temperature=<NUM_LIT:12>, horizon='<STR_LIT>',<EOL>xtol=<NUM_LIT>):
try:<EOL><INDENT>import scipy.optimize as so<EOL><DEDENT>except ImportError:<EOL><INDENT>raise ImportError('<STR_LIT>')<EOL><DEDENT>obs, sun = _ephem_setup(latitude, longitude, altitude,<EOL>pressure, temperature, horizon)<EOL>def compute_attr(thetime, target, attr):<EOL><INDENT>obs.date = thetime<EOL>sun.compute(obs)<EOL>return getattr(sun, attr) - target<EOL><DEDENT>lb = datetime_to_djd(lower_bound)<EOL>ub = datetime_to_djd(upper_bound)<EOL>djd_root = so.brentq(compute_attr, lb, ub,<EOL>(value, attribute), xtol=xtol)<EOL>return djd_to_datetime(djd_root)<EOL>
Calculate the time between lower_bound and upper_bound
where the attribute is equal to value. Uses PyEphem for
solar position calculations.

Parameters
----------
lower_bound : datetime.datetime
upper_bound : datetime.datetime
latitude : float
longitude : float
attribute : str
    The attribute of a pyephem.Sun object that
    you want to solve for. Likely options are 'alt'
    and 'az' (which must be given in radians).
value : int or float
    The value of the attribute to solve for
altitude : float, default 0
    Distance above sea level.
pressure : int or float, optional, default 101325
    Air pressure in Pascals. Set to 0 for no
    atmospheric correction.
temperature : int or float, optional, default 12
    Air temperature in degrees C.
horizon : string, optional, default '+0:00'
    arc degrees:arc minutes from geometrical horizon for sunrise and
    sunset, e.g., horizon='+0:00' to use sun center crossing the
    geometrical horizon to define sunrise and sunset,
    horizon='-0:34' for when the sun's upper edge crosses the
    geometrical horizon
xtol : float, optional, default 1.0e-12
    The allowed error in the result from value

Returns
-------
datetime.datetime

Raises
------
ValueError
    If the value is not contained between the bounds.
AttributeError
    If the given attribute is not an attribute of a
    PyEphem.Sun object.