def pyephem(time, latitude, longitude, altitude=<NUM_LIT:0>, pressure=<NUM_LIT>,<EOL>temperature=<NUM_LIT:12>, horizon='<STR_LIT>'):
<EOL>try:<EOL><INDENT>import ephem<EOL><DEDENT>except ImportError:<EOL><INDENT>raise ImportError('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>time_utc = time.tz_convert('<STR_LIT>')<EOL><DEDENT>except TypeError:<EOL><INDENT>time_utc = time<EOL><DEDENT>sun_coords = pd.DataFrame(index=time)<EOL>obs, sun = _ephem_setup(latitude, longitude, altitude,<EOL>pressure, temperature, horizon)<EOL>alts = []<EOL>azis = []<EOL>for thetime in time_utc:<EOL><INDENT>obs.date = ephem.Date(thetime)<EOL>sun.compute(obs)<EOL>alts.append(sun.alt)<EOL>azis.append(sun.az)<EOL><DEDENT>sun_coords['<STR_LIT>'] = alts<EOL>sun_coords['<STR_LIT>'] = azis<EOL>obs.pressure = <NUM_LIT:0><EOL>alts = []<EOL>azis = []<EOL>for thetime in time_utc:<EOL><INDENT>obs.date = ephem.Date(thetime)<EOL>sun.compute(obs)<EOL>alts.append(sun.alt)<EOL>azis.append(sun.az)<EOL><DEDENT>sun_coords['<STR_LIT>'] = alts<EOL>sun_coords['<STR_LIT>'] = azis<EOL>sun_coords = np.rad2deg(sun_coords)<EOL>sun_coords['<STR_LIT>'] = <NUM_LIT> - sun_coords['<STR_LIT>']<EOL>sun_coords['<STR_LIT>'] = <NUM_LIT> - sun_coords['<STR_LIT>']<EOL>return sun_coords<EOL>
Calculate the solar position using the PyEphem package.

Parameters
----------
time : pandas.DatetimeIndex
    Localized or UTC.
latitude : float
    positive is north of 0
longitude : float
    positive is east of 0
altitude : float, default 0
    distance above sea level in meters.
pressure : int or float, optional, default 101325
    air pressure in Pascals.
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

Returns
-------
pandas.DataFrame
    index is the same as input `time` argument
    The DataFrame will have the following columns:
    apparent_elevation, elevation,
    apparent_azimuth, azimuth,
    apparent_zenith, zenith.

See also
--------
spa_python, spa_c, ephemeris